:root {
  color-scheme: light;
  --app-bg: var(--tg-theme-bg-color, #f4f6f1);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-raised: #ffffff;
  --text: var(--tg-theme-text-color, #1d241f);
  --muted: var(--tg-theme-hint-color, #6e776f);
  --line: #dce3dc;
  --primary: var(--tg-theme-button-color, #287654);
  --primary-text: var(--tg-theme-button-text-color, #ffffff);
  --primary-soft: #dcecdf;
  --blue: #356d91;
  --blue-soft: #dceaf3;
  --amber: #9a6a1d;
  --amber-soft: #f3e7c9;
  --coral: #aa5948;
  --coral-soft: #f3dfda;
  --violet: #665d94;
  --violet-soft: #e7e3f2;
  --card-copy: #4f5d54;
  --card-footer: #385045;
  --status-bg: #d7f0de;
  --status-text: #124c31;
  --status-line: #82bd96;
  --chip-default-bg: #edf0ed;
  --chip-default-text: #33473a;
  --chip-default-line: #b7c3ba;
  --chip-green-bg: #dcecdf;
  --chip-green-text: #124d31;
  --chip-green-line: #86bd9a;
  --chip-blue-bg: #dceaf3;
  --chip-blue-text: #1b526f;
  --chip-blue-line: #88b9d3;
  --chip-amber-bg: #f3e7c9;
  --chip-amber-text: #69470c;
  --chip-amber-line: #d4ad5d;
  --chip-coral-bg: #f3dfda;
  --chip-coral-text: #713126;
  --chip-coral-line: #d89a8d;
  --chip-violet-bg: #e7e3f2;
  --chip-violet-text: #493b78;
  --chip-violet-line: #a79ace;
  --featured-bg: #f9fcf9;
  --featured-line: #b9d5c1;
  --locked-bg: #ecefeb;
  --locked-text: #59625b;
  --profile-bg: #eef5ef;
  --profile-line: #c6d6ca;
  --ink-deep: #10231b;
  --nav-height: 72px;
  --header-height: 66px;
  --radius: 8px;
  --shadow: 0 12px 34px rgba(26, 40, 31, 0.12);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: #dfe4df;
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
input {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 21px;
  line-height: 1.18;
}

h3 {
  font-size: 17px;
  line-height: 1.28;
}

.desktop-stage {
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(40, 118, 84, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(40, 118, 84, 0.05) 1px, transparent 1px),
    #e8ece7;
  background-size: 24px 24px;
}

.mini-app {
  position: relative;
  width: min(100%, 430px);
  min-height: calc(100vh - 48px);
  overflow: hidden;
  border: 1px solid rgba(30, 55, 41, 0.16);
  border-radius: 24px;
  background: var(--app-bg);
  box-shadow: 0 24px 70px rgba(25, 39, 30, 0.18);
}

.app-header,
.detail-header,
.search-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--header-height);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--app-bg) 92%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 7px;
}

.app-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.keeper-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--ink-deep);
  color: #f4f0df;
  font-size: 12px;
  font-weight: 850;
}

.app-kicker,
.eyebrow,
.section-label,
.item-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.screen {
  width: 100%;
  min-width: 0;
  min-height: calc(100vh - var(--header-height));
  padding: 14px 14px calc(var(--nav-height) + 24px + env(safe-area-inset-bottom));
}

.boot-loader {
  min-height: 48vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.boot-loader-mark {
  width: 28px;
  height: 28px;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: boot-loader-spin 0.8s linear infinite;
}

@keyframes boot-loader-spin {
  to {
    transform: rotate(360deg);
  }
}

.screen-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  min-width: 0;
  gap: 18px;
}

.screen-stack > * {
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-head button {
  min-height: 32px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  font-weight: 750;
}

.map-expand-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 5px 8px !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius);
  background: var(--surface) !important;
  color: var(--text) !important;
  font-size: 12px !important;
}

.map-expand-button svg {
  width: 16px;
  height: 16px;
}

.world-hero {
  position: relative;
  display: flex;
  min-height: 235px;
  overflow: hidden;
  border-radius: var(--radius);
  background: #173d35 url("./assets/world-map-banner.jpg") center / cover no-repeat;
  color: white;
  box-shadow: var(--shadow);
}

.world-hero::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(180deg, rgba(7, 25, 20, 0.06) 16%, rgba(7, 25, 20, 0.84) 100%);
}

.hero-content {
  position: relative;
  z-index: 1;
  align-self: end;
  display: grid;
  width: 100%;
  gap: 10px;
  padding: 18px;
}

.hero-content .eyebrow {
  color: rgba(255, 255, 255, 0.74);
}

.hero-content h2 {
  max-width: 320px;
  font-size: 25px;
}

.hero-stats {
  display: flex;
  gap: 18px;
}

.hero-stat strong {
  display: block;
  font-size: 19px;
}

.hero-stat span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.voice-button,
.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 50px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 800;
}

.voice-button svg,
.primary-button svg {
  width: 20px;
  height: 20px;
}

.voice-note {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.quick-stat {
  min-width: 0;
  padding: 12px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.quick-stat strong {
  display: block;
  font-size: 21px;
}

.quick-stat span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.story-card,
.quest-card,
.region-card,
.entity-card,
.inventory-card,
.skill-card,
.search-result {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.story-card,
.quest-card,
.region-card,
.entity-card,
.inventory-card,
.skill-card {
  display: grid;
  gap: 9px;
}

.story-card.featured {
  border-color: var(--featured-line);
  background: var(--featured-bg);
}

.story-card.period-summary {
  position: relative;
  border-color: color-mix(in srgb, var(--amber) 52%, var(--line));
  border-left: 4px solid var(--amber);
  background: color-mix(in srgb, var(--surface) 86%, var(--amber-soft));
}

.story-card.period-summary.monthly_summary {
  border-color: color-mix(in srgb, var(--violet) 52%, var(--line));
  border-left-color: var(--violet);
  background: color-mix(in srgb, var(--surface) 86%, var(--violet-soft));
}

.story-card.period-summary .item-meta,
.period-summary-detail-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.story-card.period-summary .item-meta svg,
.period-summary-detail-meta svg {
  width: 15px;
  height: 15px;
}

.quest-card.completed {
  background: color-mix(in srgb, var(--surface) 78%, var(--primary-soft));
  opacity: 0.82;
}

.quest-card.completed h3 {
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent);
}

.story-card p,
.quest-card p,
.region-card p,
.entity-card p,
.inventory-card p,
.skill-card p {
  color: var(--card-copy);
  font-size: 14px;
  line-height: 1.47;
}

.story-card .item-meta,
.quest-card .item-meta,
.region-card .item-meta,
.entity-card .item-meta,
.inventory-card .item-meta,
.skill-card .item-meta {
  color: var(--card-footer);
}

.card-footer,
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-footer {
  padding-top: 3px;
  color: var(--card-footer);
  font-size: 12px;
  font-weight: 800;
}

.card-footer svg {
  width: 17px;
  height: 17px;
}

.card-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 9px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--chip-default-line);
  background: var(--chip-default-bg);
  color: var(--chip-default-text);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.chip.green { border-color: var(--chip-green-line); background: var(--chip-green-bg); color: var(--chip-green-text); }
.chip.blue { border-color: var(--chip-blue-line); background: var(--chip-blue-bg); color: var(--chip-blue-text); }
.chip.amber { border-color: var(--chip-amber-line); background: var(--chip-amber-bg); color: var(--chip-amber-text); }
.chip.coral { border-color: var(--chip-coral-line); background: var(--chip-coral-bg); color: var(--chip-coral-text); }
.chip.violet { border-color: var(--chip-violet-line); background: var(--chip-violet-bg); color: var(--chip-violet-text); }

.horizontal-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(240px, 82%);
  gap: 9px;
  margin: 0 -14px;
  width: calc(100% + 28px);
  min-width: 0;
  max-width: calc(100% + 28px);
  padding: 0 14px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.horizontal-list::-webkit-scrollbar {
  display: none;
}

.horizontal-list > * {
  scroll-snap-align: start;
}

.timeline {
  position: relative;
  display: grid;
  gap: 10px;
  padding-left: 17px;
}

.timeline::before {
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 5px;
  width: 1px;
  content: "";
  background: #b9c9bd;
}

.timeline .story-card {
  position: relative;
}

.timeline .story-card::before {
  position: absolute;
  top: 21px;
  left: -17px;
  width: 9px;
  height: 9px;
  border: 3px solid var(--app-bg);
  border-radius: 50%;
  content: "";
  background: var(--primary);
}

.timeline .story-card.period-summary::before {
  border-radius: 2px;
  background: var(--amber);
  transform: rotate(45deg);
}

.timeline .story-card.period-summary.monthly_summary::before {
  background: var(--violet);
}

.segmented-scroll {
  position: sticky;
  top: calc(var(--header-height) - 1px + env(safe-area-inset-top));
  z-index: 12;
  display: flex;
  gap: 5px;
  margin: -2px -14px 14px;
  padding: 10px 14px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--app-bg) 94%, transparent);
  backdrop-filter: blur(16px);
  scrollbar-width: none;
}

.segment-button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.segment-button.active {
  border-color: var(--ink-deep);
  background: var(--ink-deep);
  color: white;
}

.region-card.opened {
  border-color: var(--featured-line);
  background: var(--featured-bg);
}

.map-section {
  display: grid;
  min-width: 0;
  gap: 0;
}

.world-map {
  position: relative;
  overflow: hidden;
  border: 1px solid #aebdb2;
  border-radius: var(--radius);
  background: #173d35;
  box-shadow: 0 8px 24px rgba(18, 39, 29, 0.14);
}

.world-map.preview {
  width: 100%;
  aspect-ratio: 3 / 2;
  cursor: zoom-in;
  touch-action: manipulation;
}

.world-map.preview:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}

.world-map-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  overflow: hidden;
}

.world-map-canvas > img,
.world-map-canvas > svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.world-map-canvas > img {
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.world-map-canvas > svg {
  pointer-events: auto;
}

.map-node-shape {
  stroke: rgba(250, 249, 236, 0.78);
  stroke-width: 5;
  vector-effect: non-scaling-stroke;
  transition: fill 160ms ease, stroke 160ms ease, filter 160ms ease;
}

.map-region-node { cursor: pointer; }

.map-region.blue .map-node-shape { fill: rgba(47, 101, 139, 0.57); }
.map-region.green .map-node-shape { fill: rgba(44, 123, 80, 0.57); }
.map-region.amber .map-node-shape { fill: rgba(176, 128, 42, 0.56); }
.map-region.violet .map-node-shape { fill: rgba(100, 83, 143, 0.57); }
.map-region.coral .map-node-shape { fill: rgba(166, 80, 62, 0.57); }
.map-region.fog .map-node-shape { fill: rgba(76, 86, 81, 0.67); }

.map-region.is-closed .map-node-shape {
  stroke: rgba(230, 234, 229, 0.56);
  stroke-dasharray: 13 9;
}

.map-region-node:hover .map-node-shape,
.map-region-node:focus .map-node-shape {
  stroke: #fff6d4;
  filter: brightness(1.12) drop-shadow(0 4px 8px rgba(7, 17, 13, 0.52));
}

.map-label rect,
.camp-label rect {
  fill: rgba(12, 31, 24, 0.88);
  stroke: rgba(255, 255, 255, 0.42);
  stroke-width: 2;
}

.map-label-title,
.map-label-meta,
.camp-label text {
  fill: #ffffff;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 800;
  paint-order: stroke;
  stroke: rgba(8, 20, 15, 0.5);
  stroke-width: 1;
}

.map-label-title {
  font-size: 28px;
}

.map-label-meta {
  fill: rgba(255, 255, 255, 0.88);
  font-size: 21px;
  font-weight: 650;
}

.map-empty-label {
  fill: #ffffff;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 30px;
  font-weight: 800;
  paint-order: stroke;
  stroke: rgba(8, 20, 15, 0.56);
  stroke-width: 2;
}

.map-road {
  fill: none;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.map-road.main {
  stroke: #f1c36e;
  stroke-width: 6;
  filter: drop-shadow(0 1px 2px rgba(33, 24, 8, 0.5));
}

.map-road.trail {
  stroke: rgba(244, 210, 143, 0.82);
  stroke-width: 4;
  stroke-dasharray: 10 7;
}

.map-road.unknown {
  stroke: rgba(228, 234, 228, 0.62);
  stroke-width: 4;
  stroke-dasharray: 4 12;
}

.camp-ring {
  fill: rgba(236, 193, 104, 0.18);
  stroke: #f0c26c;
  stroke-width: 7;
}

.camp-core {
  fill: #102d22;
  stroke: #fff1c9;
  stroke-width: 4;
}

.camp-roof {
  fill: #fff1c9;
}

.camp-label text {
  font-size: 23px;
}

.map-caption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.region-card.locked {
  background: var(--locked-bg);
  color: var(--locked-text);
}

.status-pill {
  flex: 0 0 auto;
  padding: 4px 7px;
  border-radius: 7px;
  border: 1px solid var(--status-line);
  background: var(--status-bg);
  color: var(--status-text);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.region-card.opened .status-pill {
  border-color: var(--status-line);
  background: var(--status-bg);
  color: var(--status-text);
}

.profile-band {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 13px;
  align-items: center;
  padding: 15px;
  border: 1px solid var(--profile-line);
  border-radius: var(--radius);
  background: var(--profile-bg);
}

.profile-avatar {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--ink-deep);
  color: white;
  font-size: 23px;
  font-weight: 850;
}

.profile-band p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.detail-page,
.search-page,
.map-page {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  min-height: 100%;
  background: var(--app-bg);
}

.detail-page.open,
.search-page.open,
.map-page.open {
  display: block;
}

.map-page.open {
  position: fixed;
  inset: 0;
  width: 100dvw;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.map-fullscreen-scroll {
  position: absolute;
  inset: 0;
  display: grid;
  width: 100dvw;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  place-items: center;
  background: #07110d;
}

.world-map.fullscreen {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(100dvw, 150dvh);
  height: auto;
  aspect-ratio: 3 / 2;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: translate(-50%, -50%);
}

.world-map.fullscreen .world-map-canvas {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

.world-map.fullscreen .world-map-canvas > img {
  object-fit: contain;
}

.world-map.fullscreen .map-node-shape {
  stroke-width: 3;
}

.map-page .detail-header {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left));
  z-index: 60;
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.map-page .detail-heading,
.map-page .header-spacer {
  display: none;
}

.map-page .icon-button {
  border-color: rgba(255, 255, 255, 0.42);
  background: rgba(7, 17, 13, 0.76);
  color: #ffffff;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

@media (orientation: portrait) {
  .world-map.fullscreen {
    width: min(100dvh, 150dvw);
    height: auto;
    transform: translate(-50%, -50%) rotate(90deg);
  }
}

.detail-header {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
}

.detail-heading {
  min-width: 0;
  text-align: center;
}

.detail-heading h2 {
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-content {
  display: grid;
  gap: 16px;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
}

.detail-hero {
  display: grid;
  gap: 10px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.detail-hero h2 {
  font-size: 25px;
}

.detail-hero p {
  color: var(--muted);
  line-height: 1.55;
}

.detail-section {
  display: grid;
  gap: 9px;
  padding-top: 2px;
}

.detail-section + .detail-section {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.detail-section > p,
.detail-section li {
  font-size: 15px;
  line-height: 1.58;
}

.privacy-hero {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.privacy-hero > p {
  grid-column: 1 / -1;
}

.privacy-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary);
}

.privacy-mark svg {
  width: 25px;
  height: 25px;
}

.privacy-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-left: 21px;
}

.privacy-list code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--line);
  font-size: 0.92em;
}

.privacy-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  color: var(--primary);
  font-weight: 750;
  line-height: 1.45;
}

.privacy-link svg {
  width: 16px;
  height: 16px;
}

.danger-zone {
  color: var(--coral);
}

.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--coral) 55%, var(--line));
  border-radius: var(--radius);
  background: var(--coral-soft);
  color: var(--coral);
  font-weight: 800;
}

.danger-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.danger-button svg {
  width: 18px;
  height: 18px;
}

.detail-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.causal-chain {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.causal-chain li {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-width: 0;
  padding: 0 0 14px;
}

.causal-chain li:last-child {
  padding-bottom: 0;
}

.causal-chain li:not(:last-child)::after {
  position: absolute;
  top: 28px;
  bottom: 2px;
  left: 14px;
  width: 2px;
  background: var(--primary-soft);
  content: "";
}

.causal-index {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid color-mix(in srgb, var(--primary) 45%, var(--line));
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary);
  font-size: 12px;
  font-weight: 850;
}

.causal-chain p {
  min-width: 0;
  padding-top: 3px;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.52;
}

.mini-card-list {
  display: grid;
  gap: 8px;
}

.mini-card {
  display: grid;
  gap: 5px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.mini-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.artifact-card {
  border-left: 3px solid var(--violet);
}

.connection-card {
  border-left: 3px solid var(--blue);
}

.connection-sources {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.period-summary-detail {
  display: grid;
  gap: 16px;
}

.period-summary-detail-meta {
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--amber) 42%, var(--line));
  border-radius: var(--radius);
  background: var(--amber-soft);
  color: #6e4b14;
  font-size: 13px;
  font-weight: 750;
}

.chapter-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #e9ede9;
}

.chapter-tab {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chapter-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(20, 36, 26, 0.1);
}

.source-integrity-note {
  margin: 12px 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

.source-integrity-note.verified {
  background: var(--primary-soft);
}

.source-integrity-note.warning {
  background: var(--amber-soft);
}

.source-integrity-note.invalid {
  background: var(--coral-soft);
}

.raw-entry-verbatim {
  margin: 0;
  padding: 0 0 28px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.68;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.markdown-body {
  color: var(--text);
  font-size: 16px;
  line-height: 1.68;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 22px 0 10px;
}

.markdown-body h1 { font-size: 25px; }
.markdown-body h2 { font-size: 21px; }
.markdown-body h3 { font-size: 18px; }

.markdown-body p,
.markdown-body ul {
  margin: 0 0 13px;
}

.markdown-body ul {
  padding-left: 21px;
}

.markdown-body li + li {
  margin-top: 5px;
}

.markdown-body blockquote {
  margin: 0 0 13px;
  padding: 8px 12px;
  border-left: 3px solid var(--primary);
  border-radius: 0 8px 8px 0;
  background: color-mix(in srgb, var(--primary) 7%, transparent);
  color: var(--muted);
}

.markdown-body code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface);
  font-size: 0.9em;
}

.search-header {
  display: flex;
  align-items: center;
  gap: 9px;
}

.search-field {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  flex: 1;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}

.search-field svg {
  width: 18px;
  height: 18px;
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
}

.search-results {
  display: grid;
  gap: 9px;
  padding: 14px;
}

.search-result {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 10px;
}

.search-result-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
}

.search-result-icon svg,
.search-result > svg {
  width: 17px;
  height: 17px;
}

.search-result strong,
.search-result small {
  display: block;
}

.search-result small {
  margin-top: 3px;
  color: var(--muted);
}

.empty-state {
  padding: 30px 18px;
  border: 1px dashed #c9d1ca;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  line-height: 1.55;
}

.bottom-nav {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.nav-button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 55px;
  padding: 4px 2px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
}

.nav-button svg {
  width: 21px;
  height: 21px;
  stroke-width: 2;
}

.nav-button span {
  max-width: 100%;
  overflow: hidden;
  font-size: 10px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-button.active {
  color: var(--primary);
}

.toast {
  position: fixed;
  right: 50%;
  bottom: calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
  z-index: 80;
  width: min(calc(100% - 40px), 380px);
  padding: 11px 13px;
  border-radius: var(--radius);
  background: #15271f;
  color: white;
  font-size: 13px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translate(50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(50%, 0);
}

@media (max-width: 520px) {
  html,
  body,
  .desktop-stage {
    background: var(--app-bg);
  }

  .desktop-stage {
    display: block;
    min-height: 100%;
    padding: 0;
  }

  .mini-app {
    width: 100%;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .bottom-nav,
  .toast {
    position: fixed;
  }

  .detail-page,
  .search-page,
  .map-page {
    position: fixed;
    overflow-y: auto;
  }
}

/* Telegram's own scheme takes precedence over the device setting. */
:root[data-telegram-theme="dark"]:not([data-force-light]) {
  --app-bg: var(--tg-theme-bg-color, #172019);
  --surface: var(--tg-theme-secondary-bg-color, #202b23);
  --surface-raised: #253128;
  --text: var(--tg-theme-text-color, #edf3ee);
  --muted: var(--tg-theme-hint-color, #b3c0b7);
  --line: #405047;
  --primary-soft: #244735;
  --blue-soft: #243e4f;
  --amber-soft: #4c3d20;
  --coral-soft: #4d302b;
  --violet-soft: #38334c;
  --card-copy: #d1ddd5;
  --card-footer: #edf5ef;
  --status-bg: #1f704a;
  --status-text: #f4fff7;
  --status-line: #70ce98;
  --chip-default-bg: #33453a;
  --chip-default-text: #f2faf4;
  --chip-default-line: #8fa89a;
  --chip-green-bg: #1f5a3d;
  --chip-green-text: #f3fff6;
  --chip-green-line: #71cd98;
  --chip-blue-bg: #204d68;
  --chip-blue-text: #f1faff;
  --chip-blue-line: #69bde7;
  --chip-amber-bg: #66501d;
  --chip-amber-text: #fff6dc;
  --chip-amber-line: #dfb14f;
  --chip-coral-bg: #66362e;
  --chip-coral-text: #fff1ed;
  --chip-coral-line: #ec9a84;
  --chip-violet-bg: #55436f;
  --chip-violet-text: #fbf7ff;
  --chip-violet-line: #c2a4ee;
  --featured-bg: #1d2c22;
  --featured-line: #4c7d5e;
  --locked-bg: #1c251f;
  --locked-text: #e1e9e3;
  --profile-bg: #1e3025;
  --profile-line: #385040;
  --ink-deep: #0e1712;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-telegram-theme="light"]):not([data-force-light]) {
    --app-bg: var(--tg-theme-bg-color, #172019);
    --surface: var(--tg-theme-secondary-bg-color, #202b23);
    --surface-raised: #253128;
    --text: var(--tg-theme-text-color, #edf3ee);
    --muted: var(--tg-theme-hint-color, #b3c0b7);
    --line: #405047;
    --primary-soft: #244735;
    --blue-soft: #243e4f;
    --amber-soft: #4c3d20;
    --coral-soft: #4d302b;
    --violet-soft: #38334c;
    --card-copy: #d1ddd5;
    --card-footer: #edf5ef;
    --status-bg: #1f704a;
    --status-text: #f4fff7;
    --status-line: #70ce98;
    --chip-default-bg: #33453a;
    --chip-default-text: #f2faf4;
    --chip-default-line: #8fa89a;
    --chip-green-bg: #1f5a3d;
    --chip-green-text: #f3fff6;
    --chip-green-line: #71cd98;
    --chip-blue-bg: #204d68;
    --chip-blue-text: #f1faff;
    --chip-blue-line: #69bde7;
    --chip-amber-bg: #66501d;
    --chip-amber-text: #fff6dc;
    --chip-amber-line: #dfb14f;
    --chip-coral-bg: #66362e;
    --chip-coral-text: #fff1ed;
    --chip-coral-line: #ec9a84;
    --chip-violet-bg: #55436f;
    --chip-violet-text: #fbf7ff;
    --chip-violet-line: #c2a4ee;
    --featured-bg: #1d2c22;
    --featured-line: #4c7d5e;
    --locked-bg: #1c251f;
    --locked-text: #e1e9e3;
    --profile-bg: #1e3025;
    --profile-line: #385040;
    --ink-deep: #0e1712;
  }

  :root:not([data-telegram-theme="light"]):not([data-force-light]) .chapter-tabs {
    background: var(--locked-bg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
