:root {
  color-scheme: dark;
  --bg: #050817;
  --panel: rgba(11, 18, 39, 0.9);
  --cyan: #40d9ff;
  --blue: #3675ff;
  --pink: #ff4f9a;
  --orange: #ff9b38;
  --lime: #8df58f;
  --text: #f7fbff;
  --muted: #91a0be;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(54, 117, 255, 0.23), transparent 34rem),
    radial-gradient(circle at 85% 20%, rgba(255, 79, 154, 0.17), transparent 30rem),
    #03050c;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; }

.game-shell {
  width: min(100%, 480px);
  min-height: 100svh;
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto minmax(330px, 1fr) auto;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #080e20 0%, #050817 56%, #080d1d 100%);
  border-inline: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.75);
}

.hud {
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr 76px 1fr;
  gap: 7px;
  min-height: 128px;
  padding: max(12px, env(safe-area-inset-top)) 10px 10px;
  background: linear-gradient(180deg, rgba(2, 5, 14, 0.98), rgba(7, 11, 25, 0.93));
  border-bottom: 1px solid rgba(115, 170, 255, 0.18);
}

.fighter {
  min-width: 0;
  padding: 8px 9px 9px;
  position: relative;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(255,255,255,.07), rgba(255,255,255,.02));
  overflow: hidden;
}

.fighter::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .25;
}

.fighter--player { box-shadow: inset 0 0 26px rgba(55, 143, 255, .16), 0 0 20px rgba(54, 117, 255, .08); }
.fighter--player::before { background: linear-gradient(110deg, rgba(64, 217, 255, .25), transparent 56%); }
.fighter--opponent { text-align: right; box-shadow: inset 0 0 26px rgba(255, 79, 154, .13), 0 0 20px rgba(255, 79, 154, .07); }
.fighter--opponent::before { background: linear-gradient(250deg, rgba(255, 79, 154, .22), transparent 56%); }

.fighter__head {
  display: flex;
  align-items: center;
  gap: 7px;
  position: relative;
}
.fighter__head--right { justify-content: flex-end; }

.avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .06em;
  border: 1px solid rgba(255,255,255,.28);
}
.avatar--player { background: linear-gradient(145deg, #2f8cff, #1645a8); box-shadow: 0 0 15px rgba(64,217,255,.3); }
.avatar--opponent { background: linear-gradient(145deg, #ff5e98, #a72359); box-shadow: 0 0 15px rgba(255,79,154,.28); }

.fighter__name {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .12em;
  color: #d9e7ff;
}

.fighter__score {
  display: block;
  margin-top: 4px;
  font-size: clamp(26px, 8vw, 38px);
  line-height: .95;
  letter-spacing: -.055em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(255,255,255,.22);
}

.fighter__combo {
  display: block;
  margin-top: 7px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
  color: var(--muted);
}
.fighter__combo b { color: #fff; font-size: 13px; }

.meter {
  height: 5px;
  margin-top: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.meter i {
  display: block;
  width: 50%;
  height: 100%;
  transition: width .2s ease;
}
.fighter--player .meter i { background: linear-gradient(90deg, var(--blue), var(--cyan)); box-shadow: 0 0 10px var(--cyan); }
.fighter--opponent .meter i { margin-left: auto; background: linear-gradient(90deg, var(--pink), var(--orange)); box-shadow: 0 0 10px var(--pink); }

.match-status {
  align-self: center;
  display: grid;
  justify-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
}
.match-status__label { color: #ffd365; }
.match-status strong {
  margin: 2px 0 -1px;
  font-size: 42px;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 24px rgba(255, 211, 101, .32);
}

.arena {
  min-height: 330px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(90deg, rgba(47, 140, 255, .08), transparent 29%, rgba(141, 245, 143, .035) 50%, transparent 71%, rgba(255, 79, 154, .08)),
    repeating-linear-gradient(90deg, transparent 0, transparent calc(33.333% - 1px), rgba(255,255,255,.055) calc(33.333% - 1px), rgba(255,255,255,.055) 33.333%),
    linear-gradient(180deg, #060a18, #090f22 72%, #07101d);
}

.arena::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: repeating-linear-gradient(0deg, transparent 0 42px, rgba(255,255,255,.026) 43px 44px);
  transform: perspective(380px) rotateX(7deg) scale(1.12);
  transform-origin: bottom;
}

.arena__lane {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 33.333%;
  pointer-events: none;
}
.arena__lane:nth-child(1) { left: 0; box-shadow: inset 0 0 45px rgba(54,117,255,.055); }
.arena__lane:nth-child(2) { left: 33.333%; box-shadow: inset 0 0 45px rgba(141,245,143,.035); }
.arena__lane:nth-child(3) { left: 66.666%; box-shadow: inset 0 0 45px rgba(255,79,154,.05); }

.arena__caption {
  position: absolute;
  top: 11px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  white-space: nowrap;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 999px;
  background: rgba(5, 8, 19, .62);
  color: rgba(224,236,255,.68);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
}

.danger-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 31px;
  height: 2px;
  z-index: 4;
  background: linear-gradient(90deg, transparent, var(--cyan) 16%, #fff 50%, var(--pink) 84%, transparent);
  box-shadow: 0 0 14px rgba(96, 216, 255, .7), 0 0 25px rgba(255, 79, 154, .35);
}
.danger-line span {
  position: absolute;
  right: 10px;
  bottom: 7px;
  color: rgba(218, 236, 255, .55);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .15em;
}

.equation-card {
  --accent: var(--cyan);
  position: absolute;
  top: 0;
  left: 0;
  width: calc(33.333% - 18px);
  min-width: 92px;
  height: 62px;
  display: grid;
  place-items: center;
  z-index: 3;
  border: 1px solid color-mix(in srgb, var(--accent) 76%, white 24%);
  border-radius: 17px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 27%, #10182c 73%), rgba(10, 15, 33, .96));
  box-shadow: 0 10px 25px rgba(0,0,0,.35), 0 0 20px color-mix(in srgb, var(--accent) 34%, transparent);
  color: #fff;
  font-size: clamp(23px, 7vw, 34px);
  font-weight: 950;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  will-change: transform;
}
.equation-card::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08);
}
.equation-card::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: -50px;
  height: 48px;
  z-index: -1;
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--accent) 45%, transparent));
  filter: blur(8px);
}
.equation-card--lane-0 { --accent: #43c9ff; }
.equation-card--lane-1 { --accent: #82e991; }
.equation-card--lane-2 { --accent: #ff5e9a; }
.equation-card.is-target {
  border-width: 2px;
  filter: brightness(1.15);
  box-shadow: 0 12px 26px rgba(0,0,0,.42), 0 0 27px color-mix(in srgb, var(--accent) 56%, transparent);
}
.equation-card.is-wrong { animation: card-shake .22s linear; }
.equation-card.is-player-win { animation: player-clear .28s ease-out forwards; }
.equation-card.is-opponent-win { animation: opponent-clear .28s ease-out forwards; }

@keyframes card-shake {
  0%,100% { margin-left: 0; }
  25% { margin-left: -7px; }
  75% { margin-left: 7px; }
}
@keyframes player-clear {
  to { transform: translateY(var(--last-y)) scale(1.3); opacity: 0; filter: brightness(2.2); }
}
@keyframes opponent-clear {
  to { transform: translateY(var(--last-y)) scale(.72); opacity: 0; filter: saturate(.25); }
}

.feedback {
  position: absolute;
  left: 50%;
  bottom: 62px;
  z-index: 10;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
  opacity: 0;
  white-space: nowrap;
  font-weight: 950;
  font-style: italic;
  text-shadow: 0 4px 16px rgba(0,0,0,.85), 0 0 18px currentColor;
}
.feedback.show { animation: feedback-pop .55s ease-out; }
.feedback.good { color: #fff092; font-size: 31px; }
.feedback.bad { color: #ff708a; font-size: 23px; }
.feedback.rival { color: #ff9ebd; font-size: 22px; }

@keyframes feedback-pop {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(.72); }
  22% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -22px) scale(1); }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 35%, rgba(54,117,255,.24), transparent 48%),
    linear-gradient(180deg, rgba(3,6,15,.7), rgba(3,6,15,.93));
  backdrop-filter: blur(8px);
  transition: opacity .25s ease, visibility .25s ease;
}
.overlay.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay__panel { text-align: center; max-width: 330px; }
.eyebrow { color: #7adfff; font-size: 10px; font-weight: 900; letter-spacing: .2em; }
.overlay h1 {
  margin: 8px 0 12px;
  font-size: clamp(44px, 14vw, 68px);
  line-height: .82;
  letter-spacing: -.07em;
  background: linear-gradient(180deg, #fff 0 40%, #72c8ff 75%, #6f7dff);
  -webkit-background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(76,154,255,.38));
}
.overlay p { margin: 0 auto 20px; color: #b7c4dd; font-size: 13px; line-height: 1.75; }
.primary-button {
  min-width: 210px;
  border: 1px solid rgba(255,255,255,.32);
  border-radius: 999px;
  padding: 14px 23px;
  color: #06101d;
  background: linear-gradient(100deg, #5ce4ff, #8df58f);
  box-shadow: 0 0 28px rgba(64,217,255,.27);
  font-weight: 950;
  cursor: pointer;
}
.primary-button:active { transform: translateY(1px) scale(.99); }

.controls {
  z-index: 20;
  padding: 9px 12px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(9,15,33,.98), rgba(5,8,18,1));
  border-top: 1px solid rgba(117,178,255,.18);
  box-shadow: 0 -14px 35px rgba(0,0,0,.28);
}

.answer-preview {
  min-height: 48px;
  display: grid;
  grid-template-columns: auto 52px 1fr;
  align-items: center;
  gap: 9px;
  padding: 6px 12px;
  margin-bottom: 7px;
  border: 1px solid rgba(105,180,255,.22);
  border-radius: 14px;
  background: rgba(12,21,44,.72);
}
.answer-preview span { color: #7ddcff; font-size: 9px; font-weight: 900; letter-spacing: .18em; }
.answer-preview strong { text-align: center; color: #ffe277; font-size: 29px; line-height: 1; font-variant-numeric: tabular-nums; }
.answer-preview small { color: #b4c0d8; text-align: right; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tap-guide {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 2px 7px;
}
.tap-guide strong {
  color: #dcecff;
  font-size: 11px;
  letter-spacing: .08em;
}
.tap-guide span {
  padding: 3px 8px;
  border: 1px solid rgba(141,245,143,.22);
  border-radius: 999px;
  color: #aef9b0;
  background: rgba(72,141,78,.12);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .06em;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.number-key {
  min-height: 47px;
  border: 1px solid rgba(103,178,255,.25);
  border-radius: 14px;
  color: rgba(239,246,255,.92);
  background:
    linear-gradient(180deg, rgba(28,45,82,.86), rgba(10,18,39,.95));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.08),
    inset 0 -8px 18px rgba(0,0,0,.14),
    0 5px 13px rgba(0,0,0,.18);
  font-size: 25px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .07s ease, border-color .07s ease, background .07s ease, box-shadow .07s ease;
}
.number-key--zero { grid-column: 2; }
.number-key:active,
.number-key.is-selected {
  transform: translateY(1px) scale(.97);
  border-color: rgba(118,225,255,.82);
  background:
    radial-gradient(circle, rgba(72,210,255,.42), transparent 72%),
    linear-gradient(180deg, rgba(42,94,153,.92), rgba(12,28,61,.98));
  box-shadow: inset 0 0 20px rgba(87,218,255,.2), 0 0 18px rgba(64,217,255,.25);
  color: #fff;
  text-shadow: 0 0 12px rgba(120,231,255,.8);
}
.number-key:focus-visible {
  outline: 2px solid #8be9ff;
  outline-offset: 2px;
}
.number-key:disabled {
  opacity: .36;
  cursor: default;
}

.control-note {
  margin: 7px 0 0;
  color: rgba(183,196,220,.6);
  text-align: center;
  font-size: 9px;
  line-height: 1.45;
}

@media (max-height: 760px) {
  .game-shell { grid-template-rows: auto minmax(270px, 1fr) auto; }
  .hud { min-height: 109px; padding-top: max(8px, env(safe-area-inset-top)); }
  .fighter { padding: 6px 8px 7px; }
  .fighter__score { font-size: 26px; }
  .match-status strong { font-size: 34px; }
  .controls { padding-top: 7px; }
  .answer-preview { min-height: 42px; margin-bottom: 5px; }
  .tap-guide { margin-bottom: 5px; }
  .number-pad { gap: 5px; }
  .number-key { min-height: 40px; font-size: 22px; }
  .control-note { margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
