:root {
  --bg: #14181c;
  --panel: #1c2228;
  --panel-2: #232a32;
  --border: #2e3640;
  --text: #d8dee5;
  --muted: #7a8694;
  --accent: #c4d36a;
  --warn: #d97a5f;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  overflow: hidden;
}
#layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: 100vh;
}
#sim-wrap {
  position: relative;
  background: #0a0d10;
  overflow: hidden;
}
#canvas { display: block; }
#hud {
  position: absolute;
  top: 12px; left: 12px;
  background: rgba(0,0,0,0.55);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
}
#hud .v { color: var(--accent); }
#hud .label { color: var(--muted); }
#toolbar {
  position: absolute;
  top: 12px; right: 12px;
  display: flex; gap: 6px;
}
#toolbar button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}
#toolbar button:hover { background: var(--panel-2); }
#mode {
  position: absolute;
  bottom: 12px; left: 12px;
  background: rgba(0,0,0,0.55);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.6;
  pointer-events: none;
}
#mode .chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 3px;
  font-weight: 600;
  margin-right: 8px;
}
#mode .chip.auto   { background: #2e3640; color: var(--accent); }
#mode .chip.manual { background: #d97a5f; color: #14181c; }
#mode .key {
  display: inline-block;
  padding: 1px 7px;
  margin: 0 3px;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}
#mode .key.on { background: var(--accent); color: #14181c; border-color: var(--accent); }
#mode .hint { color: var(--muted); }

#controls {
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 16px 32px;
}
#controls h1 {
  font-size: 14px;
  margin: 0 0 4px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
#controls .subtitle {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 18px;
}
.group {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.group:last-child { border-bottom: none; }
.group h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}
.slider {
  display: grid;
  grid-template-columns: 108px 1fr 64px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  min-width: 0;
}
.slider label {
  color: var(--text); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.slider input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel-2);
  height: 4px;
  border-radius: 2px;
  outline: none;
  min-width: 0;
}
.slider input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}
.slider input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.slider .val {
  text-align: right;
  color: var(--accent);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.toggle-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px;
}
.toggle-row input { accent-color: var(--accent); }
.toggle-row label { font-size: 12px; }
.btn-primary {
  flex: 1;
  background: var(--accent);
  color: #14181c;
  border: none;
  padding: 8px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* ---------- shared form controls (Bsky panel etc) ---------- */
.input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12px;
}
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}
.btn:hover { background: var(--panel); }
.row { display: flex; gap: 6px; }
.row.mb-6 { margin-bottom: 6px; }
.row.mt-8 { margin-top: 8px; }

/* ---------- Bsky loader panel ---------- */
.bsky-wrap { position: relative; }
.bsky-wrap .input { flex: 1; }
#bsky_typeahead {
  position: absolute; top: 100%; left: 0; right: 0;
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-height: 240px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
#bsky_typeahead .row-result {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
#bsky_typeahead .row-result:hover { background: var(--panel-2); }
#bsky_typeahead .avatar-img,
#bsky_typeahead .avatar-blank {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}
#bsky_typeahead .avatar-img { object-fit: cover; }
#bsky_typeahead .avatar-blank { background: var(--panel-2); }
#bsky_typeahead .text-col { min-width: 0; flex: 1; }
#bsky_typeahead .name,
#bsky_typeahead .handle {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#bsky_typeahead .name { color: var(--text); }
#bsky_typeahead .handle { color: var(--muted); font-size: 11px; }
#bsky_status { font-size: 11px; color: var(--muted); min-height: 1.5em; }

/* ---------- Perf overlay ---------- */
#perf {
  position: absolute;
  top: 8px; right: 8px;
  font: 11px ui-monospace, monospace;
  color: #aab;
  background: rgba(0,0,0,0.5);
  padding: 6px 8px;
  border-radius: 4px;
  pointer-events: none;
  white-space: pre;
  z-index: 50;
}

/* ---------- Race overlay panel ---------- */
#race-overlay {
  position: absolute;
  left: 50%; top: 24px;
  transform: translateX(-50%);
  background: rgba(20,24,28,0.92);
  color: var(--text);
  font: 13px ui-monospace, monospace;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  min-width: 240px;
  text-align: center;
  pointer-events: auto;
  z-index: 40;
  display: none;
}
#race-overlay .phase-title {
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 8px;
}
#race-overlay .muted { color: var(--muted); }
#race-overlay .pre-msg { color: var(--muted); margin-bottom: 12px; }
#race-overlay .finish-list { text-align: left; }
#race-overlay .finish-row { margin: 2px 0; }
#race-overlay .finish-row.podium-user {
  font-size: 18px;
  line-height: 1.35;
  margin: 6px 0;
  letter-spacing: 0.01em;
}
#race-overlay .finish-row.podium-user strong { color: var(--accent); font-weight: 700; }
#race-overlay .results-list { text-align: left; margin-bottom: 12px; }
#race-overlay .results-row.dnf { color: var(--muted); }
#race-overlay .time {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
#race-overlay .dist { font-variant-numeric: tabular-nums; }
#race-overlay .grace-line {
  color: var(--muted);
  font-size: 11px;
  margin-top: 8px;
}
#race-overlay .race-btn {
  background: var(--accent);
  color: #14181c;
  border: none;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
#race-overlay .race-btn.start  { padding: 10px 24px; }
#race-overlay .race-btn.respawn { padding: 8px 20px; }

/* Scene tabs */
.scene-tabs {
  display: flex;
  gap: 4px;
  margin: 4px 0 18px;
  border-bottom: 1px solid var(--border);
}
.scene-tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  padding: 6px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: -1px;
}
.scene-tab:hover { color: var(--text); }
.scene-tab.active {
  color: var(--accent);
  border-color: var(--border);
  border-bottom-color: var(--panel);
  background: var(--panel);
}

#scene-account .muted { color: var(--muted); font-size: 12px; }

/* ---------- Account horse (left area when in account scene) ---------- */
#account-horse-wrap {
  position: relative;
  background: #0a0d10;
  overflow: hidden;
}
#account-horse-canvas { display: block; }
#account-horse-wrap .row-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

/* ---------- Account right panel ---------- */
#account_identity,
#account_horse_stats { font-size: 12px; line-height: 1.55; }
#account_identity .avatar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
#account_identity .avatar-row img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
#account_identity .avatar-row .name { color: var(--text); font-weight: 600; }
#account_identity .avatar-row .handle { color: var(--muted); font-size: 11px; }
#account_identity .did {
  font-family: ui-monospace, monospace;
  color: var(--muted);
  font-size: 10px;
  word-break: break-all;
  margin-top: 6px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 2px 0;
  font-size: 12px;
}
.stat-row .label { color: var(--muted); }
.stat-row .val   { color: var(--accent); font-variant-numeric: tabular-nums; }


.event-log {
  font-size: 11px;
  line-height: 1.5;
  max-height: 320px;
  overflow-y: auto;
}

/* ---------- stable view ---------- */
.stable-view {
  font-size: 12px;
  line-height: 1.4;
  max-height: 600px;
  overflow-y: auto;
}
.stable-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 6px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.stable-header b { color: var(--accent); font-weight: 600; }
.stable-header .stable-sort-toggle {
  font-size: 10px;
  padding: 2px 8px;
  text-transform: none;
  letter-spacing: 0;
}

.stable-card {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 10px;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--panel-2);
  border-radius: 4px;
  border-left: 2px solid var(--border);
  align-items: start;
}
.stable-card.primary {
  border-left-color: var(--accent);
  background: linear-gradient(to right, rgba(196,211,106,0.10), var(--panel-2) 40%);
}
.stable-card.pinned {
  border-left-color: var(--warn);
}
.stable-card .card-canvas {
  display: block;
  background: #0a0d10;
  border-radius: 3px;
  width: 100px;
  height: 100px;
  flex-shrink: 0;
}
.stable-card .card-body { min-width: 0; }
.stable-card .card-tags {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
  min-height: 14px;
}
.card-tag {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 1px 6px;
  border-radius: 2px;
}
.card-tag.latest { background: var(--accent); color: #14181c; }
.card-tag.pinned { background: var(--warn);   color: #14181c; }
.stable-card .card-name {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-bottom: 2px;
}
.stable-card .card-text {
  color: var(--muted);
  font-size: 10px;
  font-style: italic;
  line-height: 1.35;
  word-break: break-word;
  white-space: pre-wrap;
  margin-bottom: 6px;
}
.stable-card .card-bench {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  margin-bottom: 4px;
  align-items: baseline;
}
.bench {
  padding: 1px 6px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
.bench b { font-weight: 600; }
.bench-pending { background: var(--panel); color: var(--muted); font-style: italic; }
.bench-good    { background: rgba(196,211,106,0.15); color: var(--accent); }
.bench-mid     { background: var(--panel); color: var(--text); }
.bench-dnf     { background: rgba(217,122,95,0.15); color: var(--warn); }

.stable-card .card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  margin-bottom: 6px;
}
.stable-card .card-stats .stat { color: var(--text); }
.stable-card .card-stats .muted { color: var(--muted); }
.stable-card .card-stats .medals { font-size: 11px; }
.stable-card .card-actions { display: flex; gap: 6px; }
.stable-card .card-actions .btn { font-size: 10px; padding: 3px 8px; }
.stable-card.pinned .card-actions .btn { background: var(--panel); }

/* ---------- horse-post onboarding banner ---------- */
.horse-status {
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.4;
}
.horse-status.found {
  background: rgba(196,211,106,0.08);
  border-left: 3px solid var(--accent);
}
.horse-status.missing {
  background: var(--panel-2);
  border-left: 3px solid var(--muted);
}
.horse-status .hs-headline {
  color: var(--text);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.horse-status .hs-quote {
  color: var(--text);
  font-style: italic;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 6px;
  padding-left: 8px;
  border-left: 2px solid var(--border);
}
.horse-status .hs-foot {
  color: var(--muted);
  font-size: 11px;
}
.hp-history-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin: 8px 0 6px;
}

/* ---------- horse-post rows in the account scene ---------- */
.horse-post-row {
  padding: 8px;
  margin: 0 0 6px 0;
  background: var(--panel-2);
  border-left: 2px solid var(--border);
  border-radius: 3px;
  font-size: 12px;
  line-height: 1.4;
}
.horse-post-row.latest {
  border-left-color: var(--accent);
  background: linear-gradient(to right, rgba(196,211,106,0.10), var(--panel-2) 50%);
}
.horse-post-row .hp-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
}
.horse-post-row .active-tag {
  background: var(--accent);
  color: #14181c;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 9px;
  letter-spacing: 0.5px;
}
.horse-post-row .hp-ts { font-variant-numeric: tabular-nums; }
.horse-post-row .hp-text {
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}

/* ---------- horse hover tooltip ---------- */

.horse-hover-tooltip {
  position: fixed;
  z-index: 500;
  pointer-events: none;
  min-width: 200px;
  max-width: 320px;
  background: rgba(20, 24, 28, 0.96);
  border: 1px solid var(--border, #2a3038);
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  font-size: 12px;
  color: var(--text, #d6dde5);
  line-height: 1.4;
}
.horse-hover-tooltip .hover-id { margin-bottom: 6px; }
.horse-hover-tooltip .hover-name {
  font-weight: 700;
  font-size: 13px;
}
.horse-hover-tooltip .hover-name.muted { color: var(--muted, #8c97a3); font-weight: 500; font-style: italic; }
.horse-hover-tooltip .hover-handle {
  color: var(--muted, #8c97a3);
  font-size: 11px;
}
.horse-hover-tooltip .hover-seed {
  margin: 6px 0 8px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 2px solid var(--accent, #4fa3ff);
  border-radius: 0 3px 3px 0;
  font-size: 11px;
  color: #c4ccd5;
  word-break: break-word;
}
.horse-hover-tooltip .hover-seed.muted {
  color: var(--muted, #8c97a3);
  font-style: italic;
  background: none;
  border-left-color: var(--border, #2a3038);
  padding: 0 8px;
}
.horse-hover-tooltip .hover-mods {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border, #2a3038);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.horse-hover-tooltip .hover-mod-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 10px;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}
.horse-hover-tooltip .hover-mod-label {
  color: var(--text, #d6dde5);
  text-transform: uppercase;
  font-weight: 600;
}
.horse-hover-tooltip .hover-mod-target {
  color: var(--muted, #8c97a3);
  font-family: monospace;
}
.horse-hover-tooltip .hover-mod-bar {
  position: relative;
  height: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
}
.horse-hover-tooltip .hover-mod-bar-mid {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.2);
}
.horse-hover-tooltip .hover-mod-bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 2px;
}
.horse-hover-tooltip .hover-mod-bar-fill.pos { background: var(--accent, #4fa3ff); }
.horse-hover-tooltip .hover-mod-bar-fill.neg { background: var(--warn,   #ff8c4a); }
.horse-hover-tooltip .hover-mod.inert .hover-mod-bar-fill { background: var(--muted, #8c97a3); opacity: 0.45; }
.horse-hover-tooltip .hover-mod.inert .hover-mod-label { color: var(--muted, #8c97a3); }
.horse-hover-tooltip .hover-mod-sub {
  margin-top: 2px;
  font-size: 10px;
  color: var(--muted, #8c97a3);
  font-family: monospace;
}
