/* Regatta Radar — design system.
   Tokens sourced from input/"Regatta Radar - Color & Type (Standalone).html":
   dark, maritime, sport-tracking-app feel (spec §37) — closer to a flight
   radar / Strava at night than a classic yacht-club site. Amber is reserved
   for Person & Segelnummer, the two watch types the spec asks to foreground
   (§2.2, §42); everything else stays on the cyan/neutral palette. */

:root {
  color-scheme: dark;

  --color-bg: #0B1216;
  --color-surface-1: #10171A;
  --color-surface-2: #121B20;
  --color-surface-3: #1A252B;
  --color-surface-4: #26333A;
  --color-border: #26333A;

  --color-accent-teal: #3FC4CE;
  --color-accent-teal-dark: #136B75;
  --color-accent-amber: #E3A94D;

  --color-text-primary: #F7F9FA;
  --color-text-secondary: #9FB0B5;
  --color-text-muted: #657277;

  --color-success: #4CB37F;
  --color-success-dark: #2F8F5B;
  --color-danger: #E2695A;
  --color-danger-dark: #B5392A;
  --color-warning: #E8BA4A;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Space Grotesk', var(--font-sans);
  --font-mono: 'SFMono-Regular', Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --radius-2xl: 14px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: 72px; /* clears the fixed bottom nav */
}

a {
  color: var(--color-accent-teal);
}

/* ---------- Typography ---------- */

h1, h2, h3 {
  font-family: var(--font-display);
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  font-weight: 600;
  margin: 0 0 var(--space-3);
}

h2 {
  font-size: 21px;
  line-height: 1.25;
  font-weight: 600;
  margin: 0 0 var(--space-3);
}

h3 {
  font-size: 17px;
  line-height: 1.3;
  font-weight: 600;
  margin: var(--space-6) 0 var(--space-2);
}

.card > h3:first-child,
.choice-card h3 {
  margin-top: 0;
}

.card ul {
  margin: var(--space-2) 0 0;
  padding-left: 20px;
}

.card li {
  margin-bottom: 4px;
}

.card li:last-child {
  margin-bottom: 0;
}

/* Sail numbers get the display font + amber accent so Person/Segelnummer
   watches read as prominent, per spec §2.2 / §42. */
.sail-number {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.02em;
  color: var(--color-accent-amber);
}

.sail-number-inline {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--color-accent-amber);
}

.race-results {
  font-family: var(--font-mono);
  color: var(--color-text-secondary);
  font-size: 13px;
  margin-top: 2px;
}

.race-result {
  white-space: nowrap;
}

/* Streichergebnis: still shown, but visibly not counted. */
.race-result-discarded {
  opacity: 0.6;
}

/* ---------- Layout ---------- */

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-8);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s var(--ease-out), background-color 0.15s ease, filter 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-accent-teal);
  border-color: var(--color-accent-teal);
  color: var(--color-bg);
}

.btn-secondary {
  background: transparent;
}

.btn-danger {
  background: var(--color-danger-dark);
  border-color: var(--color-danger-dark);
  color: var(--color-text-primary);
}

.btn-block {
  display: flex;
  width: 100%;
}

@media (hover: hover) {
  .btn-secondary:hover { background: var(--color-surface-3); }
  .btn-primary:hover { filter: brightness(1.08); }
  .btn-danger:hover { filter: brightness(1.1); }
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: transform 0.1s var(--ease-out), background-color 0.15s ease, color 0.15s ease;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
}

.btn-icon:active {
  transform: scale(0.97);
}

@media (hover: hover) {
  .btn-icon:hover {
    background: var(--color-surface-3);
    color: var(--color-text-primary);
  }
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions form {
  display: contents;
}

/* ---------- Forms ---------- */

.input, .select {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  transition: border-color 0.15s ease;
}

.field {
  margin-bottom: var(--space-4);
}

.field label {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--color-text-secondary);
  font-size: 13px;
}

.field-error {
  color: var(--color-danger);
  font-size: 13px;
  margin-top: var(--space-1);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
}

/* Custom checkbox: a filled square with a drawn-in check, CSS-only. */
.checkbox-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin: 0;
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  background-color: var(--color-surface-2);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px 14px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.checkbox-row input[type="checkbox"]:checked {
  background-color: var(--color-accent-teal);
  border-color: var(--color-accent-teal);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%230B1216' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E");
}

.checkbox-row input[type="checkbox"]:active {
  transform: scale(0.92);
}

/* Switch variant for rows that submit immediately on change (rule-group
   toggles). Distinct from the checkbox above: a real setting, not a
   multi-select option, so it reads as a live on/off control. */
.checkbox-row.switch-row input[type="checkbox"] {
  width: 40px;
  height: 24px;
  border-radius: 999px;
  border: none;
  background-color: var(--color-surface-4);
  background-image: none;
  position: relative;
}

.checkbox-row.switch-row input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-text-primary);
  transition: transform 0.18s var(--ease-out);
}

.checkbox-row.switch-row input[type="checkbox"]:checked {
  background-color: var(--color-accent-teal);
}

.checkbox-row.switch-row input[type="checkbox"]:checked::before {
  transform: translateX(16px);
}

.checkbox-row.switch-row input[type="checkbox"]:active {
  transform: none;
}

/* ---------- Focus & motion ---------- */

a:focus-visible,
.btn:focus-visible,
.input:focus-visible,
.select:focus-visible,
input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--color-accent-teal);
  outline-offset: 2px;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
}

.badge-active {
  background: rgba(76, 179, 127, 0.15);
  color: var(--color-success);
}

.badge-paused {
  background: rgba(159, 176, 181, 0.15);
  color: var(--color-text-secondary);
}

.badge-type {
  background: rgba(63, 196, 206, 0.15);
  color: var(--color-accent-teal);
}

/* Person & Segelnummer watches get the amber treatment (spec §2.2). */
.badge-type-highlight,
.badge-match {
  background: rgba(227, 169, 77, 0.18);
  color: var(--color-accent-amber);
}

.mono {
  font-family: var(--font-mono);
}

/* ---------- Utilities ---------- */

.text-secondary { color: var(--color-text-secondary); }
.text-center { text-align: center; }
.meta { color: var(--color-text-secondary); font-size: 13px; }
.event-meta { color: var(--color-text-secondary); margin-bottom: var(--space-4); }
.event-meta-sub { color: var(--color-text-secondary); font-size: 13px; margin-top: calc(-1 * var(--space-3)); margin-bottom: var(--space-4); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table td {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

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

.table td:last-child {
  color: var(--color-text-secondary);
  text-align: right;
}

.filter-row {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

/* ---------- Empty state ---------- */

.empty-state {
  position: relative;
  text-align: center;
  padding: 96px var(--space-4) var(--space-8);
  color: var(--color-text-secondary);
}

.empty-state::before,
.empty-state::after {
  content: "";
  position: absolute;
  left: 50%;
  border-radius: 50%;
  border: 1.5px solid var(--color-surface-4);
  transform: translateX(-50%);
}

.empty-state::before {
  top: 22px;
  width: 56px;
  height: 56px;
}

.empty-state::after {
  top: 36px;
  width: 28px;
  height: 28px;
  border-style: dashed;
}

/* ---------- Messages ---------- */

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-4);
}

.messages li {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  background: var(--color-surface-2);
  font-size: 14px;
}

/* ---------- Cards & lists ---------- */

.card {
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}

.card-danger {
  border-color: var(--color-danger);
}

/* The link fills the card edge-to-edge (negative margin = card padding)
   so hover/active feedback covers the whole tappable area, not just the
   inner text column. */
.card > a.card-link {
  display: block;
  margin: calc(-1 * var(--space-4));
  padding: var(--space-4);
  border-radius: inherit;
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.card > a.card-link:active {
  background-color: var(--color-surface-3);
}

@media (hover: hover) {
  .card > a.card-link:hover {
    background-color: var(--color-surface-2);
  }
}

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
  color: inherit;
}

.list-row:last-child {
  border-bottom: none;
}

a.list-row {
  margin: 0 calc(-1 * var(--space-4));
  padding: var(--space-2) var(--space-4);
  transition: background-color 0.15s ease;
}

a.list-row:active {
  background-color: var(--color-surface-3);
}

@media (hover: hover) {
  a.list-row:hover {
    background-color: var(--color-surface-2);
  }
}

/* ---------- Meldungen: expandable boat rows ---------- */

.entry-row {
  border-bottom: 1px solid var(--color-border);
}

.entry-row:last-child {
  border-bottom: none;
}

.entry-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  list-style: none;
}

/* Safari/older WebKit still draws the native marker despite list-style. */
.entry-summary::-webkit-details-marker {
  display: none;
}

details.entry-row > .entry-summary {
  cursor: pointer;
}

.entry-summary-main {
  flex: 1;
  min-width: 0;
}

.entry-chevron {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  margin: 0 var(--space-1);
  border-right: 2px solid var(--color-text-secondary);
  border-bottom: 2px solid var(--color-text-secondary);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

details[open] > .entry-summary > .entry-chevron {
  transform: rotate(-135deg);
}

/* .card ul / .card li would otherwise win on specificity. */
.card .crew-list {
  list-style: none;
  margin: 0 0 var(--space-2);
  padding: 0 0 0 var(--space-3);
  border-left: 2px solid var(--color-border);
}

.card .crew-row {
  display: flex;
  margin-bottom: 0;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
  padding: 4px var(--space-2);
  border-radius: var(--radius-sm);
}

.crew-row-match {
  background: rgba(227, 169, 77, 0.12);
}

.crew-row-match .crew-name {
  color: var(--color-accent-amber);
  font-weight: 600;
}

/* ---------- Choice grid ---------- */

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.choice-card {
  display: block;
  text-align: center;
  padding: var(--space-5) var(--space-3);
  text-decoration: none;
  color: var(--color-text-primary);
  transition: background-color 0.15s ease, transform 0.1s var(--ease-out);
}

.choice-card:active {
  transform: scale(0.97);
}

@media (hover: hover) {
  .choice-card:hover {
    background-color: var(--color-surface-2);
  }
}

.choice-card.wide {
  grid-column: span 2;
}

.choice-card.prominent {
  grid-column: span 2;
  background: var(--color-surface-2);
  border-color: var(--color-accent-amber);
}

.choice-card.prominent h3 {
  color: var(--color-accent-amber);
}

/* ---------- Onboarding progress ---------- */

.progress-dots {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.progress-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-surface-4);
}

.progress-dots .dot.active {
  background: var(--color-accent-teal);
}

/* ---------- Bottom nav (sidebar on desktop, see breakpoint below) ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--color-surface-1);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}

.bottom-nav a {
  flex: 1;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  transition: color 0.15s ease;
}

.bottom-nav svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
}

.bottom-nav a.active {
  color: var(--color-accent-teal);
}

@media (hover: hover) {
  .bottom-nav a:hover {
    color: var(--color-text-primary);
  }
  .bottom-nav a.active:hover {
    color: var(--color-accent-teal);
  }
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: var(--space-2);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}

.tab {
  padding: var(--space-2) var(--space-1);
  color: var(--color-text-secondary);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab.tab-active {
  color: var(--color-accent-teal);
  border-bottom-color: var(--color-accent-teal);
}

@media (hover: hover) {
  .tab:not(.tab-active):hover {
    color: var(--color-text-primary);
  }
}

/* ---------- Favorites grid ----------
   Two columns from 390px (Pixel 8a is ~412px wide), more on tablet/desktop. */

.sort-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.sort-bar select {
  background: var(--color-surface-1);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font: inherit;
}

.card-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
}

.card-grid .card {
  margin-bottom: 0;
  min-width: 0;
}

.card-grid .card h3 {
  margin-bottom: 0;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.card-grid .card h3.sail-number {
  font-size: 18px;
}

@media (min-width: 390px) {
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .page.page-wide {
    max-width: 1000px;
  }

  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .page.page-wide {
    max-width: 1200px;
  }

  .card-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ---------- Desktop ----------
   Spec §38/§62: desktop keeps the same content and information, but with
   clear primary navigation instead of a mobile bottom bar, and a roomier
   column instead of a stretched phone layout. */

@media (min-width: 768px) {
  body {
    padding-bottom: 0;
    padding-left: 88px;
  }

  .page {
    max-width: 640px;
    padding: var(--space-8) var(--space-6);
  }

  .bottom-nav {
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: 88px;
    flex-direction: column;
    justify-content: flex-start;
    gap: var(--space-2);
    padding-top: var(--space-6);
    padding-bottom: 0;
    border-top: none;
    border-right: 1px solid var(--color-border);
  }

  .bottom-nav a {
    flex: none;
    width: 100%;
    height: 64px;
    font-size: 12px;
  }
}
