:root {
  --bg: #142016;
  --bg-2: #1c2a1d;
  --ink: #f3ead7;
  --muted: #b7c2a8;
  --line: #3a4a34;
  --gold: #c4a35a;
  --gold-ink: #1a1408;
  --turf: #2f6b3a;
  --dirt: #8a5a32;
  --jump: #4a5d7a;
  --card: #f6f0e4;
  --card-ink: #1c1810;
  --card-muted: #6b6458;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --dock-h: calc(4.75rem + var(--safe-bottom));
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 var(--dock-h);
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
  background:
    radial-gradient(120% 60% at 100% -10%, #2a3d22 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
}

.app-header {
  padding: 1.1rem 1.1rem 0.4rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.28em;
  color: var(--gold);
}

h1 {
  margin: 0.2rem 0 0;
  font-family: "Zen Old Mincho", serif;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.lede {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.header-cta {
  display: block;
  width: 100%;
  margin-top: 0.85rem;
  min-height: 2.85rem;
  padding: 0.7rem 1rem;
  border-radius: 0.9rem;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
}

main {
  padding: 0.4rem 1.1rem 1.25rem;
}

fieldset {
  margin: 0.85rem 0 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 0.45rem;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chips-venues {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.4rem;
}

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

.chip {
  min-height: 2.6rem;
  padding: 0 0.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--ink);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.chip-wide {
  border-radius: 0.7rem;
}

.chips-venues .chip {
  border-radius: 0.7rem;
  padding: 0;
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.results-panel {
  margin-top: 1.25rem;
}

.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.65rem;
}

.results-head h2 {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 500;
}

#status {
  margin: 0;
  color: var(--gold);
  font-size: 0.82rem;
}

#results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.7rem;
}

#results li {
  display: contents;
}

.ticket {
  display: grid;
  gap: 0.35rem;
  width: 100%;
  padding: 0.9rem 0.95rem;
  border: 0;
  border-radius: 0.9rem;
  background: var(--card);
  color: var(--card-ink);
  text-align: left;
  text-decoration: none;
  font: inherit;
  appearance: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button.ticket:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.ticket-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
}

.ticket-date {
  font-family: "Zen Old Mincho", serif;
  font-size: 1.02rem;
  font-weight: 700;
}

.ticket-time {
  color: var(--card-muted);
  font-size: 0.82rem;
}

.ticket-place {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ticket-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.45rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #e4ddd0;
}

.pill-turf {
  background: #d7ead8;
  color: #1c4a24;
}

.pill-dirt {
  background: #ead9c8;
  color: #5a3518;
}

.pill-jump {
  background: #d7dfea;
  color: #24344a;
}

.pill-prediction {
  background: var(--gold);
  color: var(--gold-ink);
}

.ticket-name {
  margin: 0.15rem 0 0;
  color: var(--card-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.empty {
  padding: 1.4rem 0.4rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.92rem;
}

.dock {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 5.6rem 1fr;
  gap: 0.5rem;
  padding: 0.7rem 1.1rem calc(0.7rem + var(--safe-bottom));
  background: linear-gradient(180deg, transparent, #142016 28%);
}

.btn-ghost,
.btn-primary {
  min-height: 3.05rem;
  border: 0;
  font: inherit;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}

.btn-ghost {
  border-radius: 0.9rem;
  background: var(--bg-2);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-primary {
  border-radius: 0.9rem;
  background: var(--gold);
  color: var(--gold-ink);
}

@media (min-width: 720px) {
  body {
    max-width: 430px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .dock {
    right: auto;
    left: auto;
    width: 430px;
  }
}

body[data-view="detail"] .dock {
  grid-template-columns: 1fr;
}

#detail-view {
  margin-top: 0.4rem;
}

#detail-status:empty {
  display: none;
}

#detail-status {
  margin: 0 0 0.8rem;
  color: var(--gold);
}

.detail-head h2 {
  margin: 0.15rem 0 0;
  font-family: "Zen Old Mincho", serif;
  font-size: 1.5rem;
}

.detail-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.detail-title {
  margin: 0.2rem 0 0.55rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.table-wrap {
  margin-top: 1rem;
  overflow-x: auto;
  border-radius: 0.8rem;
  background: var(--card);
}

.entries {
  width: 100%;
  border-collapse: collapse;
  color: var(--card-ink);
  font-size: 0.78rem;
}

.entries th,
.entries td {
  padding: 0.55rem 0.45rem;
  text-align: right;
  white-space: nowrap;
}

.entries thead th {
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  color: var(--card-muted);
  font-weight: 500;
  text-align: right;
}

.entries .horse {
  text-align: left;
  font-weight: 700;
}

.horse-link {
  border: 0;
  padding: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 0.16em;
  cursor: pointer;
}

.btn-inline {
  margin-top: 0.75rem;
  min-height: 2.6rem;
  padding: 0 0.9rem;
  border: 0;
  border-radius: 0.7rem;
  background: var(--gold);
  color: var(--gold-ink);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.detail-head .pill {
  background: #e4ddd0;
  color: #1c1810;
}

.entries tr.clickable {
  cursor: pointer;
}

.entries tbody tr + tr {
  border-top: 1px solid #e4ddd0;
}

.payout-head {
  margin: 1.2rem 0 0.45rem;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 500;
}

.payouts {
  display: grid;
  grid-template-columns: 6.2rem 1fr;
  gap: 0.35rem 0.7rem;
  margin: 0;
}

.payouts dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.payouts dd {
  margin: 0;
  font-size: 0.84rem;
}

.predictions-section {
  margin-top: 1rem;
}

.predictions-head {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.predictions-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
  word-break: break-all;
}

.predictions-chips {
  margin-top: 0.55rem;
}

.predictions-chip[aria-selected="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.predictions-chip.chip-adopted {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold);
}

.predictions-chip.chip-adopted[aria-selected="true"] {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--gold-ink);
  box-shadow: none;
}

.predictions-table-wrap {
  margin-top: 0.55rem;
}

.predictions-empty {
  padding: 1rem 0.4rem;
}

.predictions-rank,
.predictions-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.predictions-factors {
  margin-top: 0.25rem;
  font-weight: 400;
  font-size: 0.68rem;
  line-height: 1.35;
}

.predictions-factors summary {
  cursor: pointer;
  color: var(--muted);
  list-style: none;
}

.predictions-factors summary::-webkit-details-marker {
  display: none;
}

.predictions-factors summary::before {
  content: "▸ ";
}

.predictions-factors[open] summary::before {
  content: "▾ ";
}

.predictions-factor-list {
  margin: 0.2rem 0 0;
  padding: 0;
  list-style: none;
}

.predictions-factor-list li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.predictions-factor-up {
  color: #2f6b3a;
}

.predictions-factor-down {
  color: #8b3a3a;
}

.predictions-adopted-row {
  background: #f0ead8;
}
