:root {
  --navy: #0b1224;
  --navy-2: #131d38;
  --ink: #05070d;
  --cream: #f4ecd8;
  --gold: #e3b341;
  --gold-2: #b8862a;
  --green: #2fbf71;
  --red: #e5484d;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--ink); color: var(--cream);
  font-family: Inter, system-ui, sans-serif; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
canvas#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.screen {
  position: absolute; inset: 0; display: none; z-index: 5;
  align-items: center; justify-content: center;
}
.screen.show { display: flex; }

/* ---------- Title ---------- */
#title {
  background:
    radial-gradient(1200px 600px at 75% 30%, rgba(227,179,65,.18), transparent 60%),
    linear-gradient(160deg, #0b1224 0%, #050810 100%);
  gap: 4vw; padding: max(16px, env(safe-area-inset-left));
}
#title::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 2px, transparent 2px 4px);
}
.title-art {
  height: min(86vh, 640px); aspect-ratio: 1037/1517; border-radius: 18px; overflow: hidden;
  border: 3px solid var(--gold); box-shadow: 0 0 0 6px rgba(227,179,65,.15), 0 30px 80px rgba(0,0,0,.7);
  transform: rotate(-2deg); flex-shrink: 0;
}
.title-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.title-copy { max-width: 520px; position: relative; }
.badge {
  display: inline-block; font: 700 12px/1 Inter; letter-spacing: .2em; color: var(--gold);
  border: 1px solid var(--gold-2); padding: 7px 10px; border-radius: 99px;
}
h1 {
  font-family: Bungee, Impact, sans-serif; font-weight: 400;
  font-size: clamp(34px, 6.4vw, 78px); line-height: .95; margin: 16px 0 12px;
  color: var(--gold); text-shadow: 0 4px 0 #7a5410, 0 10px 30px rgba(0,0,0,.6);
}
#t-sub { font-size: clamp(15px, 1.7vw, 20px); line-height: 1.4; margin: 0 0 26px; opacity: .9; }
.hint { margin-top: 16px; font-size: 13px; opacity: .55; letter-spacing: .03em; }

.btn {
  font-family: Bungee, Impact, sans-serif; font-size: clamp(18px, 2.2vw, 26px);
  padding: 16px 36px; border-radius: 14px; border: 0; cursor: pointer;
  text-decoration: none; display: inline-block; letter-spacing: .04em;
  transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: translateY(2px) scale(.98); }
.btn.gold {
  background: linear-gradient(180deg, #ffd36b, var(--gold) 55%, var(--gold-2));
  color: #2a1a00; box-shadow: 0 6px 0 #7a5410, 0 14px 30px rgba(227,179,65,.25);
}
.btn.gold:hover { filter: brightness(1.08); }
.btn.loading { opacity: .7; cursor: default; font-size: clamp(14px, 1.6vw, 18px); min-width: 180px; }
.btn.ghost { color: var(--cream); border: 2px solid rgba(244,236,216,.5); background: transparent; }
.btn.ghost:hover { border-color: var(--cream); }

/* ---------- Game over ---------- */
#over { background: rgba(3,5,10,.82); backdrop-filter: blur(3px); padding: 12px; }
#over .card {
  background: linear-gradient(180deg, #131d38, #0b1224);
  border: 2px solid var(--gold); border-radius: 18px;
  padding: clamp(14px, 3vh, 30px) clamp(18px, 4vw, 40px);
  width: min(560px, 100%); max-height: 100%; overflow: auto; text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
#o-title { font-family: Bungee, sans-serif; font-weight: 400; color: var(--red); margin: 0 0 10px; font-size: clamp(26px, 4vw, 40px); }
#o-stats { width: 100%; border-collapse: collapse; font-size: clamp(13px, 1.6vw, 16px); }
#o-stats td { padding: 5px 4px; border-bottom: 1px dashed rgba(244,236,216,.14); }
#o-stats td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
#o-stats tr.neg td:last-child { color: var(--red); }
#o-stats tr.pos td:last-child { color: var(--green); }
#o-stats tr.big td { font-weight: 900; color: var(--gold); border-bottom: 0; padding-top: 9px; }
#o-saved { font-family: Bungee, sans-serif; font-size: clamp(26px, 4.4vw, 44px); color: var(--gold); margin: 12px 0 4px; }
#o-phrase { font-style: italic; opacity: .85; margin: 4px 0 18px; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- Sound ---------- */
.sound {
  position: absolute; z-index: 8; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right));
  font: 700 12px Inter; letter-spacing: .08em; color: var(--cream);
  background: rgba(11,18,36,.75); border: 1px solid rgba(227,179,65,.6);
  padding: 8px 12px; border-radius: 99px; cursor: pointer;
}

@media (max-height: 520px) { body.gameover .sound { display: none; } }
#over .card { touch-action: pan-y; }

/* ---------- Touch ---------- */
#touch { position: absolute; inset: auto 0 0 0; z-index: 6; display: none; pointer-events: none;
  padding: 0 max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  justify-content: space-between; align-items: flex-end; }
body.touch.playing #touch { display: flex; }
.pad { display: flex; gap: 14px; pointer-events: auto; align-items: flex-end; }
#touch button {
  width: 84px; height: 84px; border-radius: 50%; border: 2px solid rgba(244,236,216,.45);
  background: rgba(11,18,36,.55); color: var(--cream); font: 900 28px Inter;
  touch-action: none; backdrop-filter: blur(2px);
}
#touch button.on { background: rgba(227,179,65,.55); border-color: var(--gold); }
#touch button.jump { width: 104px; height: 104px; font: 400 18px Bungee, sans-serif; background: rgba(227,179,65,.35); border-color: var(--gold); }
#touch button.excuse { font: 400 13px Bungee, sans-serif; position: relative; overflow: hidden; }
#touch button.excuse.cool { opacity: .55; }
#touch button.excuse .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(229,72,77,.45); }

/* ---------- Rotate ---------- */
#rotate { display: none; position: absolute; inset: 0; z-index: 20; background: var(--navy);
  flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
#rotate p { font: 400 18px Bungee, sans-serif; color: var(--gold); max-width: 280px; line-height: 1.3; }
.phone { width: 54px; height: 92px; border: 4px solid var(--cream); border-radius: 12px; animation: rot 1.8s ease-in-out infinite; }
@keyframes rot { 0%,20% { transform: rotate(0); } 60%,100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 820px) { body.touch.playing #rotate { display: flex; } }
body.touch .desk-only { display: none; }

/* ---------- Mobile portrait: stacked title / game over ---------- */
@media (orientation: portrait) and (max-width: 820px) {
  #title { flex-direction: column; gap: 22px; text-align: center; padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom)); }
  .title-art { height: min(46vh, 420px); transform: rotate(-2deg); }
  .title-copy { max-width: 100%; }
  h1 { font-size: clamp(34px, 11vw, 56px); margin-top: 0; }
  #t-sub { font-size: 16px; margin-bottom: 20px; }
  .btn { padding: 15px 40px; font-size: 22px; }
  #over .card { padding: 18px 16px; }
  .row .btn { flex: 1 1 100%; }
}

@media (max-height: 520px) {
  .title-art { height: 84vh; }
  #touch button { width: 70px; height: 70px; font-size: 24px; }
  #touch button.jump { width: 88px; height: 88px; }
  #over .card { padding: 12px 22px; }
  #o-stats td { padding: 3px 4px; }
  #o-saved { margin: 6px 0 2px; }
  #o-phrase { margin: 2px 0 10px; }
  .hint { display: none; }
  .btn { padding: 12px 26px; }
}
@media (max-width: 640px) and (orientation: landscape) { #t-sub { margin-bottom: 14px; } }
@media (max-height: 400px) {
  #touch button { width: 62px; height: 62px; font-size: 22px; }
  #touch button.jump { width: 80px; height: 80px; font-size: 15px; }
  #touch button.excuse { font-size: 11px; }
  .pad { gap: 10px; }
  h1 { font-size: clamp(30px, 6vw, 48px); }
}

/* ---------- Vertical phone: game on top, controls below ---------- */
body.portrait #rotate { display: none !important; }
body.portrait #touch {
  top: var(--game-bottom, 55%); bottom: 0; align-items: center;
  padding: 10px 18px max(18px, env(safe-area-inset-bottom));
}
body.portrait .pad.left { gap: 14px; }
body.portrait .pad.right { flex-direction: column-reverse; align-items: center; gap: 14px; }
body.portrait #touch button { width: 86px; height: 86px; font-size: 30px; }
body.portrait #touch button.jump { width: 112px; height: 112px; font-size: 20px; }
body.portrait #touch button.excuse { width: 82px; height: 58px; border-radius: 29px; font-size: 13px; }
