/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0c0707;
  --bg-card: #171010;
  --bg-row-alt: #2c1818;
  --accent: #d71920;
  --text: #e8e0e0;
  --text-muted: #a07070;
  --score: #2ecc71;
  --gold: #f1c40f;
  --silver: #bdc3c7;
  --bronze: #e67e22;
  --border: #2a1515;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 32px;
  background: var(--bg-card);
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  height: 48px;
  max-width: 240px;
  object-fit: contain;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ── Live Indicator ── */
.live-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--score);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--score);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* ── Countdown Timer ── */
#countdown-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.countdown-label {
  color: var(--text-muted);
}

#countdown-value {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.85rem;
}

/* ── Fullscreen Button ── */
.fullscreen-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.fullscreen-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Error Banner ── */
.error-banner {
  background: #3a0808;
  border-bottom: 1px solid var(--accent);
  color: #ff8080;
  padding: 10px 32px;
  font-size: 0.85rem;
  text-align: center;
}

/* ── Main ── */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 32px;
  margin: 0 auto;
  width: 100%;
  max-width: 1400px;
}

/* ── Scoreboard Layout ── */
.scoreboard-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 32px;
  align-items: stretch;
}

.scoreboard-layout .table-wrapper {
  flex: 3;
  min-width: 0;
  overflow-y: auto;
}

/* Image panel — hidden by default, shown when has-images class is set */
.scoreboard-images {
  display: none;
  flex: 2;
  min-width: 0;
  min-height: 0;
}

.scoreboard-layout.has-images .scoreboard-images {
  display: flex !important;
  flex-direction: column !important;
  gap: 16px;
}

.scoreboard-img-slot-wrapper {
  display: flex !important;
  flex-direction: column !important;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.scoreboard-img-slot-wrapper .scoreboard-img-slot {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-label {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  text-align: center;
  padding: 4px 0;
}

.scoreboard-img-slot {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scoreboard-img-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

/* ── Table ── */
.table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.scoreboard-table {
  width: 100%;
  border-collapse: collapse;
}

.scoreboard-table thead tr {
  background: #200c0c;
  border-bottom: 2px solid var(--border);
}

.scoreboard-table th {
  padding: 14px 28px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.scoreboard-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.2s ease;
}

.scoreboard-table tbody tr:nth-child(even) {
  background: var(--bg-row-alt);
}

.scoreboard-table tbody tr:hover {
  background: #211010;
}

.scoreboard-table tbody tr.flash-green {
  animation: flashGreen 0.6s ease;
}

@keyframes flashGreen {
  0% { background: rgba(46, 204, 113, 0.3); }
  100% { background: transparent; }
}

@keyframes blinkGreen {
  0%, 100% { background: transparent; }
  50% { background: rgba(46, 204, 113, 0.18); }
}

@keyframes blinkRed {
  0%, 100% { background: transparent; }
  50% { background: rgba(231, 76, 60, 0.18); }
}

tr.score-up   { animation: blinkGreen 0.6s ease-in-out infinite; }
tr.score-down { animation: blinkRed   0.6s ease-in-out infinite; }

.score-delta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 6px;
  vertical-align: middle;
}
.score-delta.up   { color: #2ecc71; }
.score-delta.down { color: #e74c3c; }

/* Top 3 glow */
.scoreboard-table tbody tr.rank-1 { border-left: 3px solid var(--gold); }
.scoreboard-table tbody tr.rank-2 { border-left: 3px solid var(--silver); }
.scoreboard-table tbody tr.rank-3 { border-left: 3px solid var(--bronze); }

.scoreboard-table td {
  padding: 16px 28px;
  vertical-align: middle;
}

/* ── Columns ── */
.col-rank { width: 80px; }
.col-score { width: 120px; }

/* ── Rank Badge ── */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-weight: 900;
  font-size: 1rem;
  font-family: var(--font-mono);
}

.rank-badge.gold   { background: rgba(241,196,15,0.15); color: var(--gold); box-shadow: 0 0 12px rgba(241,196,15,0.3); }
.rank-badge.silver { background: rgba(189,195,199,0.10); color: var(--silver); box-shadow: 0 0 8px rgba(189,195,199,0.2); }
.rank-badge.bronze { background: rgba(230,126,34,0.12); color: var(--bronze); box-shadow: 0 0 8px rgba(230,126,34,0.25); }
.rank-badge.default { color: var(--text-muted); font-size: 0.9rem; }

.player-name { font-weight: 600; font-size: 1rem; }

.score-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--score);
}

.time-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ── Skeleton Loading ── */
.skeleton-row td { padding: 12px 20px; }
.skeleton {
  height: 24px;
  border-radius: 4px;
  background: linear-gradient(90deg, #1e0e0e 25%, #2a1515 50%, #1e0e0e 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px;
  font-size: 0.9rem;
}

/* ── Footer ── */
.footer {
  padding: 12px 32px;
  text-align: right;
  border-top: 1px solid var(--border);
}

.admin-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.admin-link:hover { opacity: 1; }

/* ── QR slot (inside #scoreboard-images) ── */
#qr-panel {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.has-qr #img-top-wrapper {
  display: none !important;
}

/* ── Shared Form Styles ── */
.form-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.form-card h1 {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.form-card .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: #1e1214;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-group input:focus, .form-group textarea:focus {
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.btn {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  margin-top: 24px;
  transition: opacity 0.2s;
}
.btn:hover { opacity: 0.85; }
.btn.btn-sm { padding: 8px 16px; font-size: 0.85rem; margin-top: 12px; }
.btn.btn-danger { background: #c0392b; }

.form-error {
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid #e74c3c;
  border-radius: 6px;
  color: #ff8080;
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 18px;
}

.form-success {
  background: rgba(46, 204, 113, 0.1);
  border: 1px solid #2ecc71;
  border-radius: 6px;
  color: #2ecc71;
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 18px;
}

/* ── Admin Panel ── */
.admin-section {
  margin-bottom: 32px;
}

.admin-section h2 {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.status-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.status-item .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.status-item .value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
}

.value.ok { color: var(--score); }
.value.err { color: #e74c3c; }

/* ── Image Upload Slots (Admin) ── */
.img-upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 640px) {
  .img-upload-grid { grid-template-columns: 1fr; }
}

.img-upload-slot {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.img-upload-slot h3 {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.img-preview {
  width: 100%;
  height: 140px;
  background: #200c0c;
  border: 1px dashed var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  overflow: hidden;
}

.img-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.img-preview .no-image {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.img-actions {
  display: flex;
  gap: 8px;
}
