:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #05070d;
  color: #f7f7f4;
}

* {
  box-sizing: border-box;
}

html,
body,
#game-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background:
    radial-gradient(circle at 18% 18%, rgba(78, 121, 255, 0.18), transparent 34%),
    radial-gradient(circle at 82% 18%, rgba(255, 194, 71, 0.16), transparent 32%),
    #05070d;
}

#game-shell {
  position: relative;
  isolation: isolate;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

#hud {
  position: fixed;
  top: 18px;
  left: 18px;
  right: 18px;
  z-index: 2;
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 10px;
  pointer-events: none;
}

.hud-card {
  min-height: 58px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(8, 11, 19, 0.66);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px);
  display: grid;
  align-content: center;
  gap: 2px;
}

.hud-card.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.main-stat {
  min-width: 102px;
}

#left-count {
  font-size: 29px;
  font-weight: 850;
  line-height: 1;
}

.hud-card span:last-child {
  color: rgba(247, 247, 244, 0.7);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#round-label {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.05;
}

#fan-name {
  color: #fff4c9;
  font-size: 18px;
  font-weight: 850;
  line-height: 1.05;
}

#center-timer {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 2;
  transform: translate(-50%, -50%);
  min-width: 132px;
  min-height: 74px;
  padding: 9px 18px 11px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent),
    rgba(8, 11, 19, 0.68);
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.28),
    inset 0 -3px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
}

#timer-label {
  color: #fff4c9;
  font-size: 44px;
  font-weight: 950;
  line-height: 0.9;
  text-shadow:
    0 0 18px rgba(255, 198, 74, 0.42),
    0 10px 24px rgba(0, 0, 0, 0.5);
}

#center-timer span:last-child {
  color: rgba(247, 247, 244, 0.72);
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

body[data-phase="falling"] #timer-label,
body[data-phase="ended"] #timer-label {
  font-size: 30px;
}

.corner-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(520px, calc(100vw - 246px));
  align-content: flex-start;
}

.corner-pill {
  min-width: 74px;
  min-height: 28px;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(8, 11, 19, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 4px 0 0 var(--corner-color);
  color: rgba(247, 247, 244, 0.9);
  font-size: 13px;
  font-weight: 800;
}

#announcement {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 2;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 34px));
  min-height: 44px;
  padding: 11px 18px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(8, 11, 19, 0.7);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(16px);
  color: rgba(247, 247, 244, 0.92);
  font-size: 15px;
  font-weight: 750;
  text-align: center;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

#announcement.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

.joystick {
  --stick-x: 0px;
  --stick-y: 0px;
  position: fixed;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 2;
  width: 126px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 244, 201, 0.18), transparent 28%),
    linear-gradient(145deg, rgba(20, 28, 45, 0.72), rgba(5, 8, 15, 0.7));
  box-shadow:
    0 22px 46px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -10px 22px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  touch-action: none;
  transform: translateY(10px) scale(0.96);
  transition: border-color 160ms ease;
  user-select: none;
}

.joystick::before,
.joystick::after {
  content: "";
  position: absolute;
  inset: 19px;
  border-radius: 50%;
  pointer-events: none;
}

.joystick::before {
  border: 1px solid rgba(255, 255, 255, 0.13);
}

.joystick::after {
  inset: 44px;
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.joystick-stick {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 54px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.58), transparent 18%),
    linear-gradient(145deg, #fff4c9, #78dcff);
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.36),
    0 0 28px rgba(120, 220, 255, 0.22);
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
  transition:
    box-shadow 140ms ease,
    transform 70ms linear;
  will-change: transform;
}

.joystick.active {
  border-color: rgba(158, 232, 255, 0.46);
  transform: scale(1);
}

.joystick.active .joystick-stick {
  box-shadow:
    0 18px 34px rgba(0, 0, 0, 0.4),
    0 0 34px rgba(120, 220, 255, 0.34);
}

body[data-play-mode="player"][data-phase="running"] .joystick,
body[data-play-mode="player"][data-phase="falling"] .joystick,
body[data-play-mode="player"][data-phase="restoring"] .joystick {
  opacity: 1 !important;
  pointer-events: auto;
  transform: translateY(0) scale(1) !important;
}

.fan-preview {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 2;
  width: 136px;
  padding: 10px;
  border: 1px solid rgba(255, 224, 138, 0.36);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent),
    rgba(8, 11, 19, 0.76);
  box-shadow:
    0 20px 46px rgba(0, 0, 0, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(16px);
  pointer-events: none;
}

#fan-preview-name {
  display: block;
  margin-bottom: 8px;
  color: #fff4c9;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

#fan-preview-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #fff4c9;
  box-shadow: inset 0 0 0 7px rgba(0, 0, 0, 0.12);
}

.screen-panel {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px;
  background:
    linear-gradient(rgba(5, 7, 13, 0.36), rgba(5, 7, 13, 0.74)),
    radial-gradient(circle at 18% 18%, rgba(255, 210, 81, 0.16), transparent 28%),
    radial-gradient(circle at 84% 22%, rgba(51, 221, 255, 0.14), transparent 30%),
    radial-gradient(circle at 50% 86%, rgba(255, 83, 141, 0.12), transparent 34%);
  text-align: center;
  overflow: auto;
}

.screen-panel.hidden {
  display: none;
}

.settings-card {
  width: min(1080px, 100%);
  max-height: calc(100vh - 52px);
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(14, 18, 31, 0.88), rgba(8, 11, 19, 0.76)),
    rgba(8, 11, 19, 0.7);
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(22px);
  overflow: auto;
  animation: menu-rise 520ms ease both;
}

.menu-heading {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #9ee8ff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.screen-panel h1,
.screen-panel h2 {
  margin: 0;
  color: #fffaf0;
  max-width: calc(100vw - 32px);
  font-size: 82px;
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: 0;
  text-shadow:
    0 0 26px rgba(255, 200, 78, 0.2),
    0 18px 38px rgba(0, 0, 0, 0.5);
}

.screen-panel h2 {
  font-size: 72px;
}

.screen-panel p {
  max-width: 560px;
  margin: 0;
  color: rgba(247, 247, 244, 0.82);
  font-size: 18px;
  font-weight: 650;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  text-align: left;
}

.field,
.option-group {
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.field > span,
.option-group legend {
  display: block;
  margin: 0 0 10px;
  padding: 0;
  color: rgba(247, 247, 244, 0.78);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.name-field,
.theme-options,
.play-mode-options,
.audience-panel {
  grid-column: 1 / -1;
}

input[type="text"],
.number-input {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(4, 7, 13, 0.7);
  color: #fffaf0;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  outline: none;
}

input[type="text"] {
  padding: 0 14px;
}

input[type="text"]:focus,
.number-input:focus {
  border-color: rgba(158, 232, 255, 0.76);
  box-shadow: 0 0 0 3px rgba(35, 216, 255, 0.16);
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: #ffe08a;
}

.number-input {
  padding: 0 8px;
  text-align: center;
}

.field.disabled {
  opacity: 0.42;
}

.segmented,
.theme-grid {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.option-group:not(.section-options) .segmented {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mode-options .segmented {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.play-mode-options .segmented {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented label,
.theme-grid label {
  position: relative;
  min-width: 0;
}

.segmented input,
.theme-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span,
.theme-grid span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(4, 7, 13, 0.52);
  color: rgba(247, 247, 244, 0.84);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  cursor: pointer;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease,
    box-shadow 150ms ease;
}

.segmented span:hover,
.theme-grid span:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.1);
}

.segmented input:checked + span,
.theme-grid input:checked + span {
  border-color: rgba(255, 224, 138, 0.86);
  background: rgba(255, 224, 138, 0.18);
  box-shadow: 0 0 0 3px rgba(255, 224, 138, 0.12);
  color: #fffaf0;
}

.theme-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.theme-grid span {
  min-height: 48px;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  justify-items: start;
  padding: 0 12px;
}

.theme-grid span::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--swatch-a), var(--swatch-b));
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.16);
}

.audience-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.92fr) minmax(300px, 1fr);
  gap: 14px;
}

.bot-roster {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.bot-pick {
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(4, 7, 13, 0.52);
  box-shadow: none;
  color: rgba(247, 247, 244, 0.84);
  font-size: 14px;
  text-align: left;
}

.bot-pick::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  background: #78dcff;
  box-shadow: 0 0 14px rgba(120, 220, 255, 0.54);
}

.bot-pick[aria-pressed="true"] {
  border-color: rgba(255, 224, 138, 0.86);
  background: rgba(255, 224, 138, 0.18);
  color: #fffaf0;
  box-shadow: 0 0 0 3px rgba(255, 224, 138, 0.12);
}

.shirt-studio-grid {
  display: grid;
  grid-template-columns: minmax(180px, 256px) minmax(160px, 1fr);
  align-items: stretch;
  gap: 14px;
}

.shirt-canvas {
  width: 100%;
  max-width: 256px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #fff4c9;
  box-shadow:
    inset 0 0 0 8px rgba(0, 0, 0, 0.12),
    0 18px 34px rgba(0, 0, 0, 0.28);
  cursor: crosshair;
  touch-action: none;
}

.shirt-controls {
  display: grid;
  align-content: start;
  gap: 10px;
}

.swatch-row {
  display: grid;
  grid-template-columns: repeat(4, 38px);
  gap: 8px;
}

.swatch-row label {
  position: relative;
}

.swatch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.swatch-row span {
  display: block;
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: var(--swatch-a);
  cursor: pointer;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    border-color 150ms ease;
}

.ink-row span {
  box-shadow: inset 0 0 0 4px rgba(5, 7, 13, 0.24);
}

.swatch-row input:checked + span {
  border-color: rgba(255, 224, 138, 0.96);
  box-shadow:
    0 0 0 4px rgba(255, 224, 138, 0.16),
    0 0 20px rgba(255, 224, 138, 0.16);
  transform: translateY(-1px);
}

.clear-shirt-button {
  min-width: 0;
  width: 100%;
  min-height: 42px;
  background: rgba(255, 255, 255, 0.12);
  color: #fffaf0;
  box-shadow: none;
}

button {
  min-width: 138px;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: #fff4c9;
  color: #17120a;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.32);
  font: inherit;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease;
}

.start-button {
  width: min(360px, 100%);
  min-height: 58px;
  margin-top: 22px;
  background:
    linear-gradient(135deg, #fff4c9, #9ee8ff);
  box-shadow:
    0 22px 54px rgba(0, 0, 0, 0.38),
    0 0 34px rgba(158, 232, 255, 0.16);
}

button:hover {
  background: #fff9df;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

@keyframes menu-rise {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 680px) {
  #hud {
    top: 10px;
    left: 10px;
    right: 10px;
    gap: 8px;
  }

  .hud-card {
    min-height: 52px;
    padding: 8px 10px;
  }

  .main-stat {
    min-width: 76px;
  }

  #left-count {
    font-size: 24px;
  }

  .corner-counts {
    max-width: calc(100vw - 186px);
    gap: 6px;
  }

  .corner-pill {
    min-width: 56px;
    padding: 5px 7px;
    font-size: 12px;
  }

  #announcement {
    bottom: 132px;
    min-height: 40px;
    font-size: 13px;
  }

  .joystick {
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: 112px;
  }

  .joystick-stick {
    width: 48px;
  }

  .fan-preview {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    width: 108px;
    padding: 8px;
  }

  #fan-preview-name {
    font-size: 12px;
  }

  #center-timer {
    min-width: 104px;
    min-height: 62px;
    padding: 8px 13px 9px;
  }

  #timer-label {
    font-size: 34px;
  }

  body[data-phase="falling"] #timer-label,
  body[data-phase="ended"] #timer-label {
    font-size: 23px;
  }

  .screen-panel {
    align-items: flex-start;
    padding: 12px;
  }

  .settings-card {
    max-height: none;
    padding: 18px;
  }

  .screen-panel h1 {
    font-size: 46px;
  }

  .screen-panel h2 {
    font-size: 36px;
  }

  .screen-panel p {
    font-size: 16px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .field,
  .option-group {
    padding: 12px;
  }

  .segmented,
  .option-group:not(.section-options) .segmented,
  .mode-options .segmented,
  .play-mode-options .segmented,
  .theme-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .audience-panel,
  .shirt-studio-grid {
    grid-template-columns: 1fr;
  }

  .bot-roster {
    grid-template-columns: 1fr;
  }

  .shirt-canvas {
    max-width: min(256px, 100%);
  }

  .range-row {
    grid-template-columns: 1fr 64px;
  }
}

@media (min-width: 681px) and (max-width: 980px) {
  .screen-panel h1 {
    font-size: 68px;
  }

  .screen-panel h2 {
    font-size: 54px;
  }

  .settings-grid {
    gap: 12px;
  }
}
