/* ====================================================
   RPG Adventure — Dark Fantasy Styles
   ==================================================== */

:root {
  --rpg-bg:       #0a0a0f;
  --rpg-surface:  #12121a;
  --rpg-surface2: #1a1a26;
  --rpg-border:   rgba(201,168,76,.2);
  --rpg-gold:     #c9a84c;
  --rpg-gold-dim: rgba(201,168,76,.12);
  --rpg-text:     #e8dfc8;
  --rpg-muted:    #a89d85;
  --rpg-hp:       #cc3333;
  --rpg-xp:       #3a7abf;
  --rpg-danger:   #8b2020;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.rpg-body {
  font-family: 'IM Fell English', Georgia, serif;
  background: var(--rpg-bg);
  color: var(--rpg-text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* --- Back link ---------------------------------------------------- */
.rpg-back {
  display: inline-block;
  font-family: 'Cinzel', serif;
  font-size: .78rem;
  color: var(--rpg-muted);
  text-decoration: none;
  transition: color .2s;
}
.rpg-back:hover { color: var(--rpg-gold); }
.rpg-back--game {
  color: rgba(232,223,200,.7);
  font-size: .78rem;
}
.rpg-back--game:hover { color: #fff; }

/* ================================================================
   CHARACTER CREATION
   ================================================================ */

.rpg-screen { min-height: 100vh; }

.creation-wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.creation-card {
  background: var(--rpg-surface);
  border: 1px solid var(--rpg-border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  margin-top: 1rem;
  box-shadow: 0 0 60px rgba(201,168,76,.06);
}

.creation-header {
  text-align: center;
  margin-bottom: 2rem;
}
.creation-crest {
  font-size: 3rem;
  display: block;
  margin-bottom: .5rem;
  filter: drop-shadow(0 0 12px rgba(201,168,76,.5));
}
.creation-header h1 {
  font-family: 'Cinzel', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--rpg-gold);
  letter-spacing: .08em;
}
.creation-sub {
  color: var(--rpg-muted);
  font-size: .9rem;
  margin-top: .4rem;
  font-style: italic;
}

/* Form */
.creation-form { display: flex; flex-direction: column; gap: 1.5rem; }

.form-group { display: flex; flex-direction: column; gap: .5rem; }
.form-group label {
  font-family: 'Cinzel', serif;
  font-size: .8rem;
  font-weight: 600;
  color: var(--rpg-gold);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.form-label-optional {
  color: var(--rpg-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  font-style: italic;
}
.form-group input[type="text"] {
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 6px;
  color: var(--rpg-text);
  padding: .65rem .9rem;
  font-family: 'IM Fell English', Georgia, serif;
  font-size: 1rem;
}
.form-group input[type="text"]:focus {
  outline: none;
  border-color: var(--rpg-gold);
  box-shadow: 0 0 0 2px rgba(201,168,76,.15);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* Class grid */
.class-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
}
.class-card, .race-card {
  cursor: pointer;
}
/* Visually hidden but focusable + in the a11y tree (clip pattern, not display:none). */
.class-card input, .race-card input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: -1px;
  pointer-events: none;
}
.class-card input:focus-visible ~ .class-inner,
.race-card input:focus-visible ~ .race-inner {
  outline: 2px solid var(--rpg-gold);
  outline-offset: 2px;
}
.class-inner, .race-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: .75rem .5rem;
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  background: var(--rpg-bg);
  transition: all .2s;
  text-align: center;
}
.class-card input:checked ~ .class-inner,
.race-card input:checked ~ .race-inner {
  border-color: var(--rpg-gold);
  background: var(--rpg-gold-dim);
}
.class-inner:hover, .race-inner:hover {
  border-color: rgba(201,168,76,.5);
}
.class-icon, .race-icon { font-size: 1.4rem; }
.class-name, .race-name {
  font-family: 'Cinzel', serif;
  font-size: .75rem;
  font-weight: 600;
  color: var(--rpg-gold);
}
.class-desc {
  font-size: .68rem;
  color: var(--rpg-muted);
  font-style: italic;
}

/* Race grid */
.race-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
}

/* Buttons */
.rpg-btn {
  font-family: 'Cinzel', serif;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .06em;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all .2s;
  padding: .7rem 1.4rem;
}
.rpg-btn--gold {
  background: linear-gradient(135deg, #c9a84c, #a07830);
  color: #1a1000;
}
.rpg-btn--gold:hover { opacity: .9; transform: translateY(-1px); }
.rpg-btn--gold:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.rpg-btn--sm { padding: .35rem .75rem; font-size: .72rem; }
.rpg-btn--danger {
  background: rgba(139,32,32,.4);
  color: #e8a0a0;
  border: 1px solid rgba(139,32,32,.6);
}
.rpg-btn--danger:hover { background: rgba(139,32,32,.7); }

.rpg-error {
  color: #e08080;
  font-size: .82rem;
  font-style: italic;
  text-align: center;
  margin-top: .25rem;
}

.rpg-guest-hint {
  color: var(--rpg-muted);
  font-size: .78rem;
  font-style: italic;
  text-align: center;
  margin-top: .25rem;
}

/* ================================================================
   GAME SCREEN
   ================================================================ */

/* Scene banner */
.scene-banner {
  position: relative;
  height: 200px;
  overflow: hidden;
}
.scene-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .6s;
  transform-origin: 50% 50%;
}
.scene-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(10,10,15,.3) 0%, rgba(10,10,15,.85) 100%);
}
/* Radial vignette on top of the linear one — frames the scene, doubles as a
   cheap style-consistency trick across mismatched art. */
.scene-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, transparent 40%, rgba(5,5,8,.55) 100%);
}

/* ================================================================
   ATMOSPHERE — zero-generation motion. A still SVG becomes a shot.
   Alternating pan vectors (assigned in JS) so repeated scenes don't
   read identical. All disabled under prefers-reduced-motion below.
   ================================================================ */
.scene-banner img.scene-kenburns--a {
  animation: kenburns-a 26s ease-in-out infinite alternate;
}
.scene-banner img.scene-kenburns--b {
  animation: kenburns-b 30s ease-in-out infinite alternate;
}
@keyframes kenburns-a {
  0%   { transform: scale(1.06) translate(0, 0); }
  100% { transform: scale(1.16) translate(-2%, -1.5%); }
}
@keyframes kenburns-b {
  0%   { transform: scale(1.08) translate(0, 0); }
  100% { transform: scale(1.18) translate(2%, 1%); }
}

/* Drifting fog — two blurred radial layers moving opposite directions. */
.scene-fog {
  position: absolute;
  inset: -20% -30%;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: .16;
  filter: blur(18px);
}
.scene-fog--1 {
  background: radial-gradient(ellipse 45% 30% at 20% 60%, rgba(220,220,240,.5), transparent 70%);
  animation: fog-drift-1 38s linear infinite;
}
.scene-fog--2 {
  background: radial-gradient(ellipse 40% 26% at 75% 45%, rgba(200,210,255,.4), transparent 70%);
  animation: fog-drift-2 46s linear infinite;
}
@keyframes fog-drift-1 { 0% { transform: translateX(-4%); } 50% { transform: translateX(4%); } 100% { transform: translateX(-4%); } }
@keyframes fog-drift-2 { 0% { transform: translateX(5%); } 50% { transform: translateX(-5%); } 100% { transform: translateX(5%); } }

/* Per-scene mood tint, layered under the vignette so mismatched SVGs read
   as one palette (same trick as the background gradients below, applied
   to the image itself). */
.scene-tint { position: absolute; inset: 0; mix-blend-mode: multiply; opacity: .5; pointer-events: none; }
#game-screen[data-scene="dungeon"]  .scene-tint,
#game-screen[data-scene="defeat"]   .scene-tint { background: #2a1a10; }
#game-screen[data-scene="forest"]   .scene-tint { background: #0f2415; }
#game-screen[data-scene="meadow"]   .scene-tint { background: #16240f; }
#game-screen[data-scene="village"]  .scene-tint { background: #2a1c0a; }
#game-screen[data-scene="castle"]   .scene-tint { background: #101a2a; }
#game-screen[data-scene="combat"]   .scene-tint { background: #2a0f0a; }
#game-screen[data-scene="victory"]  .scene-tint { background: #2a2408; opacity: .3; }
.scene-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  gap: 1rem;
}
.scene-title {
  font-family: 'Cinzel', serif;
  font-size: .95rem;
  font-weight: 700;
  color: var(--rpg-gold);
  letter-spacing: .06em;
}

/* Layout */
.game-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: calc(100vh - 200px);
}

/* Sidebar */
.game-sidebar {
  background: var(--rpg-surface);
  border-right: 1px solid var(--rpg-border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  overflow-y: auto;
}

.char-portrait {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--rpg-gold-dim);
  border: 2px solid var(--rpg-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel', serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--rpg-gold);
  margin: 0 auto;
}

.char-name {
  text-align: center;
  font-family: 'Cinzel', serif;
  font-size: .9rem;
  font-weight: 700;
  color: var(--rpg-gold);
}
.char-class {
  font-size: .72rem;
  color: var(--rpg-muted);
  font-style: italic;
}

/* Character card: portrait + name on top, stats full-width beneath (the
   sidebar is only ~220px wide, too narrow for portrait and stats side by side). */
@media (min-width: 681px) {
  .profile-card { flex-direction: column; align-items: stretch; }
  .portrait-wrap { align-self: center; }
  .profile-card .profile-info { align-items: stretch; text-align: center; width: 100%; flex: none; }
  .profile-info .stat-block { text-align: left; margin-top: .35rem; }
  .profile-info .portrait-label { max-width: none; }
}

/* Stats */
.stat-block {
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.stat-row {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.stat-label {
  font-family: 'Cinzel', serif;
  font-size: .65rem;
  font-weight: 600;
  color: var(--rpg-muted);
  width: 28px;
  flex-shrink: 0;
  text-transform: uppercase;
}
.stat-bar {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  overflow: hidden;
}
.stat-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .5s ease;
}
.stat-fill--hp { background: linear-gradient(90deg, #8b2020, #e04444); }
.stat-fill--xp { background: linear-gradient(90deg, #1a4f8a, #3a8abf); }
.stat-value {
  font-size: .72rem;
  color: var(--rpg-text);
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.stat-gold {
  border-top: 1px solid var(--rpg-border);
  padding-top: .5rem;
  justify-content: space-between;
}
.stat-gold .stat-label { width: auto; }
.stat-gold .stat-value { color: var(--rpg-gold); font-weight: 600; }

/* Inventory */
.inventory-block {
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  padding: .75rem;
  flex: 1;
}
.inventory-title {
  font-family: 'Cinzel', serif;
  font-size: .7rem;
  font-weight: 600;
  color: var(--rpg-gold);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .5rem;
}
.inventory-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.inventory-list li {
  font-size: .78rem;
  color: var(--rpg-text);
  padding: .2rem .4rem;
  border-radius: 4px;
  background: rgba(255,255,255,.03);
}
.inv-empty { color: var(--rpg-muted) !important; font-style: italic; }

/* Clocks — the front's progress toward its impending doom. Visible clocks
   create dread; that's the point, so they're always shown, not tucked away. */
.clock-block {
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  padding: .65rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.clock-row { display: flex; flex-direction: column; gap: .3rem; }
.clock-name {
  font-size: .72rem;
  color: var(--rpg-muted);
  font-style: italic;
}
.clock-pips { display: flex; gap: .25rem; }
.pip {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--rpg-border);
  background: transparent;
  flex-shrink: 0;
}
.pip--filled { background: var(--rpg-danger); border-color: rgba(139,32,32,.6); }

/* Menaces — Wounds/Suspicion/Exhaustion. Capping one doesn't kill the run,
   it forces a consequence scene; shown as slim bars, not the HP treatment. */
.menace-block {
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  padding: .65rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.menace-row { display: flex; align-items: center; gap: .5rem; }
.menace-label {
  font-family: 'Cinzel', serif;
  font-size: .6rem;
  font-weight: 600;
  color: var(--rpg-muted);
  text-transform: uppercase;
  width: 62px;
  flex-shrink: 0;
}
.menace-bar {
  flex: 1;
  height: 5px;
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  overflow: hidden;
}
.menace-fill {
  height: 100%;
  background: linear-gradient(90deg, #6b4a1a, #c9a84c);
  border-radius: 999px;
  transition: width .5s ease;
}

/* Open threads — promises/debts owed to the story, with due dates. */
.thread-block {
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  padding: .65rem .75rem;
}
.thread-list { list-style: none; display: flex; flex-direction: column; gap: .35rem; margin-top: .4rem; }
.thread-item {
  font-size: .74rem;
  color: var(--rpg-text);
  line-height: 1.4;
  padding: .3rem .5rem;
  border-radius: 4px;
  background: rgba(255,255,255,.03);
  border-left: 2px solid var(--rpg-border);
}
.thread-item--overdue {
  border-left-color: #e06060;
  color: #f0a0a0;
}

/* Narrative log */
.game-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.narrative-log {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
  /* Centered reading column, not pinned to the sidebar's edge -- on a wide
     desktop viewport that left everything crammed against the sidebar with
     a large flat dead zone on the right. Capped a bit past choice-wrap's
     own 56em max-width so cards have a little margin inside the column. */
  max-width: 68em;
  width: 100%;
  margin: 0 auto;
}
.narrative-log::-webkit-scrollbar { width: 6px; }
.narrative-log::-webkit-scrollbar-track { background: transparent; }
.narrative-log::-webkit-scrollbar-thumb { background: var(--rpg-border); border-radius: 3px; }

/* Column, not row: a DM message stacks header -> check-banner -> bubble ->
   choices top to bottom. This was flex-row with only justify-content set,
   which put those as side-by-side columns instead of stacked — harmless-
   looking on a wide desktop viewport (each got its own column of width) but
   catastrophic on mobile, where msg-bubble was squeezed to ~50px and every
   word wrapped one character per line. align-items (not justify-content)
   now does the left/right alignment, since that's the cross axis in column mode. */
.msg { display: flex; flex-direction: column; }
.msg--user { align-items: flex-end; }
.msg--assistant { align-items: flex-start; }

.msg-bubble {
  max-width: min(78%, 34em);
  padding: .75rem 1rem;
  border-radius: 10px;
  /* Prose readability: the decorative IM Fell face (set on .rpg-body) has
     irregular historical letterforms that are a genuine hazard over a 30-turn
     read. Keep it for chrome/headers only; narrative gets a plain serif. */
  font-family: 'Literata', Georgia, 'Times New Roman', serif;
  font-size: 1rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg--assistant .msg-bubble {
  background: var(--rpg-surface2);
  border: 1px solid var(--rpg-border);
  color: var(--rpg-text);
  border-top-left-radius: 2px;
}
.msg--user .msg-bubble {
  background: var(--rpg-gold-dim);
  border: 1px solid rgba(201,168,76,.3);
  color: var(--rpg-gold);
  font-style: italic;
  border-top-right-radius: 2px;
}

/* DM header above each DM message */
.dm-header {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .3rem;
  padding-left: .2rem;
}
.dm-icon { font-size: .85rem; }
.dm-label {
  font-family: 'Cinzel', serif;
  font-size: .65rem;
  font-weight: 700;
  color: var(--rpg-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* Login-gate message shown when a guest hits the free-action limit */
.msg--login-gate .msg-bubble {
  background: var(--rpg-gold-dim);
  border: 1px solid rgba(201,168,76,.4);
}
.rpg-login-link {
  display: inline-block;
  margin-top: .4rem;
  color: var(--rpg-gold);
  font-weight: 700;
  text-decoration: underline;
}
.rpg-login-link:hover { color: var(--rpg-text); }

/* Narrative bubble paragraphs */
.msg-bubble p {
  margin: 0 0 .5rem;
  line-height: 1.7;
}
.msg-bubble p:last-child { margin-bottom: 0; }

/* Choice buttons */
.choice-wrap {
  /* Row + wrap, not a stacked column: 2-3 choices sit side by side as cards
     on desktop and wrap down as space runs out, rather than a single narrow
     vertical list. Buttons aren't paragraphs, so they get a wider cap than
     the prose bubble -- using more of the available width reads as a real
     "action bar" instead of a thin column stranded next to a lot of dead
     background. */
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: .6rem;
  margin-top: .75rem;
  max-width: min(96%, 56em);
}
.choice-btn {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem .85rem;
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: all .18s;
  flex: 1 1 260px;
  min-height: 44px;
  color: var(--rpg-text);
  font-family: 'IM Fell English', Georgia, serif;
  font-size: .92rem;
  line-height: 1.45;
}
.choice-btn:hover:not(:disabled) {
  border-color: var(--rpg-gold);
  background: var(--rpg-gold-dim);
  transform: translateY(-2px);
}
.choice-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.choice-btn--chosen {
  border-color: var(--rpg-gold) !important;
  background: rgba(201,168,76,.18) !important;
  opacity: 1 !important;
}
.choice-icon {
  font-size: 1rem;
  line-height: 1.4;
  min-width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}
.choice-text { flex: 1; }
/* Visible approach tag — the [STEALTH]/[SOCIAL]/etc taxonomy is what's being
   tested; surfacing it as a pill (not just a hover title) is the Fallen
   London affordance: know what a choice tests before you take it. */
.choice-tag {
  flex-shrink: 0;
  font-family: 'Cinzel', serif;
  font-size: .58rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--rpg-muted);
  border: 1px solid var(--rpg-border);
  border-radius: 999px;
  padding: .15rem .5rem;
}

/* Quest tracker block */
.quest-block {
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  padding: .65rem .75rem;
}
.quest-note {
  font-size: .76rem;
  color: var(--rpg-text);
  font-style: italic;
  line-height: 1.5;
  margin-top: .35rem;
  min-height: 1.2rem;
}

/* Check-outcome banner — declare/resolve beat for the roll behind an action.
   Colour AND a word, never colour alone (never rely on hue for meaning). */
.check-banner {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  align-self: flex-start;
  margin-bottom: .35rem;
  padding: .3rem .7rem;
  border-radius: 6px;
  font-family: 'Cinzel', serif;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .03em;
  border: 1px solid;
}
.check-banner--clean_success {
  color: #6fbf5a; border-color: rgba(111,191,90,.4); background: rgba(111,191,90,.1);
}
.check-banner--success_with_cost {
  color: var(--rpg-gold); border-color: rgba(201,168,76,.4); background: var(--rpg-gold-dim);
}
.check-banner--fail {
  color: #e06060; border-color: rgba(224,96,96,.4); background: rgba(224,96,96,.1);
}

/* Dice roll highlights */
.dice-roll {
  display: inline-block;
  background: rgba(201,168,76,.2);
  border: 1px solid rgba(201,168,76,.4);
  color: var(--rpg-gold);
  padding: .05rem .35rem;
  border-radius: 4px;
  font-style: normal;
  font-size: .88em;
}

/* Loading dots */
.loading-dots span {
  animation: blink 1.2s infinite;
  opacity: 0;
}
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0; }
  40% { opacity: 1; }
}

/* Action bar */
.action-bar {
  border-top: 1px solid var(--rpg-border);
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: .4rem;
  background: var(--rpg-surface);
}
/* The site-wide floating share button (.share-fab, position:fixed,
   bottom/right:24px, 52px circle) sits in the same bottom-right corner as
   the Act button on wide viewports — confirmed via elementFromPoint that
   clicks there were landing on the FAB instead of #action-btn, silently
   dropping the player's turn. Scoped to >680px only: below that breakpoint
   the action-bar sits higher up the page (guest hint text below it, shorter
   game-main budget) and reserving width here instead cascades into the dice
   panel/textarea wrapping and squeezing the narrative log back into a sliver. */
/* Clear the fixed Share FAB (bottom/right:24px, 52px circle; 46px+16px on
   ≤480px per share-button.css) without padding the whole action-bar — that
   shrank the textarea/dice-panel's width enough to force wrapping and ate
   into the narrative log's height on mobile. A margin on the button alone
   only costs the textarea a few px of flex-basis, not a whole row reflow. */
#action-btn { margin-right: 90px; }
@media (max-width: 680px) {
  #action-btn { margin-right: 0; }
}
.action-input-row {
  display: flex;
  gap: .75rem;
  align-items: flex-end;
}
.action-input {
  flex: 1;
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 6px;
  color: var(--rpg-text);
  padding: .6rem .8rem;
  font-family: 'IM Fell English', Georgia, serif;
  font-size: .92rem;
  resize: none;
  line-height: 1.4;
}
.action-input:focus { outline: none; border-color: var(--rpg-gold); }
.action-input::placeholder { color: var(--rpg-muted); font-style: italic; }

#game-error { padding: .25rem 1rem .5rem; }

/* ================================================================
   STORY TYPE SELECTOR
   ================================================================ */
.story-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .6rem;
}
.story-card { cursor: pointer; }
.story-card input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: -1px;
  pointer-events: none;
}
.story-card input:focus-visible ~ .story-inner {
  outline: 2px solid var(--rpg-gold);
  outline-offset: 2px;
}
.story-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: .75rem .5rem;
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  background: var(--rpg-bg);
  transition: all .2s;
  text-align: center;
}
.story-card input:checked ~ .story-inner {
  border-color: var(--rpg-gold);
  background: var(--rpg-gold-dim);
}
.story-inner:hover { border-color: rgba(201,168,76,.5); }
.story-icon { font-size: 1.4rem; }
.story-name {
  font-family: 'Cinzel', serif;
  font-size: .75rem;
  font-weight: 600;
  color: var(--rpg-gold);
}
.story-desc {
  font-size: .65rem;
  color: var(--rpg-muted);
  font-style: italic;
  line-height: 1.3;
}

/* ================================================================
   PROFILE CARD (character)
   ================================================================ */
.profile-card {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 10px;
  padding: .75rem;
}
.portrait-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
}
.profile-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.char-portrait-img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--rpg-gold);
  object-fit: cover;
  background: var(--rpg-gold-dim);
  display: block;
}
.portrait-label {
  font-family: 'Cinzel', serif;
  font-size: .75rem;
  font-weight: 600;
  color: var(--rpg-gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Turn counter */
.turn-block {
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  padding: .5rem .75rem;
}
.turn-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .35rem;
}
.turn-label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--rpg-muted);
  font-family: 'Cinzel', serif;
}
.turn-value {
  font-size: .72rem;
  font-family: 'Cinzel', serif;
  color: var(--rpg-gold);
  font-weight: 600;
}
.turn-bar-bg {
  height: 5px;
  background: rgba(255,255,255,.08);
  border-radius: 3px;
  overflow: hidden;
}
.turn-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--rpg-gold-dim), var(--rpg-gold));
  border-radius: 3px;
  transition: width .4s ease;
}

/* ================================================================
   DICE PANEL
   ================================================================ */
.dice-panel {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .2rem 0;
  flex-wrap: wrap;
}
.dice-label {
  font-family: 'Cinzel', serif;
  font-size: .68rem;
  color: var(--rpg-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-right: .1rem;
}
.dice-btn {
  font-family: 'Cinzel', serif;
  font-size: .72rem;
  font-weight: 700;
  padding: .22rem .48rem;
  border: 1px solid var(--rpg-border);
  border-radius: 4px;
  background: var(--rpg-bg);
  color: var(--rpg-gold);
  cursor: pointer;
  transition: all .15s;
  letter-spacing: .04em;
}
.dice-btn:hover {
  border-color: var(--rpg-gold);
  background: var(--rpg-gold-dim);
}
.dice-btn:active { transform: scale(.92); }
.dice-result {
  font-family: 'Cinzel', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--rpg-gold);
  min-width: 2.2rem;
  text-align: center;
  transition: color .1s;
}
.dice-result--rolling { color: var(--rpg-muted); }
.dice-result--settled {
  color: #fff;
  text-shadow: 0 0 8px var(--rpg-gold);
}

/* ================================================================
   TERMINAL OVERLAYS (defeat / victory)
   ================================================================ */
.terminal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  backdrop-filter: blur(4px);
}
.terminal-overlay--defeat  { background: rgba(10,5,5,.9); }
.terminal-overlay--victory { background: rgba(5,10,5,.9); }
.terminal-card {
  background: var(--rpg-surface);
  border: 1px solid var(--rpg-border);
  border-radius: 14px;
  padding: 2.5rem 2rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 0 80px rgba(201,168,76,.1);
}
.terminal-icon { font-size: 3.5rem; line-height: 1; }
.terminal-title {
  font-family: 'Cinzel', serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--rpg-gold);
}
.terminal-sub {
  font-size: .9rem;
  color: var(--rpg-muted);
  font-style: italic;
  line-height: 1.5;
}
.terminal-stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  background: var(--rpg-bg);
  border: 1px solid var(--rpg-border);
  border-radius: 8px;
  padding: .75rem;
}
.ts-item {
  font-family: 'Cinzel', serif;
  font-size: .75rem;
  color: var(--rpg-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
}
.ts-item strong {
  color: var(--rpg-gold);
  font-size: 1.15rem;
}

/* ================================================================
   SCENE ATMOSPHERE — full-screen background gradients
   ================================================================ */

/* Make panels semi-transparent so the background shows through */
.game-sidebar {
  background: rgba(12, 12, 18, 0.82) !important;
  backdrop-filter: blur(2px);
}
.action-bar {
  background: rgba(12, 12, 18, 0.88) !important;
  backdrop-filter: blur(2px);
}

/* Base transition on the game screen */
#game-screen {
  transition: background 1.4s ease;
}

/* Default / dungeon — cold underground stone, deep violet torch glow from below */
#game-screen,
#game-screen[data-scene="dungeon"] {
  background:
    radial-gradient(ellipse at 50% 110%, #3a1800 0%, #1a0830 35%, #08060f 75%);
}

/* Forest — silver-green moonlight through a dark canopy */
#game-screen[data-scene="forest"] {
  background:
    radial-gradient(ellipse at 30% -5%, #052210 0%, #031508 45%, #020a04 100%);
}

/* Meadow — open night sky, cool green ground glow, firefly warmth */
#game-screen[data-scene="meadow"] {
  background:
    radial-gradient(ellipse at 55% 0%, #0c1e04 0%, #071204 45%, #040a02 100%);
}

/* Village / town — warm amber lantern glow to the right */
#game-screen[data-scene="village"] {
  background:
    radial-gradient(ellipse at 68% 38%, #281604 0%, #160a02 45%, #0a0601 100%);
}

/* Castle — cold blue-grey stone, moonlight from high above */
#game-screen[data-scene="castle"] {
  background:
    radial-gradient(ellipse at 50% -8%, #0a1628 0%, #060d1a 42%, #030609 100%);
}

/* Combat — fiery orange-red from the right, blood on stone */
#game-screen[data-scene="combat"] {
  background:
    radial-gradient(ellipse at 78% 48%, #2e0606 0%, #180303 42%, #0a0202 100%);
}

/* Victory — warm golden radiance from the centre */
#game-screen[data-scene="victory"] {
  background:
    radial-gradient(ellipse at 50% 55%, #201900 0%, #120e00 45%, #080600 100%);
}

/* Defeat — grim dark crimson, near-black */
#game-screen[data-scene="defeat"] {
  background:
    radial-gradient(ellipse at 50% 50%, #1c0202 0%, #0e0101 55%, #070101 100%);
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 680px) {
  .form-row { grid-template-columns: 1fr; }
  .class-grid { grid-template-columns: repeat(4, 1fr); }
  .race-grid  { grid-template-columns: repeat(4, 1fr); }
  .story-grid { grid-template-columns: 1fr 1fr; }
  .class-desc, .story-desc { display: none; }
  .creation-card { padding: 1.5rem 1rem; }

  /* Shrink the banner and cap the sidebar so the story log keeps real height
     (was collapsing to a ~57px sliver at 375px). */
  .scene-banner { height: 120px; }
  /* Page flows naturally: the whole sidebar is reachable (no inner scroll
     box), then the story log + action bar get a full-screen-ish block. */
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto;
  }
  .game-main { height: max(520px, calc(100vh - 80px)); }
  /* Clear the fixed Share button at the end of the page. */
  .rpg-body { padding-bottom: 76px; }
  .game-sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: .75rem;
    padding: .75rem;
    border-right: none;
    border-bottom: 1px solid var(--rpg-border);
    /* Was 34vh, set when the sidebar only held the profile/turn/inventory
       cards. It now also carries clocks/menaces/threads, so the same budget
       left the narrative log a ~75-95px sliver below it (the story is the
       primary content; sidebar state is glanceable/scrollable by design,
       so it gets the smaller share here). */
    max-height: none;
    overflow: visible;
  }
  .char-portrait-img { width: 40px; height: 40px; }
  .portrait-label { font-size: .6rem; max-width: 44px; }
  /* Was display:none (invisible collected items on phones) — keep it, just compact. */
  .inventory-block { flex: 1 1 100%; padding: .5rem .6rem; order: 5; }
  .inventory-list { flex-direction: row; flex-wrap: wrap; }
  .clock-block, .menace-block, .thread-block { flex: 1; min-width: 160px; padding: .5rem .6rem; }
  .stat-block { flex: 1; min-width: 180px; }
  /* 40px minimum tap target for dice on touch screens. */
  .dice-btn { min-height: 40px; padding: .35rem .7rem; font-size: .8rem; }
  .choice-wrap, .msg-bubble { max-width: 100%; }
  /* No FAB-clearance padding here (deliberately, see the min-width:681px
     rule above) — reserving ~86px of an already-narrow ~300-375px action
     bar forced the dice buttons and input row to wrap, which shrank the
     narrative-log's share of game-main back down to a ~75px sliver. The
     Share FAB/Act-button overlap was only observed on desktop; on mobile
     the log staying readable is the higher-priority constraint. */
}

/* ================================================================
   REDUCED MOTION — instant reveal, no fades, dice settle immediately.
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
  #game-screen { transition: none; }
  #scene-img { transition: none !important; }
  .loading-dots span { animation: none; opacity: 1; }
  .stat-fill, .turn-bar-fill, .menace-fill { transition: none; }
  .choice-btn:hover:not(:disabled) { transform: none; }
  .dice-result--rolling, .dice-result--settled { transition: none; }
  .scene-banner img.scene-kenburns--a,
  .scene-banner img.scene-kenburns--b { animation: none; transform: none; }
  .scene-fog--1, .scene-fog--2 { animation: none; opacity: .08; }
}
