:root {
  --green: #2D7D32; --green-d: #1B6520; --lime: #6CFF00; --gold: #F5C45E;
  --cream: #FFF0C9; --ink: #1A1A1A; --red: #E53835; --brown: #A6692B;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0c2410; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--cream); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}

/* Portrait frame; on desktop it sits centred like a phone. */
#app {
  position: relative; height: 100%; height: 100dvh; max-width: 480px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #1d5a24 0%, #174a1d 45%, #113716 100%);
}
@media (min-width: 520px) { #app { box-shadow: 0 0 0 2px var(--ink), 0 0 60px rgba(0, 0, 0, .5); } }

#hud { display: flex; align-items: flex-end; justify-content: space-between; padding: 2px 4px 8px; }
.stat { display: flex; flex-direction: column; min-width: 92px; }
.stat.mid { align-items: center; }
.stat.right { align-items: flex-end; }
.lbl { font-size: 13px; font-weight: 700; letter-spacing: .08em; color: #c9d8b0; }
.val { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.val.big { font-size: 40px; color: var(--gold); }
#app.fever .val.big { color: var(--cream); }
#app.hurry .val.big { color: #ff8a80; }

#timebar { height: 10px; border-radius: 6px; background: rgba(0, 0, 0, .35); border: 2px solid var(--ink); overflow: hidden; }
#timefill { display: block; height: 100%; width: 100%; background: var(--gold); transform-origin: left center; }
#app.hurry #timefill { background: var(--red); }

#boardwrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 10px 0; }
#board { display: block; border-radius: 14px; touch-action: none; }

#foot { display: flex; align-items: center; gap: 10px; min-height: 96px; position: relative; }
#mascot { width: 92px; height: 92px; object-fit: contain; flex: 0 0 auto; transform-origin: 50% 100%; animation: bob 2.6s ease-in-out infinite; }
#mascot.hop { animation: hop .45s ease-out; }
@keyframes bob { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-3px) } }
@keyframes hop { 0% { transform: translateY(0) scale(1, 1) } 30% { transform: translateY(-16px) scale(.96, 1.05) } 70% { transform: translateY(0) scale(1.05, .95) } 100% { transform: translateY(0) scale(1, 1) } }

#side { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
#say {
  align-self: flex-start; max-width: 100%; padding: 6px 12px; border-radius: 12px;
  background: var(--cream); color: var(--ink); border: 2px solid var(--ink);
  font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#fever { display: flex; align-items: center; gap: 8px; }
#feverLbl { font-size: 13px; font-weight: 800; letter-spacing: .08em; color: #c9d8b0; min-width: 78px; }
#app.fever #feverLbl { color: var(--gold); }
#feverbar { flex: 1; height: 10px; border-radius: 6px; background: rgba(0, 0, 0, .35); border: 2px solid var(--ink); overflow: hidden; }
#feverfill { display: block; height: 100%; width: 0; background: var(--lime); }
#app.fever #feverfill { background: var(--gold); }

#snd {
  position: absolute; right: 0; top: -2px; padding: 4px 8px; border-radius: 8px;
  border: 0; background: transparent; color: rgba(255, 240, 201, .6);
  font: 600 13px "Segoe UI", system-ui, sans-serif; cursor: pointer;
}

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(8, 28, 12, .82); padding: 20px; z-index: 5;
}
.hidden { display: none !important; }
.card {
  width: 100%; max-width: 340px; text-align: center; padding: 26px 22px 20px;
  background: #1f5f27; border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 6px 0 var(--ink);
}
h1, h2 { margin: 0 0 6px; font-weight: 900; letter-spacing: .02em; color: var(--cream); }
h1 { font-size: clamp(26px, 9vw, 34px); white-space: nowrap; } h1 b { color: var(--gold); }
h2 { font-size: 28px; }
.sub { margin: 0 0 18px; font-size: 16px; font-weight: 600; color: #dbe8c4; }
.how { margin: 16px 0 0; font-size: 13px; line-height: 1.55; color: #c9d8b0; }
.fine { margin: 12px 0 0; font-size: 12px; color: rgba(255, 240, 201, .55); }
.final { margin: 0; font-size: 46px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.newbest { margin: 4px 0 0; font-size: 15px; font-weight: 800; color: var(--lime); }
.btn {
  margin-top: 14px; width: 100%; padding: 14px 0; border-radius: 14px; cursor: pointer;
  border: 3px solid var(--ink); background: var(--gold); color: var(--ink);
  font: 900 20px "Segoe UI", system-ui, sans-serif; letter-spacing: .06em; box-shadow: 0 4px 0 var(--ink);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* v3: start/over screens + fx layer */
.btn.alt { background: #2D7D32; color: var(--cream); margin-top: 10px; font-size: 17px; }
.linkbtn { margin-top: 12px; background: none; border: 0; color: rgba(255, 240, 201, .6); font: 600 13px "Segoe UI", system-ui, sans-serif; cursor: pointer; text-decoration: underline; }
.linkbtn:empty { display: none; }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; }
#app.shake { animation: appshake .28s linear; }
@keyframes appshake { 0%, 100% { transform: translate(0, 0) } 20% { transform: translate(-4px, 2px) } 40% { transform: translate(4px, -2px) } 60% { transform: translate(-3px, -1px) } 80% { transform: translate(2px, 2px) } }
#app.flash::after { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 4; background: var(--flash, #FFF0C9); animation: flash .22s ease-out forwards; }
@keyframes flash { from { opacity: .35 } to { opacity: 0 } }

.stamp {
  display: inline-block; margin: 8px 0 2px; padding: 5px 14px; border: 3px solid var(--gold); border-radius: 8px;
  color: var(--gold); font-weight: 900; font-size: 17px; letter-spacing: .06em; transform: rotate(-4deg);
  animation: stampin .32s cubic-bezier(.2, 1.6, .4, 1) forwards;
}
@keyframes stampin { from { transform: rotate(-4deg) scale(3); opacity: 0 } to { transform: rotate(-4deg) scale(1); opacity: 1 } }
.bestline { margin: 8px 0 0; font-size: 15px; font-weight: 800; color: var(--cream); }
.bestline.new { color: var(--lime); font-size: 18px; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1) } 50% { transform: scale(1.08) } }
.bestbar { height: 10px; margin: 6px auto 0; width: 80%; border-radius: 6px; background: rgba(0, 0, 0, .35); border: 2px solid var(--ink); overflow: hidden; }
.bestbar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width 1.1s cubic-bezier(.2, .8, .2, 1); }
.btn.nudge { animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: scale(1) } 50% { transform: scale(1.04) } }
.final.counting { color: var(--cream); }
#score { display: inline-block; transform-origin: left bottom; }

/* portrait-only: on a short landscape phone ask for a turn instead of a 20px board */
#rotate { display: none; z-index: 20; }
#rotate .rot { margin: 0 0 6px; font-size: 44px; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) { #rotate { display: flex; } }

/* v5: leaderboard, wallet, name entry */
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin-top: 6px; }
.row .linkbtn { margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; padding: 6px 8px 6px 12px; border-radius: 999px; background: rgba(0, 0, 0, .28); border: 2px solid var(--ink); font-size: 13px; font-weight: 700; color: var(--cream); }
.chip button { border: 0; background: rgba(255, 240, 201, .15); color: var(--cream); width: 22px; height: 22px; border-radius: 50%; font-size: 11px; cursor: pointer; }
.badge { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--tier, #8a978d); box-shadow: 0 0 0 2px rgba(0, 0, 0, .35); }
.badge.t0 { visibility: hidden; }
.chip .badge.t0 { display: none; }
#walletMsg:empty { display: none; }
#submitBox { margin-top: 10px; min-height: 22px; }
.namerow { display: flex; gap: 8px; }
.namerow input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 3px solid var(--ink); background: var(--cream); color: var(--ink); font: 700 16px "Segoe UI", system-ui, sans-serif; }
.namerow input:focus { outline: 3px solid var(--lime); outline-offset: 1px; }
.btn.small { width: auto; margin-top: 0; padding: 10px 14px; font-size: 15px; }
.rankline { margin: 8px 0 0; font-size: 15px; font-weight: 800; color: var(--gold); min-height: 20px; }
.rankline.err { color: #ff8a80; font-size: 13px; }
.rankline.muted { color: rgba(255, 240, 201, .55); font-weight: 600; font-size: 13px; }
.lbcard { max-width: 380px; padding: 18px 16px 14px; max-height: calc(100% - 20px); display: flex; flex-direction: column; }
.lbhead { display: flex; align-items: center; justify-content: space-between; }
.lbhead h2 { font-size: 22px; margin: 0; }
.close { border: 2px solid var(--ink); background: rgba(0, 0, 0, .28); color: var(--cream); width: 32px; height: 32px; border-radius: 50%; font-size: 14px; cursor: pointer; }
.tabs { display: flex; gap: 6px; margin: 12px 0 8px; }
.tab { flex: 1; padding: 8px 0; border-radius: 10px; border: 2px solid var(--ink); background: rgba(0, 0, 0, .25); color: #c9d8b0; font: 800 13px "Segoe UI", system-ui, sans-serif; cursor: pointer; }
.tab.on { background: var(--gold); color: var(--ink); }
.lblist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; min-height: 120px; text-align: left; }
.lblist li { display: grid; grid-template-columns: 34px 14px 1fr auto; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 10px; font-size: 15px; font-weight: 700; }
.lblist li:nth-child(odd) { background: rgba(0, 0, 0, .18); }
.lblist li.me { outline: 2px solid var(--lime); }
.lblist .rk { color: #c9d8b0; font-weight: 800; }
.lblist li:nth-child(1) .rk { color: var(--gold); } .lblist li:nth-child(2) .rk { color: #cbd5d8; } .lblist li:nth-child(3) .rk { color: #c17a3f; }
.lblist .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lblist .nm small { display: block; font-size: 11px; font-weight: 600; color: rgba(255, 240, 201, .5); }
.lblist .sc { font-variant-numeric: tabular-nums; color: var(--cream); }
.lblist .empty { display: block; padding: 24px 0; text-align: center; color: rgba(255, 240, 201, .55); font-weight: 600; }
.stamp.t1 { border-color: #c17a3f; color: #c17a3f; } .stamp.t2 { border-color: #cbd5d8; color: #cbd5d8; } .stamp.t3 { border-color: #f2b233; color: #f2b233; }
.stamp.t4 { border-color: #b98cff; color: #b98cff; } .stamp.t5 { border-color: #12e08a; color: #12e08a; }
