:root {
  --primary: #0f5a32;
  --primary-dark: #0a4325;
  --panel: #f6ead3;
  --text: #1d1d1b;
  --accent: #d62828;
  --good: #2fbf5b;
  --bad: #e63946;
  --sea: #2a8fb0;
  --bar-h: clamp(56px, 12vh, 110px);
  --foot-h: clamp(44px, 9vh, 80px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--panel); color: var(--text);
  font-family: 'Inter', system-ui, sans-serif; user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}
#app-root { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--panel); }

/* ---------- Brand bar ---------- */
#brand-bar {
  height: var(--bar-h); flex: 0 0 auto; display: grid; overflow: hidden;
  grid-template-columns: 1fr auto minmax(0, 1.3fr) auto 1fr; align-items: center;
  padding: 0 clamp(10px, 2.5vw, 40px); gap: clamp(8px, 2vw, 30px); position: relative; z-index: 5;
}
.brand-divider { width: 2px; height: 60%; background: var(--text); opacity: .8; }
.brand-center { text-align: center; line-height: 1; min-width: 0; }
#brand-title {
  margin: 0; font-family: 'Archivo Black', Impact, sans-serif; font-size: clamp(16px, min(4.4vh, 6vw), 46px);
  letter-spacing: .02em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#brand-title-secondary { font-family: 'Cairo', sans-serif; font-weight: 800; font-size: clamp(16px, 3.6vh, 38px); margin-top: .1em; }
.brand-side { display: flex; align-items: center; min-width: 0; height: var(--bar-h); overflow: hidden; }
.brand-left { justify-content: flex-start; }
.brand-right { justify-content: flex-end; text-align: right; }
.brand-side img {
  display: block; height: calc(var(--bar-h) * var(--logo-scale, 0.7)); width: auto;
  max-width: 100%; object-fit: contain; object-position: center;
}
.brand-left img { object-position: left center; }
.brand-right img { object-position: right center; }
.brand-text-right { line-height: 1; }
.brand-text-right .ar { font-family: 'Cairo', sans-serif; font-weight: 800; font-size: clamp(18px, 4vh, 40px); position: relative; display: inline-block; }
.brand-text-right .tag { font-family: 'Archivo Black', sans-serif; font-size: clamp(8px, 1.2vh, 13px); position: absolute; top: 0; right: -0.2em; transform: translateY(-40%); }
.brand-text-right .en { font-family: 'Archivo Black', sans-serif; font-size: clamp(10px, 2vh, 20px); letter-spacing: .06em; }

/* ---------- Stage ---------- */
#stage {
  position: relative; flex: 1 1 auto; overflow: hidden; background: var(--primary);
  /* stepped "pixel" corners like the reference frame */
  clip-path: polygon(0 3%, 1.5% 3%, 1.5% 0, 98.5% 0, 98.5% 3%, 100% 3%, 100% 97%, 98.5% 97%, 98.5% 100%, 1.5% 100%, 1.5% 97%, 0 97%);
  margin: 0 clamp(6px, 1.4vw, 22px);
}
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .35s ease, transform .35s ease; transform: scale(.98); z-index: 3;
  padding: 3vh 3vw;
}
.screen.active { opacity: 1; pointer-events: auto; transform: none; }
.hidden { display: none !important; }

/* Cream "stamp" boxes with notched corners */
.stamp {
  background: var(--panel); color: var(--text);
  clip-path: polygon(0 10px, 10px 10px, 10px 0, calc(100% - 10px) 0, calc(100% - 10px) 10px, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 10px calc(100% - 10px), 0 calc(100% - 10px));
}

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.hud-box {
  position: absolute; top: 3.5%; display: flex; align-items: center; gap: .5em;
  padding: .35em .9em; font-family: 'Archivo Black', sans-serif; font-size: clamp(16px, 3.8vh, 40px);
}
#hud-score { left: 2.5%; }
#hud-timer { right: 2.5%; }
.hud-label { font-size: .7em; }
.hud-value { color: var(--accent); min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }
#hud-timer.urgent .hud-value { animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.15); } }
.hud-box.bump .hud-value { animation: bump .25s; }
@keyframes bump { 50% { transform: scale(1.3); } }

.corner-btn {
  position: absolute; z-index: 4; bottom: 3.5%; right: 2.5%; border: 0; cursor: pointer;
  font-family: 'Archivo Black', sans-serif; font-size: clamp(13px, 2.6vh, 26px); padding: .45em 1.1em;
}

/* Standby */
.standby-card { text-align: center; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 1.6vh; max-width: 92%; }
.standby-logo img { max-height: 14vh; max-width: 40vw; object-fit: contain; filter: drop-shadow(0 4px 10px rgba(0,0,0,.3)); }
.standby-title {
  margin: 0; font-family: 'Archivo Black', sans-serif; font-size: clamp(34px, min(13vh, 12vw), 150px); line-height: .9;
  color: var(--panel); text-shadow: 0 6px 0 rgba(0,0,0,.25); letter-spacing: .02em;
}
.standby-sub { margin: 0; font-family: 'Cairo', sans-serif; font-weight: 800; font-size: clamp(20px, min(6vh, 8vw), 64px); color: var(--panel); line-height: 1; }
.standby-tagline { margin: .5vh 0 1vh; font-size: clamp(14px, 2.4vh, 24px); opacity: .92; max-width: 60ch; }
.play-btn {
  border: 0; cursor: pointer; display: inline-flex; align-items: center; gap: .55em;
  font-family: 'Archivo Black', sans-serif; font-size: clamp(24px, min(6.5vh, 8vw), 70px); padding: .35em 1.4em;
  background: var(--accent); color: #fff; border-radius: 999px; box-shadow: 0 8px 0 rgba(0,0,0,.25), 0 0 0 6px var(--panel);
  animation: breathe 1.6s ease-in-out infinite; transition: transform .1s;
}
.play-btn:active { transform: translateY(4px) scale(.98); box-shadow: 0 3px 0 rgba(0,0,0,.25), 0 0 0 6px var(--panel); }
.play-btn.small { font-size: clamp(18px, 3.6vh, 36px); animation: none; padding: .45em 1.2em; }
@keyframes breathe { 50% { transform: scale(1.06); } }
.standby-top { margin-top: 1.5vh; font-size: clamp(13px, 2.2vh, 22px); color: var(--panel); opacity: .95; min-height: 1.2em; }
.standby-top b { font-family: 'Archivo Black', sans-serif; color: #fff; }
.item-legend {
  position: absolute; bottom: 3%; left: 50%; transform: translateX(-50%); display: flex; gap: 1.2vw;
  flex-wrap: wrap; justify-content: center; max-width: 90%;
}
.legend-chip {
  display: flex; align-items: center; gap: .4em; background: rgba(0,0,0,.25); color: #fff; border-radius: 999px;
  padding: .25em .8em .25em .3em; font-weight: 800; font-size: clamp(11px, 1.9vh, 18px);
}
.legend-chip img { width: 2.1em; height: 2.1em; object-fit: contain; }
.legend-chip .pts.good { color: #9ff0b5; }
.legend-chip .pts.bad { color: #ffb1b8; }

/* Name */
.name-card { padding: clamp(18px, 4vh, 44px) clamp(20px, 4vw, 56px); width: min(680px, 92%); text-align: center; }
.name-card h2 { margin: 0 0 2.5vh; font-family: 'Archivo Black', sans-serif; font-size: clamp(22px, 5vh, 52px); }
#name-input {
  width: 100%; font: 800 clamp(22px, 5vh, 52px) 'Inter', sans-serif; text-align: center; padding: .35em .5em;
  border: 4px solid var(--text); border-radius: 14px; background: #fff; color: var(--text); outline: none;
  user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
#name-input:focus { border-color: var(--primary); box-shadow: 0 0 0 6px color-mix(in srgb, var(--primary) 25%, transparent); }
.name-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 3vh; }
.ghost-btn {
  border: 3px solid currentColor; background: transparent; color: inherit; border-radius: 999px; cursor: pointer;
  font: 800 clamp(14px, 2.6vh, 26px) 'Inter', sans-serif; padding: .45em 1.1em;
}
.name-error { color: var(--bad); font-weight: 800; min-height: 1.2em; margin: 1.5vh 0 0; }

/* Countdown */
.countdown-player { color: var(--panel); font: 800 clamp(18px, 4vh, 42px) 'Inter', sans-serif; margin-bottom: 1vh; }
.countdown-num {
  font-family: 'Archivo Black', sans-serif; font-size: clamp(120px, 42vh, 460px); line-height: 1; color: var(--panel);
  text-shadow: 0 12px 0 rgba(0,0,0,.25);
}
.countdown-num.tick { animation: tick .9s ease-out; }
@keyframes tick { 0% { transform: scale(2.2); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 85% { opacity: 1; } 100% { transform: scale(.6); opacity: 0; } }

/* Results */
.results-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 4vw; align-items: end; width: min(1400px, 96%); }
.your-score { padding: 3vh 2vw; text-align: center; align-self: center; }
.ys-label { font: 800 clamp(12px, 2vh, 20px) 'Inter'; letter-spacing: .2em; opacity: .7; }
.ys-name { font-family: 'Archivo Black', sans-serif; font-size: clamp(20px, 4.5vh, 48px); margin-top: .5vh; word-break: break-word; }
.ys-score { font-family: 'Archivo Black', sans-serif; font-size: clamp(54px, 15vh, 170px); color: var(--accent); line-height: 1; }
.ys-meta { font-weight: 600; font-size: clamp(12px, 2vh, 20px); opacity: .8; }
.ys-rank { margin-top: 1.5vh; font-family: 'Archivo Black', sans-serif; font-size: clamp(16px, 3.4vh, 34px); background: var(--primary); color: var(--panel); display: inline-block; padding: .2em .8em; border-radius: 999px; }
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 1.2vw; height: min(62vh, 640px); }
.podium-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; opacity: 0; transform: translateY(40px); animation: rise .6s ease-out forwards; }
.podium-col.p1 { animation-delay: .6s; } .podium-col.p2 { animation-delay: .3s; } .podium-col.p3 { animation-delay: 0s; }
@keyframes rise { to { opacity: 1; transform: none; } }
.podium-medal { font-size: clamp(30px, 7vh, 70px); }
.podium-name { color: #fff; font: 800 clamp(14px, 3vh, 32px) 'Inter'; text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 .3em; }
.podium-score { color: var(--panel); font-family: 'Archivo Black', sans-serif; font-size: clamp(18px, 4vh, 42px); margin-bottom: 1vh; }
.podium-block { width: 100%; background: var(--panel); display: flex; align-items: flex-start; justify-content: center; font-family: 'Archivo Black', sans-serif; font-size: clamp(30px, 8vh, 90px); color: var(--primary); padding-top: 1vh; border-radius: 10px 10px 0 0; }
.p1 .podium-block { height: 46%; background: linear-gradient(#ffe27a, #f2b705); }
.p2 .podium-block { height: 34%; background: linear-gradient(#f1f1f1, #bdbdbd); }
.p3 .podium-block { height: 24%; background: linear-gradient(#f3c49b, #c8793d); }
.podium-col.me .podium-name { color: #ffe27a; }
.tap-continue { position: absolute; bottom: 3.5%; right: 2.5%; color: var(--panel); }

/* Leaderboard */
.lb-card { width: min(980px, 94%); padding: 2.5vh 3vw; max-height: 92%; display: flex; flex-direction: column; }
.lb-card h2 { margin: 0 0 1.5vh; text-align: center; font-family: 'Archivo Black', sans-serif; font-size: clamp(22px, 5vh, 52px); }
.lb-card h2 i { color: #e2a400; }
.lb-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .8vh; overflow: hidden; }
.lb-row {
  display: grid; grid-template-columns: 3em 1fr auto; align-items: center; gap: 1em; padding: .45em 1em;
  background: #fff; border-radius: 12px; font: 800 clamp(14px, 2.9vh, 30px) 'Inter';
  opacity: 0; transform: translateX(-30px); animation: slideIn .4s ease-out forwards;
}
@keyframes slideIn { to { opacity: 1; transform: none; } }
.lb-row .rank { font-family: 'Archivo Black', sans-serif; color: var(--primary); text-align: center; }
.lb-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .sc { font-family: 'Archivo Black', sans-serif; color: var(--accent); font-variant-numeric: tabular-nums; }
.lb-row.r1 { background: #fff3c4; } .lb-row.r2 { background: #eeeeee; } .lb-row.r3 { background: #f8dcc4; }
.lb-row.me { outline: 4px solid var(--primary); }
.lb-empty { text-align: center; opacity: .6; padding: 3vh; font-weight: 800; }
.lb-you { margin-top: 1.2vh; text-align: center; font-weight: 800; opacity: .8; font-size: clamp(13px, 2.2vh, 22px); }

/* Footer */
#instructions-bar {
  height: var(--foot-h); flex: 0 0 auto; display: flex; align-items: center; justify-content: center; gap: 2vw;
  font: 800 clamp(13px, 2.6vh, 26px) 'Inter', sans-serif; padding: 0 4vw; color: var(--text);
}
#instructions-bar .line { flex: 1; height: 2px; background: var(--text); opacity: .6; max-width: 25vw; }
#fullscreen-btn {
  position: fixed; right: 8px; bottom: 8px; z-index: 50; width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.08); color: var(--text); cursor: pointer; opacity: .35;
}
#fullscreen-btn:hover { opacity: 1; }

/* Portrait screens: stack results */
@media (max-aspect-ratio: 1/1) {
  .results-wrap { grid-template-columns: 1fr; gap: 2vh; }
  .podium { height: 38vh; }
  .your-score { padding: 2vh 4vw; }
  /* portrait: logos on one row, title below */
  #brand-bar {
    --logo-row: clamp(34px, 6.5vh, 70px);
    height: auto; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "left right" "center center"; row-gap: 4px; padding-top: 8px; padding-bottom: 6px;
  }
  .brand-divider { display: none; }
  .brand-left { grid-area: left; }
  .brand-right { grid-area: right; }
  .brand-center { grid-area: center; }
  .brand-side { height: var(--logo-row); }
  .brand-side img { height: calc(var(--logo-row) * var(--logo-scale, 0.7) / 0.7); max-height: 100%; }
  .brand-text-right .ar { font-size: clamp(14px, 4.5vw, 26px); }
  .brand-text-right .en { font-size: clamp(8px, 2.4vw, 14px); }
  .brand-text-right .tag { display: none; }
  #screen-standby { justify-content: space-evenly; }
  .item-legend { position: static; transform: none; gap: 6px; }
  .legend-chip { font-size: 12px; }
  .lb-row { grid-template-columns: 2em 1fr auto; gap: .6em; }
  .hud-box { font-size: clamp(14px, 5vw, 28px); }
  #screen-results, #screen-leaderboard { justify-content: space-evenly; }
  .tap-continue { position: static; margin-top: 1.5vh; }
  .podium { height: 32vh; }
  .ys-score { font-size: clamp(48px, 11vh, 120px); }
}
