:root {
  --bg: #050308;
  --panel: #17101f;
  --answer: #1a1630;
  --accent: #b21f2d;
  --text: #f2edf4;
  --muted: #b9b4d8;
  --selected: #d6a24a;
  --good: #2fbf71;
  --bad: #c72c41;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, system-ui, sans-serif;
  background:
    radial-gradient(circle at 50% 25%, #10235f88, transparent 50%),
    radial-gradient(circle at top, #e82f4d24, transparent 42%),
    var(--bg);
  color: var(--text);
}

button, input, textarea, select { font: inherit; }

button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: linear-gradient(#303766, #171b3b);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 8px 20px #0005;
}

button:hover { filter: brightness(1.12); }
button.active { outline: 2px solid var(--selected); box-shadow: 0 0 18px color-mix(in srgb, var(--selected) 35%, transparent); }
button.gold { background: linear-gradient(#d9a63e, #805800); }
button.good { background: linear-gradient(#20b96d, #0c7040); }
button.bad, button.danger { background: linear-gradient(#af1e38, #6c1023); }
button:disabled { opacity: .45; cursor: not-allowed; }

input, textarea, select {
  width: 100%;
  background: #071126;
  color: var(--text);
  border: 1px solid #304273;
  border-radius: 10px;
  padding: 10px;
}

textarea { resize: vertical; }

label {
  display: grid;
  gap: 6px;
  color: var(--selected);
  font-weight: 900;
}

.hidden { display: none !important; }

body.mode-select-active .admin-app {
  grid-template-columns: 1fr;
}

body.mode-select-active .sidebar,
body.mode-select-active .editor-head {
  display: none;
}

body.mode-select-active .main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.mode-select-shell {
  width: min(1120px, 100%);
  padding: 34px;
  border-radius: 32px;
  border: 2px solid var(--accent);
  background: color-mix(in srgb, var(--panel) 94%, #000);
  box-shadow: 0 0 90px #000a;
  text-align: center;
}

.mode-select-shell h1 {
  font-size: clamp(46px, 6vw, 92px);
  color: var(--accent);
  margin: 0 0 6px;
}

.mode-select-shell p {
  font-size: 22px;
  color: var(--muted);
  margin: 0 0 30px;
}

.mode-select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.mode-select-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 270px;
  text-align: left;
  color: var(--text);
  padding: 24px;
  border-radius: 24px;
  border: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
  background: linear-gradient(180deg, #1a1630, #100a18);
  box-shadow: 0 12px 30px #0006;
}

.mode-select-card:hover {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.mode-select-card b {
  display: block;
  font-size: 28px;
  margin-bottom: 12px;
}

.mode-select-card span {
  display: block;
  color: var(--muted);
  line-height: 1.42;
}

.mode-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: auto;
}

button.readme-button {
  background: linear-gradient(#6d2030, #3b121b);
}

.admin-app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #050713;
  border-right: 1px solid #ffffff18;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar h1 {
  font-size: 22px;
  color: var(--accent);
  margin: 0;
}

.mode-pill {
  font-size: 13px;
  color: var(--muted);
}

.main {
  padding: 22px;
  overflow: auto;
}

.editor-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.editor-head h2 {
  color: var(--accent);
  font-size: 34px;
  margin: 0;
}

.panel {
  background: color-mix(in srgb, var(--panel) 88%, #000);
  border: 1px solid #ffffff18;
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 16px;
}

.panel h2, .panel h3 {
  margin: 0 0 12px;
  color: var(--accent);
}

.panel p {
  margin: 0 0 10px;
}

.stack {
  display: grid;
  gap: 12px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.admin-tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  border-bottom: 1px solid #ffffff18;
  padding-bottom: 12px;
}

.admin-tabs button {
  min-width: 170px;
  border-radius: 999px;
  text-align: center;
}

.grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  align-items: start;
}

.room-code-badge {
  border: 1px solid var(--selected);
  color: var(--selected);
  background: #0005;
  border-radius: 999px;
  padding: 8px 12px;
  text-align: center;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.connection {
  width: 100%;
  text-align: center;
  border: 1px solid #ffffff26;
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: #0005;
}

.connection.online {
  color: var(--good);
  border-color: var(--good);
}

.links {
  display: grid;
  gap: 8px;
}

.links a {
  display: block;
  color: var(--selected);
  text-decoration: none;
  overflow-wrap: anywhere;
  border: 1px solid color-mix(in srgb, var(--selected) 45%, transparent);
  border-radius: 999px;
  padding: 8px 12px;
  text-align: center;
  background: #0004;
  font-weight: 900;
}

.links a:hover {
  border-color: var(--selected);
  filter: brightness(1.12);
}

.mode-tabs {
  display: grid;
  gap: 8px;
}

.mode-tabs button {
  width: 100%;
  min-height: 48px;
  text-align: left;
}

.mode-current {
  width: 100%;
  border: 1px solid #ffffff24;
  border-radius: 14px;
  padding: 13px 16px;
  color: var(--muted);
  background: #0005;
}

.mode-current b {
  color: var(--selected);
}

.score-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.score-pill {
  border: 1px solid var(--accent);
  background: #0005;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 900;
}

.board {
  display: grid;
  gap: 10px;
  overflow: auto;
}

.board-head, .board-cell {
  min-width: 130px;
  min-height: 76px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  text-align: center;
  font-weight: 900;
  border: 2px solid #ffffff28;
}

.board-head {
  background: linear-gradient(#c91f43, #751226);
}

.board-cell {
  background: linear-gradient(#17406f, #0c214c);
  color: var(--text);
  font-size: 24px;
}

.board-cell.used {
  opacity: .25;
  text-decoration: line-through;
}

.board-cell.selected {
  outline: 3px solid var(--selected);
  box-shadow: 0 0 24px color-mix(in srgb, var(--selected) 45%, transparent);
}

.board-cell.open {
  outline: 3px solid var(--good);
  box-shadow: 0 0 24px color-mix(in srgb, var(--good) 35%, transparent);
}

.question-card {
  max-width: 1100px;
  margin: 18px auto 0;
  padding: 28px;
  border: 2px solid var(--accent);
  border-radius: 24px;
  background: var(--answer);
  box-shadow: 0 0 58px color-mix(in srgb, var(--accent) 22%, transparent);
}

.question-card.rank-bordered {
  border-color: var(--rank-question-border, var(--accent));
  box-shadow: 0 0 58px color-mix(in srgb, var(--rank-question-border, var(--accent)) 30%, transparent);
}

.question-card.has-background {
  background:
    linear-gradient(#090613d8, #090613d8),
    var(--question-bg-image),
    var(--answer);
  background-size: cover;
  background-position: center;
}

.question-card.empty {
  border-style: dashed;
  opacity: .78;
}

.question-card h2 {
  margin: 0 0 14px;
  font-size: clamp(30px, 4vw, 64px);
  line-height: 1.12;
  color: var(--text);
  text-align: center;
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 14px;
  max-width: 1100px;
  margin: 18px auto 0;
}

.answer {
  min-height: 78px;
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 18px;
  background: var(--answer);
  text-align: left;
  font-size: 24px;
  color: var(--text);
}

.answer-button {
  width: 100%;
  display: block;
}

.answer-button.selected-answer {
  background: color-mix(in srgb, var(--selected) 55%, var(--answer));
}

.answer-button.locked-answer {
  outline: 3px solid var(--selected);
  box-shadow: 0 0 24px color-mix(in srgb, var(--selected) 45%, transparent);
}

.answer-button.correct-answer {
  border-color: var(--good);
  background: color-mix(in srgb, var(--good) 62%, var(--answer));
}

.answer-button.wrong-answer {
  border-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 62%, var(--answer));
}

.answer-button.hidden-answer {
  opacity: .28;
  text-decoration: line-through;
  transform: scale(.985);
}

.answer-button.roulette-focus {
  outline: 5px solid var(--selected);
  border-color: var(--selected);
  transform: scale(1.055);
  filter: brightness(1.85);
  box-shadow: 0 0 42px color-mix(in srgb, var(--selected) 70%, transparent);
}

.answer-button.roulette-doomed {
  outline: 5px solid var(--bad);
  border-color: var(--bad);
  animation: doomShake .18s ease-in-out infinite alternate;
  box-shadow: 0 0 44px color-mix(in srgb, var(--bad) 80%, transparent);
}

.answer-button.roulette-removing {
  animation: removeAnswer .8s ease-in forwards;
}

.answer-button.roulette-safe {
  outline: 5px solid var(--good);
  border-color: var(--good);
  transform: scale(1.035);
  filter: brightness(1.45);
  box-shadow: 0 0 36px color-mix(in srgb, var(--good) 70%, transparent);
}

.joker-row {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 7px;
}

.joker-row button {
  width: 100%;
  padding: 9px 8px;
}

.joker-row b {
  float: right;
  color: var(--selected);
  border: 1px solid color-mix(in srgb, var(--selected) 50%, transparent);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 8px;
}

.rank-banner {
  width: min(720px, 100%);
  margin: 0 auto 12px;
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
  color: var(--rank-text, var(--text));
  border: 2px solid color-mix(in srgb, var(--rank-bg, var(--accent)) 72%, transparent);
  border-radius: 18px;
  padding: 10px 14px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--rank-bg, var(--panel)) 82%, #000), color-mix(in srgb, var(--rank-bg, var(--panel)) 52%, #000));
  box-shadow: 0 0 34px color-mix(in srgb, var(--rank-bg, var(--accent)) 34%, transparent);
}

.rank-banner.no-logo {
  grid-template-columns: 1fr;
  text-align: center;
}

.rank-logo {
  min-width: 42px;
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #0005;
  font-weight: 900;
}

.rank-banner.no-logo .rank-logo {
  display: none;
}

.rank-banner small {
  display: block;
  font-size: 12px;
  opacity: .82;
}

.rank-banner b {
  display: block;
  font-size: clamp(22px, 3vw, 40px);
  color: var(--rank-text, var(--text));
}

.rank-panel {
  align-self: start;
}

.rank-list {
  display: grid;
  gap: 8px;
  max-height: 70vh;
  overflow: auto;
  padding-right: 4px;
}

.rank-item {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 8px;
  align-items: center;
  padding: 9px;
  border-radius: 12px;
  color: var(--rank-text, var(--text));
  background: color-mix(in srgb, var(--rank-bg, var(--panel)) 70%, #000);
  border: 1px solid #ffffff18;
  opacity: .72;
}

.rank-item.current {
  opacity: 1;
  outline: 2px solid var(--selected);
  box-shadow: 0 0 22px color-mix(in srgb, var(--selected) 30%, transparent);
}

.rank-item.passed {
  opacity: .9;
}

.rank-editor-list {
  display: grid;
  gap: 10px;
}

.rank-editor-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px 120px minmax(100px, 140px);
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid #ffffff18;
  border-radius: 14px;
  background: #0003;
}

.question-media {
  display: flex;
  justify-content: center;
  margin: 10px auto 18px;
}

.question-image {
  display: block;
  max-width: min(100%, 900px);
  max-height: 420px;
  width: auto;
  height: auto;
  object-fit: contain;
  border: 2px solid var(--accent);
  border-radius: 20px;
  background: #0007;
  box-shadow: 0 12px 32px #0007;
  cursor: zoom-in;
}

.question-media.question-media-large .question-image {
  max-width: min(96vw, 1300px);
  max-height: 72vh;
}

.question-sound {
  display: flex;
  justify-content: center;
  margin: 10px auto 18px;
}

.question-sound audio,
.sound-preview audio {
  width: min(100%, 760px);
  accent-color: var(--selected);
}

.image-preview {
  min-height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #ffffff33;
  border-radius: 16px;
  background: #0003;
  color: var(--muted);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.image-preview.has-image {
  color: transparent;
}

.sound-preview {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #ffffff33;
  border-radius: 16px;
  background: #0003;
  color: var(--muted);
}

.sound-preview.has-sound {
  border-style: solid;
  border-color: color-mix(in srgb, var(--selected) 42%, transparent);
}

.image-size-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.checkbox-inline {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.checkbox-inline input {
  width: auto;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: #000d;
}

.image-modal-content {
  position: relative;
  z-index: 1;
  width: min(92vw, 1400px);
  max-height: 90vh;
  padding: 18px;
  border: 2px solid var(--accent);
  border-radius: 24px;
  background: color-mix(in srgb, var(--panel) 95%, #000);
}

.image-modal-img {
  display: block;
  max-width: 100%;
  max-height: calc(90vh - 36px);
  margin: 0 auto;
  border-radius: 16px;
  object-fit: contain;
}

.image-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 999px;
  font-size: 28px;
  line-height: 1;
}

.buzzer-status {
  text-align: center;
  font-size: clamp(22px, 3vw, 44px);
  font-weight: 900;
  color: var(--selected);
  border: 2px solid var(--selected);
  border-radius: 24px;
  padding: 14px;
  margin: 12px auto;
  background: color-mix(in srgb, var(--selected) 13%, transparent);
  box-shadow: 0 0 40px color-mix(in srgb, var(--selected) 22%, transparent);
}

.buzzer-status.open {
  color: var(--good);
  border-color: var(--good);
  background: color-mix(in srgb, var(--good) 12%, transparent);
}

.buzzer-status.locked {
  color: var(--bad);
  border-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 12%, transparent);
}

.buzzer-button {
  width: min(520px, 100%);
  min-height: 190px;
  border-radius: 24px;
  font-size: clamp(34px, 7vw, 88px);
  margin: 18px auto;
  display: block;
}

.stream-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: 16px;
  align-items: start;
}

.stream-buzzer {
  position: sticky;
  top: 16px;
  border: 2px solid color-mix(in srgb, var(--selected) 65%, transparent);
  background:
    radial-gradient(circle at top, color-mix(in srgb, var(--selected) 18%, transparent), transparent 58%),
    color-mix(in srgb, var(--panel) 90%, #000);
}

.stream-buzzer .buzzer-status {
  font-size: clamp(20px, 3vw, 38px);
}

.stream-toolbar {
  max-width: 1280px;
  margin: 0 auto 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid #ffffff18;
  border-radius: 999px;
  padding: 8px 10px 8px 16px;
  background: #0006;
  color: var(--muted);
}

.stream-toolbar b {
  color: var(--selected);
}

.team-list {
  display: grid;
  gap: 8px;
}

.player-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.player-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  border: 2px solid #ffffff1f;
  background: linear-gradient(180deg, #202653, #11162e);
  box-shadow: 0 12px 26px #0004;
}

.player-card.active {
  border-color: var(--selected);
  box-shadow: 0 0 24px color-mix(in srgb, var(--selected) 32%, transparent);
}

.player-card.out {
  opacity: .52;
  border-color: var(--bad);
  filter: grayscale(.25);
}

.player-card > b {
  font-size: 22px;
}

.player-card em {
  width: fit-content;
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--selected);
  background: #0005;
  font-style: normal;
  font-weight: 900;
}

.player-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.player-stats span {
  display: grid;
  gap: 2px;
  min-height: 54px;
  place-items: center;
  border-radius: 10px;
  background: #0004;
  font-weight: 900;
}

.player-stats small {
  color: var(--muted);
  font-size: 11px;
}

.team-line {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid #ffffff18;
  border-radius: 12px;
  padding: 10px 12px;
  background: #0004;
}

.team-line.out {
  opacity: .55;
  border-color: var(--bad);
}

.mini-stats {
  display: grid;
  gap: 8px;
}

.mini-stats span, .hint-pill {
  border: 1px solid var(--selected);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--selected);
  background: #0005;
  font-weight: 900;
  text-align: center;
}

.hint-pill {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 14px;
}

.stream-body {
  background:
    radial-gradient(circle at 50% 25%, #10235f88, transparent 50%),
    var(--bg);
}

.stream-main {
  min-height: 100vh;
  padding: 30px;
}

.stream-connect {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 280px) auto 130px;
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
}

.stream-connect h1 {
  text-align: left;
  color: var(--accent);
  font-size: clamp(34px, 5vw, 72px);
  margin: 0;
}

.stream-connect p {
  color: var(--muted);
  margin: 6px 0 0;
}

.stream-mode-tabs {
  margin-bottom: 14px;
}

.stream-body.stream-connected .stream-connect,
.stream-body.stream-connected .stream-mode-tabs {
  display: none;
}

.stream-mode {
  max-width: 1280px;
  margin: 0 auto;
}

.waiting-panel {
  max-width: 920px;
  margin: 10vh auto 0;
  text-align: center;
}

.muted { color: var(--muted); }

.credit {
  position: fixed;
  left: 16px;
  bottom: 12px;
  color: var(--muted);
  background: #0005;
  border: 1px solid #ffffff18;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  pointer-events: none;
}

@keyframes doomShake {
  from { transform: translateX(-8px) rotate(-.5deg) scale(1.045); filter: brightness(1.45); }
  to { transform: translateX(8px) rotate(.5deg) scale(1.075); filter: brightness(2); }
}

@keyframes removeAnswer {
  0% { opacity: 1; transform: scale(1.08); filter: brightness(2); }
  45% { opacity: .9; transform: scale(.95) rotate(-1deg); }
  100% { opacity: .25; transform: scale(.86); filter: grayscale(1) brightness(.55); }
}

@media (max-width: 1000px) {
  .admin-app, .grid, .stream-grid, .stream-connect, .mode-select-grid {
    grid-template-columns: 1fr;
  }

  .stream-buzzer {
    position: static;
  }

  .answers {
    grid-template-columns: 1fr;
  }

  .team-line, .rank-editor-row {
    grid-template-columns: 1fr 1fr;
  }

  .stream-toolbar {
    border-radius: 18px;
    flex-direction: column;
    align-items: stretch;
  }
}
