:root {
  color-scheme: dark;
  --bg: #080a0f;
  --panel: rgba(13, 17, 25, 0.94);
  --panel-strong: #121924;
  --text: #f7fbff;
  --muted: #9ba7b8;
  --line: rgba(255, 255, 255, 0.15);
  --saber: #62f7d5;
  --saber-2: #f9f871;
  --saber-rgb: 98, 247, 213;
  --saber-2-rgb: 249, 248, 113;
  --saber-soft: rgba(98, 247, 213, 0.14);
  --saber-glow: rgba(98, 247, 213, 0.72);
  --danger: #ff5a7a;
  --fruit: #ffbd4a;
  --leaf: #48d17a;
  --berry: #8f7cff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
a {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(var(--saber-rgb), 0.18);
  border-color: rgba(var(--saber-rgb), 0.32);
  cursor: pointer;
}

button,
.hud-item,
.switch-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

iconify-icon {
  width: 1.2em;
  height: 1.2em;
  flex: 0 0 auto;
}

button:hover {
  background: rgba(var(--saber-rgb), 0.28);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.game-page {
  overflow: hidden;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

.game-hud {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 3;
  display: flex;
  gap: 8px;
  align-items: center;
  transform: translateX(-50%);
  padding: 8px;
  border: 1px solid rgba(var(--saber-rgb), 0.22);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(var(--saber-rgb), 0.08), rgba(8, 10, 15, 0.72)),
    rgba(8, 10, 15, 0.64);
  backdrop-filter: blur(18px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.play-timer {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 3;
  min-width: 84px;
  padding: 10px 14px;
  border: 1px solid rgba(var(--saber-rgb), 0.32);
  border-radius: 999px;
  color: var(--saber);
  background:
    linear-gradient(135deg, rgba(var(--saber-rgb), 0.12), rgba(8, 10, 15, 0.76)),
    rgba(8, 10, 15, 0.68);
  font-size: 1rem;
  font-weight: 950;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.play-timer.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.combo-burst {
  position: fixed;
  top: 78px;
  left: 50%;
  z-index: 3;
  min-width: 150px;
  padding: 10px 18px;
  border-radius: 999px;
  color: var(--text);
  background: transparent;
  box-shadow: none;
  font-size: 1.35rem;
  font-weight: 1000;
  text-align: center;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px) scale(0.84);
  transition: opacity 120ms ease, transform 120ms ease;
}

.combo-burst.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.combo-burst.is-max {
  color: var(--saber-2);
  text-shadow: 0 0 12px rgba(var(--saber-2-rgb), 0.5);
}

.combo-hud {
  background: transparent;
  border: 0;
}

.game-hud.is-hidden {
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -14px);
}

.game-hud > div {
  min-width: 74px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(var(--saber-rgb), 0.08);
}

.hud-label {
  display: none;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.connection-pill {
  min-width: 112px;
  color: var(--saber);
  font-weight: 800;
  text-align: center;
}

.combo-hud.is-hot {
  color: var(--saber);
}

.combo-hud.is-max {
  color: var(--saber-2);
}

.waiting-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 4;
  display: grid;
  width: min(92vw, 370px);
  max-height: calc(100vh - 108px);
  gap: 14px;
  justify-items: center;
  transform: translate(-50%, -50%);
  padding: 20px;
  overflow-y: auto;
  border: 1px solid rgba(var(--saber-rgb), 0.25);
  border-radius: 8px;
  background:
    radial-gradient(circle at 20% 8%, var(--saber-soft), transparent 34%),
    linear-gradient(150deg, rgba(var(--saber-rgb), 0.08), rgba(13, 17, 25, 0.96) 38%, rgba(var(--saber-2-rgb), 0.055)),
    var(--panel);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.36), 0 0 34px rgba(var(--saber-rgb), 0.12);
}

.waiting-panel.is-hidden {
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -47%);
  transition: opacity 180ms ease, transform 180ms ease;
}

.brand-lockup,
.controller-topline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-lockup {
  justify-content: center;
}

.brand-icon {
  color: var(--saber);
  font-size: 2rem;
  filter: drop-shadow(0 0 12px var(--saber-glow));
}

.qr-wrap {
  display: grid;
  place-items: center;
  width: 224px;
  height: 224px;
  border: 1px solid rgba(var(--saber-rgb), 0.34);
  border-radius: 8px;
  background: #f8fbff;
  box-shadow: 0 0 24px rgba(var(--saber-rgb), 0.16);
}

.room-code {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(var(--saber-rgb), 0.14), rgba(255, 255, 255, 0.055));
  font-size: 1.7rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-align: center;
}

.status-copy {
  min-height: 1.5em;
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.switch-toggle {
  display: grid;
  grid-template-columns: 1fr auto auto;
  width: 100%;
  min-height: 50px;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  text-align: left;
  background: rgba(255, 255, 255, 0.065);
}

.switch-toggle:hover {
  background: rgba(var(--saber-rgb), 0.13);
}

.switch-label {
  justify-content: flex-start;
  font-weight: 850;
}

.switch-track {
  position: relative;
  width: 48px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  transition: background 160ms ease, border-color 160ms ease;
}

.switch-thumb {
  position: absolute;
  top: 50%;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  transform: translateY(-50%);
  transition: transform 160ms ease, background 160ms ease;
}

.switch-state {
  min-width: 28px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
  text-align: right;
}

.switch-toggle[aria-checked="true"] {
  border-color: rgba(var(--saber-rgb), 0.55);
  background: rgba(var(--saber-rgb), 0.2);
}

.switch-toggle[aria-checked="true"] .switch-track {
  border-color: rgba(var(--saber-rgb), 0.7);
  background: var(--saber);
}

.switch-toggle[aria-checked="true"] .switch-thumb {
  background: #07120f;
  transform: translate(20px, -50%);
}

.switch-toggle[aria-checked="true"] .switch-state {
  color: var(--saber);
}

.duration-picker {
  display: grid;
  width: 100%;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.duration-picker[hidden] {
  display: none;
}

.duration-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}

.duration-button {
  min-height: 36px;
  padding: 0 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  font-size: 0.82rem;
  font-weight: 900;
}

.duration-button:hover,
.duration-button.is-selected {
  color: var(--text);
  border-color: rgba(var(--saber-rgb), 0.5);
  background: rgba(var(--saber-rgb), 0.18);
}

.theme-picker {
  display: grid;
  width: 100%;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.theme-dots {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  width: 100%;
}

.color-dot {
  width: 100%;
  min-height: 34px;
  border-radius: 999px;
  padding: 0;
  background:
    radial-gradient(circle at 35% 32%, rgba(255, 255, 255, 0.82), transparent 22%),
    var(--dot-color);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.color-dot:hover,
.color-dot.is-selected {
  border-color: var(--dot-ring);
  box-shadow: 0 0 0 3px rgba(var(--dot-rgb), 0.2), 0 0 18px rgba(var(--dot-rgb), 0.32);
}

.color-dot[data-saber-color="mint"] {
  --dot-color: #62f7d5;
  --dot-ring: #f9f871;
  --dot-rgb: 98, 247, 213;
}

.color-dot[data-saber-color="blue"] {
  --dot-color: #63a7ff;
  --dot-ring: #7cf7ff;
  --dot-rgb: 99, 167, 255;
}

.color-dot[data-saber-color="violet"] {
  --dot-color: #b58cff;
  --dot-ring: #ff8cf3;
  --dot-rgb: 181, 140, 255;
}

.color-dot[data-saber-color="pink"] {
  --dot-color: #ff6fb1;
  --dot-ring: #ffd166;
  --dot-rgb: 255, 111, 177;
}

.color-dot[data-saber-color="gold"] {
  --dot-color: #ffd166;
  --dot-ring: #ff8a3d;
  --dot-rgb: 255, 209, 102;
}

.color-dot[data-saber-color="white"] {
  --dot-color: #f7fbff;
  --dot-ring: #9ba7b8;
  --dot-rgb: 247, 251, 255;
}

.waiting-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

#reset-button,
#calibrate-motion {
  background: rgba(var(--saber-rgb), 0.1);
  border-color: rgba(var(--saber-rgb), 0.22);
}

#reset-button:hover,
#calibrate-motion:hover {
  background: rgba(var(--saber-rgb), 0.18);
}

.game-footer {
  position: fixed;
  left: 50%;
  bottom: 14px;
  z-index: 5;
  transform: translateX(-50%);
}

.game-footer a {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid rgba(var(--saber-rgb), 0.22);
  border-radius: 999px;
  color: var(--text);
  background: rgba(8, 10, 15, 0.68);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
  text-decoration: none;
  backdrop-filter: blur(14px);
}

.game-footer a:hover {
  border-color: rgba(var(--saber-rgb), 0.5);
  background: rgba(var(--saber-rgb), 0.16);
}

.game-footer strong {
  color: var(--saber);
}

.controller-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(150deg, rgba(var(--saber-rgb), 0.08), transparent 34%),
    linear-gradient(320deg, rgba(var(--saber-2-rgb), 0.12), transparent 40%),
    var(--bg);
}

.controller-shell {
  width: min(100%, 430px);
}

.controller-topline {
  margin-bottom: 14px;
  color: var(--muted);
}

.controller-panel {
  display: grid;
  gap: 16px;
  padding: 20px;
  border: 1px solid rgba(var(--saber-rgb), 0.22);
  border-radius: 8px;
  background: var(--panel-strong);
}

.controller-panel h1 {
  margin: -8px 0 0;
  font-size: clamp(2.5rem, 16vw, 4rem);
  letter-spacing: 0.12em;
}

.controller-panel p {
  min-height: 1.5em;
  margin: 0;
  color: var(--muted);
}

.tilt-pad {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: 280px;
  border: 1px solid rgba(var(--saber-rgb), 0.28);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    rgba(255, 255, 255, 0.04);
  background-size: 50% 50%;
}

#tilt-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--saber);
  box-shadow: 0 0 22px var(--saber-glow);
  transform: translate(-50%, -50%);
}

.motion-readout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}

.motion-readout div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.motion-readout dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.motion-readout dd {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
}

@media (max-width: 720px) {
  .game-hud {
    top: 10px;
    width: calc(100vw - 20px);
    flex-wrap: wrap;
    justify-content: center;
  }

  .game-hud > div {
    min-width: 0;
  }

  .waiting-panel {
    padding: 18px;
  }

  .play-timer {
    top: 10px;
    right: 10px;
  }

  .combo-burst {
    top: 88px;
    min-width: 132px;
    font-size: 1.05rem;
  }

  .game-footer {
    bottom: 10px;
    width: calc(100vw - 20px);
    text-align: center;
  }

  .game-footer a {
    max-width: 100%;
    justify-content: center;
  }

  .qr-wrap {
    width: 220px;
    height: 220px;
  }
}
