:root {
  --bg: #eef2f0;
  --panel: rgba(250, 252, 251, 0.96);
  --panel-solid: #fafcfb;
  --text: #111b19;
  --muted: #66716d;
  --line: rgba(17, 27, 25, 0.14);
  --line-strong: rgba(17, 27, 25, 0.28);
  --accent: #0b6663;
  --accent-soft: rgba(11, 102, 99, 0.1);
  --shadow: 0 -18px 50px rgba(19, 38, 34, 0.13);
  --map-filter: none;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI",
    "Noto Sans JP", sans-serif;
  font-synthesis: none;
}

:root[data-mode="dark"] {
  --bg: #0d1517;
  --panel: rgba(13, 22, 24, 0.97);
  --panel-solid: #0d1618;
  --text: #eef6f4;
  --muted: #9aa9a5;
  --line: rgba(235, 248, 245, 0.14);
  --line-strong: rgba(235, 248, 245, 0.3);
  --accent: #67d8d1;
  --accent-soft: rgba(103, 216, 209, 0.12);
  --shadow: 0 -18px 54px rgba(0, 0, 0, 0.4);
  --map-filter: invert(0.9) hue-rotate(162deg) brightness(0.43) saturate(0.7);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
body { -webkit-font-smoothing: antialiased; }
button, a { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}
.map-stage {
  position: absolute;
  inset: 0 0 76px;
  overflow: hidden;
  background: #e8edeb;
}
.map { position: absolute; inset: 0; }
.map .maplibregl-canvas {
  filter: var(--map-filter);
  transition: filter 0.25s ease;
}
.map .maplibregl-ctrl-bottom-left { left: 10px; bottom: 8px; }
.map .maplibregl-ctrl-group {
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow: none;
  overflow: hidden;
}
.map .maplibregl-ctrl-group button { width: 34px; height: 34px; }
.map .maplibregl-ctrl-attrib {
  color: var(--muted);
  background: rgba(250, 252, 251, 0.72);
  font-size: 10px;
}
.map-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  background: radial-gradient(circle at 60% 35%, #dce6e2, #f0f4f2 58%, #e4ebe8);
  color: #5f6d67;
  padding: 24px;
}
.map-fallback[hidden] { display: none; }

.topbar {
  position: absolute;
  z-index: 8;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0 5px;
  pointer-events: auto;
  text-shadow: 0 1px 14px rgba(255, 255, 255, 0.82);
}
.brand-en {
  font-size: 18px;
  line-height: 1;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.brand-ja {
  font-size: 11px;
  line-height: 1.2;
  font-weight: 560;
  color: var(--muted);
  letter-spacing: 0.16em;
}
.icon-button {
  pointer-events: auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: 0 6px 20px rgba(20, 35, 31, 0.07);
  cursor: pointer;
  font-size: 16px;
}

.theme-tabs {
  position: absolute;
  z-index: 8;
  top: calc(max(16px, env(safe-area-inset-top)) + 54px);
  left: 14px;
  right: 14px;
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(250, 252, 251, 0.86), rgba(250, 252, 251, 0.5));
  backdrop-filter: blur(12px);
}
.theme-tabs::-webkit-scrollbar,
.era-scroll::-webkit-scrollbar,
.layer-tabs::-webkit-scrollbar { display: none; }
.theme-chip {
  position: relative;
  flex: 0 0 auto;
  min-height: 39px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
}
.theme-chip::after {
  content: "";
  position: absolute;
  left: 13px;
  right: 13px;
  bottom: -1px;
  height: 2px;
  background: transparent;
}
.theme-chip.is-active { color: var(--text); }
.theme-chip.is-active::after { background: var(--accent); }
.theme-chip:disabled { opacity: 0.28; cursor: default; }

.map-note {
  position: absolute;
  z-index: 7;
  left: 14px;
  bottom: 202px;
  max-width: min(76vw, 390px);
  padding: 6px 8px;
  font-size: 10px;
  line-height: 1.45;
  color: var(--muted);
  background: rgba(250, 252, 251, 0.84);
  border-left: 2px solid var(--accent);
  backdrop-filter: blur(10px);
}
.place-picker {
  position: absolute;
  z-index: 7;
  right: 12px;
  bottom: 202px;
  display: none;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.place-quick {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 2px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  backdrop-filter: blur(10px);
}
.place-quick.is-active {
  color: var(--text);
  border-color: var(--accent);
}

.era-bar {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  bottom: 0;
  height: 76px;
  border-top: 1px solid var(--line);
  background: var(--panel-solid);
  padding-bottom: env(safe-area-inset-bottom);
}
.era-scroll {
  position: relative;
  display: flex;
  align-items: stretch;
  height: 100%;
  overflow-x: auto;
  padding: 8px 10px 7px;
  scrollbar-width: none;
}
.era-scroll::before {
  content: "";
  position: absolute;
  left: 42px;
  right: 42px;
  top: 27px;
  height: 1px;
  background: var(--line-strong);
}
.era-chip {
  position: relative;
  z-index: 1;
  flex: 0 0 64px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 28px 3px 2px;
  font-size: 11px;
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
}
.era-chip::before {
  content: "";
  position: absolute;
  top: 15px;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--panel-solid);
  transform: translateX(-50%);
}
.era-chip:first-child { flex-basis: 72px; }
.era-chip.is-active { color: var(--text); font-weight: 720; }
.era-chip.is-active::before {
  width: 11px;
  height: 11px;
  top: 13px;
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 5px var(--accent-soft);
}
.era-chip:disabled { opacity: 0.28; cursor: default; }

.bottom-sheet {
  position: absolute;
  z-index: 9;
  left: 0;
  right: 0;
  bottom: 76px;
  max-height: 68dvh;
  min-height: 186px;
  transform: translateY(calc(100% - 186px));
  background: var(--panel);
  border-top: 1px solid var(--line-strong);
  border-radius: 0;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}
.bottom-sheet.is-open { transform: translateY(0); }
.bottom-sheet.is-deep { max-height: 74dvh; }
.bottom-sheet.is-quest {
  min-height: 248px;
  transform: translateY(calc(100% - 248px));
  border-top: 2px solid var(--accent);
}
.bottom-sheet.is-quest.is-open { transform: translateY(0); }
.bottom-sheet.is-quest-complete {
  min-height: 354px;
  transform: translateY(calc(100% - 354px));
}
.sheet-handle {
  display: grid;
  place-items: center;
  width: 100%;
  height: 28px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.sheet-handle span {
  width: 34px;
  height: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 36%, transparent);
}
.sheet-body {
  overflow-y: auto;
  max-height: calc(74dvh - 28px);
  padding: 0 20px calc(26px + env(safe-area-inset-bottom));
}
.empty-state {
  padding: 7px 0 30px;
  max-width: 540px;
}
.empty-state h1 { max-width: 16em; }

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 9px;
  font-size: clamp(24px, 6.4vw, 36px);
  line-height: 1.18;
  font-weight: 760;
  letter-spacing: -0.035em;
}
h2 {
  margin-bottom: 8px;
  font-size: clamp(25px, 7vw, 34px);
  line-height: 1.15;
  font-weight: 760;
  letter-spacing: -0.035em;
}
h3 {
  font-size: 16px;
  line-height: 1.45;
  font-weight: 700;
}
p {
  color: var(--muted);
  line-height: 1.72;
  font-size: 14px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 720;
  letter-spacing: 0.04em;
}
.sheet-head {
  display: grid;
  gap: 10px;
  padding-bottom: 15px;
}
.time-stamp {
  display: flex;
  align-items: baseline;
  gap: 9px;
}
.time-stamp > span {
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.sheet-summary {
  margin-bottom: 0;
  max-width: 48em;
  font-size: 15px;
  line-height: 1.68;
}
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  align-items: center;
}
.meta-pill {
  padding: 0 9px;
  border-left: 1px solid var(--line-strong);
  font-size: 12px;
  color: var(--muted);
}
.meta-pill:first-child { padding-left: 0; border-left: 0; }
.question {
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  font-weight: 650;
}
.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.primary-button, .secondary-button {
  min-height: 46px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 680;
}
.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}
.secondary-button {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
}

.layer-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  padding: 3px 0 12px;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}
.layer-chip {
  flex: 0 0 auto;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 6px 11px;
  font-size: 12px;
  cursor: pointer;
}
.layer-chip:first-child { border-left: 0; padding-left: 0; }
.layer-chip.is-active { color: var(--accent); font-weight: 700; }
.layer-card { padding: 17px 0 6px; }
.layer-card .period {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
}
.layer-card .layer-title { margin-top: 5px; margin-bottom: 8px; }
.layer-card .layer-summary { margin-bottom: 13px; }

.claim-list { display: grid; gap: 10px; }
.claim-card {
  border-top: 1px solid var(--line-strong);
  background: transparent;
  padding: 14px 0 4px;
}
.claim-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.claim-statement {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
}
.status-badge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 7px;
  font-size: 10px;
  line-height: 1;
  color: var(--muted);
}
.status-confirmed {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  background: var(--accent-soft);
}
.status-unknown, .status-disputed { border-style: dashed; }
.claim-themes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
}
.claim-theme { font-size: 11px; color: var(--muted); }

.evidence-details {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 9px;
}
.evidence-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 12px;
  list-style: none;
}
.evidence-details summary::-webkit-details-marker { display: none; }
.evidence-block { margin-top: 9px; }
.evidence-item { margin-bottom: 9px; }
.evidence-name { color: var(--text); font-size: 12px; font-weight: 650; }
.source-link {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 2px;
}

.relation-list { display: grid; gap: 10px; margin-top: 10px; }
.relation-card {
  border-left: 2px solid var(--accent);
  padding: 8px 0 8px 12px;
}
.relation-type {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}
.relation-card p { margin-bottom: 0; }
.editorial-card {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--accent-soft);
}
.editorial-card h3 { margin-bottom: 6px; }
.editorial-card p:last-child { margin-bottom: 0; }

.mode-tabs {
  display: flex;
  gap: 22px;
  margin: 2px 0 10px;
  border-bottom: 1px solid var(--line);
}
.mode-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
}
.mode-tab.is-active { color: var(--text); border-color: var(--accent); }

.anchor-warning {
  margin: 2px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}
.anchor-warning summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
}
.anchor-warning p { margin: 7px 0 0; font-size: 11px; }

.quest-active .theme-tabs {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}
.quest-active .map-note,
.quest-active .place-picker { display: none; }
.theme-tabs { transition: opacity 0.22s ease, transform 0.22s ease; }

.quest-panel {
  padding: 5px 0 24px;
}
.quest-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 780;
  letter-spacing: 0.13em;
}
.quest-state {
  min-width: 52px;
  padding: 4px 7px;
  border: 1px solid color-mix(in srgb, var(--accent) 44%, transparent);
  color: var(--accent);
  text-align: center;
  letter-spacing: 0.04em;
}
.quest-era {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 720;
}
.quest-panel h2 {
  max-width: 19em;
  margin-bottom: 8px;
  font-size: clamp(24px, 6.8vw, 33px);
}
.quest-panel > p:not(.quest-era):not(.quest-empty) {
  margin-bottom: 13px;
  font-size: 14px;
  line-height: 1.58;
}
.quest-button { width: 100%; }
.quest-progress {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 2px 0 13px;
}
.quest-progress span {
  height: 3px;
  background: var(--line-strong);
}
.quest-progress span.is-found {
  background: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 45%, transparent);
}
.quest-instruction { margin-bottom: 9px !important; }
.quest-empty {
  margin: 0;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.quest-findings {
  display: grid;
  gap: 7px;
  max-height: 93px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  padding-top: 7px;
}
.quest-finding {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 8px;
  align-items: baseline;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.quest-finding strong { color: var(--text); }
.quest-finding.is-new strong { color: var(--accent); }
.quest-conclusion {
  display: grid;
  gap: 4px;
  margin: 10px 0 14px;
  padding: 10px 0 10px 12px;
  border-left: 2px solid var(--accent);
}
.quest-conclusion span {
  color: var(--accent);
  font-size: 11px;
  font-weight: 720;
}
.quest-conclusion strong {
  font-size: 13px;
  line-height: 1.5;
}

@media (min-width: 760px) {
  .map-stage { right: 410px; bottom: 0; }
  .era-bar { left: auto; right: 0; width: 410px; }
  .bottom-sheet {
    left: auto;
    right: 0;
    bottom: 76px;
    top: 0;
    width: 410px;
    max-height: none;
    min-height: 0;
    transform: none;
    border-left: 1px solid var(--line-strong);
    box-shadow: -16px 0 44px rgba(25, 38, 34, 0.08);
  }
  .bottom-sheet.is-open, .bottom-sheet.is-deep {
    transform: none;
    max-height: none;
  }
  .bottom-sheet.is-quest,
  .bottom-sheet.is-quest-complete { transform: none; }
  .sheet-handle { display: none; }
  .sheet-body {
    max-height: calc(100dvh - 76px);
    padding: 24px 24px 30px;
  }
  .map-note { bottom: 18px; }
  .place-picker { display: flex; bottom: 18px; }
}

@media (max-width: 390px) {
  .theme-chip { padding-inline: 11px; font-size: 12px; }
  .era-chip { flex-basis: 60px; }
  .sheet-body { padding-inline: 18px; }
}
