:root {
  --bg: #0e1419;
  --surface: #161d26;
  --surface2: #1c2530;
  --border: #2a3544;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #e85d32;
  --accent-dim: #c44a28;
  --track: #1e3a5f;
  --ok: #3dd68c;
  --warn: #f0c14b;
  --radius: 10px;
  --font: "Noto Sans TC", "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Noto Sans TC", ui-monospace, monospace;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(1200px 800px at 20% -10%, #1a2840 0%, transparent 55%),
    radial-gradient(900px 600px at 100% 30%, #2a1830 0%, transparent 50%), var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: #ff8f6b;
}

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.hero {
  margin-bottom: 1.75rem;
}

.eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.5rem;
}

.hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0;
  color: var(--muted);
  max-width: 52ch;
}

.lede strong {
  color: var(--text);
  font-weight: 600;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  margin-bottom: 1rem;
}

.btn {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #243040;
  border-color: #3d4d62;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #fff;
}

.btn.primary:hover {
  background: #f06e45;
  border-color: var(--accent);
}

.btn.ghost {
  background: transparent;
  border-style: dashed;
}

.file-label {
  display: inline-flex;
  align-items: center;
}

.hint {
  min-height: 1.25rem;
  font-size: 0.875rem;
  color: var(--warn);
  margin: 0 0 1.25rem;
}

.hint.ok {
  color: var(--ok);
}

.stt-banner {
  font-size: 0.85rem;
  color: var(--warn);
  background: rgba(240, 193, 75, 0.08);
  border: 1px solid rgba(240, 193, 75, 0.25);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  margin: 0 0 1rem;
  max-width: 62ch;
}

.stt-banner[hidden] {
  display: none !important;
}

.panel-note code {
  font-family: var(--mono);
  font-size: 0.8em;
  color: #b0c0d4;
}

.sprint-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

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

.stt-btn {
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.stt-btn .mic-icon {
  font-size: 1rem;
  line-height: 1;
}

.stt-btn.listening {
  background: rgba(232, 93, 50, 0.2);
  border-color: var(--accent);
  color: #ffb39c;
  animation: stt-pulse 1.2s ease-in-out infinite;
}

@keyframes stt-pulse {
  50% {
    box-shadow: 0 0 0 2px rgba(232, 93, 50, 0.25);
  }
}

.stt-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0;
  flex: 1 1 12rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.25rem;
}

.panel h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
  font-weight: 700;
}

.panel-note {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0 0 1rem;
  max-width: 62ch;
}

.panel-note strong {
  color: #b8c5d6;
  font-weight: 600;
}

.sprint-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sprint-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1rem 0.85rem;
  position: relative;
}

.sprint-card.final-sprint {
  border-color: #4a6a8a;
  box-shadow: 0 0 0 1px rgba(232, 93, 50, 0.15);
}

.sprint-card.final-sprint::after {
  content: "決勝衝刺 · 分數雙倍";
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.sprint-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  padding-right: 9rem;
}

.sprint-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #c5d0e0;
}

.sprint-textarea {
  width: 100%;
  min-height: 7rem;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0d1117;
  color: var(--text);
}

.sprint-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(232, 93, 50, 0.2);
}

.sprint-textarea::placeholder {
  color: #5a6a7d;
}

.btn-remove-sprint {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  color: #e89898;
  border-color: #5c3838;
  background: transparent;
}

.btn-remove-sprint:hover {
  background: #2a1a1a;
}

.rider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.rider-grid.empty {
  display: block;
}

.empty-riders {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.rider-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.rider-card .name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.rider-card label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.rider-card input[type="number"] {
  width: 4.5rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0d1117;
  color: var(--text);
}

.rider-card input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}

.results-panel[hidden] {
  display: none !important;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.standings {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.standings th,
.standings td {
  padding: 0.55rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.standings th {
  background: var(--surface2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.standings tbody tr:last-child td {
  border-bottom: none;
}

.standings tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.12);
}

.standings td:nth-child(n + 3) {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.breakdown-details {
  margin-top: 1rem;
}

.breakdown-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.9rem;
}

.breakdown-pre {
  margin: 0.75rem 0 0;
  padding: 1rem;
  background: #0d1117;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
}

.footer {
  margin-top: 2rem;
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 58ch;
}

.footer p {
  margin: 0;
}

@media (max-width: 520px) {
  .sprint-card.final-sprint::after {
    position: static;
    display: block;
    margin: -0.25rem 0 0.5rem;
    padding-right: 0;
  }

  .sprint-head {
    padding-right: 0;
    flex-wrap: wrap;
  }
}
