:root {
  color-scheme: light;
  --base: #f5eee2;
  --panel: #fff9ed;
  --ink: #26342e;
  --soft: #526358;
  --accent: #235444;
  --gold: #92513b;
  --line: #d9cfbd;
  --deep-green: #142e26;
  --brass: #d1ae71;
}

body {
  min-height: 100svh;
  background: radial-gradient(ellipse at 78% 7%, #ead9bd 0%, transparent 55%), var(--base);
}
header {
  height: calc(54px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  background: var(--deep-green);
  color: #fff3da;
  border-color: #574d35;
}
.brand { letter-spacing: -.03em; }
.logo { background: #f1d8a8; color: var(--deep-green); }
header .quiet {
  border-color: #ab9468;
  color: #fff3da;
}
header .quiet:hover { background: #2c4839; }
.eyebrow, .card small, .reply small { color: var(--gold); letter-spacing: .08em; }
.quiet { border-color: #b7ad9e; }
.quiet:hover { background: #eee7da; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: #21463b; }
.primary:active, .reply:active { transform: scale(.985); }
button:focus-visible, [tabindex="0"]:focus-visible, .story-card:focus-visible, .back-library:focus-visible {
  outline-color: #976138;
}

.library-shell { padding: 26px 16px 36px; }
.library-shell h1 { font-size: clamp(2.6rem, 10vw, 4.5rem); }
.library-shell h1 i { color: #77533c; }
.library-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 22px; }
.card { background: var(--panel); border-color: var(--line); }
.story-card {
  grid-template-columns: minmax(0, 40%) minmax(0, 1fr);
  border: 1px solid #a48657;
  border-radius: 19px;
  background: radial-gradient(ellipse at 0% 100%, #38594a, transparent 70%), linear-gradient(145deg, #223e32, var(--deep-green));
  color: #fff1d8;
  box-shadow: 0 12px 24px #34372230;
}
.story-card:active { transform: scale(.99); }
.story-card img {
  width: calc(100% - 12px);
  margin: 6px;
  border: 1px solid #c8a77380;
  border-radius: 13px;
  background: var(--deep-green);
}
.story-card .game-card-copy { padding: 12px 12px 12px 8px; }
.story-card h2 { font-size: clamp(1.5rem, 6vw, 2.3rem); line-height: 1.05; }
.story-card p { font-size: .86rem; line-height: 1.4; color: #f2e4cc; margin: .4rem 0 .55rem; }
.story-card .game-card-meta {
  color: #f1d49c;
  border-top: 1px solid #d1ae714d;
  padding-top: .4rem;
}
.game-card-cta {
  border-radius: 999px;
  padding: .25rem .65rem;
  background: #f1d8a8;
  color: var(--deep-green);
}
.cover { color: #fff9ef; }
.cover:after { background: linear-gradient(0deg, #141612 0%, #141612db 24%, #14161230 58%, transparent 75%); }
.cover-image { object-position: center 25%; }
.cover .eyebrow, .scene-art .eyebrow { color: #fff0d9; }
.cover-copy p { color: #fff5e9; }
.cover .primary { background: #f1dfc6; color: #292a23; }
.back-library, .card-icon { color: var(--accent); }
.guide-progress { flex-wrap: wrap; }
.segments b { background: #d2c8b9; }
.card.current, .card:enabled:hover { background: #e5efe7; border-color: #6a927e; }
.chapter-thumb { background: #ddd0bd; }

.game {
  --art-height: clamp(140px, 25dvh, 240px);
  height: calc(100dvh - 54px - env(safe-area-inset-top));
}
.game .scene-art {
  height: var(--art-height);
  padding: 12px 16px;
  align-items: flex-end;
  color: #fff9ef;
  background: #343a2f !important;
}
.game .scene-art .chapter-art {
  display: block;
  object-position: center 10%;
}
.game .scene-art:after {
  display: block;
  background: linear-gradient(to top, #13251feb, #13251f42 40%, transparent 70%);
}
.scene-art > div { display: block; }
.scene-art h1 { font-size: clamp(1.45rem, 5.6vw, 2.1rem); margin-top: 3px; text-shadow: 0 1px 9px #101c16; }
.scene-art p { display: none; }
.image-toggle {
  position: absolute;
  top: 8px;
  right: max(12px, env(safe-area-inset-right));
  margin: 0;
  min-height: 44px;
  border-color: #f2d6a0a8;
  background: #182d24e8;
  color: #fff3da;
  border-radius: 999px;
}
.phone {
  background: radial-gradient(ellipse at 12% 10%, #fffaf0 0%, transparent 65%), var(--base);
}
.chat-head { position: relative; min-height: 54px; gap: 9px; background: var(--panel); }
.chat-head:after {
  content: "";
  position: absolute;
  inset: auto 0 -1px;
  height: 2px;
  background: linear-gradient(90deg, #95623d, var(--brass));
  transform: scaleX(var(--chapter-progress, 0));
  transform-origin: left;
  transition: transform .2s ease;
}
.avatar { flex: 0 0 32px; border-color: #94784e; background-size: cover; background-position: center top; }
.chat-identity { flex: 1; min-width: 0; line-height: 1.25; }
.chat-identity strong { font-size: .95rem; }
.chat-identity small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .75rem; }
.chat-head #counter {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  background: #efe1c7;
  color: #57442b;
  border-radius: 999px;
  padding: 2px 8px;
}
.history-toggle {
  align-self: center;
  margin: 0;
  min-height: 44px;
  padding-inline: 8px;
  border-color: #b7c9bd;
  background: #f1f6f1;
  color: var(--accent);
}
#transcript { overscroll-behavior-y: contain; padding-block: 10px; }
.bubble { padding: 8px 12px; font-size: .95rem; }
.theirs { background: #fffcf7; border: 1px solid #ded5c7; }
.mine { background: #284f40; color: #fff9eb; }
.narration { color: #555e50; padding: 4px 2px; font-size: 1rem; }
#responses {
  flex: none;
  max-height: 48%;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  background: linear-gradient(135deg, #244338, var(--deep-green) 60%);
  border-top-color: #a17f4b;
  color: #fff6e6;
  padding: 5px 12px calc(5px + env(safe-area-inset-bottom));
}
#responses > .eyebrow { display: none; }
.replies {
  gap: 0;
  margin: 0;
  border: 1px solid #998356;
  border-radius: 11px;
  background: #ffffff06;
}
.reply {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 10px;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 5px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: .94rem;
  overflow-wrap: anywhere;
}
.reply + .reply { border-top: 1px solid #d1ae7140; }
.reply:first-child { border-radius: 10px 10px 0 0; }
.reply:last-child { border-radius: 0 0 10px 10px; }
.reply:only-child { border-radius: 10px; }
.reply small { display: none; }
.reply:after {
  content: "";
  width: 7px;
  height: 7px;
  border: solid var(--brass);
  border-width: 1.5px 1.5px 0 0;
  transform: rotate(45deg);
}
.reply:hover, .reply:active { background: #ffffff1b; }
.reply:focus-visible { outline: 2px solid #ffdda0; outline-offset: -3px; }
#responses .typing { color: #f3dcb4; padding: 7px 4px; }
#responses .next { background: #efd8ad; color: #25372e; }
.ending:after { background: #18231a55; }
.ending-card, dialog { background: var(--panel); border-color: var(--line); }
.ending-card blockquote { color: var(--soft); }
.image-viewer { background: #151915; border-color: #5d6259; }
.image-viewer__close { background: #20261fe8; border-color: #858c80; }

@media (max-height: 700px) {
  .game { --art-height: clamp(105px, 20dvh, 135px); }
  .game .scene-art { padding-block: 8px; }
  .chat-head { min-height: 48px; }
}

@media (max-height: 500px) {
  .game { height: auto; min-height: calc(100dvh - 54px - env(safe-area-inset-top)); overflow: visible; }
  .phone { min-height: 340px; height: auto; }
}
