:root {
  --void: #04060c;
  --teal: #0a2a3a;
  --cyan: #6ff2ff;
  --cyan-soft: rgba(111, 242, 255, 0.55);
  --bone: #eaf6ff;
  --red: #ff2a44;
  --amber: #ffc23d;
  --blue: #2f8cff;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-sharp: cubic-bezier(0.2, 0.9, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--void);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

body {
  font-family: "Barlow Semi Condensed", system-ui, sans-serif;
  color: var(--bone);
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 4px;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--void);
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(ellipse 78% 66% at 50% 44%, rgba(4, 6, 12, 0) 42%, rgba(3, 5, 10, 0.6) 100%),
    linear-gradient(to bottom, rgba(3, 5, 10, 0.72) 0%, rgba(3, 5, 10, 0) 15%, rgba(3, 5, 10, 0) 84%, rgba(3, 5, 10, 0.7) 100%);
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.hud-score {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 10px);
  width: clamp(140px, 40vw, 250px);
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.55));
}

.hud-score .plate-bg {
  display: block;
  width: 100%;
  height: clamp(38px, 5.8vh, 52px);
  object-fit: fill;
}

.hud-copy {
  position: absolute;
  left: 11%;
  top: 6%;
  right: 12%;
  bottom: 6%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}

.score {
  font-family: "Saira Condensed", sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(22px, 6.4vw, 34px);
  line-height: 0.88;
  letter-spacing: 0.01em;
  color: var(--bone);
  text-shadow: 0 0 14px rgba(111, 242, 255, 0.4);
  white-space: nowrap;
}

.best-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: clamp(8px, 2.3vw, 11px);
  line-height: 1.1;
  letter-spacing: 0.16em;
  color: rgba(234, 246, 255, 0.58);
  font-weight: 700;
  white-space: nowrap;
}

.best-num {
  font-family: "Saira Condensed", sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: clamp(10px, 3vw, 13px);
  letter-spacing: 0.03em;
  color: rgba(234, 246, 255, 0.82);
}

.crest {
  width: clamp(13px, 3.8vw, 18px);
  height: auto;
  filter: drop-shadow(0 0 6px rgba(255, 194, 61, 0.5));
}

.hud-score + #combo + .pause-btn,
#hud .pause-btn {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  right: calc(var(--safe-r) + 10px);
  width: clamp(48px, 13.5vw, 58px);
  height: clamp(34px, 9.5vw, 41px);
  pointer-events: auto;
}

.small-plate {
  position: relative;
  display: inline-block;
  padding: 0;
}

.small-plate img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.small-plate .pl-pressed { display: none; }
.small-plate:active .pl-idle { display: none; }
.small-plate:active .pl-pressed { display: block; }
.small-plate:active { transform: scale(0.96); }

.pause-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.pause-icon i {
  display: block;
  width: 3px;
  height: 13px;
  border-radius: 2px;
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(111, 242, 255, 0.8);
}

/* combo */
.combo {
  position: absolute;
  top: calc(var(--safe-t) + 6px);
  left: 50%;
  width: clamp(50px, 14vw, 64px);
  height: clamp(50px, 14vw, 64px);
  transform: translateX(-50%) scale(0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 180ms var(--ease-out), transform 220ms var(--ease-out);
}

.combo.on {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.combo-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 7px rgba(255, 194, 61, 0.45));
  animation: spin360 9s linear infinite;
  opacity: 0.92;
}

.combo::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(4, 6, 12, 0.72) 22%, rgba(4, 6, 12, 0) 70%);
}

.combo-val {
  position: relative;
  z-index: 1;
  font-family: "Saira Condensed", sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(20px, 5.8vw, 28px);
  line-height: 1;
  color: var(--bone);
  text-shadow: 0 0 10px rgba(255, 194, 61, 0.6);
  transition: color 200ms var(--ease-out), text-shadow 200ms var(--ease-out);
}

.combo.warm .combo-val {
  color: var(--amber);
  text-shadow: 0 0 16px rgba(255, 194, 61, 0.9), 0 0 3px rgba(255, 255, 255, 0.6);
}

.combo.flare {
  animation: comboFlare 340ms var(--ease-out);
}

@keyframes spin360 { to { transform: rotate(360deg); } }

@keyframes combo-spin {
  to { transform: rotate(360deg); }
}

@keyframes comboFlare {
  0% { transform: translateX(-50%) scale(1); }
  28% { transform: translateX(-50%) scale(1.22); }
  100% { transform: translateX(-50%) scale(1); }
}

/* ---------- shared plates ---------- */

.primary-plate {
  position: relative;
  display: block;
  width: min(86vw, 400px);
  height: clamp(58px, 9.4vh, 84px);
  padding: 0;
  transition: transform 90ms var(--ease-sharp);
  filter: drop-shadow(0 8px 22px rgba(0, 0, 0, 0.5));
}

.primary-plate > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.primary-plate .pl-pressed { display: none; }
.primary-plate:active { transform: scale(0.965); }
.primary-plate:active .pl-idle { display: none; }
.primary-plate:active .pl-pressed { display: block; }

.plate-label {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: clamp(20px, 6.4vw, 30px);
  color: var(--bone);
  text-shadow: 0 0 18px rgba(111, 242, 255, 0.55), 0 1px 0 rgba(4, 6, 12, 0.7);
  padding-left: 0.24em;
}

.small-label {
  font-size: clamp(11px, 3.1vw, 14px);
  letter-spacing: 0.18em;
  text-shadow: 0 0 10px rgba(111, 242, 255, 0.45);
}

.shock {
  position: absolute;
  inset: 2%;
  border-radius: 14px;
  border: 2px solid var(--cyan);
  opacity: 0;
  pointer-events: none;
}

.primary-plate:active .shock {
  animation: shockOut 420ms var(--ease-out);
}

@keyframes shockOut {
  0% { opacity: 0.9; transform: scale(0.94); }
  100% { opacity: 0; transform: scale(1.18); }
}

/* ---------- screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 14px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 14px);
}

/* ---------- menu ---------- */

#menu {
  align-items: stretch;
  justify-content: stretch;
  padding: calc(var(--safe-t) + 2.4vh) calc(var(--safe-r) + 14px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 14px);
  background:
    linear-gradient(to bottom, rgba(4, 6, 12, 0.5) 0%, rgba(4, 6, 12, 0) 26%, rgba(4, 6, 12, 0) 66%, rgba(4, 6, 12, 0.72) 100%);
}

.menu-inner {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.menu-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: riseIn 620ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.title {
  margin: 0;
  text-align: center;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--bone);
  line-height: 0.88;
  letter-spacing: 0.04em;
  text-shadow:
    0 0 28px rgba(111, 242, 255, 0.5),
    0 0 3px rgba(111, 242, 255, 0.9),
    0 3px 0 rgba(6, 26, 38, 0.9);
}

.title-small {
  display: block;
  font-size: clamp(21px, 7vw, 46px);
  letter-spacing: 0.16em;
  margin-bottom: 0.1em;
}

.title-big {
  display: block;
  font-size: clamp(46px, 16.4vw, 104px);
  letter-spacing: 0.015em;
  color: var(--bone);
  filter: drop-shadow(0 0 22px rgba(111, 242, 255, 0.35));
}

@supports ((background-clip: text) or (-webkit-background-clip: text)) {
  .title-big {
    background: linear-gradient(180deg, #ffffff 4%, #f4fdff 42%, #cfeff7 78%, #eaf6ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}

.subtitle {
  display: flex;
  align-items: center;
  gap: clamp(8px, 3vw, 18px);
  margin-top: clamp(10px, 1.6vh, 18px);
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 2.9vw, 14px);
  letter-spacing: 0.34em;
  color: rgba(234, 246, 255, 0.78);
  text-transform: uppercase;
  white-space: nowrap;
}

.rule {
  width: clamp(18px, 7vw, 52px);
  height: 1px;
  background: linear-gradient(90deg, rgba(111, 242, 255, 0), rgba(111, 242, 255, 0.85));
  box-shadow: 0 0 8px rgba(111, 242, 255, 0.7);
}

.subtitle .rule:last-child {
  background: linear-gradient(90deg, rgba(111, 242, 255, 0.85), rgba(111, 242, 255, 0));
}

.emblem-wrap {
  position: relative;
  margin-top: clamp(10px, 2.2vh, 26px);
  height: clamp(118px, 24vh, 240px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: riseIn 720ms 60ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.emblem {
  height: 100%;
  width: auto;
  max-width: 68vw;
  object-fit: contain;
  filter: drop-shadow(0 0 18px rgba(111, 242, 255, 0.24)) drop-shadow(0 14px 24px rgba(0, 0, 0, 0.5));
  animation: emblemBob 3.8s ease-in-out infinite;
}

.emblem-halo {
  position: absolute;
  width: 78%;
  height: 74%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(111, 242, 255, 0.14) 0%, rgba(111, 242, 255, 0.05) 46%, rgba(111, 242, 255, 0) 72%);
  filter: blur(4px);
  animation: haloPulse 3.8s ease-in-out infinite;
}

@keyframes emblemBob {
  0%, 100% { transform: translateY(0) rotate(-1.2deg); }
  50% { transform: translateY(-9px) rotate(1.2deg); }
}

@keyframes haloPulse {
  0%, 100% { opacity: 0.65; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1.05); }
}

.menu-best {
  display: flex;
  padding: 6px 18px;
  background: radial-gradient(ellipse at center, rgba(4, 6, 12, 0.82) 0%, rgba(4, 6, 12, 0.5) 42%, rgba(4, 6, 12, 0) 74%);
  align-items: center;
  gap: 6px;
  margin-top: clamp(6px, 1.2vh, 14px);
  font-size: clamp(10px, 2.8vw, 13px);
  letter-spacing: 0.22em;
  font-weight: 700;
  color: rgba(234, 246, 255, 0.6);
  text-transform: uppercase;
  animation: riseIn 720ms 120ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.menu-best .crest { width: clamp(15px, 4.2vw, 20px); }

.menu-best-num {
  font-family: "Saira Condensed", sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(16px, 4.6vw, 22px);
  letter-spacing: 0.03em;
  color: var(--amber);
  text-shadow: 0 0 12px rgba(255, 194, 61, 0.4);
}

.menu-gap { flex: 1 1 auto; min-height: 8px; }

.play-btn {
  animation: riseIn 760ms 160ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.menu-hint {
  margin: clamp(8px, 1.4vh, 14px) 0 0;
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 2.7vw, 12px);
  letter-spacing: 0.28em;
  color: rgba(234, 246, 255, 0.46);
  text-transform: uppercase;
  text-align: center;
  animation: riseIn 760ms 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.menu-goal {
  margin: 5px 0 12px;
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: clamp(8px, 2.4vw, 11px);
  letter-spacing: 0.26em;
  color: rgba(234, 246, 255, 0.32);
  text-transform: uppercase;
  text-align: center;
  animation: riseIn 760ms 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@media (max-height: 620px) {
  .menu-goal { display: none; }
}

.sound-btn {
  position: absolute;
  z-index: 10;
  top: calc(var(--safe-t) + 10px);
  right: calc(var(--safe-r) + 10px);
  width: clamp(44px, 12.5vw, 54px);
  height: clamp(32px, 9vw, 39px);
}

.sound-btn .ic-on,
.sound-btn .ic-off,
.sound-toggle .ic-on,
.sound-toggle .ic-off {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: auto;
  transform: translate(-50%, -50%);
  object-fit: contain;
  filter: drop-shadow(0 0 5px rgba(111, 242, 255, 0.5));
}

.sound-btn .ic-off,
.sound-toggle .ic-off { display: none; }
.sound-off .ic-on { display: none; }
.sound-off .ic-off { display: block; }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- pause + game over ---------- */

#pause, #over { z-index: 9; }

.wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 50% 46%, rgba(6, 13, 22, 0.58) 0%, rgba(3, 5, 10, 0.9) 100%);
}

#pause .wash {
  background:
    radial-gradient(ellipse 76% 64% at 50% 46%, rgba(5, 12, 20, 0.7) 0%, rgba(2, 4, 8, 0.96) 100%);
}

.panel {
  position: relative;
  height: min(74vh, 620px);
  aspect-ratio: 555 / 1024;
  max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 40px);
  filter: drop-shadow(0 20px 44px rgba(0, 0, 0, 0.6));
  animation: panelIn 380ms var(--ease-out) both;
}

.panel-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.panel-copy {
  position: absolute;
  inset: 7% 11% 6%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: clamp(8px, 1.6vh, 18px);
}

@keyframes panelIn {
  from { opacity: 0.92; transform: scale(0.965); }
  to { opacity: 1; transform: scale(1); }
}

.panel-title {
  margin: 0;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: clamp(24px, 7.4vw, 40px);
  color: var(--bone);
  text-shadow: 0 0 22px rgba(111, 242, 255, 0.5);
}

.small-title { font-size: clamp(17px, 5vw, 26px); letter-spacing: 0.24em; }

.panel-sub {
  margin: -6px 0 0;
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 2.6vw, 12px);
  letter-spacing: 0.32em;
  color: rgba(234, 246, 255, 0.42);
  text-transform: uppercase;
}

.panel-primary {
  width: 100%;
  height: clamp(52px, 8.2vh, 70px);
}

.panel-row {
  display: flex;
  width: 100%;
  gap: 10px;
}

.panel-small {
  position: relative;
  flex: 1 1 0;
  height: clamp(46px, 7vh, 58px);
}

.panel-small .plate-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel-hint {
  margin: 0;
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: clamp(8px, 2.4vw, 11px);
  letter-spacing: 0.26em;
  color: rgba(234, 246, 255, 0.36);
  text-transform: uppercase;
}

.sound-toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 4px 12px;
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 2.6vw, 12px);
  letter-spacing: 0.22em;
  color: rgba(234, 246, 255, 0.66);
  text-transform: uppercase;
}

.sound-toggle .ic-on,
.sound-toggle .ic-off {
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  width: 20px;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 5px rgba(111, 242, 255, 0.5));
}

.final-score {
  font-family: "Saira Condensed", sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(54px, 17vw, 96px);
  line-height: 0.86;
  color: var(--bone);
  letter-spacing: 0.01em;
  text-shadow: 0 0 30px rgba(111, 242, 255, 0.4);
}

.final-best {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(9px, 2.7vw, 12px);
  letter-spacing: 0.22em;
  font-weight: 700;
  color: rgba(234, 246, 255, 0.55);
  text-transform: uppercase;
}

.new-best {
  margin-top: -4px;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: clamp(11px, 3.2vw, 15px);
  letter-spacing: 0.26em;
  color: var(--amber);
  text-shadow: 0 0 16px rgba(255, 194, 61, 0.7);
  animation: bestPulse 1.1s var(--ease-out) infinite;
}

@keyframes bestPulse {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.045); }
}

.text-btn {
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: clamp(10px, 2.9vw, 13px);
  letter-spacing: 0.26em;
  color: rgba(234, 246, 255, 0.62);
  text-transform: uppercase;
  padding: 8px 16px;
  transition: color 160ms;
}

.text-btn:hover { color: var(--bone); }

/* ---------- first run hint + flash ---------- */

.first-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 13vh);
  transform: translateX(-50%);
  z-index: 7;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 600;
  font-size: clamp(11px, 3.2vw, 15px);
  letter-spacing: 0.3em;
  color: rgba(234, 246, 255, 0.82);
  text-shadow: 0 0 16px rgba(111, 242, 255, 0.6);
  pointer-events: none;
  animation: hintBreathe 1.8s ease-in-out infinite;
  white-space: nowrap;
}

@keyframes hintBreathe {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

#flash {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse 84% 68% at 50% 64%, rgba(255, 42, 68, 0.52) 0%, rgba(255, 42, 68, 0.13) 46%, rgba(255, 42, 68, 0) 74%);
}

#flash.crash { animation: crashWash 820ms ease-out forwards; }
#flash.amber { background: radial-gradient(ellipse 70% 60% at 50% 52%, rgba(255, 194, 61, 0.4) 0%, rgba(255, 194, 61, 0.08) 52%, rgba(255, 194, 61, 0) 76%); animation: amberPulse 900ms ease-out forwards; }

@keyframes crashWash {
  0% { opacity: 0; }
  7% { opacity: 0.88; }
  42% { opacity: 0.38; }
  100% { opacity: 0; }
}

@keyframes amberPulse {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- short / wide screens ---------- */

@media (max-height: 620px) {
  .emblem-wrap { height: clamp(88px, 20vh, 150px); }
  .title-big { font-size: clamp(38px, 12.5vw, 76px); }
  .title-small { font-size: clamp(18px, 5.6vw, 34px); }
  .menu-hint { display: none; }
  .primary-plate { height: clamp(50px, 8.6vh, 64px); }
}

@media (min-width: 720px) and (orientation: landscape) {
  .menu-inner { max-width: 780px; margin: 0 auto; }
  .emblem-wrap { height: clamp(150px, 30vh, 270px); }
  .title-big { font-size: clamp(60px, 8.4vw, 110px); }
  .title-small { font-size: clamp(26px, 3.4vw, 44px); }
  .hud-score { width: 260px; }
  .panel { height: min(86vh, 640px); }
}

@media (prefers-reduced-motion: reduce) {
  .emblem, .emblem-halo, .combo-ring, .first-hint, .new-best { animation: none; }
}
