:root {
  --bg: #0b0b0b;
  --panel: #171717;
  --border: #333;
  --text: #f5f5f5;
  --muted: #9a9a9a;
  --gold: #ffd700;
  --danger: #ff4757;
  --ok: #2ed573;
  --b: #ff4757;
  --i: #2ed573;
  --n: #7289FF;
  --g: #ffa502;
  --o: #a55eea;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #1a1408 0%, #0b0b0b 55%, #050505 100%);
}

* { box-sizing: border-box; }

body.page-home,
body.page-admin {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255, 215, 0, 0.08), transparent 45%),
    radial-gradient(ellipse at 80% 100%, rgba(255, 71, 87, 0.06), transparent 40%),
    #0b0b0b;
  color: var(--text);
}

.brand {
  color: var(--gold);
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 0.35rem;
}

.brand a {
  color: inherit;
  text-decoration: none;
}

.home-wrap,
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem;
  max-width: 720px;
  margin: 0 auto;
}

.home-wrap h1,
.login-card h1,
.admin-header h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  margin: 0 0 0.75rem;
  line-height: 1.1;
}

.lead {
  color: var(--muted);
  margin: 0 0 1.5rem;
  font-size: 1.1rem;
}

.cta-row { display: flex; gap: 0.75rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1.1rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
}

.btn-gold {
  background: linear-gradient(145deg, #ffd700, #ffed4e);
  color: #111;
}

.btn-muted {
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #444;
}

.btn-danger {
  background: #5a1218;
  color: #ffd7d7;
  border: 1px solid #ff4757;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-card,
.admin-panel,
.game-card {
  background: rgba(23, 23, 23, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
}

.login-card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-card input,
.create-form input,
.link-row input {
  width: 100%;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid #555;
  background: #111;
  color: #fff;
  font-size: 1rem;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem 0.5rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.admin-main {
  padding: 1rem 1.5rem 2rem;
  display: grid;
  gap: 1rem;
}

.create-form {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 2fr 1fr auto;
  align-items: end;
}

.create-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.game-list {
  display: grid;
  gap: 0.85rem;
}

.game-card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}

.game-card h3 { margin: 0; }

.meta { color: var(--muted); margin: 0.35rem 0 0.85rem; }

.status {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid #555;
}

.status-active { color: var(--ok); border-color: var(--ok); }
.status-archived { color: var(--muted); }

.link-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  align-items: center;
}

.link-row label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.85rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.error {
  color: var(--danger);
  margin: 0.5rem 0 0;
}

.hidden { display: none !important; }

.link-banner {
  background: #7a1018;
  color: #fff;
  text-align: center;
  padding: 0.75rem 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.control-layout {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.admin-panel-wide {
  grid-column: 1 / -1;
}

.btn-block {
  width: 100%;
}

.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.live-stat {
  background: #111;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 0.75rem;
}

.live-stat .label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
}

.live-stat strong {
  font-size: 1.4rem;
  color: var(--gold);
}

.live-stat-current {
  grid-column: span 1;
}

.current-call {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.4rem;
  min-width: 4.5rem;
  margin-top: 0.2rem;
  border: 2px solid #555;
  border-radius: 999px;
  background: #111;
  padding: 0.35rem 0.85rem 0.35rem 0.55rem;
}

.call-letter {
  position: absolute;
  top: -0.35rem;
  left: -0.15rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #111;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.call-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
}

.call-value.call-empty {
  color: var(--muted);
}

.control-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.countdown-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.toggle-control {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 1rem;
  cursor: pointer;
  user-select: none;
  width: fit-content;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.toggle-switch {
  position: relative;
  width: 3.5rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: 999px;
  background: #3a3a3a;
  border: 1px solid #555;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: #f0f0f0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease;
}

.toggle-input:checked + .toggle-switch {
  background: var(--gold);
  border-color: #e6c200;
}

.toggle-input:checked + .toggle-switch::after {
  transform: translateX(1.45rem);
  background: #111;
}

.toggle-input:focus-visible + .toggle-switch {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.toggle-text {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  border: 1px solid #444;
  background: #111;
  font-weight: 700;
}

.letter-B { color: var(--b); }
.letter-I { color: var(--i); }
.letter-N { color: var(--n); }
.letter-G { color: var(--g); }
.letter-O { color: var(--o); }

.victory-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.victory-option {
  background: #111;
  color: #ddd;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
}

.victory-option.active {
  border-color: var(--gold);
  color: var(--gold);
}

.drawn-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.drawn-chip {
  position: relative;
  min-width: 3rem;
  height: 3rem;
  border-radius: 999px;
  border: 2px solid var(--gold);
  background: var(--gold);
  color: #111;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.35rem;
}

.drawn-chip-letter {
  position: absolute;
  top: -0.2rem;
  left: -0.15rem;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.drawn-chip-value {
  font-size: 1rem;
  line-height: 1;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.background-upload-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0.75rem 0 1rem;
}

.background-upload-form .field-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 0;
}

.background-upload-form input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  border: 1px solid #555;
  background: #111;
  color: #fff;
  font: inherit;
}

.background-upload-actions {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  flex-wrap: wrap;
}

.background-upload-actions .file-picker-btn {
  flex: 1 1 240px;
}

.btn-upload-submit {
  flex: 0 0 auto;
  min-width: 7.5rem;
  white-space: nowrap;
}

.file-picker-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  border: 1px solid #555;
  background: #2a2a2a;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-align: center;
}

.file-picker-btn:hover {
  border-color: #777;
  background: #333;
}

.file-picker-btn input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.file-picker-btn span {
  pointer-events: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  padding: 0 0.25rem;
}

.file-picker-btn.has-file {
  border-color: var(--gold);
  color: var(--gold);
}

.background-list {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.background-item {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.9rem;
  border: 1px solid #333;
  border-radius: 12px;
  background: #111;
}

.background-item.is-active {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(255, 215, 0, 0.25);
}

.background-item-main {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.background-thumb {
  width: 140px;
  height: 88px;
  object-fit: cover;
  border-radius: 8px;
  background: #222;
  display: block;
  flex-shrink: 0;
}

.background-meta {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1;
  min-width: 0;
}

.background-badge {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.background-name-row input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #555;
  background: #0b0b0b;
  color: #fff;
  font: inherit;
}

.background-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.background-actions .btn {
  width: 100%;
  white-space: nowrap;
  padding-left: 0.55rem;
  padding-right: 0.55rem;
}

.overlay-controls {
  display: grid;
  gap: 0.55rem;
}

.overlay-control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.overlay-control-label {
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 4.5rem;
}

.overlay-control-row strong {
  color: var(--gold);
  min-width: 3.5rem;
}

.btn-icon {
  min-width: 2.5rem;
  padding-left: 0.55rem;
  padding-right: 0.55rem;
}

.overlay-pad {
  display: grid;
  grid-template-columns: repeat(3, 2.5rem);
  grid-template-rows: repeat(3, 2.5rem);
  gap: 0.25rem;
}

.overlay-pad .pad-up { grid-column: 2; grid-row: 1; }
.overlay-pad .pad-left { grid-column: 1; grid-row: 2; }
.overlay-pad .pad-down { grid-column: 2; grid-row: 3; }
.overlay-pad .pad-right { grid-column: 3; grid-row: 2; }

@media (max-width: 720px) {
  .create-form {
    grid-template-columns: 1fr;
  }

  .admin-header {
    flex-direction: column;
  }

  .background-item-main {
    flex-direction: column;
  }

  .background-thumb {
    width: 100%;
    height: 140px;
  }

  .background-actions {
    grid-template-columns: 1fr;
  }
}
