/* ===== Custom Properties ===== */
:root {
  --color-bg: #ffffff;
  --color-text: #1a1a2e;
  --color-text-secondary: #5a5a7a;
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-surface: #f8fafc;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  --color-backdrop: rgba(0, 0, 0, 0.4);
  --font-main: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
  --transition: 150ms ease;
}

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

body {
  font-family: var(--font-main);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== Header ===== */
#site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--color-text);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

#breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  opacity: 0.8;
}

#breadcrumbs a {
  color: inherit;
  text-decoration: none;
  opacity: 0.8;
}
#breadcrumbs a:hover { opacity: 1; text-decoration: underline; }
#breadcrumbs .separator { opacity: 0.5; }

#user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
}

#user-info .user-email {
  opacity: 0.8;
}

/* ===== Sync Indicator ===== */
.sync-indicator {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.sync-synced { color: #4ade80; }
.sync-pending { color: #facc15; }
.sync-offline { color: #94a3b8; }
.sync-error { color: #f87171; }


/* ===== Main Content ===== */
#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.screen-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.screen-subtitle {
  color: var(--color-text-secondary);
  margin-bottom: 1.5rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--color-accent-hover); }

.btn-secondary {
  background: transparent;
  color: var(--color-accent);
  border-color: var(--color-border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-surface); }

.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border-color: var(--color-danger);
}
.btn-danger:hover:not(:disabled) { background: var(--color-danger); color: #fff; }

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  padding: 0.3rem 0.6rem;
}
.btn-ghost:hover:not(:disabled) { color: var(--color-text); background: var(--color-surface); }

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

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

thead th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

tbody td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

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

tbody tr:hover {
  background: var(--color-surface);
}

.table-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}

.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--color-text-secondary);
}

/* ===== Dialogs ===== */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.dialog-backdrop.hidden {
  display: none;
}

.dialog {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  animation: dialog-in 150ms ease;
}

@keyframes dialog-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.dialog-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.dialog-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 0.25rem;
  line-height: 1;
}
.dialog-close:hover { color: var(--color-text); }

.dialog-body {
  padding: 1.25rem;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--color-text-secondary);
}

.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  transition: border-color var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input.error {
  border-color: var(--color-danger);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  margin-top: 0.25rem;
}

.form-error {
  font-size: 0.75rem;
  color: var(--color-danger);
  margin-top: 0.25rem;
}


/* ===== Toasts ===== */
#toast-container {
  position: fixed;
  top: 4.5rem;
  right: 1rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--color-text);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
  animation: toast-in 200ms ease;
  pointer-events: auto;
  max-width: 360px;
}

.toast-success { background: var(--color-success); }
.toast-error { background: var(--color-danger); }
.toast-warning { background: var(--color-warning); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(1rem); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

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

/* ===== Card ===== */
.card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  background: var(--color-bg);
}

.info-line {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
}

/* ===== Section Header ===== */
.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.back-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 0.25rem;
}
.back-btn:hover { color: var(--color-text); }

/* ===== Upload Area ===== */
.upload-area {
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--color-accent);
  background: rgba(37, 99, 235, 0.04);
}

.upload-area p {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

.upload-area input[type="file"] {
  display: none;
}

/* ===== Lane Grid ===== */
.lane-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.lane-checkbox {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
}
.lane-checkbox:has(input:checked) {
  border-color: var(--color-accent);
  background: rgba(37, 99, 235, 0.08);
}
.lane-checkbox input[type="checkbox"] {
  accent-color: var(--color-accent);
}

/* ===== Preview Table ===== */
.preview-table {
  margin-top: 1rem;
  max-height: 300px;
  overflow-y: auto;
}

/* ===== Inline Confirm ===== */
.confirm-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
}

.confirm-inline span {
  color: var(--color-text-secondary);
}

/* ===== Login Screen ===== */
.login-container {
  max-width: 380px;
  margin: 4rem auto;
  text-align: center;
}

.login-container .logo-large {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.login-container .tagline {
  color: var(--color-text-secondary);
  margin-bottom: 2rem;
}

.login-form {
  text-align: left;
}

.login-form .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 0.65rem;
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--color-border);
}

/* ===== Auto Car Number ===== */
.auto-number {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--color-surface);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-accent);
}

/* ===== Checkbox List ===== */
.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--color-text);
  cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

/* ===== Group Header Row ===== */
.group-header-row td {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  padding: 0.4rem 0.75rem;
}

/* ===== Area Heading ===== */
.area-heading {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
}

/* ===== Header Mode Label ===== */
.header-mode {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
}

/* ===== Live Bar ===== */
.live-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1.5rem;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
}

.live-bar.hidden { display: none; }

.live-bar .btn {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}
.live-bar .btn:hover { background: rgba(255, 255, 255, 0.3); }

.live-badge {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  animation: live-pulse 1.5s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== Status Badges ===== */
.status-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
}

.status-idle {
  background: var(--color-surface);
  color: var(--color-text-secondary);
}

.status-active {
  background: #dbeafe;
  color: #1e40af;
}

.status-complete {
  background: #dcfce7;
  color: #166534;
}

.status-arrived {
  background: #dcfce7;
  color: #166534;
}

.status-removed {
  background: #fee2e2;
  color: #991b1b;
}

/* ===== Source Badges ===== */
.source-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
}

.source-timed {
  background: #dbeafe;
  color: #1e40af;
}

.source-manual {
  background: #fef3c7;
  color: #92400e;
}

/* ===== Check-In ===== */
.checkin-toggle {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
  accent-color: var(--color-success);
}

.checkin-counter {
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-text);
}

/* ===== Console Layout ===== */
.console-header {
  margin-bottom: 1.5rem;
}

.console-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.console-state-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  background: #dbeafe;
  color: #1e40af;
}

.console-panels {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.console-panel {
  min-width: 0;
}

.console-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

/* ===== Lane Table ===== */
.lane-table .lane-number {
  font-weight: 600;
  color: var(--color-accent);
}

/* ===== Incomplete Row ===== */
.incomplete-row {
  opacity: 0.6;
}

/* ===== Audience Display — Dark Theme ===== */
body.audience {
  background: #0a0a1a;
  color: #f0f0f5;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

body.audience #app {
  max-width: 1200px;
  width: 100%;
  padding: 2rem;
}

.audience-welcome {
  text-align: center;
  padding: 4rem 2rem;
}

.audience-logo {
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 1rem;
}

.audience-rally-name {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #c0c0e0;
}

.audience-subtitle {
  font-size: 1.25rem;
  color: #8080a0;
}

.audience-screen {
  padding: 1rem;
}

.audience-header {
  text-align: center;
  margin-bottom: 2rem;
}

.audience-section {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.audience-heat-label {
  font-size: 1.5rem;
  color: #8080a0;
  margin-top: 0.25rem;
}

.audience-staging-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.audience-staging-single {
  grid-template-columns: 1fr;
  max-width: 700px;
  margin: 0 auto;
}

.audience-staging-label {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #60a5fa;
  margin-bottom: 1.5rem;
}

.audience-upnext-label {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #8080a0;
  margin-bottom: 1.5rem;
}

.audience-complete-banner {
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #4ade80;
  margin-top: 0.5rem;
}

/* Audience Tables */
.audience-lane-table,
.audience-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.5rem;
}

.audience-lane-table td,
.audience-results-table td,
.audience-results-table th {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.audience-results-table th {
  font-size: 0.875rem;
  color: #8080a0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  text-align: left;
}

.audience-th-place { width: 3rem; }
.audience-th-car { width: 5rem; }
.audience-th-time { text-align: right; width: 8rem; }

.audience-lane-number {
  font-weight: 700;
  color: #60a5fa;
  width: 8rem;
}

.audience-car-number {
  font-weight: 700;
  width: 5rem;
}

.audience-name {
  font-weight: 500;
}

.audience-place {
  font-weight: 800;
  font-size: 1.75rem;
  width: 3rem;
  text-align: center;
}

.audience-time {
  font-family: var(--font-mono);
  text-align: right;
  width: 8rem;
}

/* Medal colors */
.audience-place-1 td { color: #fbbf24; }
.audience-place-2 td { color: #d1d5db; }
.audience-place-3 td { color: #cd7c2f; }

/* ===== Audience Reveal Animations ===== */
.audience-reveal-hidden {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  border-bottom: none !important;
}

.audience-reveal-hidden td {
  padding-top: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.audience-reveal-show {
  animation: audience-reveal-slide 0.5s ease forwards;
}

.audience-reveal-medal {
  animation: audience-reveal-bounce 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.audience-reveal-medal.audience-place-1 td {
  text-shadow: 0 0 12px rgba(251, 191, 36, 0.6), 0 0 24px rgba(251, 191, 36, 0.3);
}

.audience-reveal-medal.audience-place-2 td {
  text-shadow: 0 0 12px rgba(209, 213, 219, 0.6), 0 0 24px rgba(209, 213, 219, 0.3);
}

.audience-reveal-medal.audience-place-3 td {
  text-shadow: 0 0 12px rgba(205, 124, 47, 0.6), 0 0 24px rgba(205, 124, 47, 0.3);
}

@keyframes audience-reveal-slide {
  from {
    opacity: 0;
    max-height: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    max-height: 5rem;
    transform: translateY(0);
  }
}

@keyframes audience-reveal-bounce {
  from {
    opacity: 0;
    max-height: 0;
    transform: translateY(20px) scale(0.95);
  }
  60% {
    opacity: 1;
    max-height: 5rem;
    transform: translateY(-4px) scale(1.03);
  }
  to {
    opacity: 1;
    max-height: 5rem;
    transform: translateY(0) scale(1);
  }
}

/* ===== Responsive ===== */
@media (min-width: 900px) {
  .console-panels {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  #site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
  }

  #app {
    padding: 1.25rem 1rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    justify-content: flex-end;
  }

  .dialog {
    max-width: 100%;
    max-height: 90vh;
    margin: 0.5rem;
  }

  table {
    font-size: 0.8rem;
  }

  thead th, tbody td {
    padding: 0.5rem;
  }

  .login-container {
    margin: 2rem auto;
    padding: 0 0.5rem;
  }
}

/* ===== Fake Track Display ===== */
body.fake-track {
  background: #2c1810;
  color: #f0e6d8;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.ft-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background: #1a0e08;
  color: #f0e6d8;
  flex-shrink: 0;
}

.ft-brand {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.ft-status {
  font-size: 0.85rem;
  color: #c4a882;
  font-weight: 500;
}

/* Track container — horizontal: gate | start | surface | finish | reset */
body.fake-track #track {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  padding: 1rem;
  min-height: 0;
  gap: 0;
}

/* Gate area (left side) */
.ft-gate-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.75rem;
  flex-shrink: 0;
}

.ft-gate-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 1.25rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.3;
  text-align: center;
  border: 2px solid #5a3a20;
  border-radius: 8px;
  background: #3d2415;
  color: #8a7060;
  cursor: not-allowed;
  transition: all 200ms ease;
}

.ft-gate-btn.ft-gate-ready {
  background: #c0392b;
  color: #fff;
  border-color: #e74c3c;
  cursor: pointer;
  animation: gate-pulse 1.5s ease-in-out infinite;
}

.ft-gate-btn.ft-gate-ready:hover {
  background: #e74c3c;
  transform: scale(1.03);
}

.ft-gate-btn.ft-gate-released {
  animation: gate-drop 0.5s ease-out;
}

.ft-gate-icon {
  font-size: 1.1em;
  transition: transform 300ms ease;
}

.ft-gate-btn.ft-gate-released .ft-gate-icon {
  transform: translateX(6px);
}

@keyframes gate-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
}

@keyframes gate-drop {
  0% { transform: translateX(0); }
  40% { transform: translateX(8px); }
  100% { transform: translateX(0); opacity: 0.5; }
}

/* Start / Finish lines — vertical stripes */
.ft-line {
  width: 4px;
  background: repeating-linear-gradient(
    180deg,
    #fff 0px, #fff 12px,
    #111 12px, #111 24px
  );
  border-radius: 2px;
  flex-shrink: 0;
}

/* Track surface — lanes stacked vertically, cars race left-to-right */
.ft-surface {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    linear-gradient(90deg,
      #8B6914 0%, #a07828 15%, #9a7020 50%, #8B6914 85%, #7a5c10 100%
    );
  border-top: 3px solid #5a4010;
  border-bottom: 3px solid #5a4010;
  min-width: 200px;
  overflow: hidden;
}

/* Lanes — horizontal rows */
.ft-lane {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  padding-left: 0.4rem;
}

.ft-lane-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.45);
  position: absolute;
  left: 6px;
  z-index: 2;
}

/* Horizontal divider between lanes */
.ft-lane-divider {
  height: 2px;
  background: rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}

/* Car slot — full lane area for car to travel through */
.ft-car-slot {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Car element — positioned horizontally */
.ft-car {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 72px;
  padding: 4px 6px;
  background: var(--car-color, #e74c3c);
  border-radius: 6px;
  text-align: center;
  z-index: 5;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.4);
  transition: none; /* animated via JS */
}

.ft-car-number {
  font-size: 0.8rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  line-height: 1.1;
}

.ft-car-name {
  font-size: 0.55rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60px;
  line-height: 1.2;
}

/* Place label on finished cars — appears above */
.ft-car-place {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  white-space: nowrap;
  animation: place-pop 200ms ease;
}

.ft-place-1 { background: #f1c40f; color: #1a1a1a; }
.ft-place-2 { background: #bdc3c7; color: #1a1a1a; }
.ft-place-3 { background: #cd7f32; color: #fff; }

@keyframes place-pop {
  from { transform: translateX(-50%) scale(0); }
  to { transform: translateX(-50%) scale(1); }
}

/* Idle message */
.ft-idle-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.4);
  text-align: center;
  z-index: 1;
  pointer-events: none;
}

/* Reset button area (right side) */
.ft-reset-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.75rem;
  flex-shrink: 0;
  min-width: 48px;
}

.ft-reset-btn {
  padding: 1.25rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.3;
  text-align: center;
  border: 2px solid #e74c3c;
  border-radius: 8px;
  background: #c0392b;
  color: #fff;
  cursor: pointer;
  transition: all 200ms ease;
  animation: gate-pulse 1.5s ease-in-out infinite;
}

.ft-reset-btn:disabled {
  background: #3d2415;
  border-color: #5a3a20;
  color: #8a7060;
  cursor: not-allowed;
  animation: none;
}

.ft-reset-btn:not(:disabled):hover {
  background: #e74c3c;
  transform: scale(1.03);
}

.ft-reset-btn.ft-reset-done {
  background: #27ae60;
  border-color: #2ecc71;
  cursor: default;
  animation: none;
}

/* Track state-based visuals */
body.fake-track[data-track-state="racing"] .ft-surface {
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.3);
}
