:root {
  --bg0: #070d1d;
  --bg1: #121f45;
  --card: #16284f;
  --card2: #1d3569;
  --text: #eef4ff;
  --muted: #9db1dd;
  --accent: #6ac8ff;
  --success: #3cd885;
  --danger: #f05252;
  --warning: #ffd166;
  --r-lg: 14px;
  --r-xl: 22px;
  --sh1: 0 14px 30px rgba(4, 9, 24, .45);
  --sh2: 0 0 0 1px rgba(126, 174, 255, .22), 0 18px 44px rgba(30, 90, 196, .35);
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 18px;
  --space-4: 26px;
  --t-fast: 140ms;
  --t-med: 220ms;
  --ease: cubic-bezier(.22,.8,.23,1);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% -5%, #203b7d, transparent 38%), linear-gradient(145deg, var(--bg0), var(--bg1));
}
a { color: var(--accent); }
.container { max-width: 1380px; margin: 0 auto; padding: 24px; }
.page-head h1 { margin: 0 0 6px; font-size: clamp(2rem, 4.4vw, 4rem); letter-spacing: .02em; }
.board-shell { background: rgba(7, 14, 34, .45); border-radius: var(--r-xl); padding: var(--space-3); box-shadow: var(--sh1); }
.grid, .header-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.header-grid { margin-bottom: 12px; }
.cat {
  background: linear-gradient(180deg, #224485, #132c5e);
  border-radius: var(--r-lg);
  border: 1px solid rgba(150, 190, 255, .32);
  padding: 14px 10px;
  text-align: center;
  font-weight: 800;
  letter-spacing: .03em;
  font-size: clamp(1rem, 1.5vw, 1.3rem);
}
.tile {
  --tile-opacity-transition: var(--t-fast);
  min-height: 102px;
  border-radius: var(--r-lg);
  border: 1px solid rgba(147, 184, 248, .22);
  background: linear-gradient(180deg, var(--card2), var(--card));
  color: #fff4b2;
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 900;
  letter-spacing: .04em;
  display: grid;
  place-items: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .4);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), opacity var(--tile-opacity-transition) var(--ease), border-color var(--t-fast) var(--ease);
}
.tile--available { cursor: pointer; }
.tile--available:hover,
.tile--hover { transform: translateY(-3px); box-shadow: var(--sh2); border-color: rgba(135, 220, 255, .9); }
.tile--available:active { transform: scale(.98); }
.tile--used { opacity: .36; filter: grayscale(.2); cursor: not-allowed; }
.tile--locked { --tile-opacity-transition: 1000ms; opacity: .56; border-style: dashed; }
.tile--open { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(106, 200, 255, .75), 0 0 26px rgba(106, 200, 255, .45); }
.tile--pending-open {
  border-color: var(--warning);
  box-shadow: 0 0 0 0 rgba(255, 209, 102, 0);
  animation: tile-open-highlight-fade 220ms ease-out forwards, tile-open-highlight-pulse 600ms ease-in-out 220ms infinite;
}
.tile--viewer { pointer-events: none; cursor: default; }
.tile--viewer:hover { transform: none; box-shadow: none; }

@keyframes tile-open-highlight-fade {
  from {
    border-color: rgba(255, 209, 102, .25);
    box-shadow: 0 0 0 0 rgba(255, 209, 102, 0);
  }
  to {
    border-color: var(--warning);
    box-shadow: 0 0 0 2px rgba(255, 209, 102, .9), 0 0 20px rgba(255, 209, 102, .45);
  }
}

@keyframes tile-open-highlight-pulse {
  0%, 100% {
    box-shadow: 0 0 0 2px rgba(255, 209, 102, .88), 0 0 20px rgba(255, 209, 102, .38);
  }
  50% {
    box-shadow: 0 0 0 3px rgba(255, 209, 102, 1), 0 0 30px rgba(255, 209, 102, .65);
  }
}

.scoreboard { margin-top: 20px; background: rgba(11, 22, 48, .8); border-radius: var(--r-xl); padding: 16px; border: 1px solid rgba(147, 184, 248, .2); }
.scoreboard--modal { margin-top: 0; max-height: min(62vh, 560px); overflow: auto; }
.scoreboard h3 { margin: 0 0 12px; font-size: 1.2rem; }
.score-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; padding-bottom: 4px; }
.score-item { min-width: 0; display: flex; justify-content: space-between; gap: 12px; background: rgba(35, 63, 124, .75); border: 1px solid rgba(140, 172, 235, .33); border-radius: 999px; padding: 11px 16px; }
.score-item__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 28px; background: rgba(2, 7, 20, .72); backdrop-filter: blur(6px); opacity: 0; visibility: hidden; transition: opacity var(--t-med) var(--ease), visibility var(--t-med) var(--ease); }
.modal.open { opacity: 1; visibility: visible; }
.modal-card { width: min(1180px, 96vw); max-height: 90vh; overflow: auto; border-radius: var(--r-xl); background: linear-gradient(180deg, #1a2f5d, #102040); box-shadow: var(--sh1); border: 1px solid rgba(147, 184, 248, .28); padding: 22px; transform: scale(.98); transition: transform var(--t-med) var(--ease), opacity var(--t-med) var(--ease); }
.modal.open .modal-card { transform: scale(1); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.question-badge { background: rgba(95, 173, 255, .2); color: #cfe8ff; border: 1px solid rgba(130, 202, 255, .6); padding: 8px 14px; border-radius: 999px; font-weight: 700; }
.modal-close { width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(144, 184, 250, .5); background: rgba(22, 40, 79, .7); color: var(--text); font-size: 28px; }
#questionContent p { font-size: clamp(1.2rem, 2.7vw, 2.1rem); line-height: 1.35; margin: 0 0 14px; }

.media-frame { position: relative; border-radius: var(--r-lg); overflow: hidden; border: 1px solid rgba(147, 184, 248, .33); box-shadow: var(--sh1); }
.media-frame img { display: block; width: 100%; position: relative; z-index: 1; }
.media-skeleton { position: absolute; inset: 0; background: linear-gradient(110deg, rgba(255,255,255,.06) 8%, rgba(255,255,255,.16) 18%, rgba(255,255,255,.06) 33%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position-x: -200%; } }

#questionContent img, .image-resolve-image, .image-resolve-canvas { width: 100%; max-height: 52vh; object-fit: contain; border-radius: var(--r-lg); box-shadow: var(--sh1); background: #09152f; }

input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea { padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(147, 184, 248, .32); background: rgba(12, 27, 58, .9); }
button { padding: 10px 16px; border-radius: 12px; border: 1px solid rgba(147, 184, 248, .35); background: linear-gradient(180deg, #3973e5, #295bc0); cursor: pointer; }
button:active { transform: scale(.98); }

.container--buzzer { max-width: 760px; }
.buzzer-panel { background: rgba(11, 22, 48, .78); border-radius: var(--r-xl); border: 1px solid rgba(147, 184, 248, .28); padding: 22px; display: grid; gap: 16px; }
.buzz { width: min(100%, 560px); min-height: 140px; min-width: 320px; justify-self: center; border-radius: 20px; font-size: clamp(2rem, 5vw, 3.4rem); font-weight: 900; letter-spacing: .08em; }
.buzzer--ready { box-shadow: 0 0 0 1px rgba(125, 220, 255, .35), 0 0 34px rgba(64, 185, 255, .35); }
.buzzer--disabled { background: #4b5670; border-color: #6e7c9f; opacity: .7; cursor: not-allowed; }
.buzzer--winner { background: linear-gradient(180deg, #22b861, #16914b); border-color: #84ffd0; box-shadow: 0 0 30px rgba(68, 217, 133, .35); }
.winner { margin: 0; font-size: 1.3rem; text-align: center; color: var(--warning); }
.volume-control label { display: block; margin-bottom: 8px; color: var(--muted); font-weight: 700; }
input[type='range'] { width: 100%; accent-color: var(--accent); }

.table { width: 100%; border-collapse: collapse; }
.table td, .table th { border: 1px solid rgba(147, 184, 248, .2); padding: 8px; }
.table--board .tile { width: 100%; }
.editor-tile { width: 100%; min-height: 96px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 8px; }
.editor-tile .tile-plus { font-size: 38px; line-height: 1; color: #9fc2ff; }
.editor-tile .tile-points { font-size: 30px; font-weight: 800; }
.editor-tile .tile-module { font-size: 12px; opacity: .88; }
.editor-tile.empty { background: #13233f; }

#questionEditorForm, #moduleFields, .join-form, .players-admin-list, .player-admin-card, .moderator-actions { display: flex; flex-direction: column; gap: 10px; }
#questionEditorForm label { display: flex; flex-direction: column; gap: 6px; }
.row-actions, .moderator-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.danger { background: linear-gradient(180deg, #d64242, #a72d2d); border-color: #ff9090; }
.error-text, .upload-error { color: #ff9393; }
.viewer-actions { position: fixed; left: 16px; bottom: 16px; z-index: 50; display: flex; gap: 10px; flex-wrap: wrap; }
.viewer-actions__btn { white-space: nowrap; }
.container--scores { max-width: 1240px; }

.moderator-question-modal-card { max-height: min(90vh, 900px); }
#modalMedia { display: flex; justify-content: center; margin-bottom: 12px; }
.moderator-question-media-image { display: block; max-width: 100%; max-height: min(46vh, 420px); object-fit: contain; border-radius: 8px; }
.moderator-question-modal-actions { position: sticky; bottom: 0; background: #16233f; padding-top: 10px; }
.moderator-buzzer-panel { margin-left: auto; min-width: 240px; background: #132a50; border: 1px solid #2f497d; border-radius: 12px; padding: 12px; }

.upload-status { display: flex; align-items: center; gap: 10px; }
.upload-progress-circle { --progress: 0; width: 42px; height: 42px; border-radius: 50%; background: conic-gradient(#4a87ff calc(var(--progress) * 1%), #273861 0); position: relative; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: #dfe9ff; }
.upload-progress-circle::before { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: #16233f; }
.upload-progress-circle span { position: relative; z-index: 1; }
.music-progress-shell { position: relative; width: 238px; margin: 14px auto; }
.music-progress-wrap { --music-progress: 0; width: 170px; aspect-ratio: 1 / 1; border-radius: 50%; background: conic-gradient(#2db26f calc(var(--music-progress) * 1turn), #d23636 0); display: grid; place-items: center; position: relative; }
.music-progress-wrap::before { content: ''; position: absolute; inset: 12px; border-radius: 50%; background: #16233f; }
.music-progress-seconds { position: relative; z-index: 1; font-size: 42px; font-weight: 700; line-height: 1; }
.music-volume-rail { position: absolute; top: 50%; right: 0; transform: translateY(-50%); height: 170px; display: flex; align-items: center; }
.music-volume-slider { appearance: none; -webkit-appearance: none; writing-mode: vertical-lr; direction: rtl; width: 22px; height: 152px; margin: 0; background: transparent; }
.music-volume-slider::-webkit-slider-runnable-track, .music-volume-slider::-moz-range-track { width: 8px; border-radius: 999px; background: #2f497d; }
.music-volume-slider::-webkit-slider-thumb, .music-volume-slider::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #6ec1ff; border: 1px solid #13233f; }
.image-resolve-shell { display: flex; flex-direction: column; gap: 10px; }
.image-resolve-image { image-rendering: pixelated; filter: blur(var(--image-resolve-blur, 38px)); transition: filter .12s linear; }
.image-resolve-canvas { image-rendering: pixelated; }
.is-hidden { display: none; }

@media (max-width: 980px) {
  .grid, .header-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .viewer-actions { right: 16px; }
  .viewer-actions__btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition-duration: 1ms !important; }
}


.moderator-settings-form { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }

.moderator-settings-modal-card { max-width: min(92vw, 560px); }
