:root {
  --bg: #eef5f1;
  --paper: #f7fbf8;
  --card: #ffffff;
  --ink: #143225;
  --muted: #62746a;
  --line: #dbe8df;
  --accent: #c2413b;
  --blue: #2d62b7;
  --green: #137a4a;
  --gold: #b98212;
  --shadow: 0 8px 24px rgba(20, 50, 37, 0.08);
  --radius: 8px;
  --card-radius: 14px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding-bottom: 82px;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 10px max(16px, calc((100vw - 1120px) / 2));
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.header-action,
.text-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--green);
  padding: 9px 12px;
  font-weight: 800;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.bottom-nav button {
  display: grid;
  place-items: center;
  gap: 2px;
  min-width: 0;
  min-height: 50px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.bottom-nav span {
  font-size: 18px;
  line-height: 1;
}

.bottom-nav button.is-active {
  background: #e5f3eb;
  color: var(--green);
}

.nav-icon {
  position: relative;
  display: inline-block;
  width: 21px;
  height: 21px;
  color: currentColor;
}

.nav-icon::before,
.nav-icon::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
}

.nav-home::before {
  inset: 6px 4px 3px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 2px;
}

.nav-home::after {
  left: 4px;
  top: 3px;
  width: 13px;
  height: 13px;
  border-left: 2px solid currentColor;
  border-top: 2px solid currentColor;
  transform: rotate(45deg);
}

.nav-calendar::before {
  inset: 3px 3px 2px;
  border: 2px solid currentColor;
  border-radius: 4px;
}

.nav-calendar::after {
  left: 6px;
  right: 6px;
  top: 8px;
  border-top: 2px solid currentColor;
  box-shadow: -2px 5px 0 -1px currentColor, 4px 5px 0 -1px currentColor;
}

.nav-rank::before {
  left: 3px;
  right: 3px;
  bottom: 3px;
  height: 12px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 2px;
}

.nav-rank::after {
  left: 8px;
  top: 2px;
  width: 5px;
  height: 16px;
  background: currentColor;
  box-shadow: -6px 5px 0 -1px currentColor, 6px 3px 0 -1px currentColor;
}

.nav-horse::before {
  left: 5px;
  top: 3px;
  width: 11px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 8px 8px 5px 5px;
}

.nav-horse::after {
  left: 8px;
  top: 8px;
  width: 2px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 5px 0 0 currentColor, 2px 6px 0 currentColor;
}

.nav-more::before {
  left: 4px;
  top: 9px;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 6px 0 0 currentColor, 12px 0 0 currentColor;
}

.page-title {
  margin: 10px 0 16px;
}

.page-title h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.page-title p {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.update-banner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  margin: 0 0 14px;
  border: 1px solid #f2c6cd;
  border-left: 5px solid var(--accent);
  border-radius: var(--card-radius);
  background: #fff;
  padding: 12px;
  text-align: left;
}

.update-banner span {
  color: var(--accent);
  font-weight: 900;
}

.summary-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid #cfe0d4;
  border-radius: var(--card-radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.summary-card h1 {
  margin: 0;
  max-width: 720px;
  font-size: 22px;
  line-height: 1.35;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 92px);
  gap: 8px;
  margin: 0;
}

.summary-stats div {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 8px;
  text-align: center;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

dd {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 900;
}

.note-strip,
.panel,
.filter-panel,
.owner-group,
.article-card,
.loading-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.note-strip {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  padding: 12px 14px;
}

.note-strip span {
  color: var(--green);
  font-weight: 900;
}

.note-strip p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

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

.quick-tile {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "icon title" "icon sub";
  gap: 2px 10px;
  align-items: center;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  background: #fff;
  color: var(--ink);
  padding: 12px;
  text-align: left;
  box-shadow: var(--shadow);
}

.quick-tile .nav-icon {
  grid-area: icon;
  color: var(--green);
}

.quick-tile strong {
  grid-area: title;
  font-size: 15px;
}

.quick-tile small {
  grid-area: sub;
  color: var(--muted);
  font-weight: 800;
}

.panel,
.filter-panel,
.owner-group,
.loading-card,
.empty-state {
  margin-bottom: 18px;
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2,
.panel h2,
.owner-group h2 {
  margin: 0;
  font-size: 20px;
}

.top-featured,
.rank-mini,
.horse-list,
.more-grid {
  display: grid;
  gap: 12px;
}

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

.featured-card,
.rank-mini article,
.horse-card,
.more-card,
.award-card,
.podium-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.featured-card p,
.featured-card small,
.horse-card small,
.award-card small,
.article-card p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.featured-card p,
.featured-card h3,
.horse-card h3,
.award-card h3 {
  margin: 0 0 8px;
}

.featured-entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.featured-entry em {
  grid-column: 1 / -1;
  color: var(--accent);
  font-style: normal;
  font-weight: 900;
}

.grade {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  vertical-align: middle;
}

.grade-g1 { background: #dc2626; }
.grade-g2 { background: #2563eb; }
.grade-g3 { background: #16a34a; }
.grade-listed { background: #7c3aed; }
.grade-other { background: #64748b; }

.owner-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  border: 1px solid color-mix(in srgb, var(--owner-color), #fff 45%);
  border-radius: 999px;
  background: color-mix(in srgb, var(--owner-color), #fff 88%);
  color: var(--owner-color);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 900;
}

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

.rank-mini article {
  display: grid;
  gap: 6px;
}

.rank-mini span,
.horse-card span,
.award-card p {
  color: var(--accent);
  font-weight: 900;
}

.rank-mini b,
.podium-card strong,
.award-card strong {
  color: var(--green);
  font-size: 24px;
}

.filter-panel {
  display: grid;
  gap: 12px;
}

.timeline-filter {
  position: sticky;
  top: 66px;
  z-index: 12;
}

.page-title-with-nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
}

.week-nav {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  background: #fff;
  padding: 8px;
  box-shadow: var(--shadow);
}

.week-nav button {
  min-width: 36px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eff7f2;
  color: var(--green);
  font-weight: 900;
}

.week-nav button:disabled {
  cursor: default;
  opacity: .38;
}

.week-nav .latest-button {
  padding: 0 12px;
}

.week-nav strong,
.week-nav span {
  display: block;
}

.week-nav strong {
  font-size: 13px;
}

.week-nav span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.owner-chip {
  min-height: 36px;
  border: 1px solid color-mix(in srgb, var(--owner-color, #137a4a), #fff 48%);
  border-radius: 999px;
  background: color-mix(in srgb, var(--owner-color, #137a4a), #fff 91%);
  color: var(--owner-color, var(--green));
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 900;
}

.owner-chip.is-active {
  background: var(--owner-color, var(--green));
  color: #fff;
}

.search-info {
  margin: 0;
  border-radius: 10px;
  background: #edf7f1;
  color: var(--green);
  padding: 9px 11px;
  font-weight: 900;
}

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

.segmented button,
.control-row select,
.control-row input,
.check {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 9px 10px;
  font-weight: 800;
}

.segmented button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 8px;
}

.timeline-controls {
  grid-template-columns: minmax(220px, 1fr) auto;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.date-section {
  margin-bottom: 18px;
}

.date-section > h2 {
  position: sticky;
  top: 65px;
  z-index: 10;
  margin: 0 0 10px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px 12px;
  font-size: 18px;
}

.race-group {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.race-group-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.race-group-head p,
.race-group-head h3 {
  margin: 0;
}

.race-group-head p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.race-group-head h3 {
  margin-top: 5px;
  font-size: 20px;
}

.race-type {
  align-self: flex-start;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.entry-list {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.entry-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

.entry-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.entry-card h4 {
  margin: 0;
  font-size: 20px;
}

.entry-card p {
  margin: 4px 0 8px;
  color: var(--muted);
  font-weight: 700;
}

.entry-result {
  min-width: 104px;
  border-radius: var(--radius);
  padding: 9px 10px;
  text-align: center;
}

.entry-result strong,
.entry-result span {
  display: block;
}

.entry-result strong {
  font-size: 18px;
}

.entry-card.is-result .entry-result {
  background: #fff7ed;
  color: #9a3412;
}

.entry-card.is-scheduled .entry-result {
  background: #eff6ff;
  color: #1d4ed8;
}

.entry-card.is-win {
  border-color: #ebc65d;
  background: #fffdf5;
}

.entry-card.is-win .entry-result {
  background: #fff3bf;
  color: #7a4d00;
}

.entry-card.is-good .entry-result {
  background: #e7f6ee;
  color: var(--green);
}

.entry-card.is-board .entry-result {
  background: #f4f6f5;
  color: var(--muted);
}

.result-badge {
  width: fit-content;
  margin: 5px auto 0;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 900;
}

.result-badge.is-win {
  background: #b98212;
  color: #fff;
}

.result-badge.is-good {
  background: var(--green);
  color: #fff;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 0;
}

.result-grid div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
}

.ai-review {
  margin: 12px 0 0;
  border-left: 4px solid var(--green);
  background: #f0fdfa;
  padding: 10px;
}

.ai-review span {
  display: block;
  margin-bottom: 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.ai-review p {
  margin: 0;
}

.reaction-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-weight: 900;
}

.reaction-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 4px 9px;
}

.race-link {
  display: inline-flex;
  margin-top: 12px;
  border-bottom: 2px solid var(--blue);
  color: var(--blue);
  font-weight: 900;
}

.podium,
.award-scroll {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.podium-card {
  display: grid;
  gap: 8px;
  min-height: 180px;
}

.podium-card h3 {
  margin: 0;
  font-size: 22px;
}

.podium-card em {
  color: var(--muted);
  font-style: normal;
  font-weight: 900;
}

.rank-badge {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--owner-color, var(--green)), #fff 82%);
  color: var(--owner-color, var(--green));
  font-size: 14px;
  font-weight: 900;
}

.rank-1 .rank-badge {
  background: #f4c542;
  color: #533800;
}

.rank-2 .rank-badge {
  background: #d7dee3;
  color: #38434b;
}

.rank-3 .rank-badge {
  background: #dda675;
  color: #542c0d;
}

.point-bar,
.mini-point-bar {
  display: block;
  overflow: hidden;
  border-radius: 999px;
  background: #edf2ef;
}

.point-bar {
  height: 8px;
}

.point-bar i,
.mini-point-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--owner-color, var(--green));
}

.mini-point-bar {
  height: 6px;
}

.rank-table {
  display: grid;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.rank-table div {
  display: grid;
  grid-template-columns: 42px 1fr 140px 100px 90px;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.rank-table div:first-child {
  border-top: 0;
}

.horse-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.owner-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 12px;
  background: color-mix(in srgb, var(--owner-color), #fff 91%);
  color: var(--owner-color);
  padding: 12px 14px;
  text-align: left;
  font-weight: 900;
}

.owner-group-toggle::after {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform .15s ease;
}

.owner-group-toggle[aria-expanded="false"]::after {
  transform: rotate(-45deg);
}

.owner-group-toggle:disabled {
  cursor: default;
}

.owner-group-toggle strong {
  margin-left: auto;
  font-size: 13px;
}

.owner-group .horse-list {
  margin-top: 12px;
}

.horse-card {
  display: grid;
  gap: 6px;
  min-height: 126px;
}

.horse-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.horse-card h3 {
  margin: 0;
  font-size: 18px;
}

.horse-card p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.horse-card small {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sex-badge {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
}

.sex-male {
  background: #e8f0ff;
  color: #234f9d;
}

.sex-female {
  background: #fdebf3;
  color: #b51f65;
}

.sex-gelding,
.sex-none {
  background: #eef1ef;
  color: var(--muted);
}

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

.more-card {
  min-height: 92px;
  text-align: left;
}

.more-card strong,
.more-card span {
  display: block;
}

.more-card strong {
  font-size: 18px;
}

.more-card span {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 700;
}

.site-updated,
.guestbook-note {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 800;
}

.draft-round {
  margin-bottom: 16px;
}

.draft-round > div {
  display: grid;
  grid-template-columns: 42px auto 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  border-top: 1px solid var(--line);
  padding: 8px 0;
}

.article-list {
  display: grid;
  gap: 12px;
}

.article-card {
  padding: 16px;
}

.article-card h2 {
  margin: 0 0 10px;
}

.article-card div {
  white-space: pre-wrap;
  line-height: 1.75;
}

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

.rule-grid article {
  min-height: 110px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.rule-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.rule-grid strong {
  display: block;
  margin-top: 8px;
  line-height: 1.5;
}

.empty-state,
.loading-card {
  text-align: center;
}

@media (max-width: 780px) {
  .app-shell {
    padding: 14px 12px 24px;
  }

  .summary-card,
  .note-strip,
  .page-title-with-nav,
  .entry-main {
    grid-template-columns: 1fr;
  }

  .summary-stats,
  .top-featured,
  .rank-mini,
  .podium,
  .award-scroll,
  .horse-list,
  .more-grid,
  .rule-grid,
  .quick-grid {
    grid-template-columns: 1fr;
  }

  .control-row {
    grid-template-columns: 1fr;
  }

  .timeline-controls {
    grid-template-columns: 1fr;
  }

  .timeline-filter {
    top: 61px;
  }

  .week-nav {
    grid-template-columns: auto 1fr auto;
  }

  .week-nav .latest-button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .entry-result {
    width: 100%;
    text-align: left;
  }

  .result-badge {
    margin-left: 0;
  }

  .rank-table div {
    grid-template-columns: 48px 1fr;
  }

  .rank-table b,
  .rank-table small,
  .mini-point-bar {
    grid-column: 2;
  }

  .draft-round > div {
    grid-template-columns: 32px 1fr;
  }

  .draft-round small {
    grid-column: 2;
  }
}
