:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #9f1239;
  --brand-2: #be123c;
  --gold: #f59e0b;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --shadow: 0 12px 32px rgba(15, 23, 42, .09);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(245,158,11,.45); outline-offset: 2px; }

.app-shell { min-height: 100vh; padding-bottom: calc(82px + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(159,18,57,.96);
  color: #fff;
  box-shadow: 0 6px 20px rgba(159,18,57,.20);
  backdrop-filter: blur(14px);
}
.topbar-row { max-width: 1160px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; background: linear-gradient(145deg, #fbbf24, #f59e0b); display: grid; place-items: center; font-size: 23px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.35); }
.brand-copy { min-width: 0; flex: 1; }
.brand-title { font-size: 16px; font-weight: 900; line-height: 1.1; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-subtitle { font-size: 12px; opacity: .82; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.autosave { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; background: rgba(255,255,255,.13); padding: 7px 9px; border-radius: 999px; }
.autosave-dot { width: 7px; height: 7px; border-radius: 50%; background: #86efac; box-shadow: 0 0 0 4px rgba(134,239,172,.12); }

.main { width: min(1160px, calc(100% - 24px)); margin: 0 auto; padding: 18px 0 36px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 4px 2px 18px; }
.page-title { margin: 0; font-size: clamp(23px, 5.5vw, 34px); line-height: 1.03; letter-spacing: -.04em; }
.page-sub { color: var(--muted); margin: 8px 0 0; font-size: 14px; line-height: 1.4; }

.hero {
  border-radius: 28px;
  background: linear-gradient(135deg, #7f1d1d 0%, #9f1239 48%, #be123c 100%);
  color: #fff; padding: 22px; box-shadow: var(--shadow); position: relative; overflow: hidden; margin-bottom: 18px;
}
.hero::after { content: "🐉"; position: absolute; right: -10px; bottom: -36px; font-size: 116px; opacity: .11; transform: rotate(-7deg); }
.hero-kicker { font-size: 12px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; color: #fde68a; }
.hero h1 { margin: 8px 0 10px; max-width: 620px; font-size: clamp(28px, 8vw, 46px); line-height: .98; letter-spacing: -.045em; }
.hero p { margin: 0; max-width: 720px; font-size: 14px; line-height: 1.45; color: rgba(255,255,255,.86); }
.hero-stats { margin-top: 20px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; max-width: 540px; }
.hero-stat { background: rgba(255,255,255,.11); border: 1px solid rgba(255,255,255,.16); border-radius: 16px; padding: 11px; backdrop-filter: blur(8px); }
.hero-stat strong { display: block; font-size: 18px; }
.hero-stat span { display: block; font-size: 10px; margin-top: 2px; opacity: .78; }

.section-title { font-size: 15px; font-weight: 900; margin: 24px 2px 10px; letter-spacing: -.02em; }
.grid { display: grid; gap: 12px; }
.boat-grid { grid-template-columns: 1fr; }
.boat-card { border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); padding: 17px; box-shadow: 0 8px 24px rgba(15,23,42,.05); text-align: left; transition: transform .14s ease, box-shadow .14s ease; }
.boat-card:active { transform: scale(.985); }
.boat-card-top { display: flex; align-items: center; gap: 12px; }
.boat-icon { width: 46px; height: 46px; border-radius: 16px; display: grid; place-items: center; background: #fff1f2; font-size: 25px; flex: none; }
.boat-card h3 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.boat-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.progress { height: 8px; margin-top: 14px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand-2), var(--gold)); }
.boat-card-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 12px; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 5px 8px; font-size: 11px; font-weight: 800; }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.todo { background: var(--warn-bg); color: var(--warn); }
.badge.neutral { background: #f1f5f9; color: #475569; }

.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.action-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 15px; display: flex; align-items: center; gap: 12px; box-shadow: 0 5px 18px rgba(15,23,42,.04); }
.action-icon { width: 38px; height: 38px; border-radius: 13px; background: #f8fafc; display: grid; place-items: center; }
.action-card strong { font-size: 13px; display: block; }
.action-card span { font-size: 11px; color: var(--muted); display: block; margin-top: 3px; }

.bottom-nav {
  position: fixed; z-index: 25; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(760px, 100%); height: calc(66px + var(--safe-bottom)); padding: 6px 8px var(--safe-bottom);
  background: rgba(255,255,255,.95); border-top: 1px solid var(--line); backdrop-filter: blur(16px);
  display: grid; grid-template-columns: repeat(4, 1fr); box-shadow: 0 -8px 24px rgba(15,23,42,.06);
}
.nav-btn { border: 0; background: transparent; color: #64748b; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10px; font-weight: 800; }
.nav-btn b { font-size: 20px; line-height: 1; }
.nav-btn.active { background: #fff1f2; color: var(--brand); }

.back-row { display: flex; gap: 9px; margin-bottom: 12px; }
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 14px; min-height: 42px; padding: 10px 13px; font-weight: 800; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.btn.primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.btn.gold { border-color: #f59e0b; background: #f59e0b; color: #422006; }
.btn.danger { border-color: #fecaca; background: #fff1f2; color: #b91c1c; }
.btn.ghost { background: transparent; }
.btn.icon { width: 42px; padding: 0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.race-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; background: #e2e8f0; padding: 5px; border-radius: 16px; margin: 12px 0 14px; }
.race-tab { border: 0; background: transparent; border-radius: 12px; min-height: 42px; font-size: 12px; font-weight: 900; color: #475569; }
.race-tab.active { background: #fff; color: var(--brand); box-shadow: 0 3px 11px rgba(15,23,42,.08); }

.race-toolbar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.race-toolbar::-webkit-scrollbar { display: none; }
.race-toolbar .btn { flex: none; }

.race-status { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.metric { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 11px 10px; text-align: center; }
.metric strong { display: block; font-size: 16px; }
.metric span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }

.boat-layout { display: grid; gap: 14px; align-items: start; }
.boat-wrap { width: min(100%, 520px); margin: 0 auto; }
.boat-canvas { position: relative; width: 100%; padding: 18px 12px 20px; }
.dragon-head { text-align: center; font-size: 48px; line-height: 1; filter: drop-shadow(0 8px 8px rgba(15,23,42,.10)); margin-bottom: -9px; position: relative; z-index: 3; }
.boat-shell {
  position: relative; margin: 0 auto; width: min(92%, 430px); padding: 26px 17px 30px;
  background: linear-gradient(90deg, #7c2d12 0%, #b45309 8%, #f59e0b 15%, #fde68a 50%, #f59e0b 85%, #b45309 92%, #7c2d12 100%);
  border: 3px solid #7c2d12;
  border-radius: 46% 46% 34% 34% / 12% 12% 8% 8%;
  box-shadow: inset 0 0 0 6px rgba(255,255,255,.22), 0 18px 36px rgba(15,23,42,.13);
}
.boat-shell::before, .boat-shell::after { content: ""; position: absolute; left: 50%; transform: translateX(-50%); width: 44%; height: 18px; background: #7c2d12; border-radius: 999px; }
.boat-shell::before { top: -8px; }
.boat-shell::after { bottom: -8px; }
.boat-label { text-align: center; color: #7c2d12; font-size: 10px; font-weight: 1000; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 9px; }
.crew-stack { display: grid; gap: 8px; }
.crew-row { display: grid; grid-template-columns: 1fr 34px 1fr; align-items: stretch; gap: 7px; }
.bank { display: grid; place-items: center; font-size: 9px; font-weight: 1000; color: #7c2d12; }
.seat {
  min-height: 58px; border: 1px solid rgba(124,45,18,.3); background: rgba(255,255,255,.94); border-radius: 15px; padding: 7px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink); box-shadow: 0 4px 12px rgba(124,45,18,.09); text-align: center;
}
.seat.empty { border-style: dashed; color: #64748b; background: rgba(255,255,255,.80); }
.seat .seat-pos { font-size: 9px; font-weight: 1000; color: #9f1239; text-transform: uppercase; letter-spacing: .07em; }
.seat .seat-name { font-size: 11px; font-weight: 900; line-height: 1.1; word-break: break-word; }
.seat .plus { font-size: 16px; line-height: 1; color: #be123c; }
.special-row { margin-bottom: 10px; display: grid; grid-template-columns: 1fr; }
.special-row.stern { margin-top: 10px; margin-bottom: 0; }
.special-row .seat { min-height: 62px; border-color: rgba(159,18,57,.4); }
.boat-tail { text-align: center; font-size: 28px; margin-top: -7px; opacity: .8; }

.subs-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 13px; margin-top: 12px; }
.subs-title { font-size: 11px; font-weight: 1000; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.subs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.subs-grid .seat { min-height: 56px; }

.side-card { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 15px; box-shadow: 0 8px 24px rgba(15,23,42,.04); }
.side-card h3 { margin: 0 0 10px; font-size: 14px; }
.mini-list { display: grid; gap: 7px; }
.mini-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; background: #f8fafc; border-radius: 12px; font-size: 11px; }
.mini-row strong { font-size: 11px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.50); display: flex; align-items: flex-end; justify-content: center; padding-top: 40px; }
.modal { width: min(680px, 100%); max-height: min(88vh, 850px); background: #fff; border-radius: 26px 26px 0 0; box-shadow: 0 -20px 60px rgba(15,23,42,.25); display: flex; flex-direction: column; padding-bottom: var(--safe-bottom); }
.modal-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--line); }
.modal-grab { width: 38px; height: 4px; border-radius: 999px; background: #cbd5e1; margin: 0 auto 12px; }
.modal-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.modal p { margin: 4px 0 0; font-size: 11px; color: var(--muted); }
.modal-body { padding: 12px 14px 16px; overflow: auto; }
.search { width: 100%; height: 46px; border: 1px solid var(--line); border-radius: 14px; padding: 0 13px; background: #f8fafc; }
.athlete-options { display: grid; gap: 7px; margin-top: 10px; }
.athlete-option { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 11px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; }
.athlete-option:active { background: #f8fafc; }
.athlete-name { font-size: 13px; font-weight: 850; }
.athlete-meta { font-size: 10px; color: var(--muted); margin-top: 2px; }
.option-tag { flex: none; background: #f1f5f9; color: #475569; border-radius: 999px; padding: 4px 7px; font-size: 9px; font-weight: 900; }
.option-tag.used { background: #fff1f2; color: var(--brand); }
.clear-option { border-color: #fecaca; background: #fff1f2; color: #b91c1c; }

.list-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.list-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-main { min-width: 0; }
.list-main strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-main span { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; }
.list-side { display: flex; align-items: center; gap: 7px; }
.count-pill { min-width: 33px; height: 28px; padding: 0 8px; border-radius: 999px; background: #f1f5f9; display: grid; place-items: center; font-size: 10px; font-weight: 900; }

.form-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: 11px; color: #475569; font-weight: 900; }
.field input, .field select { width: 100%; height: 44px; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 0 12px; }

.summary-group { margin-bottom: 14px; }
.summary-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 2px 8px; }
.summary-head h3 { margin: 0; font-size: 15px; }
.summary-races { display: grid; gap: 8px; }
.summary-race { border: 1px solid var(--line); background: #fff; border-radius: 15px; padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.summary-race strong { display: block; font-size: 12px; }
.summary-race span { color: var(--muted); font-size: 10px; margin-top: 3px; display: block; }

.settings-grid { display: grid; gap: 12px; }
.settings-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 15px; }
.settings-card h3 { margin: 0 0 5px; font-size: 14px; }
.settings-card p { margin: 0 0 12px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(82px + var(--safe-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #0f172a; color: #fff; border-radius: 999px; padding: 10px 14px; font-size: 11px; font-weight: 800; box-shadow: 0 10px 30px rgba(15,23,42,.24); transition: .2s ease; white-space: nowrap; max-width: calc(100% - 28px); overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.empty-state { text-align: center; padding: 30px 18px; color: var(--muted); }
.empty-state b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 5px; }

@media (min-width: 700px) {
  .main { padding-top: 24px; }
  .boat-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-actions { grid-template-columns: repeat(4, 1fr); }
  .boat-layout { grid-template-columns: minmax(430px, 540px) minmax(250px, 1fr); justify-content: center; }
  .boat-wrap { margin: 0; }
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 26px; max-height: 82vh; }
  .modal-grab { display: none; }
}

@media (min-width: 1000px) {
  .boat-grid { grid-template-columns: repeat(3, 1fr); }
  .hero { padding: 30px; }
}

@media print {
  .topbar, .bottom-nav, .back-row, .race-tabs, .race-toolbar, .toast { display: none !important; }
  .app-shell { padding: 0; }
  .main { width: 100%; padding: 0; }
  .boat-layout { grid-template-columns: 1fr 320px; }
  .boat-shell { box-shadow: none; }
  body { background: white; }
}
