:root {
  color-scheme: dark;
  --bg: #080b0a;
  --panel: #101513;
  --panel-high: #151c19;
  --line: #25302c;
  --muted: #87948f;
  --text: #f2f6f4;
  --lime: #c9ff55;
  --lime-dark: #1d2a08;
  --red: #ff6b5e;
  --amber: #ffc857;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% 0%, rgba(201, 255, 85, 0.07), transparent 26rem),
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 100% 48px, auto;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: 44px 0 72px;
}

.masthead, .section-heading, .actions, .connection-pill, .input-wrap {
  display: flex;
  align-items: center;
}

.masthead, .section-heading { justify-content: space-between; }
.masthead { margin-bottom: 28px; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--lime);
  font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: -0.045em; }
h1 { font-size: clamp(32px, 6vw, 58px); line-height: 0.95; }
h2 { font-size: 26px; }

.connection-pill {
  gap: 9px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(16, 21, 19, 0.8);
  font-size: 13px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.connection-pill[data-state="connected"] { color: var(--lime); border-color: #40551c; }
.connection-pill[data-state="connected"] .status-dot { background: var(--lime); box-shadow: 0 0 12px var(--lime); }
.connection-pill[data-state="connecting"] .status-dot { background: var(--amber); animation: pulse 1s infinite; }
.connection-pill[data-state="error"] { color: var(--red); border-color: #67312c; }
.connection-pill[data-state="error"] .status-dot { background: var(--red); }

.control-card, .tape-card, .events-card, .arm-card, .odds-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(16, 21, 19, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

.odds-card { margin-bottom: 18px; overflow: hidden; }
.odds-heading { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; }
.odds-heading h2 { font-size: 21px; }
.socket-status {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: 700 10px ui-monospace, monospace;
  text-transform: uppercase;
}
.socket-status[data-state="connected"] { border-color: #40551c; color: var(--lime); }
.socket-status[data-state="connecting"] { border-color: #6a5522; color: var(--amber); }
.socket-status[data-state="error"] { border-color: #67312c; color: var(--red); }
.odds-meta { display: grid; grid-template-columns: .75fr .75fr 2fr; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.odds-meta > div { min-width: 0; padding: 13px 24px; border-right: 1px solid var(--line); }
.odds-meta > div:last-child { border-right: 0; }
.odds-meta span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 9px; letter-spacing: .09em; text-transform: uppercase; }
.odds-meta strong { display: block; overflow: hidden; font: 700 12px ui-monospace, monospace; text-overflow: ellipsis; white-space: nowrap; }
.odds-update { padding: 15px 24px 19px; background: #090d0b; }
.odds-update-heading { display: flex; justify-content: space-between; gap: 15px; margin-bottom: 10px; color: var(--muted); font: 10px ui-monospace, monospace; text-transform: uppercase; }
.odds-update code { display: block; max-height: 110px; overflow: auto; color: #c8d2ce; font: 12px/1.5 ui-monospace, monospace; white-space: pre-wrap; word-break: break-word; }

.arm-card { margin-bottom: 18px; overflow: hidden; }
.arm-heading { padding: 22px 24px 19px; }
.compact-button { min-height: 38px; padding: 0 12px; font-size: 12px; }
.arm-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: 700 11px ui-monospace, monospace;
  text-transform: uppercase;
}
.arm-status[data-state="active"] { border-color: #40551c; color: var(--lime); }
.arm-status[data-state="error"] { border-color: #67312c; color: var(--red); }
.arm-form { padding: 22px 24px; border-top: 1px solid var(--line); }
.arm-fields {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, 1fr);
  gap: 12px;
}
.arm-fields label > span { display: block; margin-bottom: 8px; color: #c7d0cc; font-size: 11px; }
.arm-fields input {
  height: 43px;
  padding: 0 12px;
  border: 1px solid #34403b;
  border-radius: 9px;
  background: #090d0b;
  font-size: 13px;
}
.arm-fields input:focus { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(201, 255, 85, 0.1); }
.arm-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 17px; }
.arm-footer p { margin: 0; color: var(--amber); font-size: 12px; }
.execution-result {
  margin: 0 24px 22px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #090d0b;
  color: #c8d2ce;
  font: 12px/1.55 ui-monospace, monospace;
  white-space: pre-wrap;
}
.execution-result[data-state="success"] { border-color: #40551c; color: var(--lime); }
.execution-result[data-state="error"] { border-color: #67312c; color: var(--red); }

.events-card { margin-bottom: 18px; overflow: hidden; }
.events-heading { padding: 22px 24px 19px; }
.events-actions { display: flex; align-items: center; gap: 12px; }
.event-count {
  color: var(--muted);
  font: 12px ui-monospace, monospace;
  white-space: nowrap;
}
.events-message {
  display: grid;
  min-height: 150px;
  place-items: center;
  align-content: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}
.events-message[data-state="error"] { color: var(--red); }
.events-message p { margin: 8px 20px 0; }
.table-wrap { max-height: 430px; overflow: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
th {
  position: sticky;
  z-index: 1;
  top: 0;
  padding: 11px 14px;
  background: #0c110f;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .09em;
  text-align: left;
  text-transform: uppercase;
}
td { padding: 13px 14px; border-top: 1px solid var(--line); font-size: 13px; }
tbody tr:first-child td { border-top: 0; }
tbody tr:hover { background: rgba(201, 255, 85, 0.025); }
.mono-cell { color: #c8d2ce; font: 12px ui-monospace, monospace; white-space: nowrap; }
.event-name-cell { min-width: 280px; font-weight: 650; }
.select-event {
  padding: 7px 10px;
  border: 1px solid #40551c;
  background: var(--lime-dark);
  color: var(--lime);
  font-size: 11px;
  white-space: nowrap;
}
.select-event:hover { background: #293b0c; }
.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;
}

.control-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 30px;
  padding: 24px;
}

label {
  display: block;
  margin-bottom: 9px;
  color: #c7d0cc;
  font-size: 13px;
  font-weight: 700;
}

.input-wrap {
  max-width: 520px;
  border: 1px solid #34403b;
  border-radius: 10px;
  background: #090d0b;
  transition: border-color 150ms, box-shadow 150ms;
}

.input-wrap:focus-within { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(201, 255, 85, 0.1); }
.input-wrap > span { padding-left: 14px; color: var(--lime); font: 700 12px ui-monospace, monospace; }

input {
  width: 100%;
  min-width: 0;
  padding: 13px 14px 13px 10px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: 600 16px ui-monospace, SFMono-Regular, Menlo, monospace;
}

input:disabled { color: var(--muted); }
.field-help, .field-error { margin: 8px 0 0; font-size: 12px; }
.field-help { color: var(--muted); }
.field-error { min-height: 15px; color: var(--red); }

.actions { align-self: center; gap: 9px; }
button { border-radius: 9px; font-weight: 750; transition: transform 120ms, opacity 120ms, background 120ms; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: 0.38; }
.primary, .secondary { min-height: 45px; padding: 0 17px; }
.primary { border: 1px solid var(--lime); background: var(--lime); color: #111606; }
.primary:hover:not(:disabled) { background: #dbff8a; }
.secondary { border: 1px solid var(--line); background: var(--panel-high); color: var(--text); }

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 18px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--line);
}

.metrics article { padding: 17px 20px; background: var(--panel); }
.metrics span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .09em; }
.metrics strong { display: block; overflow: hidden; color: var(--text); font: 700 16px ui-monospace, monospace; text-overflow: ellipsis; white-space: nowrap; }

.tape-card { min-height: 390px; padding: 24px; }
.section-heading { padding-bottom: 19px; border-bottom: 1px solid var(--line); }
.text-button { border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.text-button:hover { color: var(--text); }

.empty-state { display: grid; place-items: center; align-content: center; min-height: 270px; color: var(--muted); text-align: center; }
.court-mark { color: #415049; font-size: 42px; }
.event-list { margin: 0; padding: 0; list-style: none; }
.event-row {
  display: grid;
  grid-template-columns: 105px minmax(150px, 1fr) minmax(140px, auto);
  align-items: center;
  gap: 18px;
  padding: 16px 4px;
  border-bottom: 1px solid var(--line);
  animation: enter 180ms ease-out;
}
.event-row time, .event-id { color: var(--muted); font: 12px ui-monospace, monospace; }
.event-type { font: 750 15px ui-monospace, monospace; }
.event-type.runner1Score, .event-type.runner2Score { color: var(--lime); }
.event-id { overflow: hidden; text-align: right; text-overflow: ellipsis; white-space: nowrap; }

@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes enter { from { opacity: 0; transform: translateY(-5px); } }

@media (max-width: 720px) {
  .shell { padding-top: 28px; }
  .masthead { align-items: flex-end; }
  .control-card { grid-template-columns: 1fr; gap: 8px; }
  .events-heading { align-items: flex-start; gap: 18px; }
  .events-actions { align-items: flex-end; flex-direction: column-reverse; }
  .events-actions .primary { min-height: 40px; padding: 0 12px; font-size: 12px; }
  .actions { width: 100%; }
  .actions button { flex: 1; }
  .metrics article { padding: 14px; }
  .arm-heading { align-items: flex-start; gap: 16px; }
  .odds-meta { grid-template-columns: 1fr 1fr; }
  .odds-meta > div:last-child { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .arm-fields { grid-template-columns: 1fr 1fr; }
  .event-row { grid-template-columns: 82px 1fr; }
  .event-id { grid-column: 2; text-align: left; }
}

@media (max-width: 470px) {
  .arm-fields { grid-template-columns: 1fr; }
  .odds-heading { align-items: flex-start; gap: 15px; }
  .arm-footer { align-items: stretch; flex-direction: column; }
}
