:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --bg-soft: #e9eef8;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: #ffffff;
  --line: #d7dfef;
  --text: #0f172a;
  --muted: #5b6b87;
  --accent: #0f766e;
  --accent-strong: #0b5e57;
  --live: #047857;
  --warn: #b45309;
  --danger: #b91c1c;
  --shadow: 0 12px 36px rgba(22, 33, 63, 0.14);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", "Avenir Next", "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 8% -5%, rgba(15, 118, 110, 0.12), transparent 55%),
    radial-gradient(1000px 450px at 100% 0%, rgba(12, 74, 110, 0.08), transparent 48%),
    linear-gradient(180deg, #f7f9fd 0%, #eef3fb 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.auth-screen[hidden],
.app-shell[hidden],
.auth-form[hidden],
.dialog[hidden],
[hidden] {
  display: none !important;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.app-shell,
.auth-screen {
  width: min(1180px, calc(100% - 26px));
  margin: 0 auto;
}

.mobile-session-actions {
  display: none;
}

.app-shell {
  padding: 14px 0 28px;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
}

.auth-hero,
.auth-card {
  padding: 22px;
}

.auth-hero h1 {
  margin: 8px 0 0;
  font-family: "Outfit", "Avenir Next", sans-serif;
  font-size: clamp(2.6rem, 6vw, 4.8rem);
  letter-spacing: -0.04em;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.auth-tab {
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f5f8ff;
  color: var(--muted);
  font-weight: 700;
}

.auth-tab.active {
  background: #dbf2ef;
  border-color: #84d4cb;
  color: var(--accent-strong);
}

.auth-message {
  min-height: 1.2rem;
  margin: 0 0 10px;
  color: var(--muted);
}

.auth-message[data-tone="success"] {
  color: #0f766e;
}

.auth-message[data-tone="error"] {
  color: #be123c;
}

.auth-form,
.form-grid label {
  display: grid;
  gap: 8px;
}

.auth-form {
  gap: 12px;
}

.auth-form label span,
.form-grid label span,
.muted,
.race-meta,
.race-runner,
.insight-row span,
.stat-card p,
.stat-card span {
  color: var(--muted);
}

.auth-submit {
  width: 100%;
  margin-top: 4px;
}

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 14px;
  padding: 16px;
  margin-bottom: 14px;
}

.hero-copy h1,
.panel-header h2,
.dialog-header h2 {
  margin: 0;
}

.hero-copy h1 {
  margin-top: 6px;
  font-family: "Outfit", "Avenir Next", sans-serif;
  font-size: clamp(2.1rem, 3.9vw, 3.5rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.lead {
  margin: 8px 0 0;
  max-width: 54ch;
  line-height: 1.45;
  color: var(--muted);
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  font-weight: 800;
}

.hero-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
}

.session-pill {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fbff;
}

.session-pill span {
  margin-inline: 12px;
  max-width: 28ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  color: var(--muted);
}

.button {
  appearance: none;
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 0.74rem 0.95rem;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: linear-gradient(135deg, #11998e, #0f766e);
  color: #ffffff;
}

.button-secondary {
  background: #e7f5f3;
  color: var(--accent-strong);
  border-color: #bee6e1;
}

.button-ghost {
  background: #f5f8ff;
  color: #1f334f;
  border-color: var(--line);
}

.button-danger {
  background: #fff0f0;
  border-color: #f7c6c6;
  color: var(--danger);
}

.button-icon {
  width: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.button:disabled {
  opacity: 0.55;
  transform: none;
  cursor: not-allowed;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.stat-card {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
}

.stat-card p,
.stat-card strong {
  margin: 0;
}

.stat-card strong {
  margin-top: 5px;
  font-size: clamp(1.2rem, 2.7vw, 1.95rem);
  letter-spacing: -0.02em;
}

.stat-card span {
  margin-top: 6px;
  display: block;
  font-size: 0.86rem;
  line-height: 1.35;
}

.toolbar {
  display: grid;
  grid-template-columns: 1.35fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  margin-bottom: 12px;
}

.search-wrap input,
.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  padding: 0.78rem 0.9rem;
  outline: none;
}

.search-wrap input:focus,
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  border-color: #70c8be;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.filter-group {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.filter-group::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  flex: 0 0 auto;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f5f8ff;
  color: var(--muted);
  font-weight: 700;
  padding: 0.55rem 0.88rem;
}

.filter-pill.active {
  border-color: #8ccfc6;
  background: #dff3f0;
  color: var(--accent-strong);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  min-height: 42px;
  font-size: 0.9rem;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.board {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 12px;
}

.panel {
  padding: 14px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 8px;
  margin-bottom: 12px;
}

.panel-header h2 {
  font-size: 1.24rem;
  letter-spacing: -0.02em;
}

.race-list,
.insights {
  display: grid;
  gap: 10px;
}

.race-card {
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: #ffffff;
}

.race-card-upcoming {
  border-color: #b6d5f0;
  background: linear-gradient(180deg, #ffffff 0%, #f5faff 100%);
}

.race-card-live {
  border-color: #a5d6bf;
  background: linear-gradient(180deg, #ffffff 0%, #effcf5 100%);
}

.race-card-finished {
  border-color: #e0e6f2;
  background: #f8fafd;
}

.race-card-cancelled {
  border-color: #f2d3d3;
  background: #fff8f8;
}

.priority-high {
  box-shadow: inset 0 0 0 2px rgba(180, 83, 9, 0.24);
}

.race-card__top,
.race-card__footer,
.insight-row,
.dialog-header,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.race-main {
  min-width: 0;
}

.race-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.race-heading h3 {
  margin: 0;
  font-size: 1.06rem;
}

.race-runner,
.race-selection,
.race-meta {
  margin: 5px 0 0;
}

.race-selection {
  color: #1e3a5f;
  font-weight: 700;
}

.timer-block {
  min-width: 112px;
  text-align: right;
}

.timer-block span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.timer-block strong {
  font-size: clamp(1.05rem, 2.2vw, 1.4rem);
}

.progress-track {
  margin: 11px 0 10px;
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: #e7eef8;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2db3a5, #42b8d8);
}

.chip-row,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.button-mobile-select {
  display: none;
}

.chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.62rem;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid #d9e3f2;
}

.chip-high {
  color: var(--warn);
  background: #fff7eb;
  border-color: #f6d9af;
}

.chip-muted {
  background: #f5f8ff;
  color: var(--muted);
}

.badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.26rem 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.67rem;
  font-weight: 800;
}

.badge-upcoming {
  background: #e9f3ff;
  color: #1e4f8f;
}

.badge-live {
  background: #e5f9ef;
  color: var(--live);
}

.badge-finished {
  background: #edf1f8;
  color: #64748b;
}

.badge-cancelled {
  background: #ffecec;
  color: #b91c1c;
}

.insight-block {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px;
  background: #ffffff;
}

.insight-block h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.insight-row {
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #e8eef8;
}

.insight-row:last-child {
  border-bottom: 0;
}

.insight-row strong,
.insight-row span {
  display: block;
}

.muted-box {
  background: linear-gradient(180deg, #f4fbfa, #ffffff);
}

.empty-state {
  text-align: center;
  padding: 38px 14px 44px;
}

.empty-state__icon {
  font-size: 2.3rem;
  margin-bottom: 10px;
}

.empty-state h3,
.empty-state p {
  margin: 0;
}

.empty-state p {
  color: var(--muted);
  margin: 8px auto 14px;
  max-width: 42ch;
}

.dialog {
  width: min(760px, calc(100% - 20px));
  border: 0;
  border-radius: 20px;
  padding: 0;
  color: var(--text);
  background: transparent;
}

.dialog::backdrop {
  background: rgba(16, 24, 40, 0.36);
  backdrop-filter: blur(8px);
}

.dialog-form {
  border-radius: inherit;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 16px;
}

.dialog-header {
  align-items: center;
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.full-width {
  grid-column: 1 / -1;
}

.form-grid textarea {
  min-height: 104px;
  resize: vertical;
}

.dialog-actions {
  justify-content: end;
  margin-top: 14px;
}

.horse-sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
}

.horse-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
}

.horse-sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 20px 20px 0 0;
  background: #ffffff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -18px 40px rgba(15, 23, 42, 0.22);
  padding: 14px;
}

.horse-sheet__panel h3 {
  margin: 6px 0 0;
}

.horse-mode-toggle {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.horse-mode-btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4f8ff;
  color: var(--muted);
  font-weight: 700;
}

.horse-mode-btn.active {
  border-color: #8ecfc5;
  background: #dff3f0;
  color: var(--accent-strong);
}

.horse-slider-wrap {
  margin-top: 12px;
}

.horse-slider-wrap input[type="range"] {
  width: 100%;
}

.horse-slider-value {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  text-align: center;
}

.horse-quinella {
  margin-top: 12px;
}

.horse-quinella-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.horse-quinella-number {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f6f9ff;
  color: #1f334f;
  font-weight: 700;
}

.horse-quinella-number.selected {
  border-color: #82cfc4;
  background: #dff4f0;
  color: var(--accent-strong);
}

.horse-sheet-hint {
  margin: 10px 0 0;
  font-size: 0.88rem;
}

.horse-sheet__actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.focus-mode {
  position: fixed;
  inset: 0;
  z-index: 60;
  min-height: 100dvh;
  width: 100vw;
  border-radius: 0;
  background:
    radial-gradient(900px 420px at 10% 0%, rgba(15, 118, 110, 0.2), transparent 55%),
    radial-gradient(900px 420px at 100% 100%, rgba(14, 116, 144, 0.17), transparent 55%),
    linear-gradient(180deg, #f4fbfa 0%, #e8f2ff 100%);
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  padding: 18px;
}

.focus-exit {
  position: absolute;
  top: 14px;
  right: 14px;
}

.focus-label {
  margin: 0;
  font-size: clamp(0.92rem, 2.2vw, 1.35rem);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.focus-venue,
.focus-tip {
  margin: 0;
  font-family: "Outfit", "Avenir Next", sans-serif;
  letter-spacing: -0.04em;
}

.focus-venue {
  font-size: clamp(2.8rem, 11vw, 8.5rem);
  color: #12334f;
}

.focus-tip {
  font-size: clamp(2.3rem, 9.6vw, 7.3rem);
  color: var(--accent);
}

.app-shell.focus-mode-on > :not(.focus-mode) {
  display: none !important;
}

.app-shell.focus-mode-on .focus-mode {
  display: grid !important;
}

.app-shell.focus-mode-on {
  width: 100%;
  margin: 0;
  padding: 0;
}

@media (max-width: 1024px) {
  .auth-screen,
  .board {
    grid-template-columns: 1fr;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .toggle,
  #clearCompletedBtn {
    justify-self: start;
  }
}

@media (max-width: 760px) {
  .app-shell,
  .auth-screen {
    width: min(100% - 12px, 100%);
  }

  .app-shell {
    padding: 8px 0 16px;
  }

  .auth-screen {
    min-height: auto;
    padding: 10px 0 16px;
    gap: 10px;
  }

  .auth-hero,
  .auth-card,
  .hero,
  .panel,
  .toolbar,
  .dialog-form {
    border-radius: 16px;
    padding: 13px;
  }

  .auth-tabs {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    grid-template-columns: 1fr;
  }

  .hero-actions .button,
  .action-row .button,
  .dialog-actions .button {
    width: 100%;
  }

  .session-pill span {
    display: none;
  }

  #enableAlertsBtn,
  #newRaceBtn {
    display: none;
  }

  .mobile-session-actions {
    display: block;
    margin-top: 10px;
  }

  .mobile-session-actions .button {
    width: 100%;
  }

  .session-pill {
    border-radius: 14px;
  }

  .stats-grid,
  .toolbar,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .filter-group {
    order: 3;
  }

  .panel-header,
  .race-card__top,
  .race-card__footer,
  .dialog-header,
  .dialog-actions,
  .insight-row {
    flex-direction: column;
    align-items: stretch;
  }

  .timer-block {
    text-align: left;
    min-width: 0;
  }

  .chip-row .chip {
    flex: 1 1 calc(50% - 4px);
  }

  .action-row .action-desktop {
    display: none;
  }

  .action-row .button-mobile-select {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .dialog {
    width: min(100% - 10px, 100%);
  }

  .focus-mode {
    padding: 14px;
  }
}

body.horse-sheet-open {
  overflow: hidden;
}