/* Rubric by candlelight: a dark manuscript. Cream ink on warm brown, one red
   accent (the rubric), small capitals for labels. Kept deliberately calm: no
   glows, no pulsing, no flashing, no large bright areas. */
:root {
  color-scheme: dark;

  --font-body: "EB Garamond", Georgia, "Times New Roman", serif;
  --font-sc: "IM Fell English SC", "EB Garamond", Georgia, serif;
  --font-fell: "IM Fell English", "EB Garamond", Georgia, serif;

  --page: #1b1714;
  --panel: #231e19;
  --map-bg: #14110e;
  --border: #3a322a;
  --border-strong: #4a3f34;
  --divider: #2f2822;
  --divider-2: #332b24;
  --underline: #5e5345;
  --rule: #6b5e4d;
  --slot: #2a241e;

  --ink: #cfc3aa;
  --muted: #a89a82;
  --faint: #998c76;
  --fainter: #8a7d68;
  --tab: #b5a88e;
  --icon-ink: #c4b699;

  /* The one accent, and the solid fill behind the Act button. */
  --rubric: #d48a76;
  --rubric-fill: #86392c;
  --rubric-fill-ink: #ecdfc6;

  --sound: #93b3a1;
  --injured: #d4b07a;
  --hp: #a8584a;
  --hp-track: #33241f;
  --st: #6a8f7e;
  --st-track: #222b26;

  /* Map tiles and tokens (read by readPalette()). */
  --t-wall: #2a231c;
  --t-door: #7d6040;
  --t-door-closed: #5e4630;
  --t-door-broken: #3f3226;
  --t-window: #7f949a;
  --t-window-broken: #3c464a;
  --t-tree: #222b1b;
  --t-stump: #4a3624;
  --t-water: #2b3f4a;
  --t-floor: #3a3128;
  --t-road: #57493b;
  --t-grass: #273020;
  --e-you: #d48a76;
  --e-player: #9fb4c8;
  --e-npc: #b5a88e;
  --e-creature: #b5675a;
  /* Round whoever you're fighting, while a fight is on. */
  --e-hostile: #e5392a;
  --item: #d9a594;

  /* Each kind of line in the log. */
  --k-world: #cfc3aa;
  --k-speech: #9fb4c8;
  --k-emote: #b4a5c4;
  --k-combat: #d48a76;
  --k-crit: #d4b07a;
  --k-death: #c97361;
  --k-roll: #998c76;
  --k-system: #a89a82;
  --k-you: #c4b699;
  --k-tempo: #d48a76;

  --sheet-w: min(360px, 88vw);
  --ease: cubic-bezier(0.22, 0.8, 0.3, 1);

}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 19px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
input, button { font: inherit; color: inherit; }
button {
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 1px solid #d9a08f; outline-offset: 3px; }

/* The solid rubric button: Act, Enter the world. */
.act {
  flex: none;
  height: 50px;
  padding: 0 26px;
  background: var(--rubric-fill);
  color: var(--rubric-fill-ink);
  font: 18px/1 var(--font-sc);
  letter-spacing: 0.16em;
}
.act:hover { background: #923f31; }
.act:active { background: #7a3328; }
.act:disabled { background: #4a2e27; color: #a89a82; cursor: not-allowed; }

/* --- Join --- */

.overlay {
  position: fixed;
  inset: 0;
  /* Above the game (which stays rendered underneath after a death or a
     disconnect). */
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  background: var(--page);
}
.card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 34px 32px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.title {
  margin: 0;
  text-align: center;
  font: 40px/1.1 var(--font-sc);
  letter-spacing: 0.04em;
  color: var(--ink);
}
.title span { color: var(--rubric); }
/* The motto under the name, between hairlines. */
.motto {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: -4px 0 4px;
  font: 15px/1 var(--font-sc);
  letter-spacing: 0.32em;
  color: var(--rubric);
}
.motto::before, .motto::after { content: ""; flex: 1; height: 1px; background: var(--underline); }
/* The spacing trails the last letter: the same before the first keeps it centred. */
.motto::before { margin-right: 0.32em; }
.tagline { margin: 0 0 10px; text-align: center; font-size: 17px; font-style: italic; color: var(--faint); }
.card label { font: 13px/1 var(--font-sc); letter-spacing: 0.14em; color: var(--muted); }
.card .chunky-box { flex: none; border-bottom: 2px solid var(--rule); }
.card .chunky-input { height: 48px; }
.card .act { width: 100%; margin-top: 10px; }
.card .secondary {
  align-self: center;
  min-height: 32px;
  font: 15px/1 var(--font-sc);
  letter-spacing: 0.1em;
  color: var(--muted);
  border-bottom: 1px solid var(--underline);
}
.error { min-height: 1.2em; margin: 0; text-align: center; font-size: 17px; font-style: italic; color: var(--rubric); }

/* --- Layout: the left column fills the window; the sheet is 360px. --- */

#game {
  display: flex;
  gap: 20px;
  height: 100vh;
  height: 100dvh;
  /* Below this the map and the log would drop under their minimums: let the
     page scroll instead. */
  min-height: 780px;
  padding: 18px 20px;
  transition: filter 1.5s;
}
#left {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#map-wrap {
  position: relative;
  /* The roster slides up from below its edge. */
  overflow: hidden;
  flex: var(--map-grow, 0.435) 1 0;
  min-height: 236px;
  padding: 14px;
  background: var(--map-bg);
  border: 1px solid var(--border);
}
#map { display: block; width: 100%; height: 100%; cursor: crosshair; }
#floats { position: absolute; inset: 0; z-index: 4; overflow: hidden; pointer-events: none; }
#tooltip {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  padding: 3px 10px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  font-size: 16px;
  white-space: nowrap;
}
#banner {
  position: absolute;
  top: 24px;
  left: 50%;
  z-index: 6;
  transform: translateX(-50%);
  padding: 4px 16px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  font: 15px/1.4 var(--font-sc);
  letter-spacing: 0.1em;
  color: var(--muted);
  white-space: nowrap;
}

/* --- The command block: timer, input and this turn's orders --- */

#deck {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 22px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
}
/* A fight: the block's edge turns rubric and the timer says so. */
body.fighting #deck { border-color: var(--rubric); }

#turnbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 2px;
  cursor: row-resize;
  touch-action: none;
  user-select: none;
}
.tb-grip {
  flex: none;
  width: 10px;
  height: 6px;
  border-top: 1px solid var(--underline);
  border-bottom: 1px solid var(--underline);
}
#turnbar:hover .tb-grip, #turnbar:focus-visible .tb-grip { border-color: var(--muted); }
.tb-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.tb-track { position: relative; height: 2px; overflow: hidden; background: var(--border); }
#tb-fill {
  position: absolute;
  inset: 0;
  transform: scaleX(0);
  transform-origin: left;
  background: var(--rubric);
}
.tb-caption {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
  font-style: italic;
  color: var(--faint);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tb-fight {
  display: none;
  margin-right: 0.6em;
  font: 14px var(--font-sc);
  font-style: normal;
  letter-spacing: 0.14em;
  color: var(--rubric);
}
body.fighting .tb-fight { display: inline; }
.tb-time { flex: none; display: flex; align-items: baseline; gap: 4px; }
#tb-secs {
  min-width: 1.1em;
  font: 26px/1 var(--font-fell);
  font-weight: 400;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.tb-time small { font: 13px var(--font-sc); letter-spacing: 0.1em; color: var(--muted); }
#turnbar.urgent #tb-secs { color: var(--rubric); }
body.resizing, body.resizing * { cursor: row-resize !important; user-select: none; }

#cmd-form {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 0 6px 4px;
  border-bottom: 2px solid var(--rule);
}
.prompt { flex: none; font: 28px/1 var(--font-fell); color: var(--rubric); cursor: text; }
/* Orders in: the input waits for the next turn. */
body.locked #cmd-form { border-bottom-color: var(--border-strong); }
body.locked .prompt { color: var(--fainter); }
.chunky-input:disabled { cursor: not-allowed; }
/* No box round the inputs: focus brightens the rule beneath them instead. */
.chunky-input:focus-visible { outline: none; }
#cmd-form:focus-within, .card .chunky-box:focus-within { border-bottom-color: var(--muted); }

/* This turn: one line per slot, the slot in rubric small capitals. */
.plan {
  display: flex;
  flex-direction: column;
  max-height: 6.4em;
  overflow-y: auto;
  padding: 0 4px;
  font-size: 18px;
  line-height: 1.45;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.step { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 12px; min-height: 30px; }
.step .when { flex: none; min-width: 4.8em; font: 14px var(--font-sc); letter-spacing: 0.14em; color: var(--rubric); }
.step .what { flex: 1 1 12em; min-width: 0; font-style: italic; }
.step .note { font-size: 15px; color: var(--faint); }
.step.carried .what { color: var(--muted); }
.step.reading .when { color: var(--faint); }
.step.reading .what { color: var(--muted); }
/* Text buttons: strike, a choice, yes or no. */
.strike, .step .go, .step .no {
  flex: none;
  min-height: 30px;
  font: 15px/1 var(--font-sc);
  letter-spacing: 0.1em;
  color: var(--muted);
  border-bottom: 1px solid var(--underline);
}
.step .go { color: var(--rubric); }
.strike:hover, .step .no:hover, .step .option:hover { color: var(--ink); }
.step .options { display: flex; flex-wrap: wrap; gap: 2px 16px; flex-basis: 100%; padding-left: calc(4.8em + 12px); }
.step .option { min-height: 30px; font-style: italic; border-bottom: 1px solid var(--underline); }
.plan .idle { margin: 0; min-height: 30px; font-size: 16px; font-style: italic; color: var(--faint); }

/* --- Typing: the real input is invisible; chunky.js sets the type --- */

.chunky-box { position: relative; flex: 1 1 auto; min-width: 0; }
.chunky-input, .chunky-layer {
  font: 400 24px/1 var(--font-body);
  letter-spacing: 0;
  font-kerning: none;
  font-variant-ligatures: none;
  font-feature-settings: "kern" 0, "liga" 0, "clig" 0, "calt" 0;
}
.chunky-input {
  display: block;
  width: 100%;
  height: 52px;
  padding: 0;
  background: transparent;
  border: 0;
  outline: none;
  color: transparent;
  caret-color: transparent;
}
.chunky-input::placeholder { color: var(--fainter); font-style: italic; }
.chunky-input::selection { background: rgba(212, 138, 118, 0.28); color: transparent; }
.chunky-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: pre;
  pointer-events: none;
}
.chunky-ink { color: var(--ink); }
.chunky-run { position: relative; flex: none; white-space: pre; }
/* The rest of a word being completed: Tab (or a tap) takes it. */
.chunky-hint { flex: none; white-space: pre; color: var(--fainter); pointer-events: auto; cursor: pointer; }
.chunky-run > span { display: inline-block; }
.chunky-run > .pop { animation: key-in 0.16s ease-out backwards; }
@keyframes key-in { from { opacity: 0.2; transform: translateY(-0.14em); } }
.chunky-ghost { position: absolute; white-space: pre; animation: key-out 0.3s ease-in forwards; }
@keyframes key-out { to { opacity: 0; transform: translateY(0.35em); } }
.chunky-launch { position: absolute; display: flex; white-space: pre; animation: launch 0.3s ease-in forwards; }
.chunky-launch > span { display: inline-block; }
@keyframes launch { to { opacity: 0; transform: translateY(-0.6em); } }
.chunky-caret {
  position: absolute;
  top: 50%;
  left: 0;
  width: 2px;
  height: 1.05em;
  margin-top: -0.56em;
  background: var(--rubric);
  opacity: 0;
}
.chunky-layer.focused .chunky-caret { opacity: 1; }
.chunky-layer.focused .chunky-caret.blink { animation: caret-blink 1.1s steps(1) 0.5s infinite; }
@keyframes caret-blink { 50% { opacity: 0; } }

/* --- Log filters and sound switches --- */

.log-head { flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.tabs { display: flex; align-items: center; }
.tab {
  min-height: 44px;
  padding: 0 10px;
  font: 17px var(--font-sc);
  letter-spacing: 0.1em;
  color: var(--tab);
}
.tab[aria-pressed="true"] {
  color: var(--rubric);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 7px;
}
.tabs .sep { padding: 0 2px; color: var(--underline); }
.tools { display: flex; gap: 2px; }
.tool { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; color: var(--muted); }
.tool:hover { color: var(--ink); }
#sound-btn[aria-pressed="false"] .on, #sound-btn[aria-pressed="true"] .off { display: none; }
#keys-btn[aria-pressed="false"] { color: var(--fainter); }
.tool:disabled { opacity: 0.4; cursor: default; }

/* --- The log: a dark page --- */

#log {
  flex: var(--log-grow, 0.565) 1 0;
  min-height: 250px;
  overflow-y: auto;
  padding: 26px 44px 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 20px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
#log.hide-talk [data-group="talk"],
#log.hide-combat [data-group="combat"] { display: none; }

.area-head {
  margin: 0 0 14px;
  text-align: center;
  font: 15px/1.5 var(--font-sc);
  letter-spacing: 0.2em;
  color: var(--rubric);
}
.area-head:not(:first-child) { margin-top: 28px; }
/* Between turns: a small mark, no number (the world's count runs forever). */
.turn {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
  font-size: 8px;
  line-height: 1;
  color: var(--underline);
}
.turn::before, .turn::after { content: ""; flex: 1; height: 1px; background: var(--divider); }
.area-head + .turn { display: none; }
/* The end of a told turn. */
/* Muted, not rubric: it comes every turn, and the accent is kept for headings. */
.turn.end { font: 14px/1 var(--font-sc); letter-spacing: 0.14em; color: var(--muted); }

.line {
  margin: 0 0 10px;
  color: var(--k, var(--ink));
  animation: line-in 0.3s ease-out var(--d, 0ms) backwards;
}
@keyframes line-in { from { opacity: 0; } }
.line.world { --k: var(--k-world); }
/* The first line of an arrival or a look round opens with a drop cap. */
.line.opening { display: flow-root; }
.line.opening::first-letter {
  float: left;
  margin: 7px 10px 0 0;
  font: 48px/0.8 var(--font-fell);
  color: var(--rubric);
}

.line.speech .who { font: 17px var(--font-sc); letter-spacing: 0.08em; color: var(--k-speech); }
.line.speech.mine .who { color: var(--rubric); }
.line.speech .verb { font-size: 17px; font-style: italic; color: var(--faint); }
.line.speech q { quotes: "“" "”" "‘" "’"; }

.line.emote { --k: var(--k-emote); font-style: italic; }
.line.you { --k: var(--k-you); }
.line.system { --k: var(--k-system); font-size: 17px; font-style: italic; }
.line.ack { --k: var(--faint); font-size: 17px; font-style: italic; }
.line.tempo { --k: var(--k-tempo); font-style: italic; }

/* What you typed, echoed: a quiet pilcrow and your words. Not a button. */
.line.input { --k: var(--faint); margin-top: 14px; font-size: 18px; font-style: italic; }
.line.input::before {
  content: "¶";
  margin-right: 0.45em;
  font: 20px var(--font-fell);
  font-style: normal;
  color: var(--fainter);
}

/* Dice: the math behind a blow, tucked under it. */
.line.roll { --k: var(--k-roll); margin: -6px 0 12px 1.4em; font-size: 15px; line-height: 1.5; }
.line.roll b { font-weight: 500; color: var(--muted); }
.line.roll .n20 { color: var(--k-crit); }
.line.roll .n1 { color: var(--rubric); }
.line.roll .out { font: 14px var(--font-sc); letter-spacing: 0.08em; }
.line.roll .hit, .line.roll .success { color: var(--rubric); }
.line.roll .critical-hit { color: var(--k-crit); }
.line.roll .miss, .line.roll .resisted, .line.roll .fumble { color: var(--faint); }
.line.roll .dmg { color: var(--rubric); }

/* A person's moment: their name over what they said or did, in a frame.
   One person's lines in a row share it; a blow's dice go in with it. */
.moment {
  margin: 12px 0;
  padding: 7px 14px 9px;
  border: 1px solid var(--border);
  animation: line-in 0.3s ease-out var(--d, 0ms) backwards;
}
.moment > .who {
  display: block;
  margin-bottom: 1px;
  font: 15px/1.5 var(--font-sc);
  letter-spacing: 0.1em;
  color: var(--k-speech);
}
.moment.mine > .who { color: var(--rubric); }
.moment.combat { border-left: 2px solid var(--rubric-fill); }
.moment .line { margin: 0; }
.moment .line + .line { margin-top: 4px; }
.moment .line.roll { margin: 2px 0 0; }
.moment .line.impact-crit, .moment .line.impact-death { margin: 4px 0 0; }

/* Combat, by how hard the blow landed. */
.line.combat { --k: var(--k-combat); }
.line.death { --k: var(--k-death); }
.line .kw { font-weight: 600; }
.line.impact-miss { --k: var(--muted); font-style: italic; }
.line.impact-heavy { font-weight: 500; }
.line.impact-crit { --k: var(--k-crit); margin: 14px 0; font-size: 21px; }
.line.impact-death { margin: 16px 0; font-size: 21px; font-weight: 500; }
.line.impact-dire { font-style: italic; font-weight: 500; }
/* "Critical", "Severed", "Killing blow": a rubric label, as in a margin. */
.stamp { font: 15px var(--font-sc); font-style: normal; font-weight: 400; letter-spacing: 0.14em; }
.stamp::after { content: " —"; letter-spacing: 0; }

/* --- Floating numbers over the map --- */

.float {
  position: absolute;
  font: 20px/1 var(--font-fell);
  color: var(--rubric);
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  transform: translate(-50%, -100%);
  animation: float-up 1s ease-out forwards;
}
.float.big { font-size: 26px; color: var(--k-crit); }
.float.heal { color: var(--sound); }
@keyframes float-up {
  from { opacity: 0; transform: translate(-50%, -60%); }
  20% { opacity: 1; }
  to { opacity: 0; transform: translate(-50%, -190%); }
}

/* --- The roster: everyone playing here, and whose turn is in --- */

.roster-btn {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 4px;
  font: 14px/1 var(--font-sc);
  letter-spacing: 0.08em;
  color: var(--muted);
  cursor: pointer;
}
.roster-btn:hover, .roster-btn[aria-expanded="true"] { color: var(--ink); }
.roster-btn.waiting #roster-count { color: var(--ink); }
#roster {
  --roster-h: 118px;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  height: var(--roster-h);
  background: rgba(27, 23, 20, 0.95);
  border-top: 1px solid var(--border-strong);
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 220ms var(--ease), visibility 0s linear 220ms;
}
body.roster-open #roster { transform: none; visibility: visible; transition: transform 220ms var(--ease), visibility 0s; }
/* The map's buttons move up out of its way (on phones too). */
body.ui-full.roster-open #map-tools { bottom: calc(118px + 12px); }
.roster-list {
  display: flex;
  gap: 10px;
  height: 100%;
  padding: 12px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
/* A player: their likeness, their name, and a seal that's set once their
   turn is in. */
.player-card {
  flex: none;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  width: 196px;
  padding: 8px 12px 8px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.player-card canvas { grid-row: 1 / 3; width: 48px; height: 72px; image-rendering: pixelated; }
.player-card b {
  overflow: hidden;
  font: 16px/1.3 var(--font-sc);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--ink);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.player-card.you b { color: var(--rubric); }
.player-card small { display: flex; align-items: center; gap: 7px; font-size: 15px; font-style: italic; color: var(--faint); }
/* The seal: hollow while they're deciding, set when they're in. */
.player-card small::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border: 1px solid var(--rule);
  border-radius: 50%;
}
.player-card.ready { border-color: #4e6a5e; }
.player-card.ready small { color: var(--sound); }
.player-card.ready small::before { background: var(--st); border-color: var(--st); }
.player-card.aside { opacity: 0.6; }
.player-card.aside small::before { border-style: dashed; }
.roster-alone { align-self: center; margin: 0; font-size: 16px; font-style: italic; color: var(--faint); }

/* --- Speech bubbles: pixel frames (drawn in app.js), the words in type --- */

#bubbles { position: absolute; inset: 0; z-index: 5; overflow: hidden; pointer-events: none; --px: 2; }
.bubble {
  position: absolute;
  width: max-content;
  max-width: 260px;
  padding: 0 4px 1px;
  border: calc(var(--px) * 4px) solid transparent;
  border-image: var(--bubble-say) 4 fill / calc(var(--px) * 4px) round;
  image-rendering: pixelated;
  font: 16px/1.35 var(--font-body);
  color: var(--ink);
  transform-origin: 50% 100%;
  animation: bubble-in 0.18s ease-out both;
  transition: opacity 0.4s ease;
}
.bubble span { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 4; }
.bubble i {
  position: absolute;
  top: calc(100% + var(--px) * 2px);
  width: calc(var(--px) * 7px);
  height: calc(var(--px) * 7px);
  background: var(--tail-say) 0 0 / 100% 100%;
  transform: translateX(-50%);
}
.bubble.gone { opacity: 0; }
/* A shout: jagged, in rubric capitals, and it lands with a little more weight. */
.bubble.shout {
  border-width: calc(var(--px) * 6px);
  border-image: var(--bubble-shout) 6 fill / calc(var(--px) * 6px) round;
  font: 17px/1.3 var(--font-sc);
  letter-spacing: 0.04em;
  color: var(--rubric);
  animation-name: bubble-shout;
}
.bubble.shout i { top: calc(100% + var(--px) * 4px); background-image: var(--tail-shout); }
/* A whisper: dotted, quieter type. */
.bubble.whisper {
  border-image-source: var(--bubble-whisper);
  font-size: 15px;
  font-style: italic;
  color: var(--muted);
}
.bubble.whisper i { background-image: var(--tail-whisper); }
@keyframes bubble-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes bubble-shout { from { opacity: 0; transform: scale(0.85); } }

/* --- The character sheet --- */

#side {
  flex: 0 0 360px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.panel { padding: 16px 24px 20px; background: var(--panel); border: 1px solid var(--border); }
.panel h2 {
  margin: 0 0 12px;
  text-align: center;
  font: 15px/1.5 var(--font-sc);
  font-weight: 400;
  letter-spacing: 0.2em;
  color: var(--rubric);
}
.hint { margin: 0 4px; font-size: 15px; font-style: italic; color: var(--faint); }

.status-panel { display: flex; flex-direction: column; gap: 14px; padding: 20px 24px; }
#area-name { margin: 0; text-align: center; font-size: 15px; font-style: italic; color: var(--faint); }
#char-name {
  margin: -12px 0 0;
  font: 34px/1.1 var(--font-sc);
  letter-spacing: 0.04em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
#char-name .initial { color: var(--rubric); }
.vitals { display: flex; flex-direction: column; gap: 10px; }
.vital { display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; align-items: center; gap: 12px; cursor: help; }
.v-lbl { font: 14px var(--font-sc); letter-spacing: 0.1em; color: var(--muted); }
.meter { position: relative; height: 5px; background: var(--hp-track); }
.meter.st { background: var(--st-track); }
.fill { position: absolute; inset: 0 auto 0 0; width: 0; transition: width 0.35s ease; }
.fill.hp { background: var(--hp); }
.fill.st { background: var(--st); }
/* Stamina past empty: how far into the red, out of how far it can go. */
.fill.red { background: var(--rubric); }
.red-stamina #st-text, .red-stamina #hud-st-text { color: var(--rubric); }
.num { font-size: 17px; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.num .den { color: var(--fainter); }
body.low-hp #hp-text, body.low-hp #hud-hp-text { color: var(--rubric); }
.wanted { margin: 0; text-align: center; font-size: 16px; font-style: italic; color: var(--rubric); }
.conditions { margin: 0; text-align: center; font-size: 15px; font-style: italic; color: var(--faint); }
/* Buffs and debuffs: debuffs in rubric, buffs in the stamina green. */
.fx { cursor: help; }
.fx.debuff { color: var(--rubric); }
.fx.buff { color: var(--st); }
.conditions .fx + .fx::before { content: " · "; color: var(--faint); }

/* The body: the burlap doll, and the parts beside it. */
.body-wrap { display: flex; align-items: center; gap: 20px; }
#doll { flex: none; width: 124px; height: 196px; overflow: visible; }
#doll .part { cursor: help; }
#doll .part .hi { fill-opacity: 0; transition: fill-opacity 0.15s; }
#doll .part:hover .hi, #doll .part.hl .hi { fill-opacity: 0.12; }
#doll .seams, #doll .stains, #doll .face, #doll .wounds { pointer-events: none; }
#doll .stain ellipse { filter: url(#burlap-stain); }

#body { flex: 1 1 auto; min-width: 0; margin: 0; padding: 0; list-style: none; }
#body li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  column-gap: 8px;
  padding: 4px 0 5px;
  border-bottom: 1px solid var(--divider);
  font-size: 17px;
  line-height: 1.3;
  cursor: help;
}
#body li:last-child { border-bottom: 0; }
#body li:hover .p-name { color: var(--rubric); }
#body .p-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#body .state { font-size: 16px; font-style: italic; color: var(--sound); }
#body li.injured .state { color: var(--injured); }
#body li.crippled .state, #body li.destroyed .state, #body li.severed .state, #body li.bleeding .state { color: var(--rubric); }
#body .p-fx { grid-column: 1 / -1; font-size: 15px; font-style: italic; }
#body .p-fx .fx + .fx::before { content: ", "; color: var(--faint); }
#body .p-bar { grid-column: 1 / -1; height: 2px; margin-top: 4px; background: var(--divider); }
#body .p-bar i { display: block; height: 100%; background: var(--rule); }

.attrs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); text-align: center; }
.attr { display: flex; flex-direction: column; align-items: center; padding: 4px 0; cursor: help; }
.attr + .attr { border-left: 1px solid var(--border); }
.attr b { font: 28px/1.1 var(--font-fell); font-weight: 400; color: var(--ink); }
.attr.zero b { color: var(--fainter); }
.attr small { font: 13px/1.4 var(--font-sc); letter-spacing: 0.08em; color: var(--muted); }

/* Equipment and pack. */
#pack-panel { display: flex; flex-direction: column; gap: 14px; padding-bottom: 22px; }
#pack-panel h2 { margin: 0; }
/* Item sprites: 10-pixel pixel art at 3x, kept crisp. */
img.px { display: block; flex: none; width: 30px; height: 30px; image-rendering: pixelated; }

.slots { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--divider-2); }
.slot { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; color: var(--icon-ink); }
.slot span { display: flex; flex-direction: column; min-width: 0; }
.slot small { font: 12px/1.4 var(--font-sc); letter-spacing: 0.14em; color: var(--faint); }
.slot b { overflow: hidden; font-size: 19px; font-weight: 400; line-height: 1.3; color: var(--ink); white-space: nowrap; text-overflow: ellipsis; }
.slot:hover b { text-decoration: underline; text-decoration-color: var(--underline); text-underline-offset: 4px; }
.pack-head { display: flex; justify-content: space-between; align-items: baseline; }
.pack-head > span:first-child { font: 14px var(--font-sc); letter-spacing: 0.14em; color: var(--muted); }
#pack-count { font-size: 15px; font-style: italic; color: var(--faint); }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tile {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 4px;
  background: var(--slot);
  border: 1px solid var(--border-strong);
  color: var(--icon-ink);
  font-size: 13px;
  line-height: 1.1;
}
.tile span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 100%;
  text-align: center;
  color: var(--ink);
}
.tile:not(.empty):hover { border-color: var(--rule); }
.tile.empty { background: transparent; border-color: var(--divider); cursor: default; }

/* Hover cards. */
#tip {
  position: fixed;
  z-index: 60;
  width: max-content;
  max-width: min(280px, calc(100vw - 16px));
  padding: 10px 16px 12px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
#tip b { display: block; font-size: 19px; font-weight: 500; line-height: 1.25; color: var(--ink); }
#tip small { display: block; font: 13px/1.5 var(--font-sc); letter-spacing: 0.1em; color: var(--tone, var(--muted)); }
#tip ul { margin: 8px 0 0; padding: 8px 0 0; list-style: none; border-top: 1px solid var(--divider); }
#tip li { margin: 3px 0; font-size: 16px; line-height: 1.4; }
#tip li.cmd { font-style: italic; color: var(--faint); }
#tip li.cmd::before { content: "¶ "; font: 17px var(--font-fell); font-style: normal; color: var(--fainter); }
#tip.tone-healthy { --tone: var(--sound); }
#tip.tone-injured { --tone: var(--injured); }
#tip.tone-crippled, #tip.tone-destroyed, #tip.tone-severed { --tone: var(--rubric); }

/* --- The edge tab and the drawer (used once the sheet collapses) --- */

#sheet-tab {
  display: none;
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 21;
  width: 36px;
  height: 84px;
  margin-top: -42px;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-right: 0;
  color: var(--rubric);
  transition: transform 320ms var(--ease);
}
#sheet-tab svg { transition: transform 320ms var(--ease); }
body.sheet-open #sheet-tab { transform: translateX(calc(-1 * var(--sheet-w))); }
body.sheet-open #sheet-tab svg { transform: rotate(180deg); }
#sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(10, 8, 6, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms ease;
}
body.sheet-open #sheet-backdrop { opacity: 1; pointer-events: auto; }

/* --- Death --- */

#death {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  background: rgba(20, 17, 14, 0.92);
  animation: fade 1.2s ease-out both;
}
.death-title { margin: 0; font: clamp(48px, 9vw, 72px)/1 var(--font-sc); letter-spacing: 0.08em; color: var(--rubric); }
#death-text { max-width: 34ch; margin: 18px auto 0; font-size: 20px; font-style: italic; color: var(--ink); animation: fade 1s 0.6s both; }
body.dead #game { filter: grayscale(0.6) brightness(0.6); }
@keyframes fade { from { opacity: 0; } }

#hud { display: none; }
.hud-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.mini { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.mini .lbl { font: 13px var(--font-sc); letter-spacing: 0.08em; color: var(--muted); }
.mini .num { font-size: 15px; }
.hud-row { display: flex; justify-content: flex-end; gap: 16px; }
.hud-btn { min-height: 32px; font: 15px var(--font-sc); letter-spacing: 0.1em; color: var(--muted); border-bottom: 1px solid var(--underline); }
#map-tools { display: none; }

/* --- Too narrow for both columns: the sheet becomes a drawer behind an
   edge tab, sliding in over the left column. --- */
@media (max-width: 1059px) {
  #game { padding-right: 48px; }
  #side {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    width: var(--sheet-w);
    padding: 18px 16px;
    background: var(--page);
    border-left: 1px solid var(--border-strong);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 320ms var(--ease), visibility 0s linear 320ms;
  }
  body.sheet-open #side {
    transform: none;
    visibility: visible;
    box-shadow: -18px 0 40px rgba(0, 0, 0, 0.5);
    transition: transform 320ms var(--ease), visibility 0s;
  }
  #sheet-tab { display: flex; }
  #sheet-backdrop { display: block; }
}

/* --- Phones: a compact status bar on top; everything else as above. --- */
@media (max-width: 760px) {
  html, body { font-size: 18px; }
  #game {
    min-height: 640px;
    padding: max(8px, env(safe-area-inset-top)) 46px max(8px, env(safe-area-inset-bottom)) 8px;
  }
  #left { gap: 8px; }
  #hud {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: none;
    padding: 6px 12px 4px;
    background: var(--panel);
    border: 1px solid var(--border);
  }

  #map-wrap { min-height: 150px; padding: 8px; }
  #deck { gap: 6px; padding: 8px 12px; }
  #turnbar { gap: 10px; }
  .tb-caption { font-size: 14px; }
  #tb-secs { font-size: 22px; }
  #cmd-form { gap: 8px; padding-bottom: 4px; }
  .prompt { font-size: 24px; }
  .chunky-input, .chunky-layer { font-size: 20px; }
  .chunky-input { height: 44px; }
  #cmd-form .act { height: 44px; padding: 0 16px; }
  .plan { font-size: 16px; }
  .step .when { min-width: 4.4em; }
  .step .options { padding-left: 0; }
  .tab { padding: 0 8px; font-size: 16px; }
  #log { min-height: 200px; padding: 16px 16px 18px; font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }
  .float { animation: fade-out 1s linear forwards !important; animation-duration: 1s !important; }
  @keyframes fade-out { 70% { opacity: 1; } to { opacity: 0; } }
}

/* --- Accounts and the atlas (design §16.1, phase 3) --- */
.plain-input {
  width: 100%;
  height: 40px;
  padding: 0 2px;
  font: 19px/1 var(--font-body);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--rule);
  outline: none;
}
.plain-input:focus { border-bottom-color: var(--muted); }
.account-status { margin: 0 0 8px; text-align: center; font-size: 16px; font-style: italic; color: var(--muted); }
.secure-form { display: flex; flex-direction: column; gap: 8px; }
.secure-form label { font: 13px/1 var(--font-sc); letter-spacing: 0.14em; color: var(--muted); }
.secure-form .act { margin-top: 6px; }

/* A dark manuscript map over the game: no bright areas, no glow. */
.atlas-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  background: rgba(27, 23, 20, 0.92);
}
.atlas-card {
  width: 100%;
  max-width: 760px;
  padding: 12px 16px 16px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
}
/* The atlas button says so: an icon alone among the sound controls hid it. */
.atlas-tool { width: auto; gap: 6px; padding: 0 10px; font: 15px/1 var(--font-sc); letter-spacing: 0.1em; }
.atlas-head { display: flex; align-items: center; justify-content: space-between; }
.atlas-head h2 { margin: 0; font: 15px/1.5 var(--font-sc); font-weight: 400; letter-spacing: 0.2em; color: var(--rubric); }
#atlas-canvas { display: block; margin: 8px auto 0; border: 1px solid var(--border-strong); }
.atlas-info { min-height: 1.4em; margin: 10px 0 0; text-align: center; font-size: 16px; font-style: italic; color: var(--muted); }

/* --- The full-screen layout (the default; ?ui=classic for the columns):
   the map fills the window, with your health, stamina, the turn and your
   orders over it; the sheet is a drawer at every width; the command floats
   under you while you type; the log is the one strip below the map. --- */

body.ui-full #game { gap: 0; min-height: 0; padding: 0; }
body.ui-full #left { position: relative; gap: 0; }
body.ui-full #map-wrap { flex: var(--map-grow, 0.7) 1 0; min-height: 120px; padding: 0; border: 0; }
body.ui-full #map { cursor: default; touch-action: none; }
body.ui-full #map.panning { cursor: grabbing; }
body.ui-full #deck { display: contents; }

/* The card top left: health, stamina, the turn's clock, your orders. */
body.ui-full #hud {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  z-index: 8;
  width: min(340px, calc(100% - 72px));
  max-height: calc(var(--map-h, 60vh) - 24px);
  overflow-y: auto;
  padding: 10px 14px 10px;
  background: rgba(35, 30, 25, 0.9);
  border: 1px solid var(--border);
  scrollbar-width: thin;
}
body.ui-full .hud-row { display: none; }
/* The turn bar: across the window between the map and the log, and the
   handle that trades one for the other. */
body.ui-full #turnbar {
  flex: none;
  gap: 14px;
  padding: 6px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border);
}
body.ui-full.fighting #turnbar { border-top-color: var(--rubric); }
body.ui-full .tb-caption { font-size: 14px; }
body.ui-full #tb-secs { font-size: 22px; }
body.ui-full.fighting #hud { border-color: var(--rubric); }
body.ui-full #plan { font-size: 16px; }
body.ui-full #plan:has(.idle) { display: none; }
body.ui-full .step .options { padding-left: 0; }

/* The command: under you, only while you type. */
body.ui-full #cmd-form {
  display: none;
  position: absolute;
  z-index: 9;
  width: min(440px, calc(100% - 24px));
  gap: 8px;
  padding: 4px 10px 4px 14px;
  background: rgba(35, 30, 25, 0.95);
  border: 1px solid var(--border-strong);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
body.ui-full.typing #cmd-form { display: flex; }
body.ui-full #cmd-form .chunky-input { height: 42px; }
body.ui-full #cmd-form .act { height: 36px; padding: 0 14px; }

/* Bottom right of the map: zoom, follow, and on touch screens a keyboard. */
body.ui-full #map-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 8;
}
.map-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: rgba(35, 30, 25, 0.9);
  border: 1px solid var(--border);
  color: var(--muted);
}
.map-tool:hover { color: var(--ink); border-color: var(--border-strong); }
.map-tool:disabled { opacity: 0.4; cursor: default; }
#follow-btn[aria-pressed="true"] { color: var(--rubric); border-color: var(--rubric); }
#kbd-btn { display: none; }
@media (pointer: coarse) { #kbd-btn { display: flex; } }

/* The log: the strip below the turn bar. */
body.ui-full .log-head { padding: 0 12px; background: var(--page); }
body.ui-full #log {
  flex: var(--log-grow, 0.3) 1 0;
  min-height: 90px;
  padding: 10px 24px 14px;
  border-width: 0;
  font-size: 18px;
}
body.ui-full .log-head .tab { min-height: 36px; }
body.ui-full .log-head .tool { height: 36px; }

/* The sheet: a drawer behind the edge tab, at every width. */
body.ui-full #side {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: var(--sheet-w);
  padding: 18px 16px;
  background: var(--page);
  border-left: 1px solid var(--border-strong);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 320ms var(--ease), visibility 0s linear 320ms;
}
body.ui-full.sheet-open #side {
  transform: none;
  visibility: visible;
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.5);
  transition: transform 320ms var(--ease), visibility 0s;
}
body.ui-full #sheet-tab { display: flex; top: 30%; }
body.ui-full #sheet-backdrop { display: block; }

@media (max-width: 760px) {
  body.ui-full #game { padding: 0; }
  body.ui-full #hud { left: 8px; width: calc(100% - 64px); padding: 8px 12px; }
  body.ui-full .hud-stats { gap: 10px; }
  body.ui-full #map-tools { flex-direction: row; right: 8px; bottom: 8px; }
  body.ui-full #log { padding: 8px 14px 12px; font-size: 17px; }
}
