:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --panel-2: #1a232d;
  --line: #24303c;
  --ink: #e6edf3;
  --ink-dim: #8b9bab;
  --ink-faint: #5d6b7a;
  --accent: #4aa8ff;
  --good: #3fb950;
  --warn: #f0883e;
  --bad: #f85149;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 22px 20px 80px;
}

/* ---------- header ---------- */

header.masthead {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 20px;
}

.masthead h1 {
  font-size: 21px;
  margin: 0;
  letter-spacing: -0.2px;
}

.masthead h1 span {
  color: var(--accent);
}

.masthead .tag {
  color: var(--ink-dim);
  font-size: 14px;
  flex: 1;
  min-width: 260px;
}

.masthead nav {
  display: flex;
  gap: 14px;
  font-size: 13px;
}

/* ---------- layout ---------- */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 20px;
  align-items: start;
  /* Landing on #play should not put the table flush against the viewport. */
  scroll-margin-top: 14px;
}

@media (max-width: 1080px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
  }
}

.table-column {
  min-width: 0;
}

/* ---------- table ---------- */

.table-shell {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #0a0d11;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

#table {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
}

.banner {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background: rgba(6, 10, 14, 0.86);
  backdrop-filter: blur(3px);
  text-align: center;
  padding: 20px;
}

.banner.show {
  display: flex;
}

.banner h2 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.5px;
}

.banner p {
  margin: 0;
  color: var(--ink-dim);
  max-width: 420px;
  line-height: 1.55;
}

/* ---------- controls ---------- */

.controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 14px 14px;
  padding: 14px 16px;
  margin-top: -14px;
  padding-top: 24px;
}

@media (max-width: 620px) {
  .controls {
    grid-template-columns: 1fr;
  }
}

/* ---------- shot log ---------- */

.shotlog {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px 6px;
}

.shotlog-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--ink-dim);
}

.shotlog-head span + span {
  text-transform: none;
  letter-spacing: 0;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.shotlog ol {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
}

.shotlog li {
  display: flex;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
  color: var(--ink-dim);
}

.shotlog li:first-child {
  border-top: none;
}

.shotlog li.empty {
  color: var(--ink-faint);
  font-family: inherit;
}

.shotlog .who {
  flex: 0 0 34px;
  font-weight: 700;
  color: var(--ink);
}

.shotlog .who.bot {
  color: var(--warn);
}

.shotlog .what {
  flex: 1 1 auto;
  min-width: 0;
}

.shotlog .why {
  flex: 0 0 auto;
  color: var(--ink-faint);
}

.shotlog .why.foul {
  color: var(--warn);
}

.spin-widget {
  text-align: center;
}

.spin-widget canvas {
  display: block;
  cursor: pointer;
  border-radius: 50%;
}

.power-block label,
.spin-widget .caption {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--ink-faint);
  margin-bottom: 7px;
}

.power-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, #2b6cb0, #f0883e, #f85149);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--bg);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--bg);
  cursor: pointer;
}

.readout {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  min-width: 74px;
  text-align: right;
}

button {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 15px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  background: #202b37;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  background: #1b4f80;
  border-color: #2d6ba8;
}

button.primary:hover:not(:disabled) {
  background: #226199;
}

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

/* ---------- side panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 15px;
  margin-bottom: 14px;
}

.panel h3 {
  margin: 0 0 11px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-faint);
  font-weight: 700;
}

.turn-line {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 650;
  margin-bottom: 6px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.dot.bot {
  background: var(--warn);
}

.message {
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.5;
  min-height: 38px;
}

.message .foul {
  color: var(--bad);
  font-weight: 600;
}

.groups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.group-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

.group-card.active {
  border-color: var(--accent);
}

.group-card .who {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-faint);
}

.group-card .what {
  font-size: 14px;
  font-weight: 650;
  margin-top: 3px;
}

.ball-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 7px;
  min-height: 18px;
}

.pip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 9.5px;
  font-weight: 700;
  color: #101010;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 0, 0, 0.45);
}

.pip.stripe {
  background-image: linear-gradient(
    to bottom,
    #f2f2ec 0 26%,
    var(--pip) 26% 74%,
    #f2f2ec 74% 100%
  );
}

/* ---------- inspector ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  font-family: var(--mono);
  font-size: 12px;
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px dotted var(--line);
  padding-bottom: 3px;
}

.stat .k {
  color: var(--ink-faint);
}

.stat .v {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.state-chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 9px;
  border-radius: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  margin-bottom: 10px;
}

.state-chip.sliding {
  color: #ffd479;
  border-color: #6b5322;
  background: #2a2213;
}
.state-chip.rolling {
  color: var(--good);
  border-color: #26562f;
  background: #13251a;
}
.state-chip.spinning {
  color: #d2a8ff;
  border-color: #4a3568;
  background: #221a2e;
}
.state-chip.stationary {
  color: var(--ink-faint);
}
.state-chip.pocketed {
  color: var(--warn);
  border-color: #6b3a22;
  background: #2a1a13;
}

#trace {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 11px;
  border-radius: 6px;
  background: #0d1319;
}

.trace-legend {
  display: flex;
  gap: 13px;
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: 6px;
  flex-wrap: wrap;
}

.trace-legend i {
  display: inline-block;
  width: 9px;
  height: 2px;
  vertical-align: middle;
  margin-right: 4px;
}

/* ---------- bot panel ---------- */

.bot-line {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-dim);
  line-height: 1.7;
}

.bot-line b {
  color: var(--ink);
  font-weight: 600;
}

.progress {
  height: 3px;
  border-radius: 2px;
  background: var(--panel-2);
  overflow: hidden;
  margin: 9px 0;
}

.progress > div {
  height: 100%;
  width: 0;
  background: var(--warn);
  transition: width 0.08s linear;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--ink-dim);
  padding: 5px 0;
}

select {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 15px;
  height: 15px;
}

/* ---------- explainer ---------- */

.explainer {
  margin-top: 42px;
  border-top: 1px solid var(--line);
  padding-top: 30px;
}

.explainer > h2 {
  font-size: 22px;
  margin: 0 0 8px;
  letter-spacing: -0.3px;
}

.explainer > p.lede {
  color: var(--ink-dim);
  font-size: 14.5px;
  line-height: 1.65;
  max-width: 760px;
  margin: 0 0 26px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 17px 18px;
}

.card h3 {
  margin: 0 0 9px;
  font-size: 14.5px;
  color: var(--ink);
}

.card p {
  margin: 0 0 10px;
  font-size: 13.2px;
  line-height: 1.62;
  color: var(--ink-dim);
}

.card p:last-child {
  margin-bottom: 0;
}

.card code,
.explainer code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  color: #a5d6ff;
}

.eq {
  display: block;
  font-family: var(--mono);
  font-size: 12.5px;
  color: #a5d6ff;
  background: #0d1319;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 5px;
  padding: 9px 12px;
  margin: 11px 0;
  overflow-x: auto;
}

.measure {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.measure div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  flex: 1 1 120px;
}

.measure .n {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--good);
}

.measure .l {
  font-size: 10.5px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 2px;
}

footer {
  margin-top: 42px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-faint);
  line-height: 1.7;
}

.kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--ink-dim);
}
