:root {
  --bg: #f1f4f8;
  --surface: #ffffff;
  --surface-muted: #f7f9fc;
  --border: #dce3ec;
  --text: #142136;
  --text-muted: #55657d;
  --primary: #1a56db;
  --primary-hover: #1444b3;
  --accent: #0f766e;
  --go: #16a34a;
  --go-bright: #22c55e;
  --go-glow: rgba(34, 197, 94, 0.42);
  --warn: #d97706;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --gold: #b45309;
  --gold-bg: #fffbeb;
  --gold-border: #fcd34d;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 26px rgba(15, 23, 42, 0.09);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top center, #e6eef9 0%, var(--bg) 42%);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

.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;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Header */
.site-header {
  text-align: center;
  margin-bottom: 22px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
  position: relative;
}

.civic-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1e40af;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.site-header h1 {
  margin: 0 0 6px;
  font-size: clamp(1.7rem, 4.6vw, 2.35rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #0f1b33;
}

.subtitle {
  margin: 0 auto;
  max-width: 560px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* Cards & Sections */
.main-content {
  display: grid;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.section-header h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
}

.step-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: #0f172a;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

/* Venue Selection Grid */
.venue-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.venue-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.venue-card:hover {
  transform: translateY(-2px);
  border-color: #93c5fd;
  box-shadow: var(--shadow-sm);
}

.venue-card:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.venue-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.18);
}

.venue-card.locked {
  opacity: 0.65;
  cursor: not-allowed;
}

.venue-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: #cbd5e1;
}

.venue-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}

.venue-card:hover .venue-thumb-wrap img,
.venue-card.selected .venue-thumb-wrap img {
  transform: scale(1.04);
}

.venue-selected-tag {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.venue-card.selected .venue-selected-tag {
  opacity: 1;
  transform: translateY(0);
}

.venue-info {
  padding: 11px 12px 12px;
}

.venue-name {
  margin: 0 0 3px;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text);
}

.venue-desc {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Arena Hero Banner */
.arena-hero {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  height: 180px;
  margin-bottom: 16px;
  background: #1e293b;
}

.arena-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.arena-hero-overlay {
  position: absolute;
  inset: 0;
  padding: 14px 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.12) 0%, rgba(15, 23, 42, 0.78) 100%);
  color: #ffffff;
}

.arena-district {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.9;
  margin-bottom: 2px;
}

.arena-venue-name {
  margin: 0;
  font-size: clamp(1.15rem, 3.2vw, 1.45rem);
  font-weight: 900;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.status-chip {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #f8fafc;
}

.status-chip[data-state="countdown"] {
  background: rgba(217, 119, 6, 0.92);
  border-color: #fde68a;
}

.status-chip[data-state="ready"] {
  background: rgba(22, 163, 74, 0.95);
  border-color: #bbf7d0;
}

.status-chip[data-state="fail"] {
  background: rgba(220, 38, 38, 0.95);
  border-color: #fecaca;
}

/* Arena Stage */
.arena-stage {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 16px 14px;
  text-align: center;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.arena-stage[data-state="ready"] {
  background: #f0fdf4;
  border-color: #86efac;
}

.arena-stage[data-state="fail"] {
  background: var(--danger-bg);
  border-color: #fca5a5;
  animation: shake 0.36s ease;
}

.signal-lights {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
}

.light {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #cbd5e1;
  border: 2px solid #94a3b8;
  transition: background 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.light.lit-warn {
  background: #f59e0b;
  border-color: #d97706;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.75);
}

.light.lit-go {
  background: var(--go-bright);
  border-color: var(--go);
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.9);
}

.light.lit-fail {
  background: var(--danger);
  border-color: #991b1b;
  box-shadow: 0 0 14px rgba(220, 38, 38, 0.8);
}

.readout-box {
  min-height: 82px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-bottom: 14px;
}

.readout-primary {
  font-size: clamp(2rem, 8vw, 3.15rem);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: #0f172a;
}

.arena-stage[data-state="countdown"] .readout-primary {
  color: #b45309;
  animation: pop 0.25s ease;
}

.arena-stage[data-state="ready"] .readout-primary {
  color: #15803d;
}

.arena-stage[data-state="fail"] .readout-primary {
  color: var(--danger);
}

.readout-secondary {
  margin-top: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.arena-controls {
  display: grid;
  gap: 12px;
  max-width: 440px;
  margin: 0 auto;
}

/* Buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  padding: 13px 20px;
  font-size: 1rem;
  box-shadow: 0 4px 12px rgba(26, 86, 219, 0.28);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
  padding: 11px 18px;
  font-size: 0.95rem;
}

.btn-accent:hover {
  background: #0d625b;
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  padding: 10px 20px;
  font-size: 0.95rem;
}

.btn-outline:hover {
  border-color: #94a3b8;
  background: var(--surface-muted);
}

/* Main Register Button */
.btn-register {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 92px;
  padding: 16px 20px;
  border-radius: 16px;
  border: 2px solid #cbd5e1;
  background: #e2e8f0;
  color: #64748b;
}

.register-btn-title {
  font-size: 1.45rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.register-btn-sub {
  margin-top: 3px;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.9;
}

.btn-register[data-phase="idle"] {
  cursor: not-allowed;
}

.btn-register[data-phase="countdown"] {
  background: #334155;
  border-color: #475569;
  color: #cbd5e1;
  cursor: pointer;
}

.btn-register[data-phase="ready"] {
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  border-color: #15803d;
  color: #ffffff;
  box-shadow: 0 0 0 6px var(--go-glow), 0 12px 24px rgba(22, 163, 74, 0.35);
  animation: pulse-go 0.8s infinite alternate;
}

.btn-register[data-phase="ready"]:active {
  transform: scale(0.96);
}

.btn-register[data-phase="fail"] {
  background: #fee2e2;
  border-color: #ef4444;
  color: #b91c1c;
  cursor: default;
}

.btn-register[data-phase="done"] {
  background: #dcfce7;
  border-color: #4ade80;
  color: #166534;
  cursor: default;
}

.keyboard-hint {
  margin: 12px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Result Panel */
.result-panel {
  margin-top: 16px;
  padding: 18px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #ffffff;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.result-panel.is-fail {
  border-color: #fca5a5;
  background: #fff5f5;
}

.result-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  background: #dcfce7;
  color: #166534;
  margin-bottom: 8px;
}

.result-panel.is-fail .result-badge {
  background: #fee2e2;
  color: #b91c1c;
}

.result-score-wrap {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 4px 0 8px;
}

.result-score {
  font-size: clamp(2.5rem, 9vw, 3.4rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: #0f172a;
}

.result-unit {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-muted);
}

.result-comment {
  margin: 0 auto 14px;
  max-width: 460px;
  font-size: 0.94rem;
  color: var(--text);
}

.nickname-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 440px;
  margin: 0 auto 12px;
}

.nickname-input {
  flex: 1 1 210px;
  min-width: 0;
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: #ffffff;
}

.nickname-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.15);
}

.result-submitted {
  margin: 0 auto 12px;
  padding: 10px 14px;
  max-width: 420px;
  border-radius: var(--radius-sm);
  background: #eff6ff;
  color: #1e40af;
  font-size: 0.9rem;
  font-weight: 600;
}

.result-actions {
  margin-top: 6px;
}

/* Leaderboard */
.leaderboard-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.leaderboard-top .section-header {
  margin-bottom: 6px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}

.text-btn:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.leaderboard-note {
  margin: 0 0 12px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.leaderboard-note code {
  background: var(--surface-muted);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.filter-tab {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.filter-tab.active {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.rank-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

.rank-item.is-champion {
  background: linear-gradient(90deg, #fffbeb 0%, #fef3c7 100%);
  border-color: var(--gold-border);
  box-shadow: 0 3px 10px rgba(217, 119, 6, 0.12);
}

.rank-item.is-recent {
  border-color: var(--primary);
  background: #eff6ff;
}

.rank-num {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.95rem;
  background: #e2e8f0;
  color: #334155;
  font-variant-numeric: tabular-nums;
}

.rank-item.is-champion .rank-num {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
  font-size: 1.05rem;
}

.rank-item.rank-2 .rank-num {
  background: #cbd5e1;
  color: #0f172a;
}

.rank-item.rank-3 .rank-num {
  background: #fed7aa;
  color: #9a3412;
}

.rank-player {
  min-width: 0;
}

.rank-name-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.rank-name {
  font-weight: 800;
  font-size: 0.98rem;
  color: var(--text);
  word-break: break-word;
}

.champion-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  background: #b45309;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
}

.rank-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.rank-time {
  font-size: 1.1rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #0f172a;
  white-space: nowrap;
}

.rank-item.is-champion .rank-time {
  color: var(--gold);
}

.empty-hint {
  text-align: center;
  padding: 16px 12px;
  font-size: 0.88rem;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

/* Footer */
.site-footer {
  margin-top: 26px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.site-footer h2 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--text);
}

.credits-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.credits-list a {
  color: var(--primary);
  text-decoration: none;
  word-break: break-all;
}

.credits-list a:hover {
  text-decoration: underline;
}

.footer-disclaimer {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
}

/* Animations */
@keyframes pulse-go {
  from {
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.35), 0 10px 22px rgba(22, 163, 74, 0.32);
  }
  to {
    box-shadow: 0 0 0 10px rgba(34, 197, 94, 0.18), 0 14px 28px rgba(22, 163, 74, 0.45);
  }
}

@keyframes pop {
  0% {
    transform: scale(1.22);
    opacity: 0.55;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Responsive Mobile */
@media (max-width: 680px) {
  .app-shell {
    padding: 14px 12px 32px;
  }

  .card {
    padding: 14px;
    border-radius: 15px;
  }

  .venue-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .venue-card {
    flex-direction: row;
    align-items: stretch;
  }

  .venue-thumb-wrap {
    width: 124px;
    flex-shrink: 0;
    aspect-ratio: auto;
    min-height: 82px;
  }

  .venue-selected-tag {
    top: 6px;
    left: 6px;
    right: auto;
    font-size: 0.66rem;
    padding: 2px 7px;
  }

  .venue-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px 12px;
  }

  .arena-hero {
    height: 150px;
  }

  .btn-register {
    min-height: 102px;
  }

  .keyboard-hint {
    display: none;
  }

  .rank-item {
    grid-template-columns: 38px 1fr auto;
    padding: 10px 11px;
  }
}
