:root {
  color-scheme: dark;
  --bg: #0f1319;
  --bg-raised: #171d26;
  --bg-sunken: #10151c;
  --line: #263040;
  --text: #e6ecf4;
  --text-dim: #93a2b6;
  --accent: #3f9d76;
  --accent-strong: #4fc191;
  --gold: #ffd76a;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, #1b2431 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px clamp(12px, 2.5vw, 28px) 28px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  margin-right: auto;
  font-size: clamp(19px, 2.4vw, 26px);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
}

.field.wide {
  width: 100%;
}

select,
input[type="range"] {
  font: inherit;
  color: var(--text);
}

select {
  appearance: none;
  background: var(--bg-raised)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0h10L5 6z' fill='%2393a2b6'/%3E%3C/svg%3E")
    no-repeat right 10px center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 30px 7px 10px;
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

select:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, transform 0.06s;
}

.btn:hover:not(:disabled) {
  background: #202939;
  border-color: #35435a;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  border-color: transparent;
  color: #06231a;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #5fd3a1, #48a97f);
  border-color: transparent;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  padding-top: 20px;
  align-items: start;
}

.stage-wrap {
  min-width: 0;
}

/*
 * The table letterboxes inside whatever room it is given, so anything drawn on
 * top of it is sized against the stage rather than the viewport.
 */
.stage {
  position: relative;
  container-type: size;
  aspect-ratio: 3.076 / 1.656;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5), 0 2px 0 rgba(255, 255, 255, 0.04) inset;
}

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

.stage-overlay {
  position: absolute;
  left: 50%;
  bottom: 6cqh;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1.6cqh 3cqh;
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: clamp(11px, 4.4cqh, 15px);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

/*
 * `hidden` is only a UA stylesheet rule, so the `display: flex` above keeps the
 * overlay painted while `el.hidden` reads true. Every toggle needs this.
 */
.stage-overlay[hidden] {
  display: none;
}

.spinner {
  width: 1em;
  height: 1em;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

.message {
  min-height: 1.5em;
  margin: 12px 2px 0;
  color: var(--text-dim);
  font-size: 15px;
}

.message.good {
  color: var(--gold);
  font-weight: 600;
}

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

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  font-weight: 600;
}

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

.player {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  transition: border-color 0.18s, background 0.18s;
}

.player.active {
  border-color: var(--accent);
  background: #17251f;
}

.player .dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  box-shadow: inset -2px -3px 5px rgba(0, 0, 0, 0.45), inset 3px 3px 5px rgba(255, 255, 255, 0.35);
}

.player .name {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player .name small {
  display: block;
  font-weight: 400;
  font-size: 11.5px;
  color: var(--text-dim);
}

.player .score {
  font-size: 26px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.slider-row {
  display: grid;
  grid-template-columns: auto 1fr 44px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.slider-row output {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

input[type="range"] {
  appearance: none;
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 55%), #2a3547 var(--fill, 55%));
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #eef4fa;
  border: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #eef4fa;
  border: none;
}

.spin-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin: 14px 0;
}

#spin {
  width: 104px;
  height: 104px;
  touch-action: none;
  cursor: pointer;
  border-radius: 50%;
}

.hint-text {
  margin: 6px 0 0;
  font-size: 10.5px;
  color: var(--text-dim);
  max-width: 108px;
  line-height: 1.35;
}

.readout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  margin: 0;
  font-size: 13px;
  align-content: start;
}

.readout dt {
  color: var(--text-dim);
}

.readout dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}

.check input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.rules summary {
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  font-weight: 600;
}

.rules p {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.rules strong {
  color: var(--text);
}

.keys {
  line-height: 1.9;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-sunken);
  font: inherit;
  font-size: 11px;
  color: var(--text);
}

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--text-dim);
}

.foot a {
  color: var(--text-dim);
}

/* ---------- narrow ---------- */

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

  .topbar h1 {
    width: 100%;
    margin-right: 0;
  }
}

@media (max-width: 480px) {
  .topbar-actions {
    width: 100%;
  }

  .field,
  .field select {
    flex: 1 1 auto;
  }
}
