:root {
  --ink: #241c14;
  --ink-soft: #4a3f32;
  --paper: #f4eadb;
  --paper-2: #fffaf3;
  --wood: #2c2118;
  --moss: #1e4632;
  --moss-2: #2f6b4c;
  --gold: #6d4a0e;
  --gold-bg: #f6e2b3;
  --rose: #7d2e40;
  --line: #e3d3bd;
  --shadow: 0 12px 30px rgba(48, 32, 16, 0.08);
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.7), transparent 36%),
    var(--paper);
}

button, input { font: inherit; color: inherit; }

button {
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid var(--ink);
  background: var(--paper-2);
  cursor: pointer;
  touch-action: manipulation;
}

button.primary, .primary {
  background: var(--moss);
  color: #f4fff8;
  border-color: #10281c;
}

button:disabled {
  background: #e4d9c8;
  color: #4a4338;
  border-color: #cbbba6;
  cursor: not-allowed;
}

button:focus-visible, a:focus-visible {
  outline: 3px solid #1f4a34;
  outline-offset: 2px;
}

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

#app {
  max-width: 1120px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 12px;
  background: var(--wood);
  color: #fff8ee;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

.brand-text {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  letter-spacing: 0.01em;
}

.logo { width: 28px; height: 28px; }

.badges { display: flex; gap: 8px; }

.badge {
  background: var(--gold-bg);
  color: var(--gold);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 0.92rem;
}

.badge.ribbon {
  background: #f8d5dc;
  color: var(--rose);
}

header button {
  background: transparent;
  color: #fff8ee;
  border-color: rgba(255, 248, 238, 0.7);
  min-height: 44px;
}

#screen {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.page { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--paper-2);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
}

h1, h2, h3 {
  font-family: var(--serif);
  line-height: 1.15;
  margin: 0 0 8px;
}

.lede { margin: 0; color: var(--ink-soft); }

.preview {
  width: 100%;
  height: 240px;
  border-radius: 18px;
  display: block;
  background: #e7c9a0;
}

.horse-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.horse-nav h2 { margin: 0; }

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  background: #e7f3ea;
  color: #1e4632;
}

.pill.spirited { background: #ffe0cc; color: #7a2e12; }
.pill.brave { background: #d9e6ff; color: #1d3f73; }
.pill.spooky { background: #ece4ff; color: #3d2f66; }
.pill.stubborn { background: #f3e2c4; color: #5c3b16; }
.pill.calm { background: #d5efe3; color: #1e4d3a; }

.meter {
  display: grid;
  grid-template-columns: 5.2rem 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}

.bar, .meter-track {
  height: 14px;
  background: #efe4d4;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #ddcbb3;
}

.bar-fill, #ext-fill {
  height: 100%;
  background: linear-gradient(90deg, #2f6b4c, #d7a441);
  width: 0%;
}

.stats { display: flex; flex-direction: column; gap: 8px; }

.stat {
  display: grid;
  grid-template-columns: 4.8rem 1fr 2.4rem auto;
  gap: 6px;
  align-items: center;
}

.actions, .dialog-actions, .split {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions button, .split button, .dialog-actions button { flex: 1 1 140px; }

.welcome {
  background: #fff4d8;
  border: 2px solid #e3c27a;
  border-radius: 18px;
  padding: 12px 14px;
}

.list { display: flex; flex-direction: column; gap: 12px; }

.course {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.course p { margin: 0; }

.locked { opacity: 1; }

.fine {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.quiet {
  background: transparent;
  border-color: transparent;
  text-decoration: underline;
  min-height: 44px;
}

.tack-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tack-cats button {
  flex: 1 1 7.2rem;
}

.tack-cats button[aria-pressed="true"] {
  background: var(--moss);
  color: #f4fff8;
  border-color: #10281c;
}

.tack-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.tack-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.tack-row:last-child { border-bottom: 0; }

.tack-copy { flex: 1; min-width: 0; }
.tack-copy p { margin: 2px 0 0; }
.tack-row button { flex: 0 0 auto; }

.swatch {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  flex: none;
}

.ride {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 180px;
  background: #8ec8ee;
  border-radius: 16px;
  overflow: hidden;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  top: 8px;
  left: 10px;
  right: 92px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  pointer-events: none;
  color: #241c14;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
  font-weight: 700;
}

.hud p { margin: 0; }

.toast {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 64px;
  z-index: 4;
  text-align: center;
  pointer-events: none;
  background: rgba(255, 250, 243, 0.94);
  color: var(--ink);
  border-radius: 12px;
  padding: 8px 10px;
  font-weight: 650;
}

.pause-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(255, 250, 243, 0.94);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: rgba(36, 28, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: var(--paper-2);
  border-radius: 18px;
  padding: 16px;
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pace {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 0.86rem;
  font-weight: 700;
}

body[data-screen="ride"] #screen {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 8px;
}

.camera-btn, .jump-fab, .rein, .leg-aid {
  touch-action: none;
  user-select: none;
}

.camera-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
  min-width: 76px;
  background: rgba(255, 250, 243, 0.94);
}

.jump-fab {
  position: absolute;
  right: 12px;
  bottom: 148px;
  z-index: 3;
  min-width: 76px;
  background: rgba(255, 250, 243, 0.94);
}

.reins {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 0 10px;
  pointer-events: none;
}

.rein, .leg-aid {
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 84px;
  height: 92px;
  margin: 0;
  border-radius: 22px;
  background: rgba(255, 250, 243, 0.94);
  font-weight: 700;
}

.rein { padding-bottom: 12px; }
.rein.pulled { background: #f6e2b3; }
.leg-aid { width: 76px; height: 76px; margin-bottom: 6px; }
.leg-aid[aria-pressed="true"] {
  background: var(--moss);
  color: #f4fff8;
}

.rein-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.hud { left: 120px; }

.key-hint { display: none; margin: 0; }

dialog {
  border: none;
  border-radius: 18px;
  padding: 18px;
  width: min(480px, calc(100vw - 24px));
  color: var(--ink);
  background: var(--paper-2);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(36, 28, 20, 0.48); }

dialog ul { padding-left: 1.1rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  padding: 16px;
}

@media (max-width: 420px) {
  .badge-word { 
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  .brand-text { font-size: 1.15rem; }
  header { padding: 8px; }
  #screen { padding: 10px; }
  .preview { height: 210px; }
}

@media (min-width: 860px) {
  .stable-layout {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 16px;
    align-items: start;
  }
  .preview { height: 360px; }
  .key-hint { display: block; }
  #screen { padding: 22px; }
}

@media (max-height: 520px) {
  .rein, .leg-aid { width: 68px; height: 68px; }
  .jump-fab { bottom: 12px; right: 96px; }
  .pace { display: none; }
  #pace-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  button:active:not(:disabled) { transform: none; }
}
