:root {
  --blue: #0a1db0;
  --blue-hi: #1b33d6;
  --blue-lo: #07127f;
  --gutter: #000;
  --gold: #f0b43c;
  --gold-hi: #ffd36a;
  --ink: #fff;
  --ui-bg: #050a3a;
  --ui-panel: #0d1660;
  --ui-panel-2: #121d78;
  --ui-line: rgba(255, 255, 255, 0.14);
  --ui-muted: rgba(255, 255, 255, 0.62);
  --danger: #ff6b6b;
  --font-cat: 'Oswald', 'Arial Narrow', sans-serif;
  --font-value: 'Anton', 'Impact', sans-serif;
  --font-clue: 'Libre Baskerville', 'Korinna', Georgia, serif;
  --font-ui: 'Inter', system-ui, sans-serif;
  --shadow-hard: 0.06em 0.06em 0 #000;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, #0c1a8a 0%, var(--ui-bg) 60%);
  background-color: var(--ui-bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
body[data-view="play"] { background: var(--gutter); overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 16px; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-gold { background: var(--gold); color: #1a1200; }
.btn-gold:hover { background: var(--gold-hi); }
.btn-ghost { background: rgba(255, 255, 255, 0.06); border-color: var(--ui-line); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.14); }
.btn-danger { background: var(--danger); color: #2a0000; }
.btn-danger-text { color: var(--danger); }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:focus-visible, .dropzone:focus-visible, .edit-cell:focus-visible, .value-cell:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}
.icon-btn {
  background: none; border: 0; font-size: 28px; line-height: 1; cursor: pointer;
  color: var(--ui-muted); padding: 0 4px;
}
.icon-btn:hover { color: var(--ink); }

/* ---------- home ---------- */
.home { max-width: 880px; margin: 0 auto; padding: 64px 16px; }
.home-head { text-align: center; margin-bottom: 36px; }
.wordmark {
  margin: 0; font-family: var(--font-value); font-weight: 400;
  font-size: clamp(56px, 12vw, 112px); letter-spacing: 0.02em; line-height: 1;
  color: var(--ink);
  text-shadow: 0 0 0 #000, 4px 4px 0 #000, 0 0 40px rgba(60, 110, 255, 0.55);
  transform: skewX(-6deg);
}
.tagline { color: var(--ui-muted); margin: 14px 0 0; font-size: 17px; }
.home-actions { display: flex; gap: 12px; justify-content: center; margin-bottom: 36px; flex-wrap: wrap; }
.game-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.game-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 12px;
  padding: 16px 18px; flex-wrap: wrap;
}
.game-title { font-weight: 700; font-size: 18px; }
.game-meta { color: var(--ui-muted); font-size: 13px; margin-top: 4px; }
.game-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--ui-muted); }

/* ---------- editor ---------- */
.editor { padding: 16px; max-width: 1400px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.title-input {
  flex: 1; min-width: 200px; background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 10px; font-size: 22px; font-weight: 700;
}
.title-input:hover { border-color: var(--ui-line); }
.title-input:focus { outline: none; border-color: var(--gold); background: rgba(0, 0, 0, 0.2); }
.save-status { color: var(--ui-muted); font-size: 13px; min-width: 60px; text-align: right; }
.hint { color: var(--ui-muted); font-size: 14px; margin: 8px 2px 16px; }

.edit-board {
  display: grid; grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 6px; background: var(--gutter); padding: 6px; border-radius: 6px; overflow-x: auto;
}
.edit-cat {
  resize: none; border: 0; border-radius: 2px; padding: 14px 8px; min-height: 84px;
  field-sizing: content; overflow: hidden;
  background: linear-gradient(180deg, var(--blue-hi), var(--blue-lo));
  font-family: var(--font-cat); font-weight: 600; font-size: 18px; text-transform: uppercase;
  text-align: center; line-height: 1.15; text-shadow: 2px 2px 0 #000; margin-bottom: 6px;
}
.edit-cat::placeholder { color: rgba(255, 255, 255, 0.4); text-shadow: none; }
.edit-cat:focus { outline: 2px solid var(--gold); }
.edit-cell {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 112px; border: 0; border-radius: 2px; padding: 10px 8px; cursor: pointer; text-align: center;
  background: linear-gradient(180deg, var(--blue-hi), var(--blue-lo));
  transition: filter 0.15s;
}
.edit-cell:hover { filter: brightness(1.18); }
.edit-cell.is-dragging { opacity: 0.4; }
.edit-cell.is-drop-target { outline: 3px dashed var(--gold); outline-offset: -3px; filter: brightness(1.3); }
.edit-cell > * { pointer-events: none; } /* children must not fire dragleave while hovering inside the cell */
.edit-cell.is-empty { background: linear-gradient(180deg, #0b1570, #060c48); }
.edit-value { font-family: var(--font-value); font-size: 26px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.edit-snippet {
  font-size: 12px; line-height: 1.3; color: rgba(255, 255, 255, 0.85);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.is-empty .edit-snippet { color: var(--ui-muted); }
.edit-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.tag {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.35); border-radius: 4px; padding: 2px 5px;
}
.tag-warn { background: rgba(255, 107, 107, 0.25); color: #ffc2c2; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 12, 0.7);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade 0.15s ease-out;
}
.modal {
  background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 14px;
  width: 100%; max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal-small { max-width: 420px; }
.modal-wide { max-width: 720px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.confirm p { margin: 0; line-height: 1.5; }
@keyframes fade { from { opacity: 0; } }

.cell-editor-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.cell-editor-cat {
  font-family: var(--font-cat); font-weight: 600; font-size: 22px; text-transform: uppercase;
  text-shadow: 2px 2px 0 #000;
}
.value-field { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; color: var(--gold); font-weight: 700; }
.value-field input {
  width: 100px; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--ui-line); border-radius: 6px;
  padding: 4px 8px; color: var(--gold); font-weight: 700;
}
.field { margin-top: 16px; }
.field-label { display: flex; align-items: baseline; gap: 8px; font-weight: 700; margin-bottom: 6px; }
.field-label small { color: var(--ui-muted); font-weight: 400; }
.field textarea {
  width: 100%; resize: vertical; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--ui-line);
  border-radius: 8px; padding: 10px 12px; line-height: 1.45;
}
.field textarea:focus, .value-field input:focus { outline: none; border-color: var(--gold); }

.media-field { margin-top: 8px; border-radius: 10px; }
.media-field.is-over .dropzone { border-color: var(--gold); background: rgba(240, 180, 60, 0.08); }
.media-field.is-busy { opacity: 0.5; pointer-events: none; }
.dropzone {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 16px; border: 1.5px dashed var(--ui-line); border-radius: 10px; background: transparent; cursor: pointer;
  color: var(--ui-muted); font-size: 13px;
}
.dropzone strong { color: var(--ink); font-size: 14px; }
.dropzone:hover { border-color: rgba(255, 255, 255, 0.4); }
.media-preview {
  display: flex; justify-content: center; background: #000; border-radius: 10px; overflow: hidden; padding: 6px;
}
.media-preview .media { max-width: 100%; max-height: 240px; }
.media-preview .media-audio { width: 100%; }
.media-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.media-name { flex: 1; font-size: 13px; color: var(--ui-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-file { color: var(--gold); padding: 16px; font-weight: 600; }

/* ---------- play: board ---------- */
body[data-view="play"] { --scorebar-h: max(68px, 11vh); }
.play { position: fixed; inset: 0; }
.board {
  position: absolute; inset: 0 0 var(--scorebar-h) 0; display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 1.25fr repeat(5, 1fr);
  gap: 0.6vmin; padding: 0.6vmin; background: var(--gutter);
}
.cat-cell, .value-cell {
  border: 0; border-radius: 0; margin: 0; padding: 0;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 255, 255, 0.10), transparent 70%),
    linear-gradient(180deg, var(--blue-hi) 0%, var(--blue) 45%, var(--blue-lo) 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), inset 0 -0.6vmin 1.2vmin rgba(0, 0, 0, 0.35);
}
.cat-cell {
  display: flex; align-items: center; justify-content: center;
  padding: 1vmin 1.2vmin; margin-bottom: 0.8vmin;
}
.cat-text {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  overflow: hidden; text-align: center; line-height: 1.05;
  font-family: var(--font-cat); font-weight: 600; text-transform: uppercase; letter-spacing: 0.01em;
  text-shadow: 0.07em 0.07em 0 #000;
}
.value-cell {
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  font-family: var(--font-value); color: var(--gold);
  font-size: min(8.5vh, 6.4vw); letter-spacing: 0.01em;
  text-shadow: 0.06em 0.06em 0 #000;
}
.value-cell span { transform: scaleY(1.04); }
.value-cell:hover { filter: brightness(1.15); }
.value-cell.is-used { cursor: default; }
.value-cell.is-used:hover { filter: none; }

.play-again {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3vh; pointer-events: none;
}
.play-again[hidden] { display: none; }
.play-again .btn { pointer-events: auto; font-size: 20px; padding: 14px 32px; }
.play-again-title {
  font-family: var(--font-value); color: var(--gold); font-size: min(10vh, 8vw);
  text-shadow: var(--shadow-hard);
}

.play-toolbar {
  position: fixed; top: 10px; right: 10px; z-index: 20; display: flex; gap: 6px;
  opacity: 0; transition: opacity 0.2s;
}
.play-toolbar:hover, .play-toolbar:focus-within { opacity: 1; }
.play-toolbar .btn { background: rgba(0, 0, 0, 0.75); }
@media (hover: none) { .play-toolbar { opacity: 1; } }

/* ---------- play: scoreboard ---------- */
.scorebar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--scorebar-h); z-index: 45;
  display: flex; align-items: center; gap: 1.2vmin; padding: 0 1.2vmin;
  background: var(--gutter); border-top: 0.3vmin solid #16205c;
}
.players { flex: 1; min-width: 0; height: 100%; display: flex; align-items: center; gap: 1vmin; overflow-x: auto; scrollbar-width: none; }
.players::-webkit-scrollbar { display: none; }
.player {
  flex: 0 0 auto; display: flex; align-items: stretch; height: 80%;
  background: linear-gradient(180deg, var(--blue-hi) 0%, var(--blue) 45%, var(--blue-lo) 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0.4vmin 1.2vmin rgba(0, 0, 0, 0.5);
}
.player-main {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.3vmin;
  min-width: 15vmin; padding: 0 1.6vmin; border: 0; background: transparent; cursor: pointer;
}
.player-main:hover { background: rgba(255, 255, 255, 0.06); }
.player-name {
  max-width: 26vmin; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-cat); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em;
  font-size: min(2.7vh, 17px); text-shadow: 0.07em 0.07em 0 #000;
}
.player-score { font-family: var(--font-value); color: var(--gold); font-size: min(5vh, 34px); line-height: 1; text-shadow: 0.06em 0.06em 0 #000; }
.player-score.is-negative { color: var(--danger); }
.player-btns { display: flex; flex-direction: column; border-left: 1px solid rgba(255, 255, 255, 0.12); }
.score-btn {
  flex: 1; width: 6vmin; min-width: 40px; border: 0; background: rgba(255, 255, 255, 0.05); cursor: pointer;
  font-family: var(--font-ui); font-weight: 700; font-size: min(4vh, 28px); line-height: 1;
}
.score-btn + .score-btn { border-top: 1px solid rgba(255, 255, 255, 0.12); }
.score-btn.is-plus { color: #a8f0a8; }
.score-btn.is-minus { color: #ffa3a3; }
.score-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.18); }
.score-btn:disabled { opacity: 0.3; cursor: default; }
.scorebar-side { flex: 0 0 auto; display: flex; align-items: center; gap: 1.2vmin; }
.scorebar-value { font-family: var(--font-value); color: var(--gold); font-size: min(3.4vh, 24px); text-shadow: var(--shadow-hard); }
.scorebar-empty { color: var(--ui-muted); font-size: 14px; padding-left: 0.6vmin; }
.player-editor h2 { margin: 0 0 14px; font-family: var(--font-cat); font-weight: 600; text-transform: uppercase; font-size: 22px; }
.player-editor label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-weight: 700; }
.text-input {
  width: 100%; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--ui-line); border-radius: 8px;
  padding: 10px 12px; font-weight: 500;
}
.text-input:focus { outline: none; border-color: var(--gold); }

/* ---------- play: clue screen ---------- */
.clue-overlay {
  position: fixed; inset: 0 0 var(--scorebar-h) 0; z-index: 40; transform-origin: 0 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 6vh 7vw; cursor: pointer;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, 0.08), transparent 65%),
    linear-gradient(180deg, var(--blue-hi) 0%, var(--blue) 45%, var(--blue-lo) 100%);
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.25s;
}
.clue-overlay.is-closing { opacity: 0; }
.clue-content {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4vh; opacity: 0; transition: opacity 0.2s 0.3s;
}
.clue-overlay.is-open .clue-content { opacity: 1; }
.clue-text {
  width: 100%; flex: 1 1 auto; max-height: 100%; overflow: hidden;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-family: var(--font-clue); font-weight: 700; text-transform: uppercase;
  line-height: 1.35; letter-spacing: 0.01em; text-shadow: var(--shadow-hard);
}
.clue-text.is-response { color: var(--ink); }
.has-media .clue-text { flex: 0 1 auto; max-height: 30vh; }
.clue-media { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.clue-media .media {
  /* Small files (GIFs, phone screenshots) are scaled UP to at least 45vh; the browser keeps the
     aspect ratio when only one side is constrained, object-fit letterboxes the corner cases. */
  width: auto; height: auto; min-height: 45vh; max-height: 58vh; max-width: 80vw; object-fit: contain;
  border: 0.5vmin solid #000; box-shadow: 0 1.5vmin 4vmin rgba(0, 0, 0, 0.5); background: #000;
}
.clue-media .media-audio { width: min(640px, 80vw); min-height: 0; border: 0; box-shadow: none; background: transparent; }
.clue-media .media-file { font-family: var(--font-ui); font-size: 24px; background: rgba(0, 0, 0, 0.4); border-radius: 10px; }
.clue-hint {
  position: absolute; bottom: 2vh; left: 0; right: 0; text-align: center;
  font-size: 12px; color: rgba(255, 255, 255, 0.35); opacity: 0; transition: opacity 0.2s 0.6s;
}
.clue-overlay.is-open .clue-hint { opacity: 1; }

@media (max-width: 640px) {
  .home { padding: 40px 16px; }
  .game-row { flex-direction: column; align-items: stretch; }
  .topbar .title-input { order: -1; flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .clue-overlay, .clue-content, .clue-hint { transition: none; }
}
