:root {
  --paper: #F2E7D2;
  --paper-2: #EADCC2;
  --ink: #2A2730;
  --gold: #E8B23C;
  --light: #F6D98A;
  --crimson: #9E2B22;
  --violet: #17121F;
  --ember: #C4552B;
  --display: "Yeseva One", Georgia, serif;
  --text: "Alegreya Sans", "Helvetica Neue", Arial, sans-serif;
  --roman: "Cinzel", "Times New Roman", serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #120d18; color: var(--ink);
  font-family: var(--text); -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none; touch-action: none; overscroll-behavior: none;
}
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
.hidden { display: none !important; }

/* HUD */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 10;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 10px; align-items: start;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) calc(env(safe-area-inset-right, 0px) + 12px) 0 calc(env(safe-area-inset-left, 0px) + 12px);
  pointer-events: none; color: var(--paper);
}
.hud-left { max-width: 260px; }
.bar-label { font-family: var(--roman); font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; text-shadow: 0 1px 2px #000; }
.bar-label.small { font-size: 9px; letter-spacing: 0.14em; opacity: 0.9; margin-top: 3px; }
.bar { position: relative; height: 10px; margin-top: 4px; border: 1.5px solid var(--paper); background: rgba(18, 13, 24, 0.7); box-shadow: 0 1px 0 rgba(0,0,0,0.5); }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: linear-gradient(90deg, #F6D98A, #FFF3CF); transition: width 0.15s linear; }
.bar.glory { height: 6px; border-width: 1px; }
.bar.glory i { background: linear-gradient(90deg, #E8B23C, #FFE08A); }
.bar.glory.full { box-shadow: 0 0 10px 2px rgba(246, 217, 138, 0.8); }
.hud-mid { text-align: center; }
.phase {
  font-family: var(--roman); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  background: rgba(242, 231, 210, 0.94); color: var(--ink); border: 1.5px solid var(--ink);
  padding: 6px 12px; box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3px rgba(42,39,48,0.4);
}
.pips { display: flex; justify-content: center; gap: 6px; margin-top: 6px; }
.pips span { width: 14px; height: 14px; border: 1.5px solid var(--paper); background: var(--crimson); transform: rotate(45deg); box-shadow: 0 0 6px rgba(196, 85, 43, 0.8); }
.pips span.off { background: transparent; box-shadow: none; opacity: 0.6; }
.pips span.gold { background: var(--gold); box-shadow: 0 0 8px rgba(246, 217, 138, 0.9); }
.pips .sbar { width: 150px; height: 8px; transform: none; background: rgba(18,13,24,0.7); position: relative; box-shadow: none; }
.pips .sbar i { position: absolute; inset: 0; background: linear-gradient(90deg, #6a2a8a, #C4552B); }
.hud-right { display: flex; justify-content: flex-end; gap: 8px; pointer-events: auto; }
.hud-btn {
  min-height: 34px; min-width: 34px; padding: 0 10px; font-family: var(--roman); font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink); background: rgba(242, 231, 210, 0.94); border: 1.5px solid var(--ink); cursor: pointer;
}

/* spoken lines */
.line {
  position: fixed; z-index: 11; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 172px); width: min(560px, calc(100vw - 24px));
  background: rgba(242, 231, 210, 0.93); border: 1.5px solid var(--ink); padding: 9px 14px; pointer-events: none;
  font-size: 15px; line-height: 1.35; box-shadow: 4px 4px 0 rgba(0,0,0,0.3);
}
.line b { display: block; font-family: var(--roman); font-size: 10px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--crimson); margin-bottom: 2px; }
.line.steven b { color: #9a7413; }

/* touch */
#touch { position: fixed; inset: 0; z-index: 9; pointer-events: none; }
#stick-zone { position: absolute; left: 0; bottom: 0; width: 46%; height: 62%; pointer-events: auto; touch-action: none; }
/* upright, the dragon's heads fill the middle of the screen: the stick stays on the roof below them */
@media (max-aspect-ratio: 4/5) { #stick-zone { width: 56%; height: 24%; min-height: 170px; } }
#stick-base { opacity: 0.75; }
#stick-zone:active #stick-base { opacity: 1; }
#stick-base {
  position: absolute; left: calc(env(safe-area-inset-left, 0px) + 28px); bottom: calc(env(safe-area-inset-bottom, 0px) + 34px);
  width: 120px; height: 120px; margin: 0; border-radius: 50%;
  border: 2px solid rgba(242, 231, 210, 0.7); background: rgba(18, 13, 24, 0.35);
}
#stick-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(246, 217, 138, 0.85); border: 2px solid var(--ink); }
.stick-hint { position: absolute; left: calc(env(safe-area-inset-left, 0px) + 70px); bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); font-family: var(--roman); font-size: 10px; letter-spacing: 0.2em; color: var(--paper); text-transform: uppercase; text-shadow: 0 1px 2px #000; }
#buttons {
  position: absolute; right: calc(env(safe-area-inset-right, 0px) + 16px); bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 12px; align-items: end; pointer-events: auto;
}
.tbtn {
  width: 66px; height: 66px; border-radius: 50%; border: 2px solid var(--ink); background: rgba(242, 231, 210, 0.92);
  font-family: var(--roman); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink); touch-action: none;
  box-shadow: 0 3px 0 rgba(0,0,0,0.4);
}
.tbtn.big { width: 86px; height: 86px; font-size: 13px; background: #F6D98A; grid-column: 2; grid-row: 1 / span 2; }
#b-beam { grid-column: 1; grid-row: 2; }
#b-bind { grid-column: 1; grid-row: 1; }
.tbtn.dim { opacity: 0.5; }
.tbtn.down { opacity: 1; background: #fff3cf; }
.bar.glory.want { box-shadow: 0 0 0 2px #ff6a3a; }
.tbtn.ready { box-shadow: 0 0 0 3px rgba(246, 217, 138, 0.9), 0 0 18px 4px rgba(246, 217, 138, 0.7); }
.tbtn.down { transform: translateY(2px); box-shadow: none; }

/* panels */
.panel {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 14px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: radial-gradient(80% 70% at 50% 40%, rgba(18, 13, 24, 0.35), rgba(18, 13, 24, 0.82));
  overflow-y: auto; touch-action: pan-y; -webkit-user-select: text; user-select: text;
}
.panel-inner {
  width: min(560px, 100%); margin: auto; background: var(--paper); border: 1.5px solid var(--ink);
  box-shadow: inset 0 0 0 4px var(--paper), inset 0 0 0 5px rgba(42, 39, 48, 0.45), 8px 8px 0 rgba(0, 0, 0, 0.35);
  padding: 26px clamp(18px, 5vw, 34px) 22px; text-align: center;
}
.kicker { margin: 0; font-family: var(--roman); font-size: 10px; letter-spacing: 0.26em; text-transform: uppercase; color: #5a4a3a; }
.panel h1 { margin: 10px 0 6px; font-family: var(--display); font-weight: 400; font-size: clamp(1.9rem, 7vw, 2.8rem); line-height: 1.02; color: var(--crimson); }
.sub { margin: 0 0 12px; font-family: var(--roman); font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; }
.intro { margin: 0 auto 14px; max-width: 44ch; font-size: 1rem; line-height: 1.45; color: #3C4A57; }
.how { text-align: left; border-top: 1px solid rgba(42,39,48,0.5); border-bottom: 1px solid rgba(42,39,48,0.5); padding: 10px 0 6px; margin: 0 0 14px; }
.how h2 { margin: 0 0 6px; font-family: var(--roman); font-size: 11px; letter-spacing: 0.24em; text-transform: uppercase; font-weight: 400; text-align: center; }
.how ol { margin: 0 0 8px; padding-left: 1.3em; font-size: 0.95rem; line-height: 1.4; }
.how li { margin-bottom: 4px; }
.keys { margin: 0 0 6px; font-size: 0.9rem; line-height: 1.4; color: #3C4A57; }
.keys span { display: block; }
.actions { display: flex; justify-content: center; gap: 10px; }
.play {
  min-height: 50px; min-width: 170px; padding: 0 26px; font-family: var(--roman); font-size: 15px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--paper); background: var(--ink); border: 1.5px solid var(--ink); box-shadow: inset 0 0 0 2px var(--ink), inset 0 0 0 3px var(--light); cursor: pointer;
}
.play:hover { background: var(--crimson); }
.best { margin: 10px 0 0; font-size: 0.9rem; color: #3C4A57; min-height: 1.2em; }
.links { margin: 10px 0 0; font-size: 0.9rem; }
.links a { color: var(--ink); }
.quote { margin: 8px auto 12px; max-width: 40ch; font-size: 1.05rem; line-height: 1.5; font-style: italic; }
.quote b { font-style: normal; font-family: var(--roman); font-size: 10px; letter-spacing: 0.2em; display: block; margin-top: 6px; color: var(--crimson); }
.stats { margin: 0 0 10px; font-family: var(--roman); font-size: 12px; letter-spacing: 0.12em; }
.board { margin: 0 auto 14px; max-width: 320px; text-align: left; font-size: 0.92rem; }
.board ol { margin: 4px 0 0; padding-left: 1.6em; }
.board li.mine { font-weight: 700; }
.board h3 { margin: 0; font-family: var(--roman); font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; font-weight: 400; text-align: center; }

@media (max-width: 560px) {
  #hud { grid-template-columns: minmax(0, 1fr) auto; }
  .hud-mid { grid-column: 1 / -1; grid-row: 2; }
  .phase { font-size: 10px; padding: 5px 8px; display: inline-block; }
  .line { font-size: 14px; padding: 7px 12px; }
  .pips .sbar { width: 120px; }
}
@media (max-height: 460px) {
  .tbtn { width: 56px; height: 56px; }
  .tbtn.big { width: 72px; height: 72px; }
  #stick-base { width: 100px; height: 100px; bottom: 18px; }
  .line { bottom: 14px; width: min(440px, 46vw); }
  .panel-inner { padding-top: 16px; }
  .intro { display: none; }
}
@media (pointer: fine) and (hover: hover) {
  .k-touch { display: none !important; }
}
@media (pointer: coarse) {
  .k-keys { display: none !important; }
}
