:root {
  --wood: #3e2723;
  --gold: #d4af37;
  --paper: #f3e5ab;
  --ink: #1b120b;
}

* { box-sizing: border-box; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #120c08;
  font-family: "VT323", monospace;
  color: var(--paper);
  touch-action: none;
  -ms-touch-action: none;
  overscroll-behavior: none;
}

#game-root, #game-canvas {
  touch-action: none;
  -ms-touch-action: none;
}

#game-root {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#ui-root, #overlay, #hud, #touch {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 8, 4, 0.72);
  pointer-events: auto;
  z-index: 5;
}

#overlay.hidden, #hud.hidden { display: none; }

.panel {
  width: min(560px, 92%);
  max-height: 90%;
  overflow-y: auto;
  padding: 28px 24px;
  background: linear-gradient(#5d4037, #3e2723);
  border: 6px solid var(--gold);
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  text-align: center;
  touch-action: pan-y;
}

h1, h2 {
  font-family: "Press Start 2P", monospace;
  color: var(--gold);
  text-shadow: 3px 3px 0 #1b120b;
  line-height: 1.4;
}

h1 { font-size: clamp(16px, 3vw, 22px); margin: 0 0 8px; }
h2 { font-size: 14px; margin: 0 0 16px; }
.sub { letter-spacing: 3px; margin-bottom: 18px; opacity: .85; }
.playing { margin-bottom: 14px; color: var(--gold); }

button.arcade, .arcade {
  font-family: "Press Start 2P", monospace;
  font-size: 11px;
  background: var(--gold);
  color: var(--ink);
  border: 3px solid #1b120b;
  padding: 12px 16px;
  margin: 6px;
  cursor: pointer;
  min-width: 220px;
  pointer-events: auto;
  touch-action: manipulation;
}
button.arcade:hover { filter: brightness(1.1); }

input.arcade {
  font-family: "Press Start 2P", monospace;
  font-size: 16px;
  padding: 10px;
  text-align: center;
  text-transform: uppercase;
  width: min(280px, 80%);
  margin: 8px auto;
  display: block;
  pointer-events: auto;
  touch-action: manipulation;
}

.row { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.stats { font-size: 22px; line-height: 1.5; }
.tiny { font-size: 16px; opacity: .85; }
.tips {
  font-size: 18px;
  line-height: 1.45;
  color: #f3e5ab;
  text-align: left;
  margin: 12px 8px 8px;
  padding: 10px 12px;
  border: 2px dashed var(--gold);
  background: rgba(0, 0, 0, 0.22);
}
button.arcade.analysis-btn {
  min-width: 280px;
  font-size: 10px;
  margin-top: 4px;
}
.analysis {
  font-size: 18px;
  line-height: 1.5;
  text-align: left;
  margin: 8px;
  padding: 10px 12px;
  color: #f0f9fa;
  border: 2px solid #0a9396;
  background: rgba(0, 95, 115, 0.28);
}
.analysis.hidden { display: none; }
.err { color: #ff8a80; }

#hud { z-index: 4; }
.hud-top {
  display: flex;
  justify-content: space-between;
  padding: 12px 18px;
  font-size: 22px;
  text-shadow: 2px 2px 0 #000;
}
.hud-top.vs { font-size: 18px; }
.hud-title { font-family: "Press Start 2P", monospace; font-size: 11px; color: var(--gold); }
.hud-left { position: absolute; left: 16px; top: 52px; color: #e53935; font-size: 26px; }
.hud-right { position: absolute; right: 16px; top: 52px; font-size: 20px; }
.hud-bottom { position: absolute; bottom: 28px; width: 100%; text-align: center; font-size: 26px; color: var(--gold); }
.hud-p.right { text-align: right; }
.heart-label {
  display: block;
  font-family: "Press Start 2P", monospace;
  font-size: 8px;
  color: var(--gold);
  letter-spacing: 1px;
  margin-bottom: 2px;
}
.boss-hearts {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  color: #e53935;
  font-size: 26px;
  text-align: center;
  text-shadow: 2px 2px 0 #000;
}
.hud-timer {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Press Start 2P", monospace;
  font-size: 22px;
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
  letter-spacing: 2px;
}
.hud-timer.low {
  color: #e53935;
}

.banner {
  position: absolute;
  top: 42%;
  width: 100%;
  text-align: center;
  font-family: "Press Start 2P", monospace;
  font-size: 18px;
  color: var(--gold);
  text-shadow: 3px 3px 0 #000;
}

.talk {
  position: absolute;
  transform: translate(-50%, -110%);
  pointer-events: none;
  z-index: 6;
  font-family: "VT323", monospace;
  font-size: 22px;
  color: #1b120b;
  background: #f3e5ab;
  border: 3px solid #1b120b;
  padding: 3px 10px;
  white-space: nowrap;
}
.talk::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  margin-left: -7px;
  border: 7px solid transparent;
  border-top-color: #1b120b;
}
.popup {
  position: absolute;
  pointer-events: none;
  font-family: "Press Start 2P", monospace;
  font-size: 12px;
  color: #fff59d;
  text-shadow: 2px 2px 0 #000;
  z-index: 6;
  animation: float 0.8s ease-out forwards;
}
@keyframes float {
  to { transform: translateY(-40px); opacity: 0; }
}

#touch {
  display: none;
  z-index: 7;
  pointer-events: none;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 12px calc(20px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px));
}
#touch.visible { display: flex; }
#touch .move-pad {
  display: flex;
  gap: 14px;
  pointer-events: auto;
}
#touch .move-btn {
  pointer-events: auto;
  touch-action: none;
  width: 72px;
  height: 72px;
  border-radius: 14px;
  border: 3px solid #1b120b;
  background: rgba(212, 175, 55, 0.85);
  font-size: 26px;
  font-family: "Press Start 2P", monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1b120b;
}

/* Phone held upright: rotate the whole game into landscape. */
html.mobile-rot,
html.mobile-rot body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}
html.mobile-rot #game-root {
  position: fixed;
  top: 0;
  left: 100%;
  width: 100dvh;
  height: 100dvw;
  transform: rotate(90deg);
  transform-origin: top left;
}

.score-table { width: 100%; font-size: 18px; text-align: left; }
.score-table td { padding: 4px 6px; }
.chips button { min-width: unset; padding: 8px 10px; font-size: 9px; }

@media (pointer: coarse) {
  #touch.visible { display: flex; }
}
@media (pointer: coarse) and (max-height: 430px) {
  #touch .move-btn {
    width: 62px;
    height: 62px;
    font-size: 22px;
  }
  .hud-bottom { bottom: 18px; }
}
html.mobile-rot #touch .move-btn {
  width: 62px;
  height: 62px;
  font-size: 22px;
}
html.mobile-rot .hud-bottom { bottom: 18px; }
