:root {
  --bg: #0b0b1a;
  --surface: #141428;
  --glass: rgba(24, 24, 48, 0.62);
  --border: rgba(140, 150, 255, 0.18);
  --text: #e9ecff;
  --muted: #9aa0c8;
  --accent: #36e2ff;
  --accent2: #b45cff;
  --good: #3dff9e;
  --warn: #ffcc33;
  --bad: #ff4d6d;
  --single: #3aa8d8;
  --ao5: #d0802a;
  --pb: #ffd84a;
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 800px at 80% -10%, #2a1458 0%, transparent 60%),
              radial-gradient(900px 700px at -10% 110%, #06344a 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: 'Rajdhani', system-ui, sans-serif;
  font-size: 17px;
  overflow-x: hidden;
}
#bg, #confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#bg { z-index: 0; }
#confetti { z-index: 50; }
.screen { position: relative; z-index: 1; min-height: 100vh; }
.hidden { display: none !important; }

.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05);
}
.label { font-family: 'Orbitron', sans-serif; font-size: 11px; letter-spacing: .2em; color: var(--muted); }

.logo { font-family: 'Orbitron', sans-serif; font-weight: 900; letter-spacing: .08em; margin: 0; font-size: clamp(30px, 9vw, 42px); }
.logo span {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo.small { font-size: 22px; }

/* ---------- buttons ---------- */
.btn {
  font: 700 15px 'Rajdhani', sans-serif; letter-spacing: .05em;
  color: var(--text); background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 18px; cursor: pointer; transition: .15s;
}
.btn:hover { background: rgba(255, 255, 255, .12); transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border: none; color: #0b0b1a; font-size: 17px;
  box-shadow: 0 6px 24px rgba(54, 226, 255, .3);
}
.btn.ghost { background: transparent; }
.btn.tiny { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--bad); border-color: rgba(255, 77, 109, .35); }
kbd {
  font-family: 'JetBrains Mono', monospace; font-size: .85em;
  border: 1px solid var(--border); border-bottom-width: 3px;
  border-radius: 6px; padding: 1px 6px; background: rgba(255, 255, 255, .06);
}

/* ---------- auth ---------- */
#auth { display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); padding: 34px clamp(18px, 6vw, 30px) 26px; text-align: center; animation: rise .6s ease-out; }
.tag { color: var(--muted); margin: 6px 0 22px; }
.tag b { color: var(--accent); }
.tabs { display: flex; gap: 6px; background: rgba(0, 0, 0, .25); padding: 5px; border-radius: 12px; margin-bottom: 18px; }
.tab { flex: 1; background: none; border: none; color: var(--muted); padding: 9px; border-radius: 9px; font: 700 15px 'Rajdhani'; cursor: pointer; }
.tab.active { background: rgba(255, 255, 255, .1); color: var(--text); }
form label { display: block; text-align: left; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
form input:not([type=checkbox]) {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px;
  background: rgba(0, 0, 0, .3); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font: 600 17px 'Rajdhani'; outline: none; transition: .15s;
}
form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(54, 226, 255, .18); }
.check { display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 17px; height: 17px; }
.check.small { font-size: 13px; color: var(--muted); margin-top: 10px; }
#authBtn { width: 100%; margin-top: 4px; }
.https-warn { background: rgba(255, 204, 51, .1); border: 1px solid rgba(255, 204, 51, .45); color: #ffe6a3; border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.4; text-align: left; margin: 0 0 16px; }
.fineprint { color: var(--muted); font-size: 13px; margin: 14px 0 0; line-height: 1.4; }
.error { color: var(--bad); min-height: 1.2em; margin: 12px 0 0; font-weight: 600; }

.hero-cube { height: 120px; display: grid; place-items: center; perspective: 600px; margin-bottom: 10px; }

/* ---------- 3D spinning cube ---------- */
.cube3d { --s: 70px; width: var(--s); height: var(--s); position: relative; transform-style: preserve-3d; animation: spin 9s linear infinite; }
.cf { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; background: #0a0a12; border-radius: 6px; }
.cf i { border-radius: 4px; animation: sparkle 6s ease-in-out infinite; }
.cf-F { transform: translateZ(calc(var(--s) / 2)); }
.cf-B { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.cf-R { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.cf-L { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.cf-U { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.cf-D { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
@keyframes spin { from { transform: rotateX(-25deg) rotateY(0); } to { transform: rotateX(-25deg) rotateY(360deg); } }
@keyframes sparkle { 0%, 90%, 100% { filter: brightness(1); } 95% { filter: brightness(1.8); } }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }

/* ---------- app layout ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 560px) { .top-right .btn { padding: 8px 10px; font-size: 14px; } .topbar { gap: 10px; } }
.user { font-weight: 700; color: var(--accent); }
.layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; padding: 0 24px 24px; max-width: 1400px; margin: 0 auto; }
.timer-col, .stats-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; padding: 0 16px 16px; } .topbar { padding: 14px 16px; } }

/* scramble */
.scramble-card { padding: 16px 20px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr; gap: 8px 20px; align-items: center; }
.scramble-head { grid-column: 1; display: flex; gap: 12px; align-items: center; }
.scramble { grid-column: 1; font: 700 clamp(17px, 2.2vw, 24px) 'JetBrains Mono', monospace; word-spacing: .25em; line-height: 1.5; }
.scramble span { display: inline-block; animation: pop .35s backwards; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.7); } }
.net { grid-column: 2; grid-row: 1 / span 2; display: grid; grid-template-columns: repeat(4, 34px); grid-template-rows: repeat(3, 34px); gap: 3px; }
.net-face { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; }
.net-face i { border-radius: 2px; }
@media (max-width: 560px) { .scramble-card { grid-template-columns: 1fr; } .net { grid-column: 1; grid-row: auto; justify-self: center; } }

/* timer */
.timer-card { padding: 26px 20px 22px; text-align: center; position: relative; overflow: hidden; transition: box-shadow .3s, border-color .3s; cursor: pointer; user-select: none; }
.timer {
  font: 700 clamp(64px, 12vw, 150px) 'JetBrains Mono', monospace;
  line-height: 1.05; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 30px rgba(54, 226, 255, .25); transition: color .2s, text-shadow .2s, transform .2s;
}
.hint { color: var(--muted); margin-top: 6px; min-height: 1.4em; }
.hint b { color: var(--accent); }
.state-pill {
  display: inline-block; font: 700 11px 'Orbitron'; letter-spacing: .25em;
  padding: 5px 12px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted);
}
.timer-card.running { border-color: rgba(61, 255, 158, .55); box-shadow: 0 0 60px rgba(61, 255, 158, .18), inset 0 0 80px rgba(61, 255, 158, .06); }
.timer-card.running .timer { color: var(--good); text-shadow: 0 0 40px rgba(61, 255, 158, .5); }
.timer-card.running .state-pill { color: var(--good); border-color: var(--good); animation: blink 1s infinite; }
.timer-card.armed .timer { color: var(--warn); }
.timer-card.stopped .timer { animation: thump .35s; }
@keyframes blink { 50% { opacity: .45; } }
@keyframes thump { 40% { transform: scale(1.06); } }
.timer-card::before {
  content: ''; position: absolute; inset: -2px; z-index: -1; opacity: 0; transition: opacity .3s;
  background: conic-gradient(from var(--a, 0deg), transparent, var(--good), transparent 30%);
  animation: rot 2s linear infinite;
}
.timer-card.running::before { opacity: .12; }
@property --a { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
@keyframes rot { to { --a: 360deg; } }

.pr-banner {
  font: 900 22px 'Orbitron'; letter-spacing: .1em; min-height: 0; color: var(--pb);
  text-shadow: 0 0 20px rgba(255, 216, 74, .7);
}
.pr-banner.show { animation: prpop 2.8s ease-out; }
@keyframes prpop { 0% { transform: scale(.2); opacity: 0; } 12% { transform: scale(1.25); opacity: 1; } 20% { transform: scale(1); } 85% { opacity: 1; } 100% { opacity: 0; } }
.last-actions { display: flex; justify-content: center; gap: 8px; margin-top: 14px; }
.last-actions .btn.on { background: var(--accent); color: #0b0b1a; }

/* mic */
.mic-card { padding: 16px 20px; display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; align-items: center; }
.mic-btn {
  display: flex; align-items: center; gap: 9px; font: 700 16px 'Rajdhani'; cursor: pointer;
  padding: 12px 18px; border-radius: 99px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, .06); color: var(--text); transition: .2s;
}
.mic-btn.on { background: rgba(255, 77, 109, .16); border-color: var(--bad); color: #fff; animation: micpulse 1.6s infinite; }
@keyframes micpulse { 0% { box-shadow: 0 0 0 0 rgba(255, 77, 109, .5); } 100% { box-shadow: 0 0 0 16px rgba(255, 77, 109, 0); } }
.meter { width: 100%; height: 48px; }
.heard { grid-column: 1 / -1; font: 500 14px 'JetBrains Mono'; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.heard #heard { color: var(--text); }
.mic-card .check { grid-column: 1 / -1; margin: 0; }

/* stats tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tile { padding: 14px 16px; position: relative; overflow: hidden; }
.tile .v { font: 700 26px 'JetBrains Mono'; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 13px; color: var(--muted); }
.tile.hero { grid-column: span 3; display: flex; justify-content: space-between; align-items: center; background: linear-gradient(120deg, rgba(255, 216, 74, .12), rgba(180, 92, 255, .1)); }
.tile.hero .v { font-size: 40px; color: var(--pb); text-shadow: 0 0 24px rgba(255, 216, 74, .35); }
.tile.flash { animation: flash 1.2s; }
@keyframes flash { 0% { box-shadow: 0 0 0 2px var(--pb), 0 0 40px rgba(255, 216, 74, .6); } }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(2, 1fr); } .tile.hero { grid-column: span 2; } }

/* chart */
.chart-card, .history-card { padding: 16px 20px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.legend { display: flex; gap: 14px; font-size: 14px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.sw.single { background: var(--single); }
.sw.ao5 { background: var(--ao5); }
.sw.pb { width: 9px; height: 9px; border-radius: 50%; background: var(--pb); }
.chart-wrap { position: relative; height: 230px; }
#chart { width: 100%; height: 100%; display: block; }
.tooltip {
  position: absolute; pointer-events: none; background: #0b0b1a; border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 11px; font: 500 13px 'JetBrains Mono'; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); transform: translate(-50%, -110%);
}
.tooltip i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* history */
.history { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.history li {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 8px 6px; border-bottom: 1px solid rgba(255, 255, 255, .05); animation: rise .3s;
}
.history .n { color: var(--muted); font: 500 13px 'JetBrains Mono'; }
.history .t { font: 700 18px 'JetBrains Mono'; }
.history .t.pb { color: var(--pb); }
.history .t small { color: var(--muted); font-size: 12px; margin-left: 6px; }
.history .sc { display: block; font: 400 11px 'JetBrains Mono'; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .acts { display: flex; gap: 4px; }
.history .acts button { background: none; border: 1px solid transparent; color: var(--muted); border-radius: 6px; padding: 3px 7px; cursor: pointer; font: 600 12px 'Rajdhani'; }
.history .acts button:hover { border-color: var(--border); color: var(--text); }
.history .acts button.on { color: var(--warn); border-color: var(--warn); }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: #2a1020; border: 1px solid var(--bad); color: #fff; padding: 12px 18px; border-radius: 12px;
  max-width: min(640px, calc(100% - 32px)); font-weight: 600;
  white-space: pre-line; line-height: 1.45; cursor: pointer;
}


.toast.ok { background: #0f2a22; border-color: var(--good); }

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