:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #020617;
  color: #f1f5f9;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: linear-gradient(180deg, #050816, #020617);
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid #38bdf8; outline-offset: 2px; }
svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.keyboard-input {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  color: transparent;
  background: transparent;
  caret-color: transparent;
}

.hud {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(100px, 1fr) auto 42px;
  gap: .75rem;
  align-items: center;
  min-height: 74px;
  padding: max(.7rem, env(safe-area-inset-top)) .8rem .7rem;
  border-bottom: 1px solid rgba(99, 102, 241, .3);
  background: linear-gradient(100deg, rgba(15, 23, 42, .97), rgba(20, 17, 48, .95));
  box-shadow: 0 8px 30px rgba(0, 0, 0, .32), 0 1px 20px rgba(79, 70, 229, .12);
}

.skill-panel, .stats, .target-wrap, .keyboard-button, .primary-button, .mobile-hint { display: flex; align-items: center; }
.skill-panel { gap: .6rem; min-width: 0; }
.icon-tile { display: grid; place-items: center; width: 38px; height: 38px; flex: none; border: 1px solid rgba(129, 140, 248, .35); border-radius: .65rem; background: linear-gradient(145deg, rgba(79, 70, 229, .3), rgba(34, 211, 238, .1)); color: #a5b4fc; box-shadow: inset 0 0 15px rgba(99, 102, 241, .12), 0 0 18px rgba(99, 102, 241, .15); animation: icon-charge 2s ease-in-out infinite alternate; }
.eyebrow { margin: 0; color: #94a3b8; font-size: .59rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
.skill-value { margin: .08rem 0 0; color: #a5b4fc; font-size: 1.25rem; font-weight: 900; line-height: 1; text-shadow: 0 0 14px rgba(129, 140, 248, .5); }
.stats { gap: clamp(.8rem, 4vw, 1.5rem); text-align: center; }
.stat-value { margin: .15rem 0 0; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.speed { color: #34d399; }
.streak { color: #fbbf24; }

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: #cbd5e1;
  border: 1px solid #334155;
  border-radius: .65rem;
  background: #1e293b;
  cursor: pointer;
}
.icon-button:disabled { opacity: .45; cursor: default; }
.icon-button:not(:disabled):active, .keyboard-button:active, .primary-button:active { transform: scale(.96); }

.game {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: manipulation;
  isolation: isolate;
  background: radial-gradient(circle at 50% 20%, rgba(49, 46, 129, .2), transparent 45%), linear-gradient(#030617, #090d22 55%, #020617);
}

.fx-canvas { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cyber-grid { position: absolute; z-index: 2; inset: 50% -20% -20%; opacity: .2; background-image: linear-gradient(rgba(56, 189, 248, .18) 1px, transparent 1px), linear-gradient(90deg, rgba(99, 102, 241, .18) 1px, transparent 1px); background-size: 38px 38px; transform: perspective(280px) rotateX(58deg) scale(1.35); transform-origin: center bottom; mask-image: linear-gradient(transparent, #000 50%); -webkit-mask-image: linear-gradient(transparent, #000 50%); animation: grid-drive 3.8s linear infinite; pointer-events: none; }
.scanlines { position: absolute; z-index: 3; inset: 0; opacity: .035; background: repeating-linear-gradient(180deg, transparent 0 3px, #fff 4px); pointer-events: none; }

.aurora {
  position: absolute;
  z-index: 0;
  width: 55vw;
  height: 55vw;
  min-width: 260px;
  min-height: 260px;
  border-radius: 50%;
  opacity: .13;
  filter: blur(55px);
  pointer-events: none;
  will-change: transform;
}
.aurora-one { top: -18%; left: -18%; background: #4f46e5; animation: aurora-one 9s ease-in-out infinite alternate; }
.aurora-two { right: -20%; bottom: -10%; background: #0891b2; animation: aurora-two 11s ease-in-out infinite alternate; }
.scene-flash { position: absolute; z-index: 28; inset: 0; opacity: 0; pointer-events: none; }
.scene-flash.good { background: radial-gradient(circle, rgba(56, 189, 248, .22), transparent 64%); animation: scene-flash .32s ease-out; }
.scene-flash.bad { background: radial-gradient(circle at 50% 80%, rgba(239, 68, 68, .25), transparent 60%); animation: scene-flash .38s ease-out; }
.event-toast { position: absolute; z-index: 32; top: 1rem; left: 50%; padding: .45rem .85rem; color: #fff; font-size: .75rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; border: 1px solid rgba(255, 255, 255, .16); border-radius: 999px; background: rgba(15, 23, 42, .82); box-shadow: 0 10px 30px rgba(0, 0, 0, .25); opacity: 0; translate: -50% -8px; pointer-events: none; backdrop-filter: blur(8px); }
.event-toast.show { animation: toast .95s ease both; }
.event-toast.hot { color: #fde68a; border-color: rgba(250, 204, 21, .35); box-shadow: 0 0 25px rgba(250, 204, 21, .2); }

.danger-line { position: absolute; z-index: 5; left: 0; right: 0; bottom: 48px; height: 0; border-bottom: 2px dashed rgba(239, 68, 68, .4); pointer-events: none; }
.game.danger .danger-line { border-color: rgba(248, 113, 113, .92); animation: danger-pulse .65s ease-in-out infinite alternate; }
.danger-line span { position: absolute; right: 1rem; top: -.55rem; padding: 0 .5rem; color: rgba(248, 113, 113, .65); background: rgba(2, 6, 23, .85); font: 600 .58rem ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .16em; text-transform: uppercase; }

.word-box {
  position: absolute;
  z-index: 10;
  display: inline-flex;
  max-width: calc(100% - 16px);
  padding: .42rem .82rem .42rem 1rem;
  border: 1px solid rgba(129, 140, 248, .52);
  border-radius: 999px;
  background: linear-gradient(110deg, rgba(30, 41, 59, .92), rgba(30, 27, 75, .82));
  box-shadow: 0 7px 24px rgba(0, 0, 0, .38), inset 0 1px rgba(255, 255, 255, .08), -18px -2px 35px -22px rgba(99, 102, 241, .8);
  backdrop-filter: blur(9px) saturate(1.3);
  white-space: nowrap;
  will-change: transform;
  transition: border-color .18s, box-shadow .18s;
}
.word-box::before { content: ''; position: absolute; left: .42rem; top: 50%; width: 5px; height: 5px; translate: 0 -50%; border-radius: 50%; background: #818cf8; box-shadow: 0 0 9px #818cf8; }
.word-box.active-target { z-index: 20; border-color: #22d3ee; background: linear-gradient(110deg, rgba(15, 23, 42, .96), rgba(8, 47, 73, .9)); box-shadow: 0 0 8px rgba(34, 211, 238, .7), 0 0 30px rgba(56, 189, 248, .32), -35px 0 45px -30px #22d3ee, inset 0 1px rgba(255, 255, 255, .15); }
.word-box.active-target::before { background: #facc15; box-shadow: 0 0 12px #facc15; animation: marker .55s ease-in-out infinite alternate; }
.word-box.active-target::after { content: ''; position: absolute; inset: -7px; border: 1px solid rgba(56, 189, 248, .28); border-radius: inherit; animation: target-ring 1.25s ease-out infinite; pointer-events: none; }
.word-box.spawn { animation: word-arrive .38s ease-out both; }
.word-box.missed { background: rgba(239, 68, 68, .75); animation: vanish .3s ease-out forwards; }
.word-box.success { animation: success .28s ease-out forwards; }
.word-box.shake { animation: shake .2s ease-in-out; }

.char { display: inline-block; color: #e2e8f0; font: 700 clamp(1rem, 4.8vw, 1.25rem) ui-monospace, SFMono-Regular, Menlo, monospace; transition: color .12s, opacity .12s; }
.char.typed { color: #38bdf8; opacity: .34; }
.char.next-expected { color: #fff; text-decoration: none; text-shadow: 0 0 6px #facc15, 0 0 14px #f59e0b; animation: next-char .55s ease-in-out infinite alternate; }
.char.hit { animation: char-hit .25s ease-out; }
.particle { position: absolute; z-index: 25; width: 6px; height: 6px; border-radius: 50%; background: #818cf8; pointer-events: none; animation: particle .5s ease-out forwards; }
.score-pop { position: absolute; z-index: 27; color: #67e8f9; font: 900 .72rem ui-monospace, SFMono-Regular, Menlo, monospace; text-shadow: 0 0 12px rgba(34, 211, 238, .8); pointer-events: none; animation: score-pop .6s ease-out forwards; }

.overlay {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  text-align: center;
  background: radial-gradient(circle at 50% 38%, rgba(49, 46, 129, .28), transparent 32%), rgba(2, 6, 23, .9);
  backdrop-filter: blur(10px);
}
.overlay[hidden] { display: none; }
.hero-orbit { position: relative; display: grid; place-items: center; width: 104px; height: 104px; margin-bottom: .6rem; }
.hero-orbit > i { position: absolute; inset: 4px; border: 1px solid rgba(34, 211, 238, .3); border-radius: 50%; animation: orbit 5s linear infinite; }
.hero-orbit > i::after { content: ''; position: absolute; top: 8px; left: 12px; width: 7px; height: 7px; border-radius: 50%; background: #22d3ee; box-shadow: 0 0 12px #22d3ee; }
.hero-orbit > i:nth-child(2) { inset: 13px; border-color: rgba(129, 140, 248, .35); animation-direction: reverse; animation-duration: 3.8s; }
.hero-orbit > i:nth-child(2)::after { top: auto; right: 4px; bottom: 13px; left: auto; width: 5px; height: 5px; background: #a78bfa; box-shadow: 0 0 10px #a78bfa; }
.overlay-icon { display: grid; place-items: center; width: 64px; height: 64px; color: #c4b5fd; border: 1px solid rgba(129, 140, 248, .55); border-radius: 50%; background: linear-gradient(145deg, rgba(79, 70, 229, .42), rgba(8, 145, 178, .2)); box-shadow: 0 0 34px rgba(99, 102, 241, .35), inset 0 0 18px rgba(255, 255, 255, .08); }
.overlay-icon svg { width: 32px; height: 32px; }
.edition-badge { margin-bottom: .55rem; padding: .28rem .58rem; color: #67e8f9; font: 800 .58rem ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .16em; text-transform: uppercase; border: 1px solid rgba(34, 211, 238, .25); border-radius: 999px; background: rgba(8, 145, 178, .08); }
.overlay h1 { margin: 0 0 .55rem; font-size: clamp(1.75rem, 8vw, 2.4rem); letter-spacing: -.04em; background: linear-gradient(100deg, #fff 15%, #a5b4fc 55%, #67e8f9); background-clip: text; -webkit-background-clip: text; color: transparent; filter: drop-shadow(0 0 18px rgba(99, 102, 241, .22)); }
.overlay > p { max-width: 340px; margin: 0 0 1.5rem; color: #94a3b8; font-size: .9rem; line-height: 1.55; }
.feature-chips { display: flex; gap: .42rem; margin: -1rem 0 1.25rem; }
.feature-chips span { padding: .28rem .48rem; color: #cbd5e1; font-size: .58rem; font-weight: 700; border: 1px solid rgba(148, 163, 184, .16); border-radius: 999px; background: rgba(15, 23, 42, .62); }
.primary-button { position: relative; justify-content: center; gap: .5rem; width: min(100%, 320px); padding: .85rem 1.25rem; overflow: hidden; color: #fff; font-weight: 900; border: 1px solid rgba(165, 180, 252, .45); border-radius: .85rem; background: linear-gradient(110deg, #4f46e5, #7c3aed, #0891b2); background-size: 200% 100%; box-shadow: 0 12px 32px rgba(79, 70, 229, .38), inset 0 1px rgba(255, 255, 255, .2); cursor: pointer; animation: button-flow 3s linear infinite; }
.primary-button::after { content: ''; position: absolute; inset: -2px auto -2px -35%; width: 24%; transform: skewX(-20deg); background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent); animation: button-shine 2.8s ease-in-out infinite; }
.primary-button:hover { filter: brightness(1.12); }
.mobile-hint { gap: .35rem; margin-top: 1.5rem !important; margin-bottom: 0 !important; color: #64748b !important; font-size: .72rem !important; }
.mobile-hint svg { width: 16px; height: 16px; flex: none; }

.bottom-bar { position: relative; z-index: 30; display: flex; gap: .75rem; align-items: center; min-height: 60px; padding: .78rem max(.8rem, env(safe-area-inset-right)) max(.7rem, env(safe-area-inset-bottom)) max(.8rem, env(safe-area-inset-left)); border-top: 1px solid rgba(99, 102, 241, .28); background: linear-gradient(90deg, #0f172a, #11112c); box-shadow: 0 -10px 30px rgba(0,0,0,.2); }
.flow-track { position: absolute; top: 0; left: 0; right: 0; height: 3px; overflow: hidden; background: #1e293b; }
.flow-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #6366f1, #22d3ee, #facc15); box-shadow: 0 0 12px #22d3ee; transition: width .22s ease-out; }
.target-wrap { gap: .65rem; min-width: 0; flex: 1; }
.target-label { flex: none; color: #64748b; font: .7rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.target-word { overflow: hidden; color: #facc15; font: 800 clamp(1rem, 5vw, 1.18rem) ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; text-overflow: ellipsis; white-space: nowrap; }
.typed-hud { color: #818cf8; }
.remaining-hud { color: #e2e8f0; }
.keyboard-button { gap: .35rem; flex: none; padding: .52rem .65rem; color: #818cf8; font-size: .72rem; font-weight: 700; border: 1px solid rgba(99, 102, 241, .35); border-radius: .65rem; background: rgba(79, 70, 229, .18); cursor: pointer; }
.keyboard-button svg { width: 16px; height: 16px; }

.combo-burst { position: absolute; z-index: 31; top: 42%; left: 50%; display: grid; place-items: center; opacity: 0; translate: -50% -50%; pointer-events: none; }
.combo-burst span { color: #fff; font-size: clamp(4.5rem, 28vw, 8rem); font-weight: 950; line-height: .8; letter-spacing: -.08em; text-shadow: 0 0 8px #facc15, 0 0 34px rgba(250, 204, 21, .7), 0 10px 45px rgba(0,0,0,.7); }
.combo-burst small { margin-top: .55rem; color: #fde68a; font: 900 .72rem ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .32em; text-shadow: 0 0 12px #f59e0b; }
.combo-burst.show { animation: combo-burst 1s cubic-bezier(.2,.8,.2,1) both; }
.game.impact { animation: impact .22s ease-out; }
.game.flowing .aurora { opacity: .23; filter: blur(42px); }
.game.flowing .cyber-grid { opacity: .33; }

@keyframes shake { 0%, 100% { translate: 0; } 25% { translate: -8px; } 75% { translate: 8px; } }
@keyframes char-hit { 0%, 100% { transform: scale(1) translateY(0); } 50% { transform: scale(1.55) translateY(-8px); } }
@keyframes success { to { transform: translateY(-20px) scale(1.28); opacity: 0; } }
@keyframes vanish { to { transform: scale(.78); opacity: 0; } }
@keyframes particle { to { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; } }
@keyframes score-pop { from { opacity: 0; transform: translateY(3px) scale(.8); } 25% { opacity: 1; } to { opacity: 0; transform: translateY(-30px) scale(1.15); } }
@keyframes word-arrive { from { opacity: 0; scale: .7; filter: blur(4px); } to { opacity: 1; scale: 1; filter: blur(0); } }
@keyframes target-ring { from { opacity: .8; scale: .9; } to { opacity: 0; scale: 1.12; } }
@keyframes scene-flash { 0% { opacity: 0; } 35% { opacity: 1; } 100% { opacity: 0; } }
@keyframes toast { 0% { opacity: 0; translate: -50% -8px; scale: .9; } 18%, 72% { opacity: 1; translate: -50% 0; scale: 1; } 100% { opacity: 0; translate: -50% -4px; scale: .96; } }
@keyframes danger-pulse { to { filter: drop-shadow(0 0 6px rgba(239, 68, 68, .8)); } }
@keyframes aurora-one { to { transform: translate(24vw, 15vh) scale(1.2); } }
@keyframes aurora-two { to { transform: translate(-20vw, -12vh) scale(.85); } }
@keyframes icon-charge { to { color: #67e8f9; box-shadow: inset 0 0 18px rgba(34, 211, 238, .16), 0 0 22px rgba(99, 102, 241, .35); } }
@keyframes grid-drive { to { background-position: 0 38px, 38px 0; } }
@keyframes marker { to { scale: 1.45; } }
@keyframes next-char { to { scale: 1.16; translate: 0 -2px; } }
@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes button-flow { to { background-position: 200% 0; } }
@keyframes button-shine { 0%, 45% { left: -35%; } 70%, 100% { left: 125%; } }
@keyframes combo-burst { 0% { opacity: 0; scale: .35; filter: blur(8px); } 18%, 55% { opacity: 1; scale: 1; filter: blur(0); } 100% { opacity: 0; scale: 1.35; filter: blur(3px); } }
@keyframes impact { 0%,100% { translate: 0; } 30% { translate: -4px 2px; } 65% { translate: 4px -1px; } }

@media (max-width: 430px) {
  .hud { grid-template-columns: minmax(90px, 1fr) auto 38px; gap: .45rem; padding-inline: .55rem; }
  .icon-tile { display: none; }
  .stats { gap: .65rem; }
  .icon-button { width: 38px; height: 38px; }
}

@media (max-width: 340px) {
  .eyebrow { font-size: .51rem; }
  .stat-value { font-size: .72rem; }
  .skill-value { font-size: 1.05rem; }
  .keyboard-button span { display: none; }
}

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