:root {
  --cyan: #00f3ff;
  --magenta: #ff3bd4;
  --white: #f4fbff;
  --red: #ff4155;
  --yellow: #ffe56a;
  --bg-dark: #05070d;
  --glass-bg: rgba(6, 10, 20, .82);
  --font-main: "Orbitron", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; color: var(--white); background: var(--bg-dark); font-family: var(--font-main); }
button { font: inherit; }

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 50%, rgba(45, 70, 105, .2), transparent 38%),
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px),
    #05070d;
  background-size: auto, 42px 42px, 42px 42px, auto;
}

#game-container::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,.68));
}

#gameCanvas { position: absolute; inset: 0; z-index: 1; display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#gameCanvas.dragging { cursor: grabbing; }
#ui-layer { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.hidden { display: none !important; }

.glass {
  background: linear-gradient(145deg, rgba(255,255,255,.045), transparent 35%), var(--glass-bg);
  border: 1px solid rgba(180, 225, 255, .17);
  box-shadow: 0 18px 60px rgba(0,0,0,.72), inset 0 0 30px rgba(99,170,255,.035);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.panel { width: min(92vw, 530px); padding: clamp(1.5rem, 5vw, 2.7rem); border-radius: 18px; text-align: center; pointer-events: auto; }
.eyebrow { margin: 0 0 .65rem; color: #8ca2b8; font-size: .65rem; font-weight: 700; letter-spacing: .22em; }
.eyebrow.danger { color: var(--red); }
.title { margin: 0; font-size: clamp(1.85rem, 7vw, 3.1rem); font-weight: 900; line-height: 1.05; letter-spacing: .025em; }
.neon-split { color: transparent; background: linear-gradient(90deg, var(--cyan), #d8fbff 49%, #ffe2fa 51%, var(--magenta)); background-clip: text; -webkit-background-clip: text; filter: drop-shadow(0 0 10px rgba(255,255,255,.25)); }
.lead { max-width: 46ch; margin: 1.15rem auto 1.4rem; color: #b9c5d3; font-family: system-ui, sans-serif; font-size: .94rem; line-height: 1.55; }

.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.rule { display: flex; align-items: center; gap: .65rem; min-height: 68px; padding: .7rem; text-align: left; background: rgba(255,255,255,.025); border: 1px solid rgba(255,255,255,.09); border-radius: 10px; }
.rule span { min-width: 0; } .rule strong, .rule small { display: block; } .rule strong { font-size: .68rem; } .rule small { margin-top: .22rem; color: #8493a4; font: .75rem system-ui, sans-serif; }
.cyan-rule { border-color: rgba(0,243,255,.26); } .magenta-rule { border-color: rgba(255,59,212,.26); }
.cyan-rule strong { color: var(--cyan); } .magenta-rule strong { color: var(--magenta); }
.mini-core { flex: 0 0 28px; width: 28px; height: 28px; border: 3px solid currentColor; border-radius: 50%; box-shadow: 0 0 12px currentColor, inset 0 0 8px currentColor; }
.cyan-rule .mini-core { color: var(--cyan); } .magenta-rule .mini-core { color: var(--magenta); }
.warning { display: flex; justify-content: center; align-items: center; gap: .5rem; margin: 1.15rem 0; color: #9baaba; font: .78rem system-ui, sans-serif; }
.warning span { display: grid; place-items: center; width: 20px; height: 20px; color: var(--red); border: 1px solid var(--red); border-radius: 50%; font-weight: 800; }

.neon-btn { width: 100%; min-height: 50px; color: #061014; background: linear-gradient(135deg, #ebfeff, #7feef4); border: 1px solid #d9fdff; border-radius: 9px; box-shadow: 0 0 24px rgba(0,243,255,.22); cursor: pointer; font-weight: 900; letter-spacing: .14em; transition: transform .15s ease, filter .15s ease; }
.neon-btn:hover, .neon-btn:focus-visible { transform: translateY(-2px); filter: brightness(1.12); outline: 2px solid var(--cyan); outline-offset: 3px; }
.text-btn { margin-top: .85rem; padding: .55rem 1rem; color: #94a4b4; background: transparent; border: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.leaderboard-btn { width: 100%; min-height: 43px; margin-top: .7rem; color: #b8cadb; background: rgba(8,18,30,.72); border: 1px solid rgba(155,207,255,.25); border-radius: 9px; cursor: pointer; font-size: .68rem; font-weight: 700; letter-spacing: .12em; transition: .16s ease; }
.leaderboard-btn span { color: var(--yellow); margin-right: .35rem; }
.leaderboard-btn:hover, .leaderboard-btn:focus-visible { color: var(--white); border-color: var(--cyan); box-shadow: 0 0 18px rgba(0,243,255,.17); outline: none; }

.leaderboard-dialog { width: min(92vw, 540px); max-height: min(86vh, 720px); margin: auto; padding: 0; color: var(--white); background: transparent; border: 0; overflow: visible; pointer-events: auto; }
.leaderboard-dialog::backdrop { background: rgba(1,4,10,.82); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px); }
.leaderboard-shell { position: relative; max-height: min(86vh, 720px); padding: 1.5rem; border-radius: 16px; overflow: hidden auto; }
.leaderboard-shell h2 { margin: 0 0 1.1rem; color: var(--cyan); font-size: 2rem; letter-spacing: .12em; text-align: center; text-shadow: 0 0 15px rgba(0,243,255,.42); }
.dialog-close { position: absolute; top: .7rem; right: .7rem; width: 36px; height: 36px; color: #a9bacb; background: rgba(255,255,255,.035); border: 1px solid rgba(255,255,255,.13); border-radius: 8px; cursor: pointer; font-size: 1.3rem; }
.dialog-close:hover, .dialog-close:focus-visible { color: var(--red); border-color: var(--red); outline: none; }
.leaderboard-head { display: grid; grid-template-columns: 1fr auto; padding: .5rem .7rem; color: #63768b; border-bottom: 1px solid rgba(255,255,255,.1); font-size: .52rem; letter-spacing: .13em; }
.leaderboard-list { display: grid; gap: .42rem; margin: .65rem 0 0; padding: 0; list-style: none; counter-reset: rank; }
.leaderboard-row { counter-increment: rank; display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: .7rem; min-height: 53px; padding: .55rem .7rem; background: rgba(255,255,255,.025); border: 1px solid rgba(255,255,255,.075); border-radius: 9px; }
.leaderboard-row::before { content: counter(rank, decimal-leading-zero); color: #6e8196; font-size: .72rem; font-weight: 800; }
.leaderboard-row:first-child { border-color: rgba(255,229,106,.42); background: linear-gradient(90deg, rgba(255,229,106,.09), rgba(255,255,255,.02)); }
.leaderboard-row:first-child::before { color: var(--yellow); text-shadow: 0 0 8px rgba(255,229,106,.55); }
.leaderboard-meta strong, .leaderboard-meta small { display: block; }
.leaderboard-meta strong { color: #d7e6f3; font-size: .65rem; letter-spacing: .06em; }
.leaderboard-meta small { margin-top: .18rem; color: #6f8194; font: .68rem system-ui, sans-serif; }
.leaderboard-points { color: var(--white); font-size: .92rem; font-weight: 900; text-align: right; }
.leaderboard-points small { display: block; margin-top: .12rem; color: var(--cyan); font-size: .5rem; letter-spacing: .08em; }
.leaderboard-empty { margin: 1.8rem 0 .5rem; color: #718398; font: .82rem/1.6 system-ui, sans-serif; text-align: center; }

.hud { position: absolute; top: max(68px, calc(env(safe-area-inset-top) + 56px)); left: 50%; width: min(620px, calc(100% - 128px)); min-height: 72px; transform: translateX(-50%); display: grid; grid-template-columns: repeat(2,1fr) 70px repeat(2,1fr); align-items: center; background: rgba(5,9,17,.82); border: 1px solid rgba(175,220,255,.16); border-radius: 14px; box-shadow: 0 12px 35px rgba(0,0,0,.45); backdrop-filter: blur(10px); }
.hud-stat { padding: .55rem; text-align: center; }
.hud-stat small { display: block; color: #718399; font-size: .53rem; letter-spacing: .12em; }
.hud-stat strong { display: block; margin-top: .18rem; color: var(--white); font-size: clamp(.85rem, 2.6vw, 1.25rem); }
#combo { color: var(--yellow); } #level { color: var(--cyan); }
.hud-core { position: relative; display: grid; place-items: center; height: 70px; border-inline: 1px solid rgba(255,255,255,.09); }
.hud-core::before, .hud-core::after, .hud-core span { content: ""; position: absolute; border-radius: 50%; }
.hud-core::before { width: 40px; height: 40px; border: 2px solid rgba(255,255,255,.16); animation: hud-spin 5s linear infinite; border-top-color: var(--cyan); border-bottom-color: var(--magenta); }
.hud-core::after { width: 24px; height: 24px; background: #d9fbff; box-shadow: 0 0 14px var(--cyan); }
@keyframes hud-spin { to { transform: rotate(360deg); } }
.hud.critical { border-color: rgba(255,65,85,.85); animation: danger-hud .34s ease-in-out infinite alternate; }
.hud.critical .hud-core::after { background: #fff; box-shadow: 0 0 24px var(--red); }
@keyframes danger-hud { to { box-shadow: 0 0 34px rgba(255,65,85,.58), inset 0 0 22px rgba(255,65,85,.14); } }

.zone-labels { position: absolute; left: 0; right: 0; bottom: max(28px, env(safe-area-inset-bottom)); display: flex; justify-content: space-between; padding: 0 clamp(12px, 5vw, 60px); }
.zone-label { display: grid; grid-template-columns: auto auto; align-items: center; column-gap: .45rem; opacity: .86; }
.zone-label strong { font-size: clamp(.58rem, 2vw, .8rem); letter-spacing: .1em; } .zone-label small { grid-column: 2; color: #77889a; font: .7rem system-ui, sans-serif; }
.zone-label > span { grid-row: 1 / 3; font-size: 1.4rem; }
.zone-label.cyan { color: var(--cyan); } .zone-label.magenta { color: var(--magenta); text-align: right; } .zone-label.magenta small { grid-column: 1; }

.status-message { position: absolute; top: 97px; left: 50%; padding: .55rem .8rem; transform: translate(-50%, -8px); color: var(--white); background: rgba(5,9,17,.86); border: 1px solid transparent; border-radius: 7px; font-size: .68rem; font-weight: 700; letter-spacing: .08em; opacity: 0; transition: .2s ease; }
.status-message.show { transform: translate(-50%,0); border-color: rgba(255,255,255,.14); opacity: 1; }
.status-message.good { color: var(--cyan); } .status-message.bad { color: var(--red); }

.icon-btn { position: absolute; top: max(18px, env(safe-area-inset-top)); z-index: 3; width: 44px; height: 44px; color: #b7c5d4; background: rgba(5,9,17,.82); border: 1px solid rgba(255,255,255,.16); border-radius: 10px; cursor: pointer; pointer-events: auto; }
#btn-pause { right: 18px; top: 72px; } .sound-btn { left: 18px; top: 72px; }
.icon-btn:hover { color: var(--cyan); border-color: var(--cyan); }

#pause-screen h2 { margin: 0 0 1.5rem; color: var(--cyan); font-size: 2.4rem; }
.neon-red { margin: 0 0 .75rem; color: var(--red); font-size: clamp(1.45rem, 6vw, 2.35rem); text-shadow: 0 0 18px rgba(255,65,85,.7); }
.game-over-reason { margin: 0 0 1.25rem; color: #aab8c7; font: .9rem/1.5 system-ui, sans-serif; }
.results { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 1rem; border: 1px solid rgba(255,255,255,.1); border-radius: 10px; }
.results div { padding: 1rem .5rem; } .results div + div { border-left: 1px solid rgba(255,255,255,.1); }
.results small { display: block; color: #718399; font-size: .55rem; } .results strong { display: block; margin-top: .25rem; color: var(--white); font-size: 1.7rem; }
.new-record { color: var(--yellow); font-size: .75rem; font-weight: 900; letter-spacing: .16em; animation: record-pulse .65s ease-in-out infinite alternate; }
@keyframes record-pulse { to { filter: drop-shadow(0 0 8px var(--yellow)); } }
.screen-shake { animation: screen-shake .42s cubic-bezier(.36,.07,.19,.97); }
@keyframes screen-shake { 10%,90% { transform: translate3d(-2px,1px,0); } 20%,80% { transform: translate3d(4px,-2px,0); } 30%,50%,70% { transform: translate3d(-7px,3px,0); } 40%,60% { transform: translate3d(7px,-3px,0); } }

@media (max-width: 600px) {
  .hud { left: 62px; width: calc(100% - 124px); transform: none; grid-template-columns: repeat(4,1fr); min-height: 62px; }
  .hud-core { display: none; } .hud-stat { padding: .45rem .2rem; } .hud-stat small { font-size: .43rem; }
  .status-message { top: 84px; white-space: nowrap; }
  .zone-labels { padding-inline: 12px; bottom: 14px; }
  .zone-label strong { font-size: .52rem; } .zone-label small { font-size: .6rem; }
  .icon-btn { top: 18px; width: 44px; height: 44px; } #btn-pause { right: 12px; top: 68px; } .sound-btn { left: 12px; top: 68px; }
}

@media (max-width: 460px) { .rule-grid { grid-template-columns: 1fr; } .panel { padding: 1.35rem; } .lead { margin-block: .85rem; } .warning { margin-block: .85rem; } }
@media (max-width: 460px) { .leaderboard-shell { padding: 1.15rem .8rem; } .leaderboard-row { grid-template-columns: 30px 1fr auto; gap: .4rem; padding-inline: .5rem; } }
@media (max-height: 650px) { .panel { padding-block: 1.15rem; } .lead { margin-block: .7rem; } .rule { min-height: 55px; } .warning { margin-block: .65rem; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
