/* The HUD is DOM over the canvas: text stays crisp at any resolution, it
   reflows for a phone without a second layout pass, and a screen reader can
   still find the chat. Everything here is pointer-events:none by default, so
   the canvas keeps the drags unless a control explicitly claims them. */

:root {
  --gold: #e0b850;
  --wood: #b07a45;
  --ink: #10140d;
  --parch: #efe4cb;
  --blood: #b8412f;
  --friend: #6fa8d8;
  --ui-pad: max(12px, env(safe-area-inset-left));
  --font: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--ink); color: var(--parch);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas#view {
  display: block; width: 100%; height: 100%;
  touch-action: none;
}

#ui {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* #ui is pointer-transparent, and anything that wants clicks opts back in.
   A blanket `#ui > *` rule would out-specify the panels' own `auto` and quietly
   make the whole lobby unclickable, which is exactly what it did once. */
.clickable, button, input, select, textarea { pointer-events: auto; }
.lobby.on, .tune.on, .loading.on { pointer-events: auto; }

/* ---------------------------------------------------------------- loading */

.loading {
  position: fixed; inset: 0; display: none; place-items: center;
  background: radial-gradient(circle at 50% 40%, #1c2417, #0b0e08 70%);
  pointer-events: auto; z-index: 60; text-align: center;
}
.loading.on { display: grid; }
.loading h1 { font-size: clamp(22px, 4vw, 38px); margin: 0 0 22px; letter-spacing: .02em; }
.loadbar { width: min(60vw, 380px); height: 6px; background: rgba(239,228,203,.16); border-radius: 3px; overflow: hidden; }
.loadbar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .18s ease-out; }
.loading p { opacity: .6; margin-top: 14px; font-size: 14px; }

/* ------------------------------------------------------------------ lobby */

.lobby {
  position: fixed; inset: 0; display: none; overflow: auto;
  background: radial-gradient(circle at 50% 25%, #202b1a, #0b0e08 75%);
  pointer-events: auto; z-index: 50;
}
.lobby.on { display: block; }
.lobby-inner { max-width: 780px; margin: 0 auto; padding: clamp(20px, 5vh, 60px) 20px 60px; }
.lobby header h1 { font-size: clamp(26px, 5vw, 46px); margin: 0 0 6px; }
.lobby header p { margin: 0 0 28px; opacity: .65; }
.lobby h2 { font-size: 16px; letter-spacing: .09em; text-transform: uppercase; opacity: .6; margin: 0; }
.lobby section { margin-bottom: 26px; }

.lobby-you label { display: block; font-size: 13px; opacity: .7; margin-bottom: 14px; }
.lobby input[type=text], .lobby input:not([type]) {
  display: block; margin-top: 6px; width: min(320px, 100%);
  background: rgba(0,0,0,.35); border: 1px solid rgba(239,228,203,.22);
  color: var(--parch); border-radius: 7px; padding: 9px 12px; font: inherit; font-size: 15px;
}
.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.char {
  text-align: left; background: rgba(255,255,255,.045); border: 1px solid transparent;
  border-radius: 9px; padding: 10px 12px; color: inherit; font: inherit; cursor: pointer;
}
.char b { display: block; font-size: 15px; }
.char span { font-size: 12px; opacity: .55; }
.char:hover { background: rgba(255,255,255,.09); }
.char.on { border-color: var(--gold); background: rgba(224,184,80,.12); }

.games-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.game-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.game-list li {
  display: flex; align-items: center; gap: 14px;
  background: rgba(255,255,255,.05); border-radius: 9px; padding: 12px 14px;
}
.game-list li.empty { display: block; opacity: .5; font-size: 14px; }
.game-main { flex: 1; min-width: 0; }
.game-main b { display: block; }
.game-main span { font-size: 12px; opacity: .55; }
.game-meta { display: grid; text-align: right; font-size: 12px; opacity: .6; }

button.primary, button.ghost, button.join {
  font: inherit; border-radius: 8px; cursor: pointer; padding: 10px 18px;
  border: 1px solid transparent; color: var(--parch); background: rgba(255,255,255,.08);
}
button.primary { background: var(--gold); color: #241b06; font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border-color: rgba(239,228,203,.25); font-size: 13px; padding: 7px 12px; }
button.ghost:hover { background: rgba(255,255,255,.07); }
button.join { padding: 8px 16px; background: rgba(111,168,216,.2); border-color: rgba(111,168,216,.45); }
.lobby footer .hint { font-size: 12px; opacity: .45; margin-top: 14px; max-width: 48ch; }

/* -------------------------------------------------------------------- hud */

.hud-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 12; }
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 14; font-size: 14px; }
.hud > div { position: absolute; }

.hud-tl { left: var(--ui-pad); top: var(--ui-pad); }
.vital { display: flex; align-items: center; gap: 10px; }
.vital-bar {
  position: relative; width: min(34vw, 230px); height: 15px; border-radius: 8px;
  background: rgba(10,14,8,.62); overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.vital-bar i, .vital-bar b { position: absolute; inset: 0 auto 0 0; display: block; border-radius: 8px; }
.vital-bar b { background: rgba(232,120,90,.5); }
.vital-bar i { background: linear-gradient(#8fd07a, #5f9c4a); z-index: 1; transition: width .08s linear; }
.vital-bar i.low { background: linear-gradient(#e08a6a, #b8412f); }
.vital-name { font-weight: 700; text-shadow: 0 1px 3px #000; }
.purse { margin-top: 8px; display: flex; gap: 14px; text-shadow: 0 1px 3px #000; }
.purse .coin { color: var(--gold); } .purse .log { color: var(--wood); }
.purse b { font-size: 16px; }

.hud-tr { right: var(--ui-pad); top: var(--ui-pad); text-align: right; }
.phase { font-weight: 700; text-shadow: 0 1px 3px #000; letter-spacing: .02em; }
.nests { margin-top: 6px; display: grid; gap: 4px; justify-items: end; }
.nest { position: relative; width: 130px; height: 15px; background: rgba(10,14,8,.6); border-radius: 4px; overflow: hidden; }
.nest span { position: absolute; inset: 0; z-index: 1; font-size: 11px; line-height: 15px; padding-right: 6px; text-align: right; }
.nest i { position: absolute; inset: 0 auto 0 0; background: rgba(200,80,60,.55); }
.nest.gone { opacity: .35; }
.nest.gone i { background: rgba(120,140,120,.4); }

.hud-bc { left: 50%; transform: translateX(-50%); bottom: 96px; text-align: center; width: min(92vw, 640px); }
.prompt { opacity: 0; transition: opacity .16s; text-shadow: 0 1px 4px #000; font-size: 15px; }
.prompt.on { opacity: 1; }
.prompt b { color: var(--gold); }
.prompt .bad, .notice-line.bad { color: #ffa08c; }
.notice { margin-top: 8px; display: grid; gap: 3px; }
.notice-line { font-size: 13px; text-shadow: 0 1px 4px #000; animation: rise .25s ease-out; }
.notice-line.good { color: #a7e08a; }
.notice-line.story { color: #f0e0b8; font-style: italic; font-size: 15px; }
.notice-line.bark { color: #cfe0ff; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.hud-bl { left: var(--ui-pad); bottom: var(--ui-pad); width: min(46vw, 380px); }
.chat-log { max-height: 26vh; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
.chat-line { font-size: 13px; text-shadow: 0 1px 3px #000; padding: 1px 0; transition: opacity .4s; }
.chat-line b { color: #9fd0ff; }
.chat-line.sys { opacity: .6; font-style: italic; }
.chat-form { display: none; margin-top: 6px; }
.hud.chatting .chat-form { display: block; }
.hud.chatting .chat-log { background: rgba(8,10,6,.5); border-radius: 8px; padding: 6px 8px; }
.chat-input {
  width: 100%; background: rgba(8,10,6,.8); border: 1px solid rgba(239,228,203,.3);
  border-radius: 7px; padding: 7px 10px; color: var(--parch); font: inherit; font-size: 14px;
}

.hud-dead { inset: 0; display: none; place-content: center; text-align: center; background: rgba(60,10,6,.3); }
.hud-dead.on { display: grid; }
.hud-dead h2 { font-size: 30px; margin: 0; text-shadow: 0 2px 8px #000; }
.dead-timer { opacity: .75; }

.hud-buttons { right: var(--ui-pad); bottom: var(--ui-pad); display: flex; gap: 8px; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer;
  background: rgba(10,14,8,.55); border: 1px solid rgba(239,228,203,.2); color: var(--parch);
}
.iconbtn:hover { background: rgba(10,14,8,.8); }

/* touch controls, only when a finger last touched something */
.touch { display: none; inset: 0; pointer-events: none; }
.hud.touching .touch { display: block; }
.tbtn {
  position: absolute; border-radius: 50%; border: 2px solid rgba(239,228,203,.3);
  background: rgba(10,14,8,.42); color: var(--parch); font-size: 26px; pointer-events: auto;
}
.tbtn:active { background: rgba(224,184,80,.4); }
.tbtn-attack { right: 22px; bottom: 92px; width: 88px; height: 88px; font-size: 34px; }
.tbtn-roll { right: 122px; bottom: 132px; width: 58px; height: 58px; }
.tbtn-use { right: 122px; bottom: 62px; width: 58px; height: 58px; }
.tbtn-guard { right: 30px; bottom: 194px; width: 52px; height: 52px; font-size: 20px; }
.hud.touching .hud-bl { width: min(40vw, 260px); bottom: 200px; }

/* -------------------------------------------------------------- cinematic */

.cine { position: fixed; inset: 0; pointer-events: none; z-index: 30; --bar: 0vh; }
.cine-bar { position: absolute; left: 0; right: 0; height: var(--bar); background: #070905; transition: height .5s ease; }
.cine-top { top: 0; } .cine-bottom { bottom: 0; }
.cine-text { position: absolute; left: 0; right: 0; bottom: calc(var(--bar) + 22px); text-align: center; padding: 0 24px; }
.cine-text p {
  margin: 0 auto; max-width: 62ch; font-size: clamp(16px, 2.4vw, 23px); line-height: 1.45;
  text-shadow: 0 2px 10px #000, 0 0 30px rgba(0,0,0,.8); opacity: 0;
}
.cine-text p.in { animation: cinefade 0.5s ease-out forwards; }
@keyframes cinefade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.cine-title { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; opacity: 0; transition: opacity .8s; }
.cine-title.on { opacity: 1; }
.cine-title h1 { font-size: clamp(30px, 7vw, 68px); margin: 0; letter-spacing: .06em; text-shadow: 0 4px 24px #000; }
.cine-title h2 { font-size: clamp(13px, 2vw, 18px); margin: 8px 0 0; font-weight: 400; opacity: .7; letter-spacing: .22em; text-transform: uppercase; }
.cine-skip {
  position: absolute; right: 22px; bottom: calc(var(--bar) + 22px); pointer-events: auto;
  background: rgba(0,0,0,.4); border: 1px solid rgba(239,228,203,.28); color: var(--parch);
  border-radius: 20px; padding: 7px 16px; font: inherit; font-size: 13px; cursor: pointer;
  opacity: 0; transition: opacity .4s;
}
.cine.on .cine-skip { opacity: .8; }
.cine-skip:hover { opacity: 1; background: rgba(0,0,0,.7); }

/* ------------------------------------------------------------------- tune */

.tune {
  position: fixed; inset: 0; display: none; place-items: center; z-index: 40;
  background: rgba(6,8,5,.55); pointer-events: auto; backdrop-filter: blur(2px);
}
.tune.on { display: grid; }
.tune-panel {
  width: min(94vw, 760px); max-height: min(88vh, 720px); display: flex; flex-direction: column;
  background: #171d13; border: 1px solid rgba(239,228,203,.16); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6); overflow: hidden;
}
.tune-panel header { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-bottom: 1px solid rgba(239,228,203,.12); }
.tune-panel header h2 { margin: 0; font-size: 17px; flex-shrink: 0; }
.tune-search {
  flex: 1; background: rgba(0,0,0,.35); border: 1px solid rgba(239,228,203,.18);
  border-radius: 7px; padding: 7px 10px; color: var(--parch); font: inherit; font-size: 13px;
}
.tune-tabs { display: flex; gap: 4px; padding: 10px 14px 0; flex-wrap: wrap; }
.tune-tabs button {
  font: inherit; font-size: 12px; padding: 6px 11px; border-radius: 7px 7px 0 0; cursor: pointer;
  background: transparent; border: none; color: rgba(239,228,203,.55);
}
.tune-tabs button.on { background: rgba(255,255,255,.08); color: var(--parch); }
.tune.searching .tune-tabs { display: none; }
.tune-body { flex: 1; overflow: auto; padding: 10px 16px 16px; }
.tune-group { display: none; }
.tune-group.on { display: block; }
.tune.searching .tune-group.on { display: block; }
.tune.searching .tune-group.on h3 { margin-top: 18px; }
.tune-group h3 { font-size: 14px; margin: 6px 0 2px; display: flex; gap: 8px; align-items: baseline; }
.tune-group h3 em { font-style: normal; font-size: 11px; opacity: .45; letter-spacing: .04em; }
.tune-hint { font-size: 12px; opacity: .5; margin: 0 0 12px; }
.tune-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(140px, 1.4fr); gap: 12px; align-items: center; padding: 5px 0; }
.tune-row label { font-size: 13px; display: grid; }
.tune-row label em { font-style: normal; font-size: 11px; opacity: .42; line-height: 1.35; }
.tune-control { display: flex; gap: 8px; align-items: center; }
.tune-control input[type=range] { flex: 1; accent-color: var(--gold); min-width: 60px; }
.tune-control.is-bool { justify-content: flex-start; }
.tune-control input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }
.tune-num {
  width: 66px; background: rgba(0,0,0,.35); border: 1px solid rgba(239,228,203,.18);
  border-radius: 6px; padding: 4px 6px; color: var(--parch); font: inherit; font-size: 12px;
}
.tune-panel footer { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-top: 1px solid rgba(239,228,203,.12); }
.tune-note { flex: 1; font-size: 12px; opacity: .6; }
.tune-note.good { color: #a7e08a; opacity: 1; }
.tune-note.bad { color: #ffa08c; opacity: 1; }

@media (max-width: 640px) {
  .tune-row { grid-template-columns: 1fr; gap: 2px; }
  .hud-bc { bottom: 76px; }
}

/* The HUD stands down for a cinematic; the canvas overlay it draws into goes
   with it, or health bars would float over the letterbox. */
.hud.hidden, .hud.hidden ~ .hud-canvas { opacity: 0; pointer-events: none; }
.hud { transition: opacity .35s; }

/* A narration beat keeps the voice and the position but not the bars: the game
   is still being played underneath it. */
.cine.narrating .cine-bar { height: 0; }
.cine.narrating .cine-text { bottom: 132px; }
.cine.narrating .cine-text p { font-size: clamp(15px, 2vw, 19px); color: #f2e6c8; }

/* The hall bar only appears once the hall has been hit, and then it stays. */
.hud-hall {
  left: 50%; transform: translateX(-50%); top: var(--ui-pad);
  width: min(46vw, 300px); text-align: center; opacity: 0;
  transition: opacity .5s; pointer-events: none;
}
.hud-hall.on { opacity: 1; }
.hud-hall span { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; opacity: .75; text-shadow: 0 1px 3px #000; }
.hall-bar { height: 8px; margin-top: 4px; background: rgba(10,14,8,.66); border-radius: 4px; overflow: hidden; }
.hall-bar i { display: block; height: 100%; background: linear-gradient(#9fc8e8, #5f88b0); transition: width .2s; }
.hud-hall.urgent .hall-bar i { background: linear-gradient(#e88a6a, #b8412f); }
.hud-hall.urgent span { color: #ffb4a0; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* The ending. Shown after the last line of the cinematic, never over it. */
.hud-over {
  inset: 0; display: none; place-content: center; text-align: center;
  background: radial-gradient(circle at 50% 45%, rgba(12,16,10,.72), rgba(6,8,5,.94));
  pointer-events: auto;
}
.hud-over.on { display: grid; animation: fadein 1.2s ease-out; }
@keyframes fadein { from { opacity: 0; } }
.hud-over h1 { font-size: clamp(28px, 6vw, 56px); margin: 0 0 10px; letter-spacing: .03em; }
.hud-over.victory h1 { color: var(--gold); }
.hud-over.defeat h1 { color: #d99080; }
.over-sub { opacity: .7; margin: 0 auto 26px; max-width: 44ch; }
.over-stats { display: flex; gap: 26px; justify-content: center; margin: 0 0 30px; flex-wrap: wrap; }
.over-stats dt { font-size: 11px; letter-spacing: .13em; text-transform: uppercase; opacity: .5; }
.over-stats dd { margin: 3px 0 0; font-size: 22px; font-weight: 700; }
