:root {
  --bg: #14110d;
  --bg2: #1d1812;
  --surface: #26201880;
  --surface-solid: #271f17;
  --line: #3a3023;
  --text: #f0e8da;
  --muted: #b3a489;
  --accent: #c79a4b;       /* tack-leather gold */
  --accent2: #7fae6b;      /* pasture green */
  --danger: #d4756b;
  --radius: 16px;
  --tap: 44px;
  --maxw: 720px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: radial-gradient(120% 80% at 50% 0%, #1f1810 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0 0 .4em; font-weight: 650; letter-spacing: .2px; }
button { font: inherit; color: inherit; cursor: pointer; }
.app { max-width: var(--maxw); margin: 0 auto; padding: 14px; }

/* header */
.top { display: flex; align-items: center; gap: 10px; padding: 6px 4px 14px; }
.top .logo { font-size: 22px; font-weight: 750; letter-spacing: .3px; }
.top .logo b { color: var(--accent); }
.top .sub { color: var(--muted); font-size: 12.5px; margin-left: auto; text-align: right; }

/* views */
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; backdrop-filter: blur(8px);
}
.grid { display: grid; gap: 12px; }

/* horse card */
.horse-card { display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; transition: border-color .15s, transform .05s; }
.horse-card:active { transform: scale(.99); }
.horse-card:hover { border-color: var(--accent); }
.horse-card .pic { width: 92px; flex: 0 0 92px; background: #0d0b08; border-radius: 12px; padding: 4px; }
.horse-card .pic svg { display: block; width: 100%; height: auto; }
.horse-card .meta { min-width: 0; }
.horse-card .meta .nm { font-weight: 650; font-size: 17px; display: flex; gap: 8px; align-items: baseline; }
.horse-card .meta .nm .sex { font-size: 12px; color: var(--muted); font-weight: 500; }
.horse-card .meta .ph { color: var(--accent); font-size: 14px; margin-top: 2px; }
.horse-card .meta .nt { color: var(--muted); font-size: 12.5px; margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 44px; opacity: .5; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-solid); font-weight: 600; }
.btn.primary { background: linear-gradient(180deg, var(--accent), #a87f37); color: #1a1206; border: none; }
.btn.green { background: linear-gradient(180deg, var(--accent2), #5f8a4d); color: #11200c; border: none; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #5a352f; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }

/* preview block (inspect / live) */
.preview { display: flex; gap: 14px; align-items: center; }
.preview .pic { width: 150px; flex: 0 0 150px; background: #0d0b08; border-radius: 14px; padding: 6px; }
.preview .pic svg { display: block; width: 100%; height: auto; }
.preview .name { font-size: 22px; font-weight: 700; }
.preview .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: #2e2619; border: 1px solid var(--line); color: var(--muted); }
.tag.pat { color: var(--accent2); border-color: #38492c; }

/* warnings */
.warn { border-left: 3px solid var(--danger); background: #2a1b18; color: #f0cfc8;
  padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-top: 8px; }

/* gene editor */
.fields { display: grid; gap: 10px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, select {
  width: 100%; min-height: var(--tap); background: #0f0c08; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; }
.field textarea { min-height: 64px; resize: vertical; }

.gene-section > summary { cursor: pointer; font-weight: 650; padding: 10px 2px; list-style: none;
  display: flex; align-items: center; gap: 8px; color: var(--text); }
.gene-section > summary::-webkit-details-marker { display: none; }
.gene-section > summary::before { content: "▸"; color: var(--accent); transition: transform .15s; }
.gene-section[open] > summary::before { transform: rotate(90deg); }
.gene-row { display: grid; grid-template-columns: 1fr; gap: 4px; padding: 8px 0; border-top: 1px solid #2a2218; }
.gene-row .gl { font-size: 13px; color: var(--muted); }
.gene-row .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* breed pickers + results */
.cross { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.cross .x { color: var(--accent); font-size: 20px; font-weight: 700; }
.outcome { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid #2a2218; }
.outcome .pic { width: 56px; flex: 0 0 56px; background: #0d0b08; border-radius: 8px; padding: 2px; }
.outcome .pic svg { display: block; width: 100%; height: auto; }
.outcome .ob { min-width: 0; flex: 1; }
.outcome .on { font-size: 14.5px; font-weight: 600; }
.outcome .bar { height: 7px; border-radius: 4px; background: #2a2218; margin-top: 5px; overflow: hidden; }
.outcome .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.outcome .pct { flex: 0 0 auto; font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 650; width: 52px; text-align: right; }

/* bottom dock nav */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, var(--bg) 60%, transparent); }
.dock button { flex: 1; max-width: 160px; min-height: 54px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-solid); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--muted); }
.dock button.active { color: var(--accent); border-color: var(--accent); background: #2a2014; }
.dock button .ic { font-size: 19px; }

/* modal sheet */
.sheet-backdrop { position: fixed; inset: 0; background: #000a; z-index: 50; display: none; }
.sheet-backdrop.open { display: block; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; max-height: 92dvh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg2); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0;
  transform: translateY(100%); transition: transform .22s ease; max-width: var(--maxw); margin: 0 auto; }
.sheet.open { transform: translateY(0); }
.sheet-head { flex: 0 0 auto; padding: 8px 16px 10px; border-bottom: 1px solid var(--line); background: var(--surface-solid); }
.sheet-head .grab { width: 40px; height: 4px; border-radius: 4px; background: #4a3d2a; margin: 0 auto 8px; }
.sheet-title { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.preview-compact { display: flex; gap: 12px; align-items: center; }
.preview-compact .pic { width: 88px; flex: 0 0 88px; background: #0d0b08; border-radius: 10px; padding: 4px; }
.preview-compact .pic svg { display: block; width: 100%; height: auto; }
.preview-compact .name { font-size: 19px; font-weight: 700; line-height: 1.15; }
.sheet-head .gr-grid { margin-top: 8px; }
.sheet-body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 6px; }
.sheet .actions { flex: 0 0 auto; display: flex; gap: 8px;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface-solid); border-top: 1px solid var(--line); }

/* breeding outcome — tap to reveal genes */
.outcome { cursor: pointer; }
.outcome .on { display: flex; align-items: center; gap: 6px; }
.outcome .more { font-size: 11px; color: var(--muted); font-weight: 500; }
.outcome.open .more { color: var(--accent); }
.outcome-detail { padding: 4px 0 10px 66px; border-top: 1px dashed #2a2218; margin-top: -2px; }
.outcome-detail .gr-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin: 6px 0 4px; }
.sheet .actions .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px);
  background: var(--surface-solid); border: 1px solid var(--accent); color: var(--text);
  padding: 10px 16px; border-radius: 12px; z-index: 80; opacity: 0; transition: all .2s; font-size: 14px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

body.lock { overflow: hidden; }
.sheet { overscroll-behavior: contain; }

/* coat picker */
.coat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.coat-tile { display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--surface-solid); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 3px; font-size: 11px; color: var(--muted); line-height: 1.1; text-align: center; }
.coat-tile svg { width: 100%; height: auto; max-width: 72px; }
.coat-tile.on { border-color: var(--accent); background: #2a2014; color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }

/* gene readout — book-style */
.genes-readout { margin-top: 10px; border-top: 1px solid #2a2218; padding-top: 8px; }
.gr-label { font-size: 10.5px; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .5px; }
.gr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; }
.gr { font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; gap: 6px; }
.gr b { color: var(--muted); font-weight: 500; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mt { margin-top: 14px; } .mut { color: var(--muted); } .sm { font-size: 13px; }
