:root {
  --ink: #f5efe1;
  --muted: #b9ad98;
  --paper: rgba(27, 26, 23, 0.82);
  --paper-strong: rgba(38, 35, 30, 0.92);
  --blacktop: #090908;
  --charcoal: #14120f;
  --line: rgba(245, 239, 225, 0.14);
  --gold: #d6a54a;
  --amber: #e38b37;
  --teal: #45b8a2;
  --red: #c44c42;
  --blue: #405f80;
  --shadow: rgba(0, 0, 0, 0.48);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--blacktop);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  background:
    linear-gradient(90deg, rgba(214, 165, 74, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(214, 165, 74, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 17% 7%, rgba(196, 76, 66, 0.22), transparent 30rem),
    radial-gradient(circle at 88% 18%, rgba(69, 184, 162, 0.15), transparent 28rem),
    linear-gradient(135deg, #070707 0%, #12100c 48%, #201715 100%);
  background-size: 44px 44px, 44px 44px, auto, auto, auto;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.weather-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.28;
  mix-blend-mode: screen;
  z-index: 0;
}

.weather-layer span {
  position: absolute;
  top: -20vh;
  width: 1px;
  height: 22vh;
  background: linear-gradient(transparent, rgba(245, 239, 225, 0.32), transparent);
  animation: rainFall 2.9s linear infinite;
}

.weather-layer span:nth-child(1) { left: 12%; animation-delay: -0.4s; }
.weather-layer span:nth-child(2) { left: 31%; animation-delay: -1.7s; }
.weather-layer span:nth-child(3) { left: 52%; animation-delay: -0.9s; }
.weather-layer span:nth-child(4) { left: 73%; animation-delay: -2.3s; }
.weather-layer span:nth-child(5) { left: 91%; animation-delay: -1.2s; }

@keyframes rainFall {
  to { transform: translate3d(-12vw, 125vh, 0); }
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1380px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 0 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.3rem, 6vw, 5.8rem);
  line-height: 0.88;
  letter-spacing: 0;
  text-wrap: balance;
}

h2 {
  margin-bottom: 0;
  line-height: 1.05;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.icon-btn,
.text-btn,
.choice-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(245, 239, 225, 0.08);
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 12px;
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.86rem;
}

.icon-btn:hover,
.text-btn:hover,
.choice-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(214, 165, 74, 0.58);
  background: rgba(214, 165, 74, 0.14);
  box-shadow: 0 12px 30px var(--shadow);
}

.icon-btn[aria-pressed="true"] {
  border-color: rgba(69, 184, 162, 0.7);
  background: rgba(69, 184, 162, 0.13);
}

.icon {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.icon.speaker::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 2px 0 0 2px;
  background: var(--gold);
  clip-path: polygon(0 25%, 45% 25%, 100% 0, 100% 100%, 45% 75%, 0 75%);
}

.icon.speaker::after {
  content: "";
  position: absolute;
  right: 1px;
  top: 4px;
  width: 8px;
  height: 10px;
  border: 2px solid var(--gold);
  border-left: 0;
  border-radius: 0 9px 9px 0;
}

.icon.wave::before,
.icon.wave::after {
  content: "";
  position: absolute;
  left: 1px;
  width: 16px;
  height: 7px;
  border-bottom: 2px solid var(--teal);
  border-radius: 50%;
}

.icon.wave::before { top: 3px; }
.icon.wave::after { top: 8px; opacity: 0.65; }

.icon.restart::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 2px solid var(--gold);
  border-right-color: transparent;
  border-radius: 50%;
}

.icon.restart::after {
  content: "";
  position: absolute;
  top: 1px;
  right: 2px;
  width: 0;
  height: 0;
  border-left: 6px solid var(--gold);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(28deg);
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(310px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

.story-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 22px 70px var(--shadow);
  backdrop-filter: blur(18px);
}

.story-panel {
  overflow: hidden;
}

.scene-art {
  position: relative;
  height: clamp(260px, 36vw, 470px);
  overflow: hidden;
  background:
    linear-gradient(to top, rgba(7, 7, 7, 0.88), transparent 45%),
    radial-gradient(circle at var(--moon-x, 74%) 18%, rgba(245, 239, 225, 0.18), transparent 8rem),
    linear-gradient(180deg, var(--sky-a, #15151d) 0%, var(--sky-b, #29303a) 55%, var(--ground, #18120d) 100%);
}

.scene-art::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 58%, transparent 0 24%, rgba(0, 0, 0, 0.22) 45%, rgba(0, 0, 0, 0.7) 100%),
    repeating-linear-gradient(118deg, rgba(245, 239, 225, 0.06) 0 1px, transparent 1px 12px);
  opacity: var(--fog, 0.7);
}

.scene-art::after {
  content: attr(data-label);
  position: absolute;
  right: 18px;
  bottom: 14px;
  color: rgba(245, 239, 225, 0.18);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: clamp(2.4rem, 8vw, 7rem);
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.scene-art[data-place="church"] {
  --sky-a: #0d1118;
  --sky-b: #26211c;
  --ground: #17100c;
  --moon-x: 18%;
  --fog: 0.52;
}

.scene-art[data-place="woods"] {
  --sky-a: #07100d;
  --sky-b: #213029;
  --ground: #0b130e;
  --moon-x: 82%;
  --fog: 0.78;
}

.scene-art[data-place="playground"] {
  --sky-a: #191014;
  --sky-b: #37242f;
  --ground: #15100f;
  --moon-x: 64%;
  --fog: 0.6;
}

.scene-art[data-place="station"] {
  --sky-a: #0e151d;
  --sky-b: #29394b;
  --ground: #101215;
  --moon-x: 40%;
  --fog: 0.83;
}

.scene-art[data-place="hospital"] {
  --sky-a: #0d1615;
  --sky-b: #2d3f3d;
  --ground: #121514;
  --moon-x: 76%;
  --fog: 0.56;
}

.scene-art[data-place="river"] {
  --sky-a: #091018;
  --sky-b: #19304b;
  --ground: #06111a;
  --moon-x: 28%;
  --fog: 0.72;
}

.scene-art[data-place="market"] {
  --sky-a: #180d12;
  --sky-b: #3d1f24;
  --ground: #170b0e;
  --moon-x: 71%;
  --fog: 0.48;
}

.moon {
  position: absolute;
  left: var(--moon-x, 74%);
  top: 38px;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #f2e6c8;
  box-shadow: 0 0 36px rgba(242, 230, 200, 0.46);
  transform: translateX(-50%);
}

.cloud {
  position: absolute;
  width: 220px;
  height: 42px;
  border-radius: 50%;
  background: rgba(245, 239, 225, 0.1);
  filter: blur(8px);
  animation: cloudDrift 18s linear infinite;
}

.cloud-a { left: 10%; top: 70px; }
.cloud-b { left: 52%; top: 120px; animation-duration: 24s; opacity: 0.55; }

@keyframes cloudDrift {
  50% { transform: translateX(42px); }
}

.skyline {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 118px;
  display: flex;
  align-items: end;
  justify-content: space-around;
  padding: 0 7%;
  opacity: 0.86;
}

.skyline span {
  width: clamp(42px, 8vw, 104px);
  height: var(--h, 120px);
  background: linear-gradient(180deg, rgba(245, 239, 225, 0.1), rgba(0, 0, 0, 0.64));
  clip-path: polygon(0 100%, 0 18%, 22% 18%, 22% 0, 70% 0, 70% 28%, 100% 28%, 100% 100%);
}

.skyline span:nth-child(1) { --h: 108px; }
.skyline span:nth-child(2) { --h: 172px; }
.skyline span:nth-child(3) { --h: 136px; }
.skyline span:nth-child(4) { --h: 194px; }
.skyline span:nth-child(5) { --h: 122px; }

.road {
  position: absolute;
  bottom: -26px;
  height: 190px;
  background: linear-gradient(180deg, rgba(214, 165, 74, 0.14), rgba(0, 0, 0, 0.62));
  clip-path: polygon(46% 0, 54% 0, 96% 100%, 4% 100%);
  transform-origin: bottom;
}

.road-left { left: -12%; width: 58%; transform: rotate(18deg); }
.road-mid { left: 26%; width: 48%; }
.road-right { right: -12%; width: 58%; transform: rotate(-18deg); }

.lamp {
  position: absolute;
  bottom: 104px;
  width: 6px;
  height: 118px;
  background: rgba(12, 10, 8, 0.9);
}

.lamp::before {
  content: "";
  position: absolute;
  left: -14px;
  top: -18px;
  width: 34px;
  height: 28px;
  border-radius: 18px 18px 4px 4px;
  background: var(--gold);
  box-shadow: 0 0 34px rgba(214, 165, 74, 0.64);
}

.lamp-a { left: 18%; }
.lamp-b { right: 20%; transform: scale(0.74); opacity: 0.64; }

.figure {
  position: absolute;
  left: 50%;
  bottom: 76px;
  width: 74px;
  height: 132px;
  transform: translateX(-50%);
  filter: drop-shadow(0 18px 26px rgba(0, 0, 0, 0.6));
}

.figure .coat {
  position: absolute;
  left: 17px;
  bottom: 0;
  width: 40px;
  height: 84px;
  border-radius: 20px 20px 8px 8px;
  background: linear-gradient(180deg, #dbb24d, #a66d2b);
}

.figure .head {
  position: absolute;
  left: 21px;
  top: 14px;
  width: 32px;
  height: 34px;
  border-radius: 50%;
  background: #3b241b;
  box-shadow: inset 0 -11px 0 #1d110d;
}

.figure .light {
  position: absolute;
  right: -95px;
  top: 66px;
  width: 136px;
  height: 42px;
  background: linear-gradient(90deg, rgba(245, 239, 225, 0.7), transparent);
  clip-path: polygon(0 36%, 100% 0, 100% 100%, 0 64%);
  opacity: 0.7;
  animation: lightSweep 4s ease-in-out infinite;
}

@keyframes lightSweep {
  50% { transform: rotate(-7deg); opacity: 0.9; }
}

.scene-copy {
  padding: 22px 24px 8px;
}

.scene-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  color: var(--gold);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

#sceneTitle {
  margin: 12px 0 14px;
  font-size: clamp(2rem, 4vw, 4.1rem);
  text-wrap: balance;
}

#sceneText {
  max-width: 78ch;
  margin-bottom: 0;
  color: #e9dec9;
  font-size: clamp(1.03rem, 1.6vw, 1.22rem);
  line-height: 1.74;
}

.choice-list {
  display: grid;
  gap: 10px;
  padding: 16px 24px 24px;
}

.choice-btn {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 13px;
  min-height: 66px;
  width: 100%;
  padding: 12px 14px;
  color: var(--ink);
  text-align: left;
}

.choice-btn:focus-visible,
.icon-btn:focus-visible,
.text-btn:focus-visible {
  outline: 3px solid rgba(69, 184, 162, 0.8);
  outline-offset: 2px;
}

.choice-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
  box-shadow: none;
}

.choice-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(214, 165, 74, 0.44);
  border-radius: 50%;
  color: var(--gold);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
}

.choice-main strong {
  display: block;
  margin-bottom: 3px;
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.98rem;
}

.choice-main span {
  display: block;
  color: var(--muted);
  font-size: 0.91rem;
  line-height: 1.4;
}

.choice-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.tag {
  max-width: 112px;
  padding: 4px 7px;
  border: 1px solid rgba(245, 239, 225, 0.16);
  border-radius: 999px;
  color: var(--muted);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.69rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag.good { color: #a9e8dd; border-color: rgba(69, 184, 162, 0.45); }
.tag.bad { color: #f1a39c; border-color: rgba(196, 76, 66, 0.45); }
.tag.warn { color: #f1c980; border-color: rgba(214, 165, 74, 0.45); }

.side-stack,
.lower-grid {
  display: grid;
  gap: 16px;
}

.lower-grid {
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  margin-top: 16px;
}

.panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  font-size: 1.04rem;
  font-family: "Segoe UI", Tahoma, sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.panel-heading span,
.save-state {
  color: var(--muted);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
}

.meters {
  display: grid;
  gap: 13px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.82rem;
}

.track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(245, 239, 225, 0.09);
}

.track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--amber), var(--teal));
  transition: width 260ms ease;
}

.track.danger span {
  background: linear-gradient(90deg, var(--gold), var(--red));
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 34px;
  color: var(--muted);
}

.chip-list.empty {
  align-items: center;
  font-style: italic;
}

.chip {
  max-width: 100%;
  padding: 7px 9px;
  border: 1px solid rgba(245, 239, 225, 0.14);
  border-radius: 999px;
  background: rgba(245, 239, 225, 0.06);
  color: #ede4d2;
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.79rem;
  overflow-wrap: anywhere;
}

.family-cast {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
  padding-right: 2px;
}

.family-card {
  padding: 10px;
  border: 1px solid rgba(245, 239, 225, 0.12);
  border-radius: var(--radius);
  background: rgba(245, 239, 225, 0.04);
}

.family-card.active {
  border-color: rgba(214, 165, 74, 0.58);
  background: rgba(214, 165, 74, 0.11);
}

.family-card strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.88rem;
}

.family-card span {
  display: block;
  margin-bottom: 5px;
  color: var(--gold);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.family-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.38;
}

.route-map {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.map-node {
  min-height: 64px;
  padding: 9px;
  border: 1px solid rgba(245, 239, 225, 0.12);
  border-radius: var(--radius);
  background: rgba(245, 239, 225, 0.04);
  color: rgba(245, 239, 225, 0.46);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.76rem;
  line-height: 1.25;
}

.map-node.visited {
  border-color: rgba(69, 184, 162, 0.52);
  color: var(--ink);
  background: rgba(69, 184, 162, 0.1);
}

.map-node.current {
  border-color: rgba(214, 165, 74, 0.7);
  background: rgba(214, 165, 74, 0.14);
}

.path-log {
  max-height: 310px;
  margin: 0;
  padding-left: 22px;
  overflow: auto;
}

.path-log li {
  margin: 0 0 10px;
  padding-left: 5px;
  color: #e4dac8;
  line-height: 1.45;
}

.path-log li::marker {
  color: var(--gold);
  font-weight: 800;
}

.text-btn {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--muted);
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.78rem;
}

.ending-archive {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ending-card {
  min-height: 74px;
  padding: 10px;
  border: 1px solid rgba(245, 239, 225, 0.12);
  border-radius: var(--radius);
  background: rgba(245, 239, 225, 0.04);
}

.ending-card.found {
  border-color: rgba(214, 165, 74, 0.46);
  background: rgba(214, 165, 74, 0.09);
}

.ending-card strong {
  display: block;
  margin-bottom: 5px;
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 0.83rem;
}

.ending-card span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 3;
  max-width: min(360px, calc(100% - 32px));
  padding: 12px 14px;
  border: 1px solid rgba(69, 184, 162, 0.42);
  border-radius: var(--radius);
  background: rgba(13, 17, 15, 0.94);
  color: var(--ink);
  box-shadow: 0 18px 40px var(--shadow);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1040px) {
  .game-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .side-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1380px);
    padding-top: 14px;
  }

  .masthead {
    align-items: start;
    flex-direction: column;
  }

  .top-actions,
  .icon-btn {
    width: 100%;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .icon-btn {
    justify-content: center;
    padding-inline: 8px;
  }

  .icon-btn span:last-child {
    display: none;
  }

  .scene-copy {
    padding: 18px 16px 6px;
  }

  .choice-list {
    padding: 14px 16px 18px;
  }

  .choice-btn {
    grid-template-columns: auto 1fr;
  }

  .choice-tags {
    grid-column: 2;
    justify-content: flex-start;
  }

  .side-stack {
    grid-template-columns: 1fr;
  }

  .ending-archive {
    grid-template-columns: 1fr;
  }

  .route-map {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
