@font-face {
  font-family: 'Barlow Condensed';
  src: url('/barlow-condensed.woff2') format('woff2');
  font-weight: 800;
  font-display: swap;
}

@font-face {
  font-family: 'Space Grotesk';
  src: url('/space-grotesk.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  color: #f5f5ee;
  background: #101116;
  font-synthesis: none;
  --bg: #101116;
  --panel: #181a22;
  --line: #32343e;
  --text: #f5f5ee;
  --muted: #b0b2bf;
  --acid: #deff43;
  --accent: var(--acid);
  --bevel: #899c22;
  --glint: #f4ffae;
  --ink: #151a04;
  --display: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 20%, var(--wash, #242532), var(--bg) 76%);
  transition: background-color 150ms;
}

body::before {
  position: fixed;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  content: '';
  background: radial-gradient(circle, #ffffff17 .7px, transparent .9px) center / 12px 12px;
  mask-image: linear-gradient(#000, transparent 83%);
}

body[data-result='win'] {
  --bg: #0c261b;
  --wash: #1d5839;
  --accent: #6dffa4;
  --bevel: #32965c;
  --glint: #c5ffda;
  --ink: #042113;
}

body[data-result='loss'] {
  --bg: #310f19;
  --wash: #661f2e;
  --accent: #ff7884;
  --bevel: #ad354b;
  --glint: #ffc2c8;
  --ink: #30050f;
}

h1, h2, p { margin: 0; }
button, input { font: inherit; }
button, summary, input[type='radio'] { -webkit-tap-highlight-color: transparent; }
button, summary { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.app {
  position: relative;
  width: min(100%, 478px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.app.in-room { height: 100dvh; min-height: 480px; }

.app-header, .header-actions, .wordmark { display: flex; align-items: center; }
.app-header { justify-content: space-between; flex: 0 0 auto; min-height: 44px; }
.header-actions { gap: 8px; }
.wordmark { font: 800 1.85rem/.87 var(--display); letter-spacing: -.025em; }
.wordmark-accent { color: var(--acid); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-right: 9px;
  border-radius: 9px 9px 9px 3px;
  background: var(--acid);
  color: #181c08;
}

.bolt {
  display: block;
  width: 15px;
  height: 20px;
  background: currentColor;
  clip-path: polygon(54% 0, 100% 0, 67% 41%, 96% 41%, 20% 100%, 38% 57%, 0 57%);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  list-style: none;
  cursor: pointer;
}

.profile-badge {
  display: grid;
  place-items: center;
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #e4fa86;
  color: #171923;
  font-weight: 700;
}
.profile-badge:empty::before, .profile-badge:empty::after { position: absolute; background: currentColor; content: ''; }
.profile-badge:empty::before { top: 5px; width: 7px; height: 7px; border-radius: 50%; }
.profile-badge:empty::after { bottom: 5px; width: 14px; height: 8px; border-radius: 8px 8px 3px 3px; }

summary::-webkit-details-marker { display: none; }
.menu { position: relative; z-index: 3; }
.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 172px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #20222a;
  box-shadow: 0 12px 25px #0006;
}
.menu-panel button { width: 100%; min-height: 44px; padding: 0 10px; border: 0; border-radius: 7px; color: var(--text); background: none; text-align: left; white-space: nowrap; }
.dots { width: 4px; height: 4px; border-radius: 50%; background: currentColor; box-shadow: -6px 0, 6px 0; }

.sound-icon { position: relative; display: block; width: 23px; height: 20px; }
.sound-icon::before {
  position: absolute;
  inset: 2px auto 2px 0;
  width: 12px;
  background: currentColor;
  clip-path: polygon(0 27%, 35% 27%, 100% 0, 100% 100%, 35% 73%, 0 73%);
  content: '';
}
.sound-icon::after { position: absolute; right: 2px; top: 3px; width: 8px; height: 14px; border-right: 2px solid; border-radius: 50%; content: ''; }
#sound[aria-pressed='false'] { color: var(--muted); }
#sound[aria-pressed='false'] .sound-icon::after { right: 0; top: 2px; width: 10px; height: 15px; content: '×'; border: 0; font: 700 1.05rem/1 system-ui; }

.lobby { width: 100%; margin: auto 0; padding: 5px 0 12px; }
.lobby-intro { text-align: center; }
.lobby-intro h1 { margin-top: 2px; font: 800 clamp(3.3rem, 12vw, 4.9rem)/.93 var(--display); letter-spacing: -.022em; }
.lobby-intro p { margin-top: 9px; color: var(--muted); }

.lobby-art {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(133px, 25dvh, 218px);
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    linear-gradient(transparent 49.7%, #b0b2bf25 50%, transparent 50.3%),
    repeating-radial-gradient(circle at center, #c1c2d127 0 1px, transparent 1px 23px),
    radial-gradient(ellipse at center, #393e23, #171922 68%);
}
.art-cross { position: absolute; width: 10px; height: 10px; color: #838692; }
.art-cross::before, .art-cross::after { position: absolute; inset: 4px 0; background: currentColor; content: ''; }
.art-cross::after { transform: rotate(90deg); }
.art-cross:nth-child(1) { top: 13px; left: 13px; }
.art-cross:nth-child(2) { top: 13px; right: 13px; }
.art-cross:nth-child(3) { bottom: 13px; left: 13px; }
.art-cross:nth-child(4) { bottom: 13px; right: 13px; }

.lobby-console { margin-top: 21px; border: 1px solid var(--line); border-radius: 19px; background: var(--panel); padding: 13px; box-shadow: 0 10px 32px #0003; }
.mode-switch { margin: 0 0 14px; padding: 3px; border: 1px solid #343642; border-radius: 10px; background: #111219; display: grid; grid-template-columns: 1fr 1fr; }
.mode-switch label { position: relative; text-align: center; }
.mode-switch input { position: absolute; inset: 0; margin: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.mode-switch span { display: grid; min-height: 39px; place-items: center; padding: 4px; border-radius: 7px; color: var(--muted); font-weight: 700; font-size: .9375rem; }
.mode-switch input:checked + span { background: #30323e; color: var(--text); box-shadow: inset 0 1px #ffffff18; }
.mode-switch input:focus-visible + span { outline: 2px solid var(--accent); }
.input-label { display: block; margin: 0 0 5px; color: var(--text); font-size: .875rem; font-weight: 700; }
.text-input { width: 100%; height: 46px; padding: 0 12px; border: 1px solid #3b3e4b; border-radius: 9px; background: #111219; color: var(--text); }
.text-input::placeholder { color: #9698a7; }
.code-field { margin-top: 9px; }
.code-input { text-transform: uppercase; letter-spacing: .16em; }
.code-input::placeholder { letter-spacing: normal; text-transform: none; }
.primary-button { display: block; width: 100%; min-height: 47px; border: 1px solid transparent; border-radius: 9px; background: var(--acid); color: #171b05; font-weight: 700; box-shadow: inset 0 -2px #0004; }
.primary-button:disabled { opacity: .66; }
.primary-button:focus-visible { outline-offset: 4px; }
#enter-room { margin-top: 12px; }
.form-error { margin-top: 8px; color: #ffacb4; font-size: .875rem; }

.game { min-height: 0; flex: 1; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 10px; }
.room-bar { display: grid; grid-template-columns: 1fr auto auto; align-items: stretch; gap: 7px; min-height: 40px; }
.room-round, .room-code, .connection { align-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.room-round { display: flex; gap: 6px; padding: 0 11px; color: var(--muted); font-size: .8125rem; font-weight: 700; letter-spacing: .07em; }
.room-round strong { color: var(--text); font-size: 1rem; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.connection { display: flex; gap: 6px; padding: 0 8px; color: var(--muted); font-size: .8125rem; font-weight: 700; }
.connection::before { display: block; width: 6px; height: 6px; border-radius: 50%; background: #ffad69; content: ''; }
.connection[data-live='true']::before { background: #96ffab; box-shadow: 0 0 8px #96ffab70; }
.room-code { display: flex; gap: 8px; justify-content: center; min-width: 103px; padding: 0 9px; color: var(--text); font-size: .875rem; font-weight: 700; letter-spacing: .12em; }
.copy-icon { position: relative; display: inline-block; width: 13px; height: 14px; }
.copy-icon::before, .copy-icon::after { position: absolute; width: 9px; height: 10px; border: 1px solid currentColor; border-radius: 2px; content: ''; }
.copy-icon::before { top: 3px; left: 0; }
.copy-icon::after { top: 0; left: 3px; background: var(--panel); }

.arena {
  position: relative;
  display: grid;
  grid-template-rows: 28px minmax(0, 1fr) 20px 25px;
  align-items: center;
  justify-items: center;
  height: clamp(215px, 43dvh, 370px);
  padding: 8px 12px 5px;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 20%, #2c2c39);
  border-radius: 18px;
  background:
    linear-gradient(transparent 47.8%, #ffffff0f 48%, transparent 48.2%),
    repeating-radial-gradient(circle at 50% 48%, #ffffff16 0 1px, transparent 1px 25px),
    radial-gradient(circle at 50% 48%, color-mix(in srgb, var(--accent) 19%, #161721), var(--bg) 78%);
}
.arena-heading { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; font-weight: 700; color: var(--accent); }
.arena-message { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); text-align: center; font-size: .875rem; }
.buzzer-well { width: 100%; height: 100%; display: grid; place-items: center; }
.buzzer {
  --diameter: clamp(112px, 27dvh, 228px);
  position: relative;
  display: grid;
  place-items: center;
  width: var(--diameter);
  height: var(--diameter);
  padding: 0;
  flex: 0 0 auto;
  border: 1px solid #ffffff30;
  border-radius: 50%;
  background: linear-gradient(150deg, #474953, #24262e 45%, #111219 80%);
  box-shadow: inset 0 1px #ffffff36, inset 0 -2px #0007, 0 13px 23px #0008;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}
.buzzer-face {
  position: absolute;
  inset: 7% 8% 12%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--glint);
  border-radius: 50%;
  background: radial-gradient(ellipse at 36% 12%, var(--glint), var(--accent) 54%, color-mix(in srgb, var(--accent) 85%, var(--bevel)));
  box-shadow: 0 5px 0 var(--bevel), 0 9px 9px #0009, inset 0 0 0 3px #ffffff28, inset 0 -8px 18px #0002;
  transition: transform 80ms, box-shadow 80ms;
}
.buzzer:not(:disabled):active .buzzer-face, .buzzer[data-pending] .buzzer-face { transform: translateY(5px); box-shadow: 0 1px 0 var(--bevel), 0 4px 5px #000a, inset 0 0 0 3px #ffffff28; }
.buzzer:disabled[data-idle] .buzzer-face { filter: saturate(.25) brightness(.79); }
.buzzer[data-demo] { --diameter: clamp(92px, 17dvh, 146px); transform: translateY(-3px); }
.buzzer[data-demo] .bolt { width: 43%; height: 53%; }
.buzzer-well .bolt { width: clamp(14px, 3dvh, 23px); height: clamp(18px, 3.8dvh, 30px); }
#buzz-label { font: 800 clamp(2.1rem, 6.2dvh, 3.7rem)/.94 var(--display); letter-spacing: .02em; }

.timer { width: min(100%, 220px); align-self: end; padding-bottom: 2px; }
.timer-text { display: flex; justify-content: space-between; margin-bottom: 2px; color: var(--muted); font-size: .75rem; line-height: 1.1; }
#time-left { color: var(--text); font-variant-numeric: tabular-nums; }
.timer-track { height: 3px; overflow: hidden; border-radius: 5px; background: #ffffff30; }
#timer-progress { height: 100%; background: var(--accent); transform-origin: left; }

.scoreboard { display: flex; flex-direction: column; min-height: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); }
.score-header { display: flex; align-items: center; justify-content: space-between; flex: 0 0 auto; min-height: 36px; padding: 0 11px; border-bottom: 1px solid var(--line); }
.score-header h2 { font-size: .875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; }
#player-count { color: var(--muted); font-size: .8125rem; }
.player-list { min-height: 0; flex: 1; margin: 0; padding: 0 9px; overflow-y: auto; overscroll-behavior: contain; list-style: none; scrollbar-width: thin; scrollbar-color: #55586a transparent; }
.player-row { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 2px 0; }
.player-row + .player-row { border-top: 1px solid #ffffff12; }
.avatar { display: grid; place-items: center; width: 27px; height: 27px; flex: 0 0 auto; border-radius: 8px; background: var(--avatar, #e4fa86); color: #171923; font-size: .8125rem; font-weight: 700; }
.avatar[data-custom='true'] { font-size: 1rem; }
.player-row[data-color='1'] { --avatar: #c3bdff; }
.player-row[data-color='2'] { --avatar: #83edff; }
.player-row[data-color='3'] { --avatar: #ffb197; }
.player-row[data-color='4'] { --avatar: #ffa9de; }
.player-row[data-away='true'] .avatar { opacity: .56; }
.player-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9375rem; }
.player-tag { margin-left: 4px; color: var(--muted); font-size: .75rem; }
.rank { color: var(--accent); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.score-actions { display: flex; align-items: center; gap: 2px; }
.score-action { width: 36px; min-height: 38px; padding: 0; border: 1px solid #373946; border-radius: 7px; background: #242632; color: var(--text); font-size: 1.15rem; line-height: 1; }
.score-action:disabled { opacity: .5; }
.score-value { min-width: 29px; padding: 0 2px; color: var(--text); text-align: center; font-size: .9375rem; font-variant-numeric: tabular-nums; font-weight: 700; }
.score-actions:has(.score-action[hidden]) .score-value { padding-right: 4px; }

.host-controls { display: grid; grid-template-columns: 1.35fr 1fr; gap: 8px; }
.control { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 3px 7px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: #242631; font-size: .9375rem; font-weight: 700; }
.control:disabled { opacity: .55; }
.control-icon { color: var(--accent); font: 600 1.15rem/1 system-ui; }

.dialog { width: min(calc(100% - 24px), 440px); max-height: calc(100dvh - 24px); padding: 16px; border: 1px solid #464855; border-radius: 17px; background: #1b1d27; color: var(--text); box-shadow: 0 20px 60px #0009; }
.dialog::backdrop { background: #08090dcc; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 13px; }
.dialog-heading h2 { font: 800 2.3rem/1 var(--display); }
.profile-dialog .dialog-heading h2 { font-size: clamp(1.9rem, 8vw, 2.3rem); }
.close-dialog { font: 400 1.6rem/1 system-ui; }
.avatar-picker { margin: 14px 0; padding: 0; border: 0; }
.avatar-picker legend { margin-bottom: 5px; font-size: .875rem; font-weight: 700; }
.avatar-options { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
.avatar-choice { position: relative; }
.avatar-choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.avatar-choice span { display: grid; min-height: 43px; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: #111219; font-size: 1.25rem; }
.avatar-choice:first-child span { font-size: .875rem; font-weight: 700; }
.avatar-choice input:checked + span { border-color: var(--acid); background: #2d351c; }
.avatar-choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.sound-picker { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.sound-select { position: relative; }
.sound-select select { appearance: none; padding-right: 30px; }
.sound-select::after { position: absolute; top: 17px; right: 13px; width: 8px; height: 8px; border-bottom: 2px solid var(--muted); border-right: 2px solid var(--muted); transform: rotate(45deg); content: ''; pointer-events: none; }
.play-icon { display: inline-block; width: 10px; height: 12px; background: var(--accent); clip-path: polygon(0 0, 100% 50%, 0 100%); }
#preview-sound { padding-inline: 10px; }
#save-profile { margin-top: 12px; }
.rule-modes { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; }
.rule-modes legend { margin-bottom: 5px; font-size: .875rem; color: var(--muted); }
.rule-option { display: flex; align-items: center; gap: 9px; min-height: 52px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.rule-option:has(:checked) { border-color: color-mix(in srgb, var(--acid) 60%, var(--line)); background: #272c1f; }
.rule-option input { margin: 0; accent-color: var(--acid); }
.rule-option strong, .timer-setting strong { display: block; font-size: .9375rem; }
.rule-option small, .timer-setting small, .rules-note { display: block; color: var(--muted); font-size: .8125rem; }
.timer-setting { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.timer-setting:has(:disabled) { opacity: .55; }
.seconds-field { position: relative; flex: 0 0 67px; }
.seconds-field input { width: 100%; height: 42px; padding: 0 19px 0 8px; border: 1px solid #484b59; border-radius: 8px; background: #111219; color: var(--text); appearance: textfield; }
.seconds-field input::-webkit-inner-spin-button, .seconds-field input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.seconds-field span { position: absolute; right: 8px; top: 9px; color: var(--muted); pointer-events: none; }
.rules-note { margin: 9px 0; }
#install-help { line-height: 1.5; color: var(--muted); }
.toast { position: fixed; z-index: 5; inset: auto 12px max(14px, env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 24px); margin: 0 auto; padding: 9px 13px; border: 1px solid #4a4c5b; border-radius: 9px; background: #242631; box-shadow: 0 7px 24px #0008; color: var(--text); font-size: .875rem; }

@media (hover: hover) {
  .icon-button:hover, .room-code:hover, .control:hover:not(:disabled), .score-action:hover:not(:disabled), .menu-panel button:hover { background: #353744; }
  .primary-button:hover:not(:disabled) { background: #eaff80; }
  .buzzer:not(:disabled):hover .buzzer-face { filter: brightness(1.06); }
}

@media (min-height: 760px) {
  .app { padding-top: max(21px, env(safe-area-inset-top)); padding-bottom: max(21px, env(safe-area-inset-bottom)); }
  .lobby-console { padding: 16px; }
  .score-header { min-height: 41px; }
  .player-row { min-height: 47px; }
}

@media (min-width: 600px) {
  .app { width: 455px; padding-left: 17px; padding-right: 17px; }
  .app.in-room { max-height: 850px; }
}

@media (max-width: 350px) {
  .app { padding-inline: 10px; }
  .header-actions { gap: 5px; }
  .room-bar { gap: 5px; }
  .room-round { padding: 0 7px; }
  .room-code { min-width: 91px; gap: 5px; }
  .player-row { gap: 5px; }
  .score-action { width: 31px; }
}

@media (max-height: 650px) {
  .app { padding-top: max(7px, env(safe-area-inset-top)); gap: 8px; }
  .game { gap: 7px; }
  .arena { height: clamp(195px, 38dvh, 247px); grid-template-rows: 24px minmax(0, 1fr) 18px 21px; }
  .buzzer-well .buzzer { --diameter: clamp(98px, 23dvh, 150px); }
  .lobby { padding: 0; }
  .lobby-art { margin-bottom: 7px; }
  .lobby-console { margin-top: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; }
}
