/* Endless Maze — ink & lamplight.
 * Near-black ground, parchment text, hairline brass rules.
 * Display: Cormorant Garamond. Working text: IBM Plex Mono.
 */

:root {
  --ink: #0b0a08;
  --ink-2: #121110;
  --ink-3: #1a1816;
  --parchment: #d8cfc0;
  --parchment-dim: #8d8576;
  --brass: #c9a227;
  --brass-dim: #6e5a1d;
  --blood: #c0554a;
  --region-accent: #8b93ad;
  --region-glow: #aab3d0;
  --hairline: 1px solid #2a2620;
}

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

html, body {
  height: 100%;
  background: var(--ink);
  color: var(--parchment);
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 13px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: 46px 1fr;
  grid-template-columns: 1fr 318px;
  grid-template-areas:
    'header header'
    'stage  panel';
  height: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 12px 12px;
  gap: 10px;
  position: relative;          /* anchors the floating chronicle */
}

/* ---------------- header ---------------- */
#header {
  grid-area: header;
  display: flex;
  align-items: baseline;
  gap: 18px;
  border-bottom: var(--hairline);
  padding: 12px 4px 8px;
}
#btn-name { color: var(--brass) !important; border-color: var(--brass-dim) !important; }
#btn-name.hidden { display: none; }
#h-room {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 23px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--parchment);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#h-region {
  color: var(--region-accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  white-space: nowrap;
}
#h-coords {
  color: var(--parchment-dim);
  font-size: 11px;
  margin-left: auto;
  white-space: nowrap;
}
#header .hbtns { display: flex; gap: 8px; margin-left: auto; }
#header button {
  background: none;
  border: 1px solid #2e2a23;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
}
#header button:hover { color: var(--brass); border-color: var(--brass-dim); }

/* ---------------- stage ---------------- */
#stage {
  grid-area: stage;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, #131110 0%, #0b0a08 75%);
  border: var(--hairline);
  min-height: 0;
}
#game-canvas {
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 780 / 572;
  image-rendering: auto;
  display: block;
}

/* ---------------- chronicle (the game log, on screen) ---------------- */
/* desktop: a quiet ribbon floating over the bottom-left of the board */
#chronicle {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: min(42%, 440px);
  max-height: 30%;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(6,5,4,0) 0%, rgba(6,5,4,0.6) 42%);
  border-radius: 3px;
  z-index: 8;
  pointer-events: none;
}
#chron-feed {
  max-height: 30vh;
  overflow: hidden;
  padding: 6px 12px 4px;
  font-size: 11.5px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

/* ---------------- spell quickbar (bottom-centre of stage) ---------------- */
#spellbar {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 56%;
  z-index: 9;
}
.spell-slot {
  position: relative;
  min-width: 58px;
  background: rgba(12, 11, 10, 0.82);
  border: 1px solid #3a342a;
  border-left: 3px solid var(--sp, #c9a227);
  color: var(--parchment);
  font: inherit;
  font-size: 10px;
  padding: 4px 7px 5px;
  cursor: pointer;
  text-align: left;
  line-height: 1.25;
}
.spell-slot:hover { border-color: var(--brass-dim); border-left-color: var(--sp); }
.spell-slot .sk { color: var(--brass); font-weight: 700; margin-right: 4px; }
.spell-slot .sn { color: var(--parchment); display: block; margin-top: 1px; white-space: nowrap; }
.spell-slot .sc { position: absolute; top: 3px; right: 5px; color: var(--parchment-dim); font-size: 9px; }

/* ---------------- traveler panel ---------------- */
#panel {
  grid-area: panel;
  border: var(--hairline);
  background: var(--ink-2);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel-h {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--brass-dim);
  border-bottom: var(--hairline);
  padding-bottom: 4px;
  margin-bottom: 6px;
}
#p-name {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 20px;
  font-weight: 600;
}
#p-level { color: var(--parchment-dim); font-size: 11px; }

.bar {
  height: 10px;
  background: #060505;
  border: 1px solid #2a2620;
  position: relative;
  margin: 4px 0 2px;
}
.bar-fill {
  height: 100%;
  transition: width 0.25s ease;
}
#hp-fill { background: linear-gradient(180deg, #d0685c, #963f35); }
#xp-fill { background: linear-gradient(180deg, #d9b958, #8a6f1f); }
.bar-num {
  font-size: 10px;
  color: var(--parchment-dim);
  display: flex;
  justify-content: space-between;
}

.tallies {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  text-align: center;
}
.tally:nth-child(2) b { color: #e0b84e; }   /* gold */
.tally {
  border: var(--hairline);
  padding: 6px 2px;
  background: var(--ink-3);
}
.tally b { display: block; font-size: 15px; color: var(--parchment); font-weight: 600; }
.tally span { font-size: 9px; letter-spacing: 1px; text-transform: uppercase; color: var(--parchment-dim); }

.stat-row { display: flex; justify-content: space-between; font-size: 12px; }
.stat-row span:first-child { color: var(--parchment-dim); }

.panel-block { display: flex; flex-direction: column; gap: 6px; }
.panel-h-note { color: var(--parchment-dim); letter-spacing: 0; text-transform: none; font-size: 9px; }

/* status chips */
#status-row { display: flex; flex-wrap: wrap; gap: 4px; min-height: 0; }
#status-row:empty { display: none; }
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 9.5px;
  padding: 2px 6px;
  border: 1px solid;
  border-radius: 10px;
  background: rgba(0,0,0,0.25);
  white-space: nowrap;
}
.status-chip .sct { opacity: 0.7; }

/* shield overlay on the vitality bar */
.bar-shield {
  position: absolute;
  top: 0; left: 0; height: 100%;
  background: repeating-linear-gradient(135deg, rgba(143,212,234,0.55) 0 4px, rgba(143,212,234,0.2) 4px 8px);
  pointer-events: none;
}

/* bearing two-column */
.bearing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; }

/* equipment grid */
#equip { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.eq-slot {
  border-left: 2px solid var(--region-accent);
  padding: 4px 7px;
  background: var(--ink-3);
  line-height: 1.25;
  cursor: pointer;
  min-height: 38px;
}
.eq-slot:hover { background: #211e1a; }
.eq-slot .eql { display: block; font-size: 8.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--brass-dim); }
.eq-slot .eqn { font-size: 10.5px; color: var(--parchment); }
.eq-slot.empty { border-left-color: #2a2620; cursor: default; }
.eq-slot.empty .eqn { color: #5a5446; font-style: italic; }

#bag { display: flex; flex-direction: column; gap: 4px; }
.bag-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 3px 6px;
  background: var(--ink-3);
  border: var(--hairline);
}
.bag-empty { color: var(--parchment-dim); font-style: italic; font-size: 11px; }
.bag-actions { display: flex; gap: 4px; flex-shrink: 0; }
.bag-actions button, #btn-salve {
  background: none;
  border: 1px solid #3a342a;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 10px;
  padding: 2px 7px;
  cursor: pointer;
}
.bag-actions button:hover, #btn-salve:hover:not(:disabled) { color: var(--brass); border-color: var(--brass-dim); }
#btn-salve { width: 100%; padding: 6px; margin-top: 4px; }
#btn-salve:disabled { opacity: 0.35; cursor: default; }

/* ---------------- chronicle lines ---------------- */
.log-line { color: var(--parchment-dim); text-shadow: 0 1px 3px rgba(0,0,0,0.9); }
.log-line.room {
  color: var(--parchment);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 14px;
  margin-top: 4px;
}
.log-line.good { color: #a8c08a; }
.log-line.dim { color: #6b6457; font-style: italic; }
.log-line.discover { color: var(--region-glow); }
.log-line.mark { color: #d6b25c; }
.log-line.level { color: var(--brass); }
.log-line.death { color: var(--blood); }

/* ---------------- overlays ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 5, 4, 0.82);
  z-index: 50;
}
.overlay.open { display: flex; }
.ov-card {
  background: var(--ink-2);
  border: 1px solid #3a342a;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.8);
  padding: 26px 30px;
  max-width: 460px;
  width: calc(100% - 60px);
  max-height: 80%;
  overflow-y: auto;
  position: relative;
}
.ov-card h2 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}
.ov-sub { color: var(--parchment-dim); font-size: 11px; margin-bottom: 14px; }
.ov-close {
  position: absolute;
  top: 10px; right: 12px;
  background: none;
  border: none;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.ov-close:hover { color: var(--brass); }

.helps { display: grid; grid-template-columns: 92px 1fr; gap: 5px 14px; font-size: 12px; }
.helps kbd {
  font-family: inherit;
  border: 1px solid #3a342a;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--brass);
  text-align: center;
}
.helps span { color: var(--parchment-dim); }
.help-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: var(--hairline); }
.help-toggles { display: flex; gap: 8px; }
.help-foot #btn-mute, .help-foot #btn-music {
  background: none; border: 1px solid #3a342a; color: var(--parchment-dim);
  font: inherit; font-size: 11px; padding: 4px 12px; cursor: pointer;
}
.help-foot #btn-mute:hover, .help-foot #btn-music:hover { color: var(--brass); border-color: var(--brass-dim); }

/* onboarding quick guide */
.guide-grid { display: flex; flex-direction: column; gap: 9px; margin: 4px 0 18px; }
.guide-item { display: grid; grid-template-columns: 74px 1fr; gap: 12px; align-items: baseline; }
.guide-item b {
  font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 600; font-size: 16px;
  color: var(--brass); text-align: right;
}
.guide-item span { color: #c4bbaa; font-size: 12px; line-height: 1.5; }
.guide-item kbd {
  font-family: inherit; border: 1px solid #3a342a; padding: 0 5px;
  font-size: 10px; color: var(--brass);
}
.guide-item em { color: #cfc4ab; font-style: italic; }
#ov-guide .ov-actions { justify-content: center; }
#ov-guide .ov-actions button { padding: 9px 32px; }

#map-canvas { display: block; background: #0a0908; border: var(--hairline); }
#map-stats { color: var(--parchment-dim); font-size: 11px; margin-top: 10px; }
#ov-map .ov-card { max-width: 560px; }

.shop-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border: var(--hairline);
  background: var(--ink-3);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.shop-name { font-size: 13px; }
.shop-desc { color: var(--parchment-dim); font-size: 11px; margin-top: 2px; }
.shop-item button {
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 11px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.shop-item button:disabled { opacity: 0.35; cursor: default; }
.shop-item button.gold { color: #e0b84e; border-color: #8a6f2a; }
#shop-marks { color: var(--brass); font-size: 12px; margin-bottom: 12px; }

/* charges (quests) & journal */
.quest-offer-box {
  border: 1px solid var(--brass-dim);
  background: var(--ink-3);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.quest-desc { font-size: 13px; color: var(--parchment); }
.quest-reward { font-size: 11px; color: #a8c08a; }
.quest-accept {
  align-self: flex-start;
  margin-top: 3px;
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 11px;
  padding: 5px 12px;
  cursor: pointer;
}
.quest-accept:hover:not(:disabled) { background: var(--brass); color: var(--ink); }
.quest-accept:disabled { opacity: 0.35; cursor: default; }
.quest-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border: var(--hairline);
  background: var(--ink-3);
  padding: 8px 11px;
  margin-bottom: 6px;
}
.quest-prog { font-size: 11px; color: var(--parchment-dim); margin-top: 2px; }
.quest-none { font-size: 12px; color: #6b6457; font-style: italic; }
.journal-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 2px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  margin-bottom: 4px;
  cursor: pointer;
}
.journal-item:hover { background: var(--ink-3); }
.story-text {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 16px;
  line-height: 1.65;
  color: #cfc4ab;
}
#ov-story h2 { color: var(--parchment); }

.travel-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  background: var(--ink-3);
  border: var(--hairline);
  color: var(--parchment);
  font: inherit;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 7px;
  cursor: pointer;
}
.travel-item:hover { border-color: var(--brass-dim); }
.travel-item.here { opacity: 0.45; cursor: default; }
.travel-sub { color: var(--parchment-dim); font-size: 11px; margin-top: 2px; }

#carve-input, #rename-input {
  width: 100%;
  background: #060505;
  border: 1px solid #3a342a;
  color: var(--parchment);
  font: inherit;
  font-size: 13px;
  padding: 9px 10px;
  margin: 6px 0 14px;
}
#carve-input:focus, #rename-input:focus { outline: none; border-color: var(--brass-dim); }
#ov-rename .ov-card { border-color: #4a4226; }
.ov-actions { display: flex; gap: 10px; justify-content: flex-end; }
.ov-actions button {
  background: none;
  border: 1px solid #3a342a;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 12px;
  padding: 7px 16px;
  cursor: pointer;
}
.ov-actions button.primary { color: var(--brass); border-color: var(--brass-dim); }
.ov-actions button:hover { color: var(--brass); }

#lore-text {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 17px;
  font-style: italic;
  line-height: 1.6;
  color: #cfc4ab;
}

/* ---------------- tavern (chat) ---------------- */
.ov-card-chat { max-width: 520px; }
#chat-auth { display: flex; flex-direction: column; gap: 9px; }
#chat-user, #chat-pass, #chat-input {
  width: 100%;
  background: #060505;
  border: 1px solid #3a342a;
  color: var(--parchment);
  font: inherit;
  font-size: 13px;
  padding: 9px 10px;
}
#chat-user:focus, #chat-pass:focus, #chat-input:focus { outline: none; border-color: var(--brass-dim); }
.chat-msg { font-size: 11px; min-height: 14px; color: var(--parchment-dim); margin-top: 2px; }
.chat-msg.err { color: var(--blood); }
#chat-feed {
  height: 340px;
  max-height: 52vh;
  overflow-y: auto;
  border: var(--hairline);
  background: #060505;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 8px;
}
.chat-line { color: var(--parchment); margin-bottom: 2px; word-break: break-word; }
.chat-who-name { color: var(--brass); font-weight: 700; }
.linkname {
  background: none; border: none; padding: 0; font: inherit;
  cursor: pointer;
}
.linkname:hover { text-decoration: underline; }
.chat-flag {
  background: none; border: none; color: #5a5446; font: inherit; font-size: 9px;
  cursor: pointer; margin-left: 6px; opacity: 0; transition: opacity 0.15s;
}
.chat-line:hover .chat-flag { opacity: 1; }
.chat-flag:hover { color: var(--blood); text-decoration: underline; }
.chat-flag.done { color: var(--blood); opacity: 1; cursor: default; text-decoration: none; }
body.touch .chat-flag { opacity: 0.7; }   /* no hover on touch — keep flags visible */
.chat-whisper .chat-wlabel { color: #b79be0; font-weight: 700; font-style: italic; }
.chat-whisper .chat-body { color: #c8badf; font-style: italic; }
.chat-system { color: #6b6457; font-style: italic; }
.chat-inputrow { display: flex; gap: 8px; }
.chat-inputrow #chat-input { flex: 1; }
#chat-send {
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 12px;
  padding: 7px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.chat-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--parchment-dim);
}
.linkbtn {
  background: none; border: none; color: var(--parchment-dim);
  font: inherit; font-size: 11px; cursor: pointer; text-decoration: underline;
}
.linkbtn:hover { color: var(--brass); }
.hidden { display: none !important; }

#ov-death .ov-card { text-align: center; border-color: #4a2622; }
#death-where { color: var(--parchment-dim); font-size: 12px; margin: 8px 0 20px; }
#btn-respawn {
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 13px;
  padding: 10px 26px;
  cursor: pointer;
}

/* ---------------- title screen ---------------- */
#title-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0b0a08;
  transition: opacity 0.7s ease, visibility 0s 0.7s;
  overflow: hidden;
}
#title-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 46%;
  opacity: 0.62;
}
#title-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(11,10,8,0.20) 0%, rgba(11,10,8,0.72) 52%, rgba(11,10,8,0.96) 100%),
    linear-gradient(180deg, rgba(11,10,8,0.65) 0%, rgba(11,10,8,0.1) 26%, rgba(11,10,8,0.55) 64%, rgba(11,10,8,0.95) 100%);
}
.title-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#title-screen.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.title-rule {
  width: 220px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brass-dim), transparent);
  margin: 18px 0;
}
#title-screen h1 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 62px;
  font-weight: 600;
  letter-spacing: 14px;
  text-indent: 14px;
  color: var(--parchment);
  text-shadow: 0 0 40px rgba(201, 162, 39, 0.15);
}
.title-sub {
  color: var(--parchment-dim);
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
}
.title-lore {
  max-width: 430px;
  text-align: center;
  color: #7d7568;
  font-size: 12.5px;
  line-height: 1.7;
  margin-top: 6px;
}
#onboard { display: flex; flex-direction: column; align-items: center; gap: 13px; margin-top: 26px; width: 300px; }
#ob-user, #ob-pass {
  width: 100%;
  background: #060505;
  border: none;
  border-bottom: 1px solid #3a342a;
  color: var(--parchment);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  text-align: center;
  padding: 8px 14px;
}
#ob-user:focus, #ob-pass:focus { outline: none; border-bottom-color: var(--brass); }
#ob-user::placeholder, #ob-pass::placeholder { color: #55503f; font-style: italic; }
#ob-terms {
  display: flex; align-items: flex-start; gap: 7px;
  font-size: 11px; color: var(--parchment-dim); line-height: 1.45;
  text-align: left; max-width: 300px; cursor: pointer;
}
#ob-terms a { color: var(--brass); }
#ob-agree { margin-top: 2px; accent-color: var(--brass); flex-shrink: 0; }
#ob-msg { font-size: 11.5px; color: var(--blood); min-height: 14px; text-align: center; }
.ob-hint { font-size: 10.5px; color: #5a5446; max-width: 300px; line-height: 1.5; text-align: center; }
#resume-block { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 26px; }
.resume-line { color: var(--parchment); font-family: 'Cormorant Garamond', Georgia, serif; font-size: 19px; }
.resume-line b { color: var(--brass); font-weight: 600; }
#btn-switch { margin-top: 2px; }
.title-actions { display: flex; gap: 14px; margin-top: 22px; }
.title-actions button {
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 11px 28px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.title-actions button:hover { background: var(--brass); color: var(--ink); }
.title-actions button.hidden { display: none; }
.title-foot {
  position: absolute;
  bottom: 24px;
  color: #55503f;
  font-size: 10.5px;
  letter-spacing: 1px;
}

/* ---------------- touch controls (phones / tablets) ---------------- */
#game-canvas { touch-action: none; }
.touch-only { display: none; }

/* drawer dismissal: a tappable scrim behind open drawers + close buttons */
#drawer-scrim {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 190;
}
#drawer-scrim.show { display: block; }
.drawer-close {
  display: none;
  position: absolute;
  top: 6px; right: 8px;
  z-index: 3;
  background: rgba(12, 11, 10, 0.9);
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit; font-size: 11px;
  padding: 5px 11px;
  border-radius: 5px;
  cursor: pointer;
}

#touch-controls {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 90;                 /* above the board, below the title screen (100) */
}
body.touch #touch-controls { display: flex; }
#touch-controls > * { pointer-events: auto; }

#dpad { display: grid; grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); gap: 5px; }
.dbtn {
  display: flex; align-items: center; justify-content: center;
  background: rgba(12, 11, 10, 0.8);
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  border-radius: 7px;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.dbtn:active { background: rgba(201, 162, 39, 0.28); }
.dbtn.up { grid-column: 2; grid-row: 1; }
.dbtn.left { grid-column: 1; grid-row: 2; }
.dbtn.wait { grid-column: 2; grid-row: 2; }
.dbtn.right { grid-column: 3; grid-row: 2; }
.dbtn.down { grid-column: 2; grid-row: 3; }
.dbtn i { display: block; width: 0; height: 0; }
.dbtn.up i { border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 11px solid currentColor; }
.dbtn.down i { border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 11px solid currentColor; }
.dbtn.left i { border-top: 8px solid transparent; border-bottom: 8px solid transparent; border-right: 11px solid currentColor; }
.dbtn.right i { border-top: 8px solid transparent; border-bottom: 8px solid transparent; border-left: 11px solid currentColor; }
.dbtn.wait i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

#touch-actions { display: flex; flex-direction: column; gap: 7px; }
.abtn {
  background: rgba(12, 11, 10, 0.8);
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit; font-size: 13px;
  padding: 10px 18px;
  border-radius: 7px;
  min-width: 66px; text-align: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.abtn:active { background: rgba(201, 162, 39, 0.28); }
.abtn.act-e { font-weight: 700; font-size: 16px; }

/* full mobile layout: canvas on top, the log on screen, controls below;
   the satchel is a slide-in drawer, the tavern is its overlay */
@media (max-width: 1100px) {
  body.touch .touch-only { display: inline-block; }
  body.touch .drawer-close { display: block; }
  body.touch #app {
    grid-template-columns: 1fr;
    grid-template-rows: 44px auto minmax(48px, 1fr) auto;
    grid-template-areas: 'header' 'stage' 'log' 'controls';
    max-width: none;
    padding: 0 6px;
    gap: 5px;
  }
  body.touch #stage {
    grid-area: stage;
    border: none;
    align-items: center;
    overflow: hidden;
  }
  body.touch #game-canvas { width: 100%; height: auto; max-height: 60vh; }
  /* the chronicle is now an on-screen log panel below the board */
  body.touch #chronicle {
    grid-area: log;
    position: static;
    width: auto;
    max-height: none;
    overflow-y: auto;
    pointer-events: auto;
    background: rgba(6, 5, 4, 0.5);
    border: 1px solid rgba(58, 52, 42, 0.4);
    border-radius: 4px;
  }
  body.touch #chronicle #chron-feed {
    max-height: none;
    overflow: visible;
    justify-content: flex-start;
    padding: 6px 11px;
  }
  body.touch #spellbar { bottom: 8px; right: 8px; max-width: 64%; }
  body.touch #touch-controls {
    position: static;
    grid-area: controls;
    padding: 4px 10px calc(env(safe-area-inset-bottom, 0px) + 6px);
  }
  /* satchel drawer */
  body.touch #panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(88%, 360px);
    max-height: none;
    flex-direction: column; flex-wrap: nowrap;
    z-index: 200;
    transform: translateX(103%);
    transition: transform 0.22s ease;
    box-shadow: -12px 0 50px rgba(0, 0, 0, 0.7);
  }
  body.touch #panel.open { transform: none; }
  body.touch #panel > * { flex: 0 0 auto; }
}

/* ---------------- narrow screens (non-touch / fallback) ---------------- */
@media (max-width: 940px) {
  body:not(.touch) #app {
    grid-template-columns: 1fr;
    grid-template-rows: 46px minmax(300px, 1fr) auto;
    grid-template-areas: 'header' 'stage' 'panel';
  }
  body:not(.touch) #panel { flex-direction: row; flex-wrap: wrap; align-content: flex-start; max-height: 40vh; }
  body:not(.touch) #panel > * { flex: 1 1 240px; }
  body:not(.touch) #chronicle { width: min(60%, 380px); }
}
@media (max-width: 560px) {
  #title-screen h1 { font-size: 38px; letter-spacing: 7px; text-indent: 7px; }
  #onboard { width: 280px; }
  .spell-slot { min-width: 50px; font-size: 9.5px; }
  .ov-card { padding: 20px 18px; }
}
