:root {
  color-scheme: dark;
  --ink: #12080e;
  --paper: #f6f1e7;
  --amber: #ffb000;
  --teal: #2ee6c8;
  --gold: #f0d7a6;
  --danger: #ff4b3e;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body { position: fixed; inset: 0; }

#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  aspect-ratio: 16 / 9;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  background: var(--ink);
  container-type: size;
  overflow: hidden;
}

#app { position: absolute; inset: 0; }

#view {
  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 at 50% 58%, transparent 42%, rgba(0, 0, 0, 0.45) 100%);
}

#hud, #overlay, #toast {
  position: absolute;
  inset: 0;
}

#hud { z-index: 4; pointer-events: none; }
#overlay { z-index: 3; pointer-events: none; display: grid; place-items: center; }
#toast {
  z-index: 5;
  inset: auto;
  left: 50%;
  top: 16%;
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  pointer-events: none;
  color: var(--paper);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 13px;
  font-weight: 650;
  text-shadow: 0 2px 0 #000;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

#app[data-state="loading"] #overlay,
#app[data-state="menu"] #overlay,
#app[data-state="paused"] #overlay,
#app[data-state="dead"] #overlay {
  pointer-events: auto;
  background: linear-gradient(180deg, rgba(18, 8, 14, 0.15), rgba(18, 8, 14, 0.62));
}

.panel { display: none; text-align: center; max-width: 92%; max-height: 100%; padding: 4% 6%; }
#app[data-state="loading"] .panel-loading,
#app[data-state="menu"] .panel-menu,
#app[data-state="paused"] .panel-paused,
#app[data-state="dead"] .panel-dead { display: block; }

.eyebrow {
  margin: 0 0 6px;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--gold);
}

.logo {
  margin: 0;
  font-weight: 750;
  letter-spacing: 0.2em;
  padding-left: 0.2em;
  line-height: 0.9;
  font-size: 64px;
  font-size: clamp(34px, 16cqh, 88px);
  background: linear-gradient(100deg, var(--amber) 0%, #fff6e4 46%, var(--teal) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tag, .hint, .bestline, .scoreword {
  margin: 10px 0 0;
  color: rgba(246, 241, 231, 0.82);
  font-size: 15px;
}

.launch {
  display: inline-block;
  margin: 18px 0 0;
  padding: 8px 16px;
  border: 1px solid rgba(246, 241, 231, 0.35);
  border-radius: 999px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 13px;
  color: var(--paper);
  animation: pulse 1.8s ease-in-out infinite;
}

.lang {
  margin-top: 16px;
  min-width: 52px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(246, 241, 231, 0.3);
  background: transparent;
  color: var(--paper);
  letter-spacing: 0.08em;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.overtitle, .pausetitle {
  margin: 0;
  font-size: clamp(28px, 8cqh, 48px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper);
}

.bigscore {
  margin: 6px 0 0;
  font-size: clamp(42px, 16cqh, 84px);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: white;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.newbest {
  margin: 4px 0 0;
  color: var(--amber);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 13px;
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }
button:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  min-width: min(280px, 70cqw);
  min-height: 56px;
  padding: 12px 32px;
  border: none;
  border-radius: 6px;
  background: var(--paper);
  color: #1c1210;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 5px 5px 0 var(--teal);
}
.btn-primary:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--teal); }

.btn-reward {
  min-width: min(220px, 56cqw);
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 6px;
  border: 1px solid #e0b15c;
  background: #1a1214;
  color: var(--gold);
  font-size: 16px;
  letter-spacing: 0.03em;
}
.btn-reward .film { font-size: 1.2em; margin-right: 8px; }
.btn-reward:active:not(:disabled) { background: #2a1c1a; }

#scoreblock {
  display: none;
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  text-align: right;
  pointer-events: none;
  text-shadow: 0 2px 0 #000;
}
#app[data-state="playing"] #scoreblock,
#app[data-state="paused"] #scoreblock,
#app[data-state="dead"] #scoreblock { display: block; }

#score {
  font-size: clamp(26px, 6cqh, 40px);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: white;
  line-height: 1;
}
#combo {
  color: var(--teal);
  font-weight: 750;
  letter-spacing: 0.08em;
  font-size: 16px;
}
#bestHud { color: rgba(246, 241, 231, 0.75); font-size: 13px; margin-top: 2px; }

.iconbar {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  pointer-events: none;
}
.iconbtn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(246, 241, 231, 0.22);
  background: rgba(12, 6, 10, 0.5);
  color: var(--paper);
}
#pauseBtn { display: none; }
#app[data-state="playing"] #pauseBtn { display: grid; }
#muteBtn .icon-off { display: none; }
#muteBtn.is-muted .icon-on { display: none; }
#muteBtn.is-muted .icon-off { display: block; }

#coach {
  display: none;
  position: absolute;
  left: 50%;
  bottom: max(64px, calc(env(safe-area-inset-bottom) + 58px));
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 6, 10, 0.55);
  color: var(--paper);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
  white-space: nowrap;
}
#app[data-state="playing"] #coach.show { display: block; }

[hidden] { display: none !important; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@media (prefers-reduced-motion: reduce) {
  .launch { animation: none; }
  #toast { transition: none; }
}
