/* =========================================================================
   World of Adventure — native-web UI
   Event-driven rendering with real typography and button-based choices.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,400;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --bg:         #0d0e10;
  --bg-card:    #15181c;
  --bg-elev:    #1d2026;
  --border:     #2a2f36;
  --border-mut: #232830;
  --fg:         #d9d3c7;
  --fg-dim:     #8a8578;
  --accent:     #5a3;
  --accent-h:   #7c4;
  --danger:     #c44;

  --c-red:      #e07c75;
  --c-green:    #88d099;
  --c-yellow:   #f0cf6a;
  --c-blue:     #7ab0e0;
  --c-purple:   #b99ce0;
  --c-orange:   #e8a862;
  --c-cyan:     #7fd0c2;

  --font-mono:  "JetBrains Mono", "Fira Code", "Consolas", "Menlo", monospace;
  --font-prose: "Crimson Pro", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  padding: 0;
  font-family: var(--font-prose);
  font-size: 16px;
  line-height: 1.55;
  overscroll-behavior-y: none;
}

/* ---------- Landing ---------- */

body.landing {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5em;
}
.landing-card {
  max-width: 540px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: .5em;
  padding: 2em 1.5em;
}
.landing-card h1 {
  color: var(--c-yellow);
  font-size: 1.8em;
  margin: 0 0 .5em;
  font-weight: 700;
}
.landing-card h1 small {
  display: block;
  font-size: .55em;
  color: var(--fg-dim);
  font-weight: 400;
  letter-spacing: .1em;
  margin-top: .3em;
  text-transform: uppercase;
}
.landing-card .blurb { line-height: 1.6; }
.landing-card .blurb.small { color: var(--fg-dim); font-size: .95em; }
.landing-card .sub { color: var(--fg-dim); font-size: .85em; margin: 1em 0 0; }
.landing-card button {
  background: var(--accent);
  color: #0b0c0d;
  border: none;
  padding: .9em 1.2em;
  font: inherit;
  font-weight: 700;
  border-radius: .3em;
  cursor: pointer;
  width: 100%;
  margin-top: 1.5em;
  font-size: 1.1em;
}
.landing-card button:hover { background: var(--accent-h); }
.landing-card button:disabled { opacity: .5; cursor: default; }

/* ---------- Play shell ---------- */

body.play {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.play-header {
  flex: 0 0 auto;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: .4em .8em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8em;
  font-size: .8em;
  color: var(--fg-dim);
  font-family: var(--font-mono);
}
.play-header .brand { color: var(--c-yellow); font-weight: 700; }
.play-header .session { color: var(--fg-dim); font-size: .85em; flex: 1; text-align: center; }
.play-header #mute-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: .3em;
  padding: .25em .55em;
  cursor: pointer;
  font-size: 1em;
}
.play-header #mute-toggle:hover { background: var(--bg-elev); }

/* ---------- HUD ---------- */

.hud {
  flex: 0 0 auto;
  width: 100%;
  background: linear-gradient(180deg, #16191e 0%, #12151a 100%);
  border-bottom: 1px solid var(--border);
  padding: .55em .75em .65em;
  display: flex;
  flex-direction: column;
  gap: .45em;
  transition: opacity .2s, max-height .25s ease, padding .25s ease;
  font-family: var(--font-mono);
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
/* Collapsed mode — keeps the identity row + one thin composite bar row,
   hides the rest. Toggled by the ▾ button in the header. */
.hud.collapsed { padding: .35em .75em .4em; gap: .25em; }
.hud.collapsed .hud-stats,
.hud.collapsed .hud-enemy,
.hud.collapsed .hud-player-effects { display: none; }
.hud.collapsed .hud-id { gap: .45em; }
.hud.collapsed .hud-collapse { transform: rotate(180deg); }
.hud.hud-empty { opacity: .35; }

/* -- Identity row (avatar + name/class + gold) -- */
.hud-id {
  display: flex;
  align-items: center;
  gap: .6em;
}
.hud-avatar {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: .3em;
  font-size: 1.2em;
  font-weight: 700;
  background: linear-gradient(180deg, #2a2f36, #1a1e24);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  text-transform: uppercase;
  font-family: var(--font-prose);
  letter-spacing: 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04), 0 1px 2px rgba(0,0,0,.35);
}
.hud-avatar[data-cls="warrior"] { background: linear-gradient(180deg, #6a2a28, #3d1715); color: var(--c-red); border-color: #7a3836; }
.hud-avatar[data-cls="warlock"] { background: linear-gradient(180deg, #3a2658, #22143a); color: var(--c-purple); border-color: #4a306a; }
.hud-avatar[data-cls="shaman"]  { background: linear-gradient(180deg, #1c4a44, #0c2a28); color: var(--c-cyan); border-color: #2a5c56; }
.hud-avatar[data-cls="hunter"]  { background: linear-gradient(180deg, #2c4a2a, #122810); color: var(--c-green); border-color: #3c5c3a; }
.hud-avatar[data-cls="rogue"]   { background: linear-gradient(180deg, #5a4418, #2a1d08); color: var(--c-yellow); border-color: #6a5428; }
.hud-avatar[data-cls="priest"]  { background: linear-gradient(180deg, #4a4a58, #202028); color: #eae5d9; border-color: #5c5c6a; }
.hud-avatar[data-cls="mage"]    { background: linear-gradient(180deg, #1c3c5c, #0a2038); color: var(--c-blue); border-color: #2c4c6e; }

.hud-id-stack { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 0; }
.hud-name {
  font-family: var(--font-prose);
  font-weight: 700;
  font-size: 1.05em;
  color: var(--fg);
  letter-spacing: .01em;
  line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hud-char-name { color: var(--c-yellow); }
.hud-sub {
  font-family: var(--font-mono);
  font-size: .72em;
  color: var(--fg-dim);
  letter-spacing: .04em;
  text-transform: uppercase;
  display: flex; gap: .35em; align-items: baseline;
  line-height: 1.3;
}
.hud-dot { opacity: .5; }
.hud-level { color: var(--c-green); font-weight: 600; }
.hud-level-num { color: var(--c-green); }
.hud-gold {
  display: flex;
  gap: .3em;
  align-items: center;
  color: var(--c-orange);
  font-family: var(--font-mono);
  font-size: .85em;
  font-weight: 700;
  padding: .15em .5em;
  background: rgba(232, 168, 98, .08);
  border: 1px solid rgba(232, 168, 98, .2);
  border-radius: .25em;
  flex: 0 0 auto;
}
.hud-gold-icon { font-size: 1.05em; }

/* HUD collapse toggle — small chevron button to the right of gold. */
.hud-collapse {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: 1em;
  border-radius: .25em;
  cursor: pointer;
  transition: background .1s, transform .25s;
}
.hud-collapse:hover { background: var(--bg-elev); color: var(--fg); }

/* Status-effect badges — appear under enemy HP (DoTs) and below HUD
   (player HoTs / curses). One pill per active effect with name + rounds. */
.hud-effects {
  display: flex;
  flex-wrap: wrap;
  gap: .3em;
  padding: 0;
}
.hud-effects:empty { display: none; }
.hud-player-effects { margin-top: .15em; }
.hud-effect {
  font-family: var(--font-mono);
  font-size: .7em;
  letter-spacing: .03em;
  padding: .2em .5em;
  border-radius: 999px;
  border: 1px solid var(--border-mut);
  background: var(--bg-elev);
  color: var(--fg);
  white-space: nowrap;
}
.hud-effect .hud-effect-icon { margin-right: .3em; opacity: .85; }
.hud-effect .hud-effect-rounds { color: var(--fg-dim); margin-left: .3em; font-weight: 600; }
.hud-effect.dot   { color: var(--c-red);    border-color: rgba(224, 124, 117, .35); background: rgba(224, 124, 117, .08); }
.hud-effect.hot   { color: var(--c-green);  border-color: rgba(136, 208, 153, .35); background: rgba(136, 208, 153, .08); }
.hud-effect.buff  { color: var(--c-blue);   border-color: rgba(122, 176, 224, .35); background: rgba(122, 176, 224, .08); }
.hud-effect.debuff{ color: var(--c-purple); border-color: rgba(185, 156, 224, .35); background: rgba(185, 156, 224, .08); }

/* -- Stats (HP / Resource / XP) -- */
.hud-stats { display: flex; flex-direction: column; gap: .22em; }
.hud-stat {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: .5em;
  align-items: center;
  font-family: var(--font-mono);
  font-size: .78em;
}
.stat-icon {
  font-size: .95em;
  text-align: center;
  line-height: 1;
  opacity: .9;
}
.stat-bar {
  position: relative;
  height: 10px;
  background: #0a0c10;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.6), 0 0 0 1px var(--border-mut);
}
.stat-fill {
  position: absolute; inset: 0;
  width: 0%;
  border-radius: 999px;
  transition: width .35s cubic-bezier(.2,.9,.3,1);
}
/* Subtle glossy highlight line along the top of each bar */
.stat-shine {
  position: absolute;
  top: 1px; left: 2px; right: 2px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255,255,255,.25) 0%, rgba(255,255,255,.08) 100%);
  pointer-events: none;
}
.stat-values {
  font-variant-numeric: tabular-nums;
  font-size: .9em;
  color: var(--fg);
  font-weight: 600;
  min-width: 4.5em;
  text-align: right;
  white-space: nowrap;
}
.stat-sep { opacity: .4; margin: 0 .15em; }

/* Bar colors */
.stat-hp .stat-icon     { color: var(--c-red); }
.stat-hp .stat-fill     { background: linear-gradient(180deg, #ef8a82 0%, #c24840 60%, #8a2a22 100%); box-shadow: 0 0 8px rgba(224,124,117,.35); }
.stat-hp.low .stat-fill { animation: pulse-danger 1.2s ease-in-out infinite; }

.stat-res .stat-icon { color: var(--c-blue); }
.stat-res .stat-fill { background: linear-gradient(180deg, #8cc0e8 0%, #4878b0 60%, #2a4c78 100%); box-shadow: 0 0 8px rgba(122,176,224,.3); }
.stat-res.rage   .stat-icon { color: var(--c-orange); }
.stat-res.rage   .stat-fill { background: linear-gradient(180deg, #f0b878 0%, #b07030 60%, #724818 100%); box-shadow: 0 0 8px rgba(232,168,98,.35); }
.stat-res.energy .stat-icon { color: var(--c-yellow); }
.stat-res.energy .stat-fill { background: linear-gradient(180deg, #f6da7a 0%, #a08038 60%, #604818 100%); box-shadow: 0 0 8px rgba(240,207,106,.3); }

.stat-xp .stat-icon { color: var(--c-purple); }
.stat-xp .stat-fill { background: linear-gradient(180deg, #c9aff0 0%, #7858b8 60%, #4c3878 100%); box-shadow: 0 0 6px rgba(185,156,224,.3); }
.stat-xp { font-size: .74em; }
.stat-xp .stat-bar { height: 6px; }

/* Enemy panel */
.hud-enemy {
  display: none;
  border-top: 1px solid var(--border-mut);
  padding-top: .4em;
  margin-top: .15em;
  flex-direction: column;
  gap: .25em;
}
.hud-enemy.visible { display: flex; }
.hud-enemy-head {
  display: flex;
  gap: .45em;
  align-items: center;
  font-family: var(--font-mono);
  font-size: .78em;
}
.hud-enemy-icon { color: var(--c-red); font-size: 1em; }
.hud-enemy-name {
  flex: 1 1 auto;
  color: var(--c-red);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hud-enemy-lvl {
  color: var(--fg-dim);
  font-size: .92em;
}
.stat-enemy-hp .stat-icon { color: var(--c-red); opacity: .75; }
.stat-enemy-hp .stat-fill {
  background: linear-gradient(180deg, #b04848 0%, #702828 60%, #401818 100%);
  box-shadow: 0 0 6px rgba(176,72,72,.3);
}

@keyframes pulse-danger {
  50% { filter: brightness(1.35); box-shadow: 0 0 12px rgba(228,60,60,.55); }
}

/* Bar flash when HP drops */
.stat-bar.hit { animation: hit-flash .45s ease-out; }
@keyframes hit-flash {
  0%   { box-shadow: inset 0 1px 2px rgba(0,0,0,.6), 0 0 0 2px rgba(224,124,117,.9), 0 0 12px rgba(224,124,117,.6); }
  100% { box-shadow: inset 0 1px 2px rgba(0,0,0,.6), 0 0 0 1px var(--border-mut), 0 0 0 rgba(224,124,117,0); }
}

/* ---------- Log (scene chunk container) ---------- */

#log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1em 1.2em 1.2em;
  font-family: var(--font-prose);
  -webkit-overflow-scrolling: touch;
}

/* ---------- Headings ---------- */

#log h1.scene-title {
  font-family: var(--font-prose);
  color: var(--c-yellow);
  font-size: 1.7em;
  font-weight: 700;
  margin: 0 0 .5em;
  padding-bottom: .25em;
  border-bottom: 1px solid var(--border);
  letter-spacing: .01em;
}
#log h2.section-title {
  font-family: var(--font-prose);
  color: var(--c-purple);
  font-size: 1.2em;
  font-weight: 700;
  margin: 1em 0 .4em;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ---------- Prose blocks ---------- */

#log p.prose {
  font-family: var(--font-prose);
  margin: .4em 0;
  line-height: 1.55;
}
#log p.prose-narrator {
  color: var(--c-cyan);
  font-style: italic;
  font-size: 1.05em;
}
#log p.prose-stage {
  color: var(--fg-dim);
  font-size: .95em;
  font-style: italic;
}

/* ---------- Dialog ---------- */

#log .dialog-block {
  margin: .5em 0;
  padding-left: .8em;
  border-left: 3px solid var(--c-yellow);
}
#log .dialog-speaker {
  display: block;
  font-family: var(--font-mono);
  font-size: .82em;
  color: var(--c-yellow);
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: .15em;
}
#log .dialog-text {
  display: block;
  font-style: italic;
  color: var(--fg);
}

/* Blinking cursor shown while a dialog line is mid-typewriter.
   Uses a 2 px wide bar (like a real text-insertion cursor) instead of a
   block glyph. */
#log .dialog-text.typewriter-active::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: .82em;
  background: var(--c-yellow);
  margin-left: 2px;
  vertical-align: -.05em;
  animation: tw-cursor-blink .6s step-end infinite;
}
@keyframes tw-cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ---------- Combat lines (card-row with icon + message + amount) ---------- */

#log .combat-line {
  display: flex;
  align-items: center;
  gap: .5em;
  padding: .35em .6em;
  margin: .25em 0;
  background: rgba(255,255,255,.025);
  border-left: 3px solid var(--border);
  border-radius: .25em;
  font-family: var(--font-mono);
  font-size: .8em;
  line-height: 1.35;
}
/* Icon prefix — differentiates attacker type at a glance. */
#log .combat-line::before {
  content: "·";
  flex: 0 0 1.1em;
  text-align: center;
  color: var(--fg-dim);
  font-size: 1.05em;
  opacity: .9;
}
#log .combat-line.actor-player::before { content: "⚔"; color: var(--c-green); }
#log .combat-line.actor-enemy::before  { content: "✗"; color: var(--c-red); }
#log .combat-line.combat-heal::before  { content: "✦"; color: var(--c-green); }
#log .combat-line.combat-crit::before  { content: "⚡"; color: var(--c-yellow); }

#log .combat-line.actor-player { border-left-color: rgba(136, 208, 153, .6); }
#log .combat-line.actor-enemy  { border-left-color: rgba(224, 124, 117, .6); background: rgba(224, 124, 117, .04); }
#log .combat-line.combat-crit  { border-left-color: var(--c-yellow); background: rgba(240, 207, 106, .07); }
#log .combat-line.combat-heal  { border-left-color: rgba(136, 208, 153, .6); background: rgba(136, 208, 153, .04); }

#log .combat-msg    { flex: 1 1 auto; color: var(--fg); min-width: 0; }
#log .combat-amount {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 1.05em;
  padding: .1em .5em;
  border-radius: .2em;
  background: rgba(224, 124, 117, .15);
  color: var(--c-red);
  min-width: 2.4em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
#log .combat-line.combat-heal .combat-amount  { background: rgba(136, 208, 153, .15); color: var(--c-green); }
#log .combat-line.combat-crit .combat-amount  { background: rgba(240, 207, 106, .18); color: var(--c-yellow); font-size: 1.2em; }
#log .combat-line.combat-xp   .combat-amount  { background: rgba(240, 207, 106, .12); color: var(--c-yellow); }

/* ---------- Notices (success / warning / failure / xp / gold) ---------- */

#log .notice {
  font-family: var(--font-mono);
  padding: .35em .6em;
  border-radius: .25em;
  margin: .3em 0;
  font-size: .9em;
  display: inline-block;
}
#log .notice-success { color: var(--c-green);  background: rgba(136, 208, 153, .08); border-left: 3px solid var(--c-green); }
#log .notice-warning { color: var(--c-orange); background: rgba(232, 168, 98, .08);  border-left: 3px solid var(--c-orange); }
#log .notice-failure { color: var(--c-red);    background: rgba(224, 124, 117, .08); border-left: 3px solid var(--c-red); }
#log .notice-xp      { color: var(--c-yellow); background: rgba(240, 207, 106, .08); border-left: 3px solid var(--c-yellow); }
#log .notice-gold    { color: var(--c-orange); background: rgba(232, 168, 98, .08); border-left: 3px solid var(--c-orange); font-weight: 700; }

/* ---------- Loot ---------- */

#log .loot-line {
  margin: .2em 0;
  font-family: var(--font-mono);
  font-size: .92em;
}
#log .loot-label { color: var(--c-blue); margin-right: .4em; font-weight: 600; }
.loot-q-common    { color: #eae5d9; }
.loot-q-uncommon  { color: var(--c-green); }
.loot-q-rare      { color: var(--c-blue); }
.loot-q-epic      { color: var(--c-purple); }
.loot-q-poor      { color: var(--fg-dim); }

/* ---------- Legacy lines (print() fallback) ---------- */

#log .legacy-line {
  font-family: var(--font-mono);
  font-size: .9em;
  color: var(--fg);
  white-space: pre-wrap;
}

/* ---------- Choices ---------- */

.choices {
  margin: 1em 0 .4em;
  padding: .8em .9em;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: .4em;
}
.choices-prompt {
  font-family: var(--font-mono);
  color: var(--fg-dim);
  font-size: .82em;
  margin-bottom: .5em;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.choices-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .45em;
}
/* Combat puts its main actions (auto / spells / flee) in a 2-column
   grid on mobile to fit more options in-viewport without scrolling. */
.choices-combat {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .4em;
}

/* Pre-combat prep menu: same 2-column layout so Fight / Inventory /
   Character / Quests / Talents don't stack vertically and push the
   "You face X" stage line off-screen on mobile. */
.choices-kind-prep .choices-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .4em;
}

/* Mid-cast prompt — subtle purple tint to reinforce that the player is
   in the middle of a spell, not a normal free-action turn. */
.choices-kind-casting {
  border-color: rgba(185, 156, 224, .45);
  background: rgba(185, 156, 224, .04);
}
.choices-kind-casting .choices-prompt {
  color: var(--c-purple);
}

/* Compact secondary row for the "View" buttons (Inventory, Character,
   Quests) that would otherwise steal vertical space in combat. Three
   small buttons on one line. */
.choices-submenu {
  display: flex;
  gap: .35em;
  align-items: center;
  margin-top: .45em;
  padding-top: .45em;
  border-top: 1px dashed var(--border-mut);
}
.choices-submenu-label {
  font-family: var(--font-mono);
  font-size: .7em;
  color: var(--fg-dim);
  letter-spacing: .1em;
  text-transform: uppercase;
  padding-right: .3em;
  flex: 0 0 auto;
}
.choices-submenu .choice.choice-compact {
  flex: 1 1 0;
  min-height: 44px;                 /* meets iOS + Android tap-target floor */
  padding: .55em .4em;
  text-align: center;
  align-items: center;
  flex-direction: row;
  justify-content: center;
}
.choices-submenu .choice.choice-compact .choice-title {
  font-size: .88em;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.choice {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: .3em;
  color: var(--fg);
  padding: .75em .9em;
  font: inherit;
  font-size: 1em;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: .2em;
  transition: background .1s, transform .05s, border-color .1s;
  font-family: var(--font-prose);
}
.choice:hover:not(:disabled) { background: var(--bg-elev); border-left-color: var(--accent-h); }
.choice:active:not(:disabled) { transform: translateY(1px); }
.choice:disabled { opacity: .45; cursor: default; }
.choice.default { box-shadow: 0 0 0 2px rgba(90, 170, 50, .35); }
.choice-auto     { border-left-color: var(--c-red); }
.choice-spell    { border-left-color: var(--c-purple); }
.choice-menu     { border-left-color: var(--c-blue); }
.choice-flee     { border-left-color: var(--c-orange); }
.choice-yes      { border-left-color: var(--c-green); }
.choice-no       { border-left-color: var(--c-red); }
.choice-cancel   { border-left-color: var(--fg-dim); }
.choice-continue { border-left-color: var(--accent); }
.choice-title {
  font-weight: 700;
  font-size: 1.05em;
}
.choice-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5em .9em;
  font-family: var(--font-mono);
  font-size: .78em;
  color: var(--fg-dim);
  margin-top: .1em;
}
.choice-damage { color: var(--c-red); font-weight: 600; }
.choice-cost   { color: var(--c-blue); }
.choice-desc   { flex-basis: 100%; color: var(--fg-dim); font-style: italic; }
.choice-disabled-reason { color: var(--c-orange); }

/* Mobile: keep description visible on combat cards but collapsed to a
   single smaller italic line under the meta row. No more hiding
   information that desktop players get. */
@media (max-width: 600px) {
  .choices-combat .choice { padding: .4em .5em; }
  .choices-combat .choice-title { font-size: .86em; }
  .choices-combat .choice-meta { gap: .25em .45em; font-size: .67em; }
  .choices-combat .choice-desc {
    flex-basis: 100%;
    font-size: .66em;
    font-style: italic;
    color: var(--fg-dim);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

@media (min-width: 500px) {
  .choices-grid:not(.choices-combat) { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .choices-combat { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* Desktop (≥900px) — ensure non-combat pickers use 2-3 columns since
   there's plenty of room. Class/race/difficulty menus render as a
   grid, not a single stacked column. */
@media (min-width: 900px) {
  .choices-grid:not(.choices-combat) {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }
}

/* Desktop keyboard shortcut badge — shows the data-send key on each
   choice card. Hidden on mobile (no keyboard) and on compact sub-row
   buttons. */
@media (min-width: 601px) {
  .choice { position: relative; }
  .choice:not(.choice-compact)::after {
    content: attr(data-send);
    position: absolute;
    top: .35em;
    right: .55em;
    font-family: var(--font-mono);
    font-size: .7em;
    font-weight: 700;
    color: var(--fg-dim);
    background: rgba(255,255,255,.06);
    padding: 0 .45em;
    border-radius: .2em;
    letter-spacing: .04em;
    text-transform: uppercase;
    opacity: .8;
  }
  .choice[data-send=""]::after { content: "↵"; }
}

/* ---------- Combat choices: collapse toggle + More panel ---------- */

/* Header row inside combat choices — prompt label on the left,
   collapse toggle on the right. */
.choices-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5em;
}
.choices-header-prompt {
  font-family: var(--font-mono);
  color: var(--fg-dim);
  font-size: .82em;
  letter-spacing: .05em;
  text-transform: uppercase;
}

/* ▾ / ▲ collapse button that shows/hides the action grid. */
.choices-collapse-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: .72em;
  padding: .2em .6em;
  border-radius: .25em;
  cursor: pointer;
  flex: 0 0 auto;
  line-height: 1;
  transition: background .1s, color .1s, border-color .1s;
  letter-spacing: .04em;
}
.choices-collapse-btn:hover {
  background: var(--bg-elev);
  color: var(--fg);
  border-color: var(--fg-dim);
}

/* Collapsed state — grid and More wrap vanish; only the header bar remains
   so the player can still tap ▲ to bring actions back. */
.choices-collapsed .choices-grid,
.choices-collapsed .choices-more-wrap {
  display: none;
}

/* More button — the single entry point for Flee / Bag / Sheet / Quests. */
.choices-more-wrap {
  margin-top: .45em;
  padding-top: .45em;
  border-top: 1px dashed var(--border-mut);
}
.choices-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45em;
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: .78em;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: .45em .75em;
  border-radius: .3em;
  cursor: pointer;
  min-height: 36px;
  transition: background .1s, color .1s, border-color .1s;
}
.choices-more-btn:hover,
.choices-more-expanded .choices-more-btn {
  background: var(--bg-elev);
  color: var(--fg);
  border-color: var(--c-blue);
}
.choices-more-arrow {
  display: inline-block;
  opacity: .75;
  font-size: .9em;
}

/* Panel is hidden until More is clicked. */
.choices-more-panel {
  display: none;
  grid-template-columns: repeat(2, 1fr);
  gap: .35em;
  margin-top: .4em;
}
.choices-more-expanded .choices-more-panel {
  display: grid;
}

/* ---------- Enemy modifier affix prefixes ---------- */
/* "Elite Gnoll", "Cursed Scorpid", "Gleaming Raptor" — pops the affix
   word so rare spawns feel rare. Italic + color + subtle glow matches
   the intent the CLI got from ANSI color codes. */

.mod-affix {
  font-style: italic;
  font-weight: 700;
  letter-spacing: .01em;
}
.mod-affix-elite    { color: var(--c-blue);   text-shadow: 0 0 6px rgba(122, 176, 224, .45); }
.mod-affix-cursed   { color: var(--c-purple); text-shadow: 0 0 6px rgba(185, 156, 224, .45); }
.mod-affix-gleaming { color: var(--c-yellow); text-shadow: 0 0 8px rgba(240, 207, 106, .55); }
.mod-affix-withered { color: var(--c-orange); opacity: .9; }
.mod-affix-furious  { color: var(--c-red);    text-shadow: 0 0 6px rgba(224, 124, 117, .5); }

/* ---------- Zone banner ---------- */

#log .zone-banner {
  margin: .6em 0 1em;
  padding: 1.4em 1em;
  border-radius: .4em;
  text-align: center;
  font-family: var(--font-prose);
  position: relative;
  overflow: hidden;
}
#log .zone-banner::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(13,14,16,.35) 0%, rgba(13,14,16,.7) 100%);
}
#log .zone-banner-sub {
  position: relative;
  color: var(--c-yellow);
  font-size: .85em;
  letter-spacing: .15em;
  text-transform: uppercase;
  opacity: .9;
  text-shadow: 0 1px 4px rgba(0,0,0,.9);
}
#log .zone-banner-title {
  position: relative;
  color: var(--c-yellow);
  font-size: 1.9em;
  font-weight: 700;
  letter-spacing: .03em;
  text-shadow: 0 2px 8px rgba(0,0,0,.9);
  margin-top: .1em;
}
.zone-valley     { background: linear-gradient(135deg, #3a2a1a 0%, #5c3a24 60%, #8a5a38 100%); }
.zone-durotar    { background: linear-gradient(135deg, #5c3020 0%, #8a4028 60%, #b05030 100%); }
.zone-echo       { background: linear-gradient(135deg, #163548 0%, #204858 60%, #2a6878 100%); }
.zone-razorhill  { background: linear-gradient(135deg, #3a2618 0%, #584028 60%, #806040 100%); }
.zone-crossroads { background: linear-gradient(135deg, #5c4a28 0%, #806840 60%, #b09868 100%); }
.zone-coldridge  { background: linear-gradient(135deg, #1c2838 0%, #385878 60%, #80a0c0 100%); }

/* ---------- Screen flash — crit / damage / heal reactions ---------- */

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  opacity: 0;
  box-shadow: inset 0 0 0 0 transparent;
  transition: opacity .35s ease-out;
}
body.flash-crit::after   { animation: flash-yellow .45s ease-out; }
body.flash-damage::after { animation: flash-red    .45s ease-out; }
body.flash-heal::after   { animation: flash-green  .45s ease-out; }
@keyframes flash-yellow {
  0%   { opacity: 1; box-shadow: inset 0 0 0 6px rgba(240, 207, 106, .85), inset 0 0 80px rgba(240, 207, 106, .35); }
  100% { opacity: 0; box-shadow: inset 0 0 0 6px rgba(240, 207, 106, 0); }
}
@keyframes flash-red {
  0%   { opacity: 1; box-shadow: inset 0 0 0 4px rgba(224, 84, 75, .7), inset 0 0 60px rgba(224, 84, 75, .3); }
  100% { opacity: 0; box-shadow: inset 0 0 0 4px rgba(224, 84, 75, 0); }
}
@keyframes flash-green {
  0%   { opacity: 1; box-shadow: inset 0 0 0 4px rgba(136, 208, 153, .65), inset 0 0 60px rgba(136, 208, 153, .3); }
  100% { opacity: 0; box-shadow: inset 0 0 0 4px rgba(136, 208, 153, 0); }
}

/* ---------- Zone-tinted viewport border ---------- */

body[data-zone]::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  transition: box-shadow .8s ease;
  box-shadow: inset 0 0 0 0 transparent;
}
body[data-zone="valley"]::before     { box-shadow: inset 0 0 0 2px rgba(232, 168, 98, .25),   inset 0 -40px 80px -40px rgba(232, 168, 98, .18); }
body[data-zone="durotar"]::before    { box-shadow: inset 0 0 0 2px rgba(176, 80, 48, .25),    inset 0 -40px 80px -40px rgba(176, 80, 48, .18); }
body[data-zone="echo"]::before       { box-shadow: inset 0 0 0 2px rgba(42, 104, 120, .3),    inset 0 -40px 80px -40px rgba(42, 104, 120, .22); }
body[data-zone="razorhill"]::before  { box-shadow: inset 0 0 0 2px rgba(128, 96, 64, .25),    inset 0 -40px 80px -40px rgba(128, 96, 64, .18); }
body[data-zone="crossroads"]::before { box-shadow: inset 0 0 0 2px rgba(176, 152, 104, .25),  inset 0 -40px 80px -40px rgba(176, 152, 104, .18); }
body[data-zone="coldridge"]::before  { box-shadow: inset 0 0 0 2px rgba(128, 160, 192, .3),   inset 0 -40px 80px -40px rgba(128, 160, 192, .22); }

/* ---------- Landing notice banner ---------- */

.landing-notice {
  max-width: 540px;
  margin: 0 auto 1em;
  padding: .6em 1em;
  background: rgba(240, 207, 106, .12);
  border: 1px solid rgba(240, 207, 106, .4);
  border-radius: .3em;
  color: var(--c-yellow);
  font-size: .9em;
  text-align: center;
}

/* ---------- Deathcard share button ---------- */

.run-summary-actions {
  display: flex;
  gap: .5em;
  justify-content: center;
  margin-top: 1em;
}
.run-summary-btn {
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: .6em 1.2em;
  border-radius: .3em;
  cursor: pointer;
  font: inherit;
  font-size: .9em;
}
.run-summary-btn:hover { background: var(--border); }
.run-summary-btn.primary { background: var(--c-yellow); color: #111; border-color: var(--c-yellow); }
.run-summary-btn.primary:hover { background: #f8dd7a; }

/* ---------- Floating damage numbers ---------- */

.fx-layer { position: fixed; top: 0; left: 0; right: 0; height: 0; pointer-events: none; z-index: 30; }
.fx-float {
  position: absolute;
  font-weight: 700;
  font-size: 1.3em;
  font-family: var(--font-mono);
  text-shadow: 0 2px 6px rgba(0,0,0,.7);
  animation: fx-float-up 1200ms ease-out forwards;
}
.fx-float.dmg      { color: var(--c-red); }
.fx-float.dmg-crit { color: var(--c-yellow); font-size: 1.7em; }
.fx-float.heal     { color: var(--c-green); }
@keyframes fx-float-up {
  0%   { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-48px); opacity: 0; }
}

/* ---------- Choice dock (bottom-anchored on mobile) ---------- */

.choice-dock {
  flex: 0 0 auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 0;
  max-height: 55vh;
  overflow-y: auto;
}
.choice-dock:empty { display: none; }
.choice-dock .choices {
  margin: 0;
  border-radius: 0;
  border: none;
  padding: .6em .7em;
  box-shadow: 0 -8px 24px rgba(0,0,0,.3);
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg) 100%);
}
/* Desktop routes choices into the log inline (left empty dock), so we
   just collapse the dock to zero height there. */
@media (min-width: 601px) {
  .choice-dock { display: none; }
}

/* ---------- Prompt row (text input fallback) ---------- */

#prompt-row {
  flex: 0 0 auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: .45em .8em calc(.45em + env(safe-area-inset-bottom, 0px));
}
/* Action-cards container is unused in the event-driven UI; hide it. */
#action-cards, #quick-row { display: none !important; }

#input-row {
  display: none;
  gap: .4em;
  align-items: center;
}
#prompt-label { color: var(--c-green); font-weight: 700; min-width: 1em; text-align: center; }
#cmd {
  flex: 1;
  background: var(--bg-card);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: .7em;
  font: inherit;
  font-family: var(--font-mono);
  border-radius: .3em;
}
#cmd:disabled { opacity: .5; }
#cmd:focus { outline: none; border-color: var(--accent); }
#send {
  background: var(--accent);
  color: #0b0c0d;
  border: none;
  padding: .7em 1em;
  font: inherit;
  font-weight: 700;
  border-radius: .3em;
  cursor: pointer;
}
#send:disabled { opacity: .5; cursor: default; }

/* ---------- Level-up overlay ---------- */

.level-up-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: radial-gradient(ellipse at center, rgba(185, 156, 224, .35) 0%, rgba(0,0,0,.8) 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.level-up-overlay.show {
  opacity: 1;
  pointer-events: auto;
  animation: lu-fade 2.4s ease-out forwards;
}
@keyframes lu-fade {
  0%, 15%, 85%, 100% {}
  0% { opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; pointer-events: none; }
}
.level-up-card {
  background: var(--bg-card);
  border: 2px solid var(--c-purple);
  border-radius: .6em;
  padding: 2em 2.5em;
  text-align: center;
  box-shadow: 0 0 40px rgba(185, 156, 224, .5);
  animation: lu-scale .4s cubic-bezier(.2, .9, .3, 1.2);
  font-family: var(--font-prose);
}
@keyframes lu-scale {
  0% { transform: scale(.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.level-up-title { color: var(--c-purple); font-size: 1.2em; letter-spacing: .1em; text-transform: uppercase; }
.level-up-level { color: var(--c-yellow); font-size: 3em; font-weight: 700; margin: .1em 0; }
.level-up-sub   { color: var(--fg-dim); font-size: 1em; }

/* ---------- Run-summary modal (shown on death) ---------- */

.run-summary-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, .85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.run-summary-overlay.show { opacity: 1; pointer-events: auto; }
.run-summary-card {
  background: var(--bg-card);
  border: 1px solid var(--c-red);
  border-radius: .6em;
  max-width: 480px;
  width: 100%;
  padding: 1.8em 1.6em 1.2em;
  box-shadow: 0 0 40px rgba(224, 124, 117, .3);
  font-family: var(--font-prose);
  text-align: center;
  animation: rs-scale .35s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes rs-scale {
  0% { transform: scale(.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.run-summary-title {
  font-family: var(--font-prose);
  color: var(--c-red);
  font-size: 1.8em;
  font-weight: 700;
  letter-spacing: .05em;
  margin: 0;
}
.run-summary-sub {
  color: var(--fg-dim);
  font-size: .95em;
  margin: .2em 0 1.2em;
  font-style: italic;
}
.run-summary-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5em .8em;
  margin: 1em 0;
  text-align: left;
}
.run-summary-stat {
  background: var(--bg-elev);
  border: 1px solid var(--border-mut);
  border-radius: .3em;
  padding: .55em .7em;
  font-family: var(--font-mono);
}
.run-summary-stat-label {
  display: block;
  font-size: .7em;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: .1em;
}
.run-summary-stat-value {
  display: block;
  color: var(--c-yellow);
  font-size: 1.3em;
  font-weight: 700;
  margin-top: .15em;
}

/* ---------- Talent tree visual ---------- */

#log .talent-tree {
  margin: 1em 0;
  padding: 1em;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: .4em;
}
#log .talent-tree-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .8em;
  font-family: var(--font-mono);
  font-size: .85em;
}
#log .talent-tree-points {
  color: var(--c-yellow);
  font-weight: 700;
  background: rgba(240, 207, 106, .12);
  padding: .15em .6em;
  border-radius: .25em;
}
#log .talent-tree-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1em;
  position: relative;
}
#log .talent-tree-branch {
  display: flex;
  flex-direction: column;
  gap: .45em;
  position: relative;
}
#log .talent-tree-branch-name {
  font-family: var(--font-mono);
  font-size: .75em;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-align: center;
  color: var(--fg-dim);
  padding-bottom: .3em;
  border-bottom: 1px solid var(--border-mut);
  margin-bottom: .2em;
}
#log .talent-node {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: .3em;
  padding: .55em .5em;
  text-align: center;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: border-color .15s, background .15s, transform .05s;
  display: flex;
  flex-direction: column;
  gap: .1em;
}
#log .talent-node:hover:not(:disabled):not(.taken) { border-color: var(--accent); background: var(--bg-elev); }
#log .talent-node:active:not(:disabled) { transform: translateY(1px); }
#log .talent-node.taken {
  border-color: var(--c-green);
  background: rgba(136, 208, 153, .08);
  cursor: default;
}
#log .talent-node.locked {
  opacity: .4;
  cursor: not-allowed;
}
#log .talent-node .talent-node-title {
  font-size: .78em;
  font-weight: 700;
  color: var(--fg);
}
#log .talent-node.taken .talent-node-title { color: var(--c-green); }
#log .talent-node .talent-node-effect {
  font-size: .65em;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  line-height: 1.2;
}
#log .talent-node .talent-node-tier {
  position: absolute;
  top: -8px;
  right: 6px;
  font-size: .55em;
  color: var(--fg-dim);
  background: var(--bg-card);
  padding: 0 .4em;
  border-radius: .2em;
  border: 1px solid var(--border-mut);
  letter-spacing: .1em;
}
/* Connecting lines between tiers in the same branch. */
#log .talent-node + .talent-node::before {
  content: "";
  position: absolute;
  top: -.35em;
  left: 50%;
  width: 1px;
  height: .45em;
  background: var(--border);
  transform: translateX(-50%);
}
#log .talent-node.taken + .talent-node::before { background: var(--c-green); }

@media (max-width: 600px) {
  #log .talent-tree-grid { grid-template-columns: 1fr; gap: .7em; }
  #log .talent-node + .talent-node::before { display: none; }
}

/* ---------- Game-over ---------- */

.msg-game-over {
  color: var(--c-red);
  font-weight: 700;
  margin-top: 1em;
  padding: 1em;
  border: 1px solid var(--c-red);
  border-radius: .4em;
  text-align: center;
  font-family: var(--font-prose);
  font-size: 1.1em;
}

/* ---------- Mobile ---------- */

@media (max-width: 600px) {
  html, body { font-size: 16px; }
  .play-header .session { display: none; }
  .play-header { padding: .3em .6em; }
  .hud { padding: .35em .6em .4em; gap: .22em; }
  .hud-name { font-size: .78em; }
  .hud-bar { height: 16px; }
  .hud-xp { height: 8px; }
  /* Bump HUD label text (+1 px equivalent at 16px base) */
  .hud-bar-label { font-size: .74em; }
  .hud-xp .hud-bar-label { font-size: .66em; }
  #log { padding: .9em 1em 1.2em; font-size: 16px; }
  #log p.prose         { line-height: 1.65; margin: .5em 0; }
  #log p.prose-narrator{ font-size: 1.1em; }
  #log p.prose-stage   { font-size: 1.0em; }
  #log .dialog-speaker { font-size: .88em; }   /* global is .82em; +1 px here */
  #log .dialog-text    { font-size: 1.08em; line-height: 1.62; }
  #log .combat-line    { font-size: .84em; }   /* smaller than prose — secondary info */
  #log h1.scene-title  { font-size: 1.5em; }
  #log h2.section-title{ font-size: 1.15em; }
  .choices { padding: .5em .6em; }
  .choice { padding: .45em .6em; }
  .choice-title { font-size: .88em; }
  .choice-meta { font-size: .7em; gap: .3em .6em; }
  #log .zone-banner { padding: 1em .8em; }
  #log .zone-banner-title { font-size: 1.5em; }
  #cmd { padding: .65em; font-size: 16px; }
  #send { padding: .65em .9em; }
}

@media (min-width: 900px) and (max-width: 1023px) {
  .hud, #log, #prompt-row > * {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
  }
  .hud { padding-left: 2em; padding-right: 2em; }
  #log { padding-left: 2.5em; padding-right: 2.5em; }
}

/* Desktop layout — HUD becomes a left sidebar so the horizontal space
   isn't wasted. Header spans the top; log + prompt fill the main pane. */
@media (min-width: 1024px) {
  body.play {
    display: grid;
    grid-template-areas:
      "header header"
      "hud    main"
      "hud    prompt";
    grid-template-columns: 320px 1fr;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
    height: 100dvh;
  }
  .play-header { grid-area: header; }
  .hud {
    grid-area: hud;
    border-right: 1px solid var(--border);
    border-bottom: none;
    box-shadow: 2px 0 6px rgba(0,0,0,.3);
    overflow-y: auto;
    padding: 1em 1.1em;
    gap: .7em;
  }
  .hud .hud-bar { height: 22px; }
  .hud .stat-xp .stat-bar { height: 8px; }
  .hud-name { font-size: 1.05em; }
  .hud-avatar { width: 42px; height: 42px; flex-basis: 42px; font-size: 1.35em; }
  #log {
    grid-area: main;
    max-width: none;
    margin: 0;
    padding: 1.5em 2em 1em;
  }
  #prompt-row {
    grid-area: prompt;
    max-width: none;
    margin: 0;
  }
  /* Constrain log line length for readability even when the pane is
     wide; leave choices to stretch fully. */
  #log h1.scene-title,
  #log h2.section-title,
  #log p.prose,
  #log .dialog-block,
  #log .combat-line,
  #log .notice,
  #log .loot-line,
  #log .zone-banner {
    max-width: 720px;
  }
  .choices { max-width: none; }

  /* ── Desktop text scale ────────────────────────────────────────────────
     Sections are shorter now so there is more vertical real estate. Use it:
     larger, more comfortable prose at reading distance, better line-height,
     slightly larger headings and combat cards.                            */
  #log { font-size: 17px; }
  #log p.prose         { line-height: 1.68; margin: .6em 0; }
  #log p.prose-narrator{ font-size: 1.18em; }
  #log p.prose-stage   { font-size: 1.02em; }
  #log .dialog-block   { margin: .75em 0; }
  #log .dialog-speaker { font-size: .85em; }
  #log .dialog-text    { font-size: 1.06em; line-height: 1.6; }
  #log .combat-line    { font-size: .82em; padding: .4em .65em; margin: .3em 0; }
  #log .notice         { font-size: .95em; padding: .4em .7em; }
  #log .loot-line      { font-size: .96em; }
  #log h1.scene-title  { font-size: 1.9em; margin-bottom: .6em; }
  #log h2.section-title{ font-size: 1.35em; margin: 1.1em 0 .45em; }
}

/* ==========================================================================
   Visual UI Panels — Inventory / Character Sheet / Shop
   Each panel is appended into #log as a card-style surface.
   The log's own overflow-y: auto makes it scrollable.
   ========================================================================== */

/* ---------- Shared panel shell ---------- */

.ui-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: .4em;
  margin: .8em 0;
  overflow: hidden;
}

.ui-panel-header {
  display: flex;
  align-items: center;
  gap: .6em;
  padding: .65em 1em;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

.ui-panel-title {
  flex: 1 1 auto;
  font-family: var(--font-mono);
  font-size: .82em;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: .05em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ui-panel-gold {
  font-family: var(--font-mono);
  font-size: .8em;
  color: var(--c-orange);
  font-weight: 700;
  white-space: nowrap;
  flex: 0 0 auto;
}

.ui-panel-close {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: .28em .65em;
  font: inherit;
  font-family: var(--font-mono);
  font-size: .75em;
  border-radius: .25em;
  cursor: pointer;
  white-space: nowrap;
  transition: background .1s, color .1s;
}
.ui-panel-close:hover { background: var(--bg); color: var(--fg); border-color: var(--fg-dim); }

.ui-panel-empty {
  color: var(--fg-dim);
  font-style: italic;
  text-align: center;
  padding: 2.5em 1em;
  font-family: var(--font-prose);
}

/* ---------- Item quality — left border accent on cards ---------- */

.loot-q-border-poor     { border-left: 3px solid #5a5a60 !important; }
.loot-q-border-common   { border-left: 3px solid #aaa9a4 !important; }
.loot-q-border-uncommon { border-left: 3px solid var(--c-green) !important; }
.loot-q-border-rare     { border-left: 3px solid var(--c-blue)  !important; }
.loot-q-border-epic     { border-left: 3px solid var(--c-purple) !important; }

/* ---------- Inventory grid ---------- */

.inv-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .5em;
  padding: .65em .7em;
}
@media (min-width: 500px)  { .inv-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 800px)  { .inv-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1200px) { .inv-grid { grid-template-columns: repeat(5, 1fr); } }

/* ---------- Item card ---------- */

.inv-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-mut);
  border-radius: .3em;
  padding: .55em .65em;
  display: flex;
  flex-direction: column;
  gap: .28em;
  font-size: .9em;
  transition: border-color .12s;
  cursor: default;
  min-width: 0;
}
.inv-card:hover { border-color: var(--border); }

.inv-card-header {
  display: flex;
  align-items: baseline;
  gap: .3em;
  flex-wrap: wrap;
  line-height: 1.2;
}

.inv-card-name {
  font-weight: 700;
  font-family: var(--font-prose);
  font-size: 1em;
  line-height: 1.2;
  word-break: break-word;
}

.inv-card-count {
  font-family: var(--font-mono);
  font-size: .75em;
  color: var(--fg-dim);
}

.inv-card-upgrade {
  font-family: var(--font-mono);
  font-size: .68em;
  color: var(--c-green);
  background: rgba(136, 208, 153, .1);
  border: 1px solid rgba(136, 208, 153, .3);
  padding: .08em .3em;
  border-radius: .2em;
  letter-spacing: .03em;
  white-space: nowrap;
}

.inv-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .22em;
}

.inv-card-tag {
  font-family: var(--font-mono);
  font-size: .68em;
  padding: .1em .38em;
  border-radius: .2em;
  border: 1px solid var(--border-mut);
  background: var(--bg-card);
  color: var(--fg-dim);
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.tag-slot  { color: var(--c-cyan);   background: rgba(127, 208, 194, .07); border-color: rgba(127, 208, 194, .28); }
.tag-use   { color: var(--c-blue);   background: rgba(122, 176, 224, .07); border-color: rgba(122, 176, 224, .28); }
.tag-quest { color: var(--c-yellow); background: rgba(240, 207, 106, .07); border-color: rgba(240, 207, 106, .28); }

.inv-card-stats {
  display: flex;
  flex-direction: column;
  gap: .1em;
}

.inv-card-stat {
  font-family: var(--font-mono);
  font-size: .74em;
  color: var(--c-green);
  line-height: 1.3;
}

.inv-card-desc {
  font-family: var(--font-prose);
  font-size: .83em;
  color: var(--fg-dim);
  font-style: italic;
  margin: 0;
  line-height: 1.35;
}

.inv-card-price {
  font-family: var(--font-mono);
  font-size: .78em;
  color: var(--c-orange);
  font-weight: 700;
  margin-top: auto;
}
.inv-price-broke { color: var(--c-red); opacity: .6; }

.inv-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .28em;
  margin-top: auto;
  padding-top: .3em;
}

/* -- Action buttons inside cards -- */

.inv-btn {
  font: inherit;
  font-family: var(--font-mono);
  font-size: .72em;
  font-weight: 700;
  padding: .32em .6em;
  border-radius: .22em;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg);
  cursor: pointer;
  letter-spacing: .04em;
  text-transform: uppercase;
  transition: background .1s, border-color .1s, color .1s, opacity .1s;
  white-space: nowrap;
}
.inv-btn:hover { background: var(--bg-elev); }
.inv-btn.disabled, .inv-btn:disabled { opacity: .32; cursor: not-allowed; pointer-events: none; }

.inv-btn-equip {
  background: rgba(136, 208, 153, .08);
  border-color: rgba(136, 208, 153, .38);
  color: var(--c-green);
}
.inv-btn-equip:hover {
  background: rgba(136, 208, 153, .18);
  border-color: var(--c-green);
}

.inv-btn-use {
  background: rgba(122, 176, 224, .08);
  border-color: rgba(122, 176, 224, .38);
  color: var(--c-blue);
}
.inv-btn-use:hover {
  background: rgba(122, 176, 224, .18);
  border-color: var(--c-blue);
}

.inv-btn-inspect {
  background: transparent;
  border-color: var(--border-mut);
  color: var(--fg-dim);
}
.inv-btn-inspect:hover { color: var(--fg); border-color: var(--border); }

.inv-btn-unequip {
  background: rgba(224, 124, 117, .07);
  border-color: rgba(224, 124, 117, .32);
  color: var(--c-red);
  opacity: .8;
  font-size: .68em;
}
.inv-btn-unequip:hover { opacity: 1; background: rgba(224, 124, 117, .15); border-color: rgba(224, 124, 117, .6); }

/* ---------- Character sheet panel ---------- */

.char-body {
  display: flex;
  min-height: 0;
}

.char-stats-col {
  flex: 0 0 50%;
  max-width: 50%;
  padding: .65em .85em;
  border-right: 1px solid var(--border-mut);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}

.char-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5em;
  font-family: var(--font-mono);
  font-size: .78em;
  padding: .3em 0;
  border-bottom: 1px solid var(--border-mut);
}
.char-stat-row:last-child { border-bottom: none; }

.char-stat-label {
  color: var(--fg-dim);
  white-space: nowrap;
}

.char-stat-value {
  color: var(--fg);
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.char-stat-bonus {
  color: var(--c-green);
  font-size: .85em;
  font-weight: 400;
  opacity: .9;
}

.char-gear-col {
  flex: 1 1 auto;
  padding: .65em .85em;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}

.char-gear-title {
  font-family: var(--font-mono);
  font-size: .73em;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--fg-dim);
  padding-bottom: .3em;
  border-bottom: 1px solid var(--border-mut);
  margin-bottom: .2em;
}

.char-gear-row {
  display: flex;
  align-items: center;
  gap: .4em;
  padding: .28em 0;
  border-bottom: 1px solid var(--border-mut);
  flex-wrap: wrap;
}
.char-gear-row:last-child { border-bottom: none; }

.char-gear-slot-label {
  font-family: var(--font-mono);
  font-size: .7em;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
  flex: 0 0 4.2em;
  width: 4.2em;
}

.char-gear-item {
  font-family: var(--font-prose);
  font-size: .88em;
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.char-gear-stats {
  font-family: var(--font-mono);
  font-size: .68em;
  color: var(--c-green);
  flex: 0 0 auto;
  white-space: nowrap;
}

.char-gear-empty {
  font-style: italic;
  color: var(--fg-dim);
  font-size: .82em;
  opacity: .45;
}

/* Mobile: stack stats / gear columns vertically */
@media (max-width: 520px) {
  .char-body { flex-direction: column; }
  .char-stats-col { flex: none; max-width: 100%; border-right: none; border-bottom: 1px solid var(--border-mut); }
  .char-gear-col  { flex: none; }
}

/* ---------- Shop panel ---------- */

.shop-section-title {
  font-family: var(--font-mono);
  font-size: .76em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--fg-dim);
  padding: .55em 1em .1em;
  border-top: 1px solid var(--border-mut);
}
.shop-panel > .shop-section-title:first-of-type { border-top: none; }

/* ---------- Item inspect full-screen overlay ---------- */

.item-inspect-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, .82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5em;
  animation: rs-scale .25s cubic-bezier(.2, .9, .3, 1.1);
}

.item-inspect-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: .5em;
  max-width: 380px;
  width: 100%;
  padding: 1.4em 1.6em 1.2em;
  font-family: var(--font-prose);
  box-shadow: 0 10px 48px rgba(0, 0, 0, .65);
  display: flex;
  flex-direction: column;
  gap: .5em;
}
/* Full-border quality overrides (higher specificity than loot-q-border-* left-only rules) */
.item-inspect-card.loot-q-border-poor     { border: 2px solid #5a5a60 !important; }
.item-inspect-card.loot-q-border-common   { border: 2px solid #aaa9a4 !important; }
.item-inspect-card.loot-q-border-uncommon { border: 2px solid var(--c-green) !important;  box-shadow: 0 10px 48px rgba(136, 208, 153, .2); }
.item-inspect-card.loot-q-border-rare     { border: 2px solid var(--c-blue)  !important;  box-shadow: 0 10px 48px rgba(122, 176, 224, .25); }
.item-inspect-card.loot-q-border-epic     { border: 2px solid var(--c-purple) !important; box-shadow: 0 10px 48px rgba(185, 156, 224, .3); }

.item-inspect-name {
  font-family: var(--font-prose);
  font-size: 1.3em;
  font-weight: 700;
  line-height: 1.15;
}

.item-inspect-slot {
  font-family: var(--font-mono);
  font-size: .74em;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-top: -.25em;
}

.item-inspect-desc {
  font-style: italic;
  color: var(--fg-dim);
  font-size: .95em;
  line-height: 1.45;
  margin: 0;
}

.item-inspect-stats {
  display: flex;
  flex-direction: column;
  gap: .18em;
}

.item-inspect-vs {
  padding-top: .45em;
  border-top: 1px solid var(--border-mut);
  display: flex;
  flex-direction: column;
  gap: .2em;
}

.item-inspect-vs-label {
  font-family: var(--font-mono);
  font-size: .7em;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: .07em;
}

.item-inspect-vs-name {
  font-family: var(--font-prose);
  font-weight: 600;
  color: var(--fg);
  font-size: .95em;
}

.item-inspect-price {
  font-family: var(--font-mono);
  font-size: .8em;
  color: var(--c-orange);
  text-align: right;
  margin-top: .2em;
}

/* ---------- Level-up card — new spell + talent point lines ---------- */

.level-up-spell {
  font-family: var(--font-mono);
  font-size: .8em;
  color: var(--c-cyan);
  letter-spacing: .03em;
  margin-top: .5em;
  padding: .3em .8em;
  background: rgba(127, 208, 194, .1);
  border: 1px solid rgba(127, 208, 194, .3);
  border-radius: .25em;
  display: inline-block;
}

.level-up-talent {
  font-family: var(--font-mono);
  font-size: .74em;
  color: var(--c-yellow);
  letter-spacing: .03em;
  margin-top: .3em;
  padding: .25em .7em;
  background: rgba(240, 207, 106, .1);
  border: 1px solid rgba(240, 207, 106, .3);
  border-radius: .25em;
  display: inline-block;
  animation: talent-pulse 2.2s ease-in-out infinite;
}

@keyframes talent-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 207, 106, 0); }
  50%       { box-shadow: 0 0 10px 2px rgba(240, 207, 106, .22); }
}

/* ---------- HUD talent badge (unspent points indicator) ---------- */

.hud-talent-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: .65em;
  font-weight: 700;
  color: var(--c-yellow);
  background: rgba(240, 207, 106, .14);
  border: 1px solid rgba(240, 207, 106, .38);
  border-radius: .25em;
  padding: .08em .32em;
  letter-spacing: .04em;
  vertical-align: middle;
  margin-left: .3em;
  animation: talent-pulse 2.2s ease-in-out infinite;
  white-space: nowrap;
}

/* ---------- Gold gain notice (enhanced) ---------- */

.gold-coin { margin-right: .15em; }

/* ---------- iPhone / Android home-bar safe area ---------- */
/* On notched phones the choice dock sits directly above the home
   indicator. Add padding so choices aren't obscured. */

@media (max-width: 600px) {
  .choice-dock {
    padding-bottom: max(0px, env(safe-area-inset-bottom, 0px));
  }
}

/* =========================================================================
   Achievement unlock overlay
   Slides in from the bottom-right. Tier-coloured border driven by
   data-tier="common|rare|epic|legendary" on #achievement-overlay.
   ========================================================================= */

.achievement-overlay {
  position: fixed;
  bottom: -180px;   /* hidden below viewport */
  right: 1.5rem;
  z-index: 190;     /* below level-up (200) so level-up always wins */
  opacity: 0;
  pointer-events: none;
  transition: bottom .42s cubic-bezier(.22,.9,.36,1.1), opacity .38s ease;
  max-width: 320px;
  min-width: 220px;
}
.achievement-overlay.show {
  bottom: 5.5rem;   /* clear the choice-dock */
  opacity: 1;
}

.achievement-card {
  background: var(--bg-elev);
  border: 2px solid var(--c-green);   /* default: common (green) */
  border-radius: 10px;
  padding: .85rem 1.1rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.65), 0 0 14px rgba(136,208,153,.25);
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.achievement-header {
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--c-green);   /* overridden per tier below */
}

.achievement-title {
  font-size: .98rem;
  font-weight: 700;
  color: var(--fg);
  line-height: 1.25;
}

.achievement-desc {
  font-size: .8rem;
  color: var(--fg-dim);
  line-height: 1.35;
}

/* ── Tier overrides ── */

.achievement-overlay[data-tier="common"]    .achievement-card {
  border-color: var(--c-green);
  box-shadow: 0 4px 24px rgba(0,0,0,.65), 0 0 14px rgba(136,208,153,.25);
}
.achievement-overlay[data-tier="common"]    .achievement-header { color: var(--c-green); }

.achievement-overlay[data-tier="rare"]      .achievement-card {
  border-color: var(--c-blue);
  box-shadow: 0 4px 24px rgba(0,0,0,.65), 0 0 14px rgba(122,176,224,.3);
}
.achievement-overlay[data-tier="rare"]      .achievement-header { color: var(--c-blue); }

.achievement-overlay[data-tier="epic"]      .achievement-card {
  border-color: var(--c-purple);
  box-shadow: 0 4px 24px rgba(0,0,0,.65), 0 0 16px rgba(185,156,224,.35);
}
.achievement-overlay[data-tier="epic"]      .achievement-header { color: var(--c-purple); }

.achievement-overlay[data-tier="legendary"] .achievement-card {
  border-color: var(--c-orange);
  box-shadow: 0 4px 24px rgba(0,0,0,.65), 0 0 18px rgba(232,168,98,.45);
}
.achievement-overlay[data-tier="legendary"] .achievement-header { color: var(--c-orange); }

/* =========================================================================
   Affix modifier tooltip
   Fixed-position overlay; one element shared across all [data-mod] targets.
   Shown on hover (desktop) or press-and-hold (mobile via JS).
   ========================================================================= */

.mod-tooltip {
  position: fixed;
  z-index: 400;           /* above everything */
  background: var(--bg-elev);
  border: 1px solid rgba(232, 168, 98, .55);   /* warm gold outline */
  border-radius: 7px;
  padding: .5rem .8rem;
  font-family: var(--font-mono);
  font-size: .72rem;
  line-height: 1.5;
  color: var(--fg);
  max-width: 280px;
  pointer-events: none;   /* tooltip never intercepts clicks / touches */
  box-shadow: 0 4px 18px rgba(0,0,0,.6);
  white-space: normal;
  animation: mod-tooltip-in .12s ease;
}

@keyframes mod-tooltip-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0);    }
}

/* Affix glyphs in the HUD enemy name are tappable / hoverable */
.mod-affix[data-mod] {
  cursor: help;
  text-decoration: underline dotted rgba(255,255,255,.3);
  text-underline-offset: 3px;
}
