:root {
  --ink: #15231f;
  --muted: #64736e;
  --paper: #f5f1e8;
  --card: #fffdf8;
  --green: #12382d;
  --green-2: #1d5847;
  --mint: #d9ebe2;
  --gold: #d7a93f;
  --line: #dcd8ce;
  --danger: #9e382f;
  --shadow: 0 14px 36px rgb(18 56 45 / 9%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Yu Gothic UI", "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 90% -5%, rgb(215 169 63 / 22%), transparent 22rem),
    linear-gradient(180deg, #f9f6ef 0, var(--paper) 35rem);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  min-height: 48px;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.site-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  color: #fff;
  background: var(--green);
  border-bottom: 3px solid var(--gold);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-weight: 800;
  letter-spacing: .02em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--green);
  background: var(--gold);
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 900;
}

.busy-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgb(255 255 255 / 40%);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.app-shell {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}

.hero {
  padding: 38px 6px 28px;
}

.hero h1,
.completion-hero h1 {
  margin: 5px 0 12px;
  color: var(--green);
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(42px, 13vw, 68px);
  line-height: .98;
  letter-spacing: -.045em;
}

.hero h1 em {
  color: var(--green-2);
  font-weight: 400;
}

.hero > p:last-child,
.completion-hero > p:last-child {
  max-width: 34rem;
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

.eyebrow {
  margin: 0;
  color: var(--green-2);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .18em;
}

.setup-stack {
  display: grid;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid rgb(21 35 31 / 10%);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.step-card {
  padding: 20px;
}

.step-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.step-heading {
  justify-content: flex-start;
}

.step-heading h2,
.section-heading h2 {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.2;
}

.step-number {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  place-items: center;
  color: #fff;
  background: var(--green);
  border-radius: 14px;
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: 700;
}

label {
  display: block;
  margin: 0 0 7px;
  font-size: 14px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 50px;
  padding: 11px 13px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bbb9b1;
  border-radius: 11px;
}

input::placeholder {
  color: #989c98;
}

.input-block {
  display: grid;
  gap: 10px;
}

.hint {
  margin: -3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.field-error {
  margin: 6px 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.participant-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 13px;
}

.chip {
  min-width: 44px;
  padding: 7px 11px;
  color: var(--green);
  background: var(--mint);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0;
  color: var(--muted);
  font-size: 12px;
}

.divider::before,
.divider::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.manual-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 850;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.button:not(:disabled):active {
  transform: translateY(1px);
}

.button:disabled {
  color: #9b9e9b;
  background: #e7e5df;
  border-color: #dedbd4;
  box-shadow: none;
}

.button-primary {
  color: #fff;
  background: var(--green);
  box-shadow: 0 10px 22px rgb(18 56 45 / 20%);
}

.button-secondary {
  color: var(--green);
  background: #fff;
  border-color: #9eb5ac;
}

.button-ghost {
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}

.button-danger {
  color: #fff;
  background: var(--danger);
}

.button-full {
  width: 100%;
}

.start-button {
  min-height: 60px;
  margin-top: 4px;
  font-size: 17px;
}

.race-summary,
.order-list {
  margin-top: 16px;
  padding: 14px;
  background: #f1f4f0;
  border-radius: 12px;
}

.race-summary-title {
  margin: 0 0 10px;
  font-weight: 850;
}

.mini-horse-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-horse {
  padding: 5px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 12px;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.order-list:not(.empty-state) {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}

.order-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 8px 10px;
  background: #f1f4f0;
  border-radius: 10px;
  font-weight: 800;
}

.order-rank {
  color: var(--green-2);
  font-family: Georgia, serif;
  font-size: 18px;
}

.notice {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 0;
  padding: 13px 14px;
  color: #fff;
  background: var(--green-2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.5;
}

.notice.error {
  background: var(--danger);
}

.icon-button {
  min-width: 44px;
  min-height: 44px;
  margin: -10px -10px -10px 0;
  color: inherit;
  background: transparent;
  border: 0;
  font-size: 24px;
}

.turn-banner {
  position: sticky;
  z-index: 10;
  top: 0;
  margin: 0 -16px 28px;
  padding: 24px 20px 20px;
  color: #fff;
  background:
    radial-gradient(circle at 85% 15%, rgb(215 169 63 / 25%), transparent 9rem),
    var(--green);
  border-bottom: 3px solid var(--gold);
  text-align: center;
  box-shadow: 0 10px 24px rgb(18 56 45 / 18%);
}

.turn-banner .eyebrow {
  color: #c8e2d6;
}

.turn-label {
  margin: 9px 0 -4px;
  font-size: 13px;
}

.turn-banner h1 {
  margin: 0;
  font-family: Georgia, "Yu Mincho", serif;
  font-size: 45px;
}

.turn-banner #progress-label {
  margin: 7px 0 0;
  color: #d8e4df;
  font-size: 13px;
}

.content-section {
  margin: 0 0 24px;
}

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

.horse-button {
  position: relative;
  min-height: 92px;
  padding: 12px 9px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid #aebbb6;
  border-radius: 14px;
  box-shadow: 0 5px 14px rgb(18 56 45 / 7%);
  text-align: left;
}

.horse-button:not(:disabled):hover {
  border-color: var(--green);
}

.horse-button:disabled {
  color: #727772;
  background: #dedfdc;
  border-color: #c6c8c4;
  box-shadow: none;
}

.horse-number {
  display: block;
  color: var(--green);
  font-family: Georgia, serif;
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}

.horse-button:disabled .horse-number {
  color: #6f746f;
}

.horse-name {
  display: block;
  margin-top: 7px;
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picked-by {
  display: block;
  margin-top: 5px;
  font-size: 10px;
  font-weight: 850;
}

.results-card {
  padding: 20px;
}

.results-list {
  display: grid;
  gap: 10px;
}

.participant-result {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  min-height: 58px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.participant-result:first-child {
  border-top: 0;
}

.participant-avatar {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  color: #fff;
  background: var(--green);
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 20px;
  font-weight: 900;
}

.result-owner {
  margin: 0 0 5px;
  font-size: 13px;
  font-weight: 850;
}

.result-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.result-pick {
  padding: 5px 8px;
  color: var(--ink);
  background: #f0f2ee;
  border-radius: 7px;
}

.action-stack {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.completion-hero {
  padding: 42px 4px 30px;
  text-align: center;
}

.completion-hero h1 {
  font-size: clamp(38px, 12vw, 58px);
}

.completion-hero > p:last-child {
  margin-inline: auto;
}

.finish-mark {
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  place-items: center;
  color: var(--green);
  background: var(--gold);
  border-radius: 50%;
  font-size: 30px;
  font-weight: 900;
  box-shadow: 0 10px 25px rgb(215 169 63 / 28%);
}

.confirm-dialog {
  width: min(calc(100% - 32px), 420px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  box-shadow: 0 30px 70px rgb(0 0 0 / 30%);
}

.confirm-dialog::backdrop {
  background: rgb(7 22 17 / 65%);
}

.confirm-dialog form {
  padding: 24px;
}

.confirm-dialog h2 {
  margin: 5px 0 10px;
}

.confirm-dialog p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.7;
}

.dialog-actions {
  display: grid;
  gap: 9px;
  margin-top: 22px;
}

.busy-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  background: rgb(245 241 232 / 34%);
  cursor: wait;
}

[hidden] {
  display: none !important;
}

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

@media (min-width: 560px) {
  .horse-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .dialog-actions {
    grid-template-columns: 1fr 1.45fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
