/* =========================================================================
   Time Stamp — Shared Stylesheet
   Theme: Bright, modern postal/stamp aesthetic
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;900&family=DM+Sans:wght@400;500;600;700&display=swap');

/* ── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
  --bg:           #FFF8F0;
  --bg-alt:       #FFF0E0;
  --primary:      #C0392B;
  --primary-dark: #922B21;
  --secondary:    #2C3E7A;
  --secondary-lt: #3B54A8;
  --accent:       #E4A227;
  --accent-lt:    #F5C842;
  --success:      #1E8449;
  --success-lt:   #27AE60;
  --dark:         #1A1A2E;
  --muted:        #7F8C8D;
  --card-bg:      #FFFFFF;
  --border:       #E0D4C0;
  --shadow:       rgba(44, 62, 122, 0.12);

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, -apple-system, sans-serif;

  --radius:       12px;
  --radius-lg:    20px;
  --perf-size:    14px; /* perforation size */
}

/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--dark);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; }

/* ── Utility Classes ────────────────────────────────────────────────────── */
/* Hide x-cloak elements until Alpine initialises */
[x-cloak] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.gap-8 { gap: 32px; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Stamp Card ──────────────────────────────────────────────────────────── */
.stamp-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  box-shadow: 0 4px 20px var(--shadow);
  position: relative;
  overflow: hidden;
}

/* Perforated bottom edge */
.stamp-card::after {
  content: '';
  display: block;
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 14px;
  background:
    radial-gradient(circle at 50% 0%, var(--bg) 7px, transparent 7px),
    radial-gradient(circle at 0% 50%, transparent 0, transparent 0);
  background-size: 22px 14px, 100% 100%;
  background-repeat: repeat-x, no-repeat;
}

.stamp-card-inner {
  padding: 24px 28px 36px;
}

/* ── Postmark Circle ────────────────────────────────────────────────────── */
.postmark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid currentColor;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.85;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
  letter-spacing: 0.03em;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(192,57,43,0.35);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 6px 20px rgba(192,57,43,0.45);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(44,62,122,0.3);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--secondary-lt);
}

.btn-ghost {
  background: transparent;
  color: var(--secondary);
  border: 2px solid var(--secondary);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 18px 40px;
  font-size: 1.2rem;
  border-radius: 14px;
}

.btn-block { width: 100%; }

/* ── Input Field ─────────────────────────────────────────────────────────── */
.input-field {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  font-family: var(--font-body);
  font-size: 1.1rem;
  color: var(--dark);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}
.input-field:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(44,62,122,0.15);
}
.input-field.large {
  font-size: 2rem;
  text-align: center;
  padding: 18px 24px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.input-field::placeholder { color: var(--muted); font-weight: 400; }

/* ── Error Message ──────────────────────────────────────────────────────── */
.error-msg {
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 12px;
  background: rgba(192,57,43,0.08);
  border-radius: 8px;
  border-left: 3px solid var(--primary);
}

/* ── Progress / Submitted Bar ───────────────────────────────────────────── */
.progress-dots {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.progress-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s, transform 0.2s;
}
.progress-dot.submitted {
  background: var(--success-lt);
  transform: scale(1.15);
}

/* ── Score Badge ─────────────────────────────────────────────────────────── */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 100px;
  font-weight: 700;
  font-size: 0.95rem;
}
.score-badge.plus-2 { background: var(--success-lt); color: #fff; }
.score-badge.plus-1 { background: var(--accent); color: var(--dark); }
.score-badge.zero   { background: var(--border);  color: var(--muted); }

/* ── Player Chip ─────────────────────────────────────────────────────────── */
.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 100px;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 2px 8px var(--shadow);
  transition: border-color 0.2s;
}
.player-chip.host {
  border-color: var(--accent);
}
.player-chip .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success-lt);
}

/* ── Countdown Ring ─────────────────────────────────────────────────────── */
.countdown-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.countdown-number {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1;
  color: var(--primary);
}
.countdown-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
}

/* ── Animated entrance ──────────────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pop {
  0%   { transform: scale(0.85); opacity: 0; }
  70%  { transform: scale(1.05); }
  100% { transform: scale(1);    opacity: 1; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

.animate-in    { animation: fadeInUp 0.45s ease both; }
.animate-pop   { animation: pop 0.4s ease both; }

/* State panel base — preserves display:flex when Alpine x-show toggles back on */
.state-panel   { display: flex; flex-direction: column; align-items: center; width: 100%; }
.animate-pulse { animation: pulse 1.4s ease-in-out infinite; }

/* ── Decorative Stamp Border (top stripe) ───────────────────────────────── */
.stamp-header-stripe {
  height: 8px;
  background: repeating-linear-gradient(
    90deg,
    var(--primary) 0px, var(--primary) 20px,
    var(--accent)  20px, var(--accent)  40px,
    var(--secondary) 40px, var(--secondary) 60px,
    var(--bg-alt) 60px, var(--bg-alt) 80px
  );
}

/* ── Leaderboard Row ─────────────────────────────────────────────────────── */
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  font-size: 1.1rem;
  font-weight: 600;
  transition: all 0.3s;
}
.leaderboard-row.rank-1 {
  border-color: var(--accent);
  background: linear-gradient(135deg, #FFF8E7, #FFFDF0);
  box-shadow: 0 4px 16px rgba(228,162,39,0.25);
}
.leaderboard-row .rank-num {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--muted);
  min-width: 36px;
}
.leaderboard-row.rank-1 .rank-num { color: var(--accent); }
.leaderboard-row .player-name { flex: 1; }
.leaderboard-row .score-val {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--secondary);
}
.leaderboard-row.rank-1 .score-val { color: var(--accent-lt); }

/* ── Final Round drag item ──────────────────────────────────────────────── */
.sort-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1rem;
  user-select: none;
  transition: box-shadow 0.2s, transform 0.15s;
}
.sort-item:active { box-shadow: 0 8px 24px var(--shadow); transform: scale(1.01); }
.sort-item .sort-handle {
  color: var(--muted);
  font-size: 1.2rem;
  cursor: grab;
}
.sort-item-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--bg);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.sort-item-btn:hover { background: var(--bg-alt); }
.sort-item-btn:disabled { opacity: 0.3; cursor: default; }

/* ── Result Reveal Card ──────────────────────────────────────────────────── */
.result-answer-box {
  text-align: center;
  padding: 28px 36px;
  background: linear-gradient(135deg, var(--secondary), var(--secondary-lt));
  border-radius: var(--radius-lg);
  color: #fff;
  margin-bottom: 24px;
}
.result-answer-box .answer-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.75;
  margin-bottom: 6px;
}
.result-answer-box .answer-num {
  font-family: var(--font-display);
  font-size: 4rem;
  font-weight: 900;
  line-height: 1;
}
.result-answer-box .answer-question {
  font-size: 0.9rem;
  opacity: 0.8;
  margin-top: 8px;
}

/* ── Winner banner ──────────────────────────────────────────────────────── */
.winner-banner {
  background: linear-gradient(135deg, var(--accent), var(--accent-lt));
  color: var(--dark);
  border-radius: var(--radius-lg);
  padding: 20px 32px;
  text-align: center;
  box-shadow: 0 6px 28px rgba(228,162,39,0.4);
}
.winner-banner h2 {
  font-family: var(--font-display);
  font-size: 2rem;
}
.winner-icon { font-size: 3rem; display: block; margin-bottom: 8px; }

/* =========================================================================
   TV-specific styles (index.html)
   ========================================================================= */

.tv-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  padding: 0;
}

.tv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 40px;
  background: var(--secondary);
  color: #fff;
  flex-shrink: 0;
}
.tv-logo {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 12px;
}
.tv-logo .stamp-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  background: var(--secondary-lt);
  border-radius: 8px;
  font-size: 1.3rem;
  border: 3px solid rgba(255,255,255,0.3);
}
.tv-round-indicator {
  font-weight: 700;
  font-size: 1.1rem;
  opacity: 0.85;
}

.tv-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  gap: 0;
}

.tv-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 28px;
}

.tv-sidebar {
  width: 260px;
  background: var(--bg-alt);
  border-left: 2px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex-shrink: 0;
}
.tv-sidebar-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.tv-question-box-wrapper {
  display: inline-block;
  filter: 
    drop-shadow(2px 0 var(--border)) 
    drop-shadow(-2px 0 var(--border)) 
    drop-shadow(0 2px var(--border)) 
    drop-shadow(0 -2px var(--border));
}
/* TV Question Box */
.tv-question-box {
  max-width: 820px;
  width: 100%;
  text-align: center;
  /* padding: 48px 56px; */
  background: var(--card-bg);

  --r: 18px;
  padding: var(--r);
  mask: 
    radial-gradient(50% 50%,#0000 66%,#000 67%) round 
     var(--r) var(--r)/calc(2*var(--r)) calc(2*var(--r)), 
    conic-gradient(#000 0 0) content-box;

  }

.tv-question-box .question-text {
  font-family: var(--font-display);
  margin: 20px;
  font-size: 2.8rem;
  line-height: 1.25;
  color: var(--dark);
}
.tv-question-box .question-meta {
  margin-top: 16px;
  margin-bottom: 20px;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 500;
}

/* URL Join card */
.tv-join-card {
  text-align: center;
  max-width: 650px;
  width: 100%;
}
.tv-join-card .join-url {
  font-family: var(--font-display);
  font-size: 2.4rem;
  color: var(--primary);
  font-weight: 900;
  letter-spacing: 0.01em;
  border-bottom: 4px dashed var(--primary);
  display: inline-block;
  padding-bottom: 2px;
  margin: 12px 0;
}
.tv-join-card h2 {
  font-size: 1.4rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.tv-join-card .player-count-label {
  font-size: 0.95rem;
  color: var(--muted);
  margin-top: 12px;
}
.tv-join-card .lobby-qr {
  display: block;
  margin: 16px auto 4px;
  width: 180px;
  height: 180px;
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.25);
}

/* TV Lobby players grid */
.tv-players-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 700px;
}

/* TV Result rows */
.tv-result-list {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tv-result-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  font-size: 1.15rem;
}
.tv-result-row.best   { border-color: var(--success-lt); background: #EAFAF1; }
.tv-result-row.second { border-color: var(--accent);     background: #FEF9E7; }
.tv-result-row .rr-name { flex: 1; font-weight: 700; }
.tv-result-row .rr-answer { font-size: 1.4rem; font-weight: 900; font-family: var(--font-display); color: var(--secondary); }
.tv-result-row .rr-diff { font-size: 0.85rem; color: var(--muted); }

/* TV Scores layout */
.tv-scores-list {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* TV Final round events grid */
.tv-final-events {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 800px;
  width: 100%;
}
.tv-final-event-card {
  padding: 20px 24px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 16px;
}
.tv-final-event-card .event-letter {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--secondary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 900;
  flex-shrink: 0;
}
.tv-final-event-card .event-name { font-weight: 600; font-size: 1rem; line-height: 1.3; }

/* TV Final result — correct order chain */
.tv-order-chain {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 600px;
  width: 100%;
}
.tv-order-chain-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-weight: 600;
}
.tv-order-chain-item .chain-rank {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--success-lt);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.tv-order-chain-item .chain-year { color: var(--muted); font-size: 0.9rem; margin-left: 4px; }

/* TV Final player results */
.tv-final-player-results {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 700px;
  width: 100%;
}
.tv-player-result-chip {
  padding: 12px 22px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  min-width: 120px;
}
.tv-player-result-chip .prc-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 4px; }
.tv-player-result-chip .prc-pts { font-family: var(--font-display); font-size: 2rem; color: var(--success-lt); font-weight: 900; }

/* TV Game Over */
.tv-gameover-scores {
  max-width: 540px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Timer bar */
.timer-bar-wrap {
  width: 100%;
  max-width: 820px;
  height: 8px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  border-radius: 100px;
  background: var(--accent);
  transition: width 1s linear, background 0.5s;
}
.timer-bar.urgent { background: var(--primary); }

/* =========================================================================
   Controller-specific styles (control.html)
   ========================================================================= */

.ctrl-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.ctrl-header {
  background: var(--secondary);
  color: #fff;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.ctrl-logo {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 900;
  color: #fff;
}
.ctrl-header-icon {
  font-size: 1.4rem;
}
.ctrl-round-badge {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  border-radius: 100px;
  padding: 4px 14px;
  font-size: 0.85rem;
  font-weight: 600;
}

.ctrl-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  gap: 20px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.ctrl-section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}

/* Join form */
.ctrl-join-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 24px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  box-shadow: 0 4px 16px var(--shadow);
}
.ctrl-join-card h2 {
  font-size: 1.6rem;
  color: var(--secondary);
}
.ctrl-join-card p {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Waiting state */
.ctrl-waiting {
  text-align: center;
  padding: 40px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.ctrl-waiting .waiting-icon {
  font-size: 4rem;
  animation: pulse 2s ease-in-out infinite;
}
.ctrl-waiting h3 { font-size: 1.4rem; color: var(--secondary); }
.ctrl-waiting p  { color: var(--muted); font-size: 0.95rem; }

/* Prompt / Answer */
.ctrl-question-box {
  background: var(--secondary);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px 22px;
}
.ctrl-question-box .q-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.65;
  margin-bottom: 8px;
  font-weight: 700;
}
.ctrl-question-box .q-text {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.5;
}

.ctrl-answer-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Sort items (final round) */
.ctrl-sort-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Leaderboard on controller */
.ctrl-score-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ctrl-score-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  font-weight: 600;
}
.ctrl-score-row .rank { color: var(--muted); min-width: 24px; font-weight: 700; }
.ctrl-score-row .name { flex: 1; }
.ctrl-score-row .pts  { font-family: var(--font-display); font-size: 1.3rem; color: var(--secondary); }
.ctrl-score-row.me    { border-color: var(--secondary); background: #EDF2FF; }
