:root {
  --bg: #e7edf4;
  --land: #ffffff;
  --hover: #7fbaf0;
  --selected: #0e7ac9;
  --ink: #17212b;
  --muted: #4d5d6d;
  --panel: #ffffff;
  --line: #d2dce8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

#map {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
}

.hud-left,
.hud-right {
  position: fixed;
  z-index: 12;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.hud-left {
  left: 16px;
  top: 16px;
  width: fit-content;
  max-width: min(760px, calc(100vw - 34px));
  min-height: clamp(72px, 9.5vh, 98px);
  display: flex;
  align-items: stretch;
  gap: clamp(8px, 1.2vw, 12px);
  padding: 8px 10px;
}

.hud-left h1 {
  margin: 0 0 3px;
  font-size: 17px;
}

.hud-left p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.hud-brand-logo-wrap {
  width: clamp(64px, 7.8vw, 86px);
  min-width: clamp(64px, 7.8vw, 86px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  overflow: hidden;
}

.hud-brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.hud-brand-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  max-width: 520px;
}

@media (max-width: 820px) {
  .hud-left {
    left: 8px;
    top: max(8px, env(safe-area-inset-top));
    max-width: calc(100vw - 16px);
    min-height: clamp(66px, 9vh, 90px);
    gap: 6px;
    padding: 6px 8px;
  }

  .hud-brand-logo-wrap {
    width: clamp(56px, 13vw, 76px);
    min-width: clamp(56px, 13vw, 76px);
  }

  .hud-left h1 {
    font-size: 14px;
  }

  .hud-left p {
    font-size: 11px;
  }

  .hud-right {
    right: 8px;
    top: max(8px, env(safe-area-inset-top));
    max-width: calc(100vw - 16px);
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .hud-btn {
    padding: 6px 8px;
    font-size: 11px;
  }

  .hud-sources {
    left: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 16px);
    padding: 3px 6px;
    font-size: 10px;
    gap: 6px;
  }
}

.hud-right {
  right: 16px;
  top: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.hud-sources {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 12;
  max-width: min(700px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 11px;
  line-height: 1.15;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-sources-content {
  min-width: 0;
}

.hud-sources-content a {
  color: #0e7ac9;
  text-decoration: underline;
}

.hud-sources-edit {
  padding: 4px 8px;
  font-size: 11px;
  line-height: 1.1;
  white-space: nowrap;
}

.hud-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}

.hud-btn:hover { border-color: var(--selected); }

.sidebar {
  position: fixed;
  right: 0;
  top: 0;
  width: min(460px, 94vw);
  height: 100dvh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 18px 16px 16px;
  overflow-y: auto;
  z-index: 15;
  transform: translateX(105%);
  transition: transform 180ms ease;
}

.sidebar.open { transform: translateX(0); }

.close-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  border: 0;
  background: transparent;
  font-size: 30px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.sidebar h2 { margin: 0 24px 6px 0; font-size: 24px; }
.sidebar h3 { margin: 14px 0 7px; font-size: 15px; }
.meta { margin: 0 0 10px; color: var(--muted); }
.small { margin: 0; color: var(--muted); }

.info-box,
.link-row,
.section-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}

.links { display: flex; flex-direction: column; gap: 8px; }

.link-row a {
  color: var(--selected);
  text-decoration: none;
  word-break: break-word;
}
.link-row a:hover { text-decoration: underline; }
.link-row summary {
  cursor: pointer;
  list-style: none;
}
.link-row summary::-webkit-details-marker {
  display: none;
}
.link-row summary::before {
  content: "▸";
  color: #5f7388;
  margin-right: 6px;
}
.link-row[open] summary::before {
  content: "▾";
}
.link-meta {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.formatted-text {
  white-space: normal;
  line-height: 1.35;
}
.formatted-text a {
  color: #0e7ac9;
  text-decoration: underline;
}
.formatted-text p,
.formatted-text div {
  margin: 0 0 0.35em;
}
.formatted-text p:last-child,
.formatted-text div:last-child {
  margin-bottom: 0;
}
.formatted-text p + p,
.formatted-text div + div {
  margin-top: 0;
}
.formatted-text ul,
.formatted-text ol {
  margin: 0.1em 0 0.35em 1.05em;
  padding-left: 0.3em;
}
.formatted-text li {
  margin: 0.05em 0;
}

.summary-collapse summary {
  cursor: pointer;
  color: #1f5f95;
  margin-bottom: 6px;
}

.summary-collapse .summary-full {
  display: none;
}

.summary-collapse[open] .summary-full {
  display: block;
}

textarea,
input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
}

.edit-actions {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.link-editor {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px;
  margin-top: 6px;
}

.link-edit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-edit-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfdff;
}

.rich-editor-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 6px 0 10px;
  overflow: hidden;
}

.rich-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border-bottom: 1px solid var(--line);
  background: #f7fbff;
}

.rich-btn {
  padding: 4px 8px;
}

.rich-font,
.rich-size {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  background: white;
}

.rich-color {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.rich-color-label {
  font-weight: 700;
  color: #0e7ac9;
}

.rich-input {
  min-height: 90px;
  padding: 8px;
  outline: none;
  white-space: pre-wrap;
}
