:root {
  color-scheme: dark;
  --bg: #0d1312;
  --surface: #141c1a;
  --surface-2: #192320;
  --line: #2c3935;
  --text: #f1f2eb;
  --muted: #9aa7a1;
  --accent: #d5a94f;
  --accent-strong: #edc566;
  --green: #17684e;
  --green-deep: #0e4d3a;
  --danger: #e06e5d;
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(32, 92, 71, 0.12), transparent 36rem),
    var(--bg);
}

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

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  gap: 1rem;
  min-height: 100vh;
  padding: 1rem;
}

.table-panel, .controls {
  align-self: start;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
}

.table-panel { min-width: 0; padding: 1.25rem; display: flex; flex-direction: column; }
.controls-heading, .section-label, .range-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
h2 { margin: 0; font-size: 1.25rem; }
h3 { margin: 0; font-size: 0.9375rem; font-weight: 650; }

.switch-label { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); font-size: 0.875rem; cursor: pointer; }
.switch-label input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 36px; height: 20px; padding: 2px; border-radius: 20px; background: #33413d; transition: .2s; }
.switch::after { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: #87948f; transition: .2s; }
.switch-label input:checked + .switch { background: var(--green); }
.switch-label input:checked + .switch::after { transform: translateX(16px); background: white; }
.switch-label input:focus-visible + .switch { outline: 2px solid var(--accent-strong); outline-offset: 3px; }

.table-stage {
  position: relative;
  flex: 0 0 auto;
  aspect-ratio: 2.04 / 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #26322f;
  border-radius: 8px;
  background: #0a0f0e;
}

#table-canvas { display: block; width: 100%; height: 100%; min-height: 0; touch-action: none; cursor: crosshair; }
#table-canvas:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: -4px; }
.canvas-hint { position: absolute; left: 50%; bottom: 0.85rem; transform: translateX(-50%); margin: 0; padding: 0.42rem 0.75rem; border: 1px solid rgba(255,255,255,.1); border-radius: 5px; color: #c5cec9; background: rgba(7, 13, 11, .74); backdrop-filter: blur(4px); font-size: 0.8125rem; white-space: nowrap; pointer-events: none; }
.selected-indicator, .preview-indicator { position: absolute; top: .75rem; padding: .35rem .6rem; border: 1px solid rgba(255,255,255,.12); border-radius: 4px; color: #dce3df; background: rgba(7,13,11,.7); font-size: .75rem; pointer-events: none; }
.selected-indicator { left: .75rem; opacity: 0; transition: opacity .2s; }
.selected-indicator.visible { opacity: 1; }
.preview-indicator { right: .75rem; }
.preview-indicator.pocket-result { color: var(--accent-strong); border-color: var(--accent); background: #151b16; }

.spin-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem 1rem; margin-top: .75rem; padding: .45rem .75rem; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--muted); font-size: .75rem; }
.spin-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend-swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.swatch-draw { background: #ef6f6c; }
.swatch-slide { background: #5cc8ff; }
.swatch-follow { background: #ff9f43; }
.swatch-roll { background: linear-gradient(to right, #f6d067 50%, #ebefe2 50%); }
.swatch-sidespin { width: 10px; height: 10px; border: 2px solid #d6a4ff; border-right-color: transparent; border-radius: 50%; background: transparent; }

.telemetry { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; margin-top: .65rem; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--line); }
.telemetry div { min-width: 0; padding: 0.7rem 0.85rem; background: var(--surface-2); }
.telemetry span { display: block; margin-bottom: .2rem; color: var(--muted); font-size: .75rem; }
.telemetry strong { display: block; overflow: hidden; font-size: .875rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }

.controls { padding: .75rem 1rem; }
.controls-heading { padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.controls-heading h2 { font-size: 1.125rem; }
.text-button { padding: .35rem .25rem; border: 0; color: var(--accent-strong); background: transparent; font-size: .8125rem; cursor: pointer; }
.text-button:hover { color: #ffe39b; }
.text-button:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.control-section { padding: .375rem 0; border-bottom: 1px solid var(--line); }
.section-label output, .range-heading output { color: var(--accent-strong); font-size: .875rem; font-weight: 650; }
.range-heading { font-size: .9375rem; font-weight: 650; }

.spin-section { text-align: center; }
.spin-pad { position: relative; width: 108px; height: 108px; margin: .65rem auto .45rem; border: 2px solid #c7c5b5; border-radius: 50%; background: radial-gradient(circle at 36% 30%, #fffef1 0, #ddd9c9 54%, #a9a596 100%); box-shadow: 0 0 0 6px #202a27, inset -8px -10px 18px rgba(38,42,39,.22); cursor: crosshair; touch-action: none; }
.spin-pad:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 8px; }
.spin-axis { position: absolute; display: block; background: rgba(27,40,35,.24); pointer-events: none; }
.spin-axis-x { left: 12%; right: 12%; top: 50%; height: 1px; }
.spin-axis-y { top: 12%; bottom: 12%; left: 50%; width: 1px; }
.spin-ring { position: absolute; inset: 25%; border: 1px solid rgba(27,40,35,.18); border-radius: 50%; }
.spin-marker { position: absolute; left: 50%; top: 50%; width: 15px; height: 15px; border: 3px solid white; border-radius: 50%; background: var(--danger); box-shadow: 0 1px 5px rgba(0,0,0,.35); transform: translate(-50%, -50%); pointer-events: none; }
.spin-label { position: absolute; left: calc(100% + 12px); color: var(--muted); font-size: .75rem; pointer-events: none; }
.spin-top { top: 18%; }
.spin-bottom { bottom: 18%; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; white-space: nowrap; clip-path: inset(50%); }
.aim-section { min-width: 0; margin: 0; border: 0; border-bottom: 1px solid var(--line); }
.aim-section .section-label { gap: .5rem; }
.aim-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; margin-top: .4rem; }
.aim-buttons button { min-height: 36px; padding: .2rem .35rem; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: var(--surface-2); font: inherit; font-size: .8125rem; }
.aim-buttons button:not(:disabled) { cursor: pointer; }
.aim-buttons button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-strong); }

.range { display: block; width: 100%; height: 24px; margin: .2rem 0 0; appearance: none; background: transparent; cursor: pointer; }
.range::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--accent) var(--range-fill, 37%), #35433f var(--range-fill, 37%)); }
.range::-moz-range-track { height: 4px; border-radius: 4px; background: #35433f; }
.range::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
.range::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -7px; appearance: none; border: 4px solid var(--surface); border-radius: 50%; background: var(--accent-strong); box-shadow: 0 0 0 1px var(--accent-strong); }
.range::-moz-range-thumb { width: 11px; height: 11px; border: 4px solid var(--surface); border-radius: 50%; background: var(--accent-strong); box-shadow: 0 0 0 1px var(--accent-strong); }
.range:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 1px; border-radius: 4px; }

.shot-status { display: flex; align-items: center; gap: .65rem; margin: .55rem 0; padding: .45rem .65rem; border: 1px solid #31423c; border-radius: 7px; background: #18231f; }
.status-icon { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #6fbd96; box-shadow: 0 0 0 5px rgba(111,189,150,.09); }
.shot-status.busy .status-icon { background: var(--accent); box-shadow: 0 0 0 5px rgba(213,169,79,.1); }
.shot-status.finished .status-icon { background: #72a9c5; box-shadow: 0 0 0 5px rgba(114,169,197,.1); }
.shot-status strong, .shot-status small { display: block; }
.shot-status strong { font-size: .875rem; }
.shot-status small { margin-top: .15rem; color: var(--muted); font-size: .75rem; }

.primary-actions { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.primary-actions button, .utility-actions button { min-height: 36px; border-radius: 6px; cursor: pointer; }
.primary-button { border: 1px solid #e4bd62; color: #17140d; background: var(--accent-strong); font-weight: 750; }
.primary-button:hover:not(:disabled) { background: #f8d77d; }
.secondary-button { min-width: 84px; border: 1px solid var(--line); background: var(--surface-2); }
button:disabled { cursor: not-allowed; opacity: .42; }
.utility-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-top: .5rem; }
.utility-actions button { border: 1px solid var(--line); color: #c7d0cc; background: transparent; font-size: .75rem; }
.utility-actions button:hover:not(:disabled), .secondary-button:hover:not(:disabled) { border-color: #50615b; background: #1d2925; }
.trajectory-control { justify-content: space-between; margin-top: .6rem; padding: .45rem 0; border-top: 1px solid var(--line); }
.shot-advice p { margin: .35rem 0; color: var(--muted); font-size: .8125rem; line-height: 1.45; }
.shot-advice button { min-height: 32px; margin: .15rem 0 .35rem; font-size: .8125rem; cursor: pointer; }
.model-details { margin-top: .6rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .8125rem; line-height: 1.5; }
.model-details summary { padding-top: .5rem; color: #d7ddd9; cursor: pointer; }
.model-details p { margin: .7rem 0 0; }

@media (max-width: 1050px) {
  .workbench { grid-template-columns: 1fr; }
  .controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
  .controls-heading, .shot-status, .primary-actions, .utility-actions, .trajectory-control, .shot-advice, .model-details { grid-column: 1 / -1; }
  .control-section { min-width: 0; }
  .spin-section { grid-row: span 3; }
}

@media (max-width: 700px) {
  .workbench { padding: .5rem; }
  .table-panel, .controls { padding: .85rem; }
  .table-stage, #table-canvas { min-height: 0; }
  .canvas-hint { max-width: calc(100% - 1rem); overflow: hidden; text-overflow: ellipsis; }
  .telemetry { grid-template-columns: repeat(2, 1fr); }
  .telemetry div:last-child { grid-column: 1 / -1; }
  .controls { display: block; }
  .spin-label { display: none; }
  .preview-indicator { top: .3rem; right: .3rem; }
  .selected-indicator.visible + .preview-indicator { top: 2.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
