:root {
  color-scheme: light;
  --bg: #f7f7fb;
  --panel: #ffffff;
  --ink: #151820;
  --muted: #667085;
  --line: #d9dee8;
  --primary: #e22f2f;
  --primary-dark: #b91f28;
  --accent: #0c7c59;
  --gold: #f2b705;
  --shadow: 0 12px 32px rgba(22, 26, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(247, 247, 251, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(217, 222, 232, 0.8);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
}

h2 {
  font-size: 22px;
  margin-bottom: 14px;
}

h3 {
  font-size: 16px;
  margin-bottom: 10px;
}

.app-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 16px 14px 96px;
}

.grid {
  display: grid;
  gap: 12px;
}

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

.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.card {
  padding: 14px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.search-picker {
  position: relative;
}

.picker-results {
  position: absolute;
  top: calc(100% - 4px);
  right: 0;
  left: 0;
  z-index: 18;
  display: grid;
  max-height: 274px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.picker-results:empty {
  display: none;
}

.picker-results button,
.picker-empty {
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #edf0f5;
  background: #fff;
  color: var(--ink);
  text-align: left;
  font-weight: 800;
}

.picker-results button:last-child {
  border-bottom: 0;
}

.picker-results button:active,
.picker-results button:hover {
  background: #f5f7fb;
}

.picker-empty {
  color: var(--muted);
  font-weight: 700;
}

.segmented,
.rank-grid {
  display: grid;
  gap: 8px;
}

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

.segmented button,
.rank-grid button,
.primary,
.secondary,
.chip {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.segmented button.active,
.rank-grid button.active,
.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.primary {
  width: 100%;
  min-height: 52px;
  font-size: 16px;
}

.secondary {
  background: #f5f7fb;
}

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

.rank-grid button {
  aspect-ratio: 1;
  font-size: 20px;
}

.sticky-submit {
  position: sticky;
  bottom: 72px;
  z-index: 6;
  padding-top: 6px;
  background: linear-gradient(rgba(247, 247, 251, 0), var(--bg) 34%);
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.bottom-nav button,
.icon-button {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.bottom-nav button {
  min-height: 48px;
  font-size: 13px;
}

.bottom-nav button.active {
  background: #191c24;
  color: #fff;
}

.icon-button {
  width: 44px;
  height: 44px;
  font-size: 24px;
}

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

.stat {
  padding: 14px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.stat b {
  display: block;
  font-size: 24px;
}

.stat span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.race-row {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 10px;
  align-items: start;
}

.placement {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: #191c24;
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.course-name {
  margin-bottom: 4px;
  font-weight: 900;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.note-preview {
  margin: 7px 0 0;
  color: #364152;
  font-size: 13px;
}

.table-list {
  display: grid;
  gap: 8px;
}

.bar-list {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 1fr 68px;
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0f5;
}

.bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.filters {
  display: grid;
  gap: 10px;
}

.course-picker {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 3px;
}

.tabs button,
.chip {
  white-space: nowrap;
  padding: 8px 12px;
}

.tabs button.active,
.chip.active {
  background: #191c24;
  border-color: #191c24;
  color: #fff;
}

.empty-state {
  padding: 32px 16px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 84px;
  z-index: 30;
  padding: 13px 14px;
  border-radius: 8px;
  background: #191c24;
  color: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.mini-chart {
  width: 100%;
  height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

@media (min-width: 760px) {
  .app-shell {
    padding-bottom: 32px;
  }

  .grid.two,
  .course-picker {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .bottom-nav {
    right: 24px;
    bottom: 20px;
    left: 24px;
    width: min(680px, calc(100% - 48px));
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }

  .sticky-submit {
    bottom: 0;
  }

  .stat-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
