/* Black is not a style choice here: on an OLED phone an unlit pixel draws no
   current, so every surface that is not the active dial stays at #000. */

:root {
  --bar-h: 58px;
  --gap: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
  color: #fff;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- board ---------- */

.board {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  grid-template-columns: 1fr;
  /* Rows must be explicitly equal: an `auto` row would size to its content,
     and the dial inside it is sized at height:100%, which would collapse. */
  grid-auto-rows: 1fr;
}

/* Three players is the tuned case: one column of full-width rows gives the
   largest possible dials. Four and up need a second column, which still beats
   stacking because the cells stay closer to square. */
.board[data-n="4"],
.board[data-n="5"],
.board[data-n="6"],
.board[data-n="7"],
.board[data-n="8"] { grid-template-columns: 1fr 1fr; }

.board[data-n="7"],
.board[data-n="8"] { gap: 6px; }

@media (orientation: landscape) {
  .board[data-n="2"],
  .board[data-n="3"] { grid-template-columns: repeat(var(--n), 1fr); }
  .board[data-n="4"],
  .board[data-n="5"],
  .board[data-n="6"] { grid-template-columns: repeat(3, 1fr); }
  .board[data-n="7"],
  .board[data-n="8"] { grid-template-columns: repeat(4, 1fr); }
}

/* The whole cell is the tap target, not just the circle inside it. */
.dial {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
  min-height: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 18px;
  transition: transform 90ms ease;
}

.dial:active { transform: scale(0.975); }

.dial svg {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: visible;
}

.face {
  fill: color-mix(in srgb, var(--c) 10%, #000);
  transition: fill 140ms ease;
}

.dial.active .face {
  /* Rich rather than fully saturated: keeps white numerals legible on amber
     and lime, and lights far fewer subpixels than a pastel fill would. */
  fill: color-mix(in srgb, var(--c) 52%, #000);
}

.stripes { display: none; }
.dial.over .stripes { display: block; }

.track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.10);
  stroke-width: 5;
}

.ring {
  fill: none;
  stroke: var(--c);
  stroke-width: 5;
  stroke-linecap: round;
}

.dial.active .ring { filter: drop-shadow(0 0 3px var(--c)); }
.dial.over .ring { stroke: #ff4d4f; }

.prep-ring {
  fill: none;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0;
}

.dial.prepping .prep-ring { opacity: 1; }

.d-name {
  fill: var(--c);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-anchor: middle;
  text-transform: uppercase;
}

.dial.active .d-name { fill: rgba(255, 255, 255, 0.92); }

.d-time {
  fill: #fff;
  font-size: 21px;
  font-weight: 650;
  text-anchor: middle;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.dial.over .d-time { fill: #ff5a5c; }

.d-sub {
  fill: rgba(255, 255, 255, 0.62);
  font-size: 6.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-anchor: middle;
  text-transform: uppercase;
}

/* ---------- control bar ---------- */

.bar {
  flex: 0 0 var(--bar-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}

.bar-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.66);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font: inherit;
  cursor: pointer;
}

.bar-btn .glyph { font-size: 17px; line-height: 1; }
.bar-btn .label { font-size: 10px; letter-spacing: 0.05em; }
.bar-btn:active { background: rgba(255, 255, 255, 0.07); }
.bar-btn[aria-pressed="true"] { color: #38bdf8; }
.bar-btn[disabled] { opacity: 0.3; }

/* ---------- editor ---------- */

.editor {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000;
  padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.editor[hidden] { display: none; }

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.editor-head h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}

.prep-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 14px;
}

.prep-field { display: flex; align-items: baseline; gap: 6px; }
.prep-field .unit { color: rgba(255, 255, 255, 0.45); font-size: 12px; }

.rows { display: flex; flex-direction: column; gap: 10px; }

.row {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-left: 4px solid var(--c);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row-top { display: flex; align-items: center; gap: 8px; }
.row-top .name { flex: 1; min-width: 0; }
.row-top .bank { width: 88px; text-align: center; }

input {
  appearance: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  color: #fff;
  font: inherit;
  font-size: 15px;
  padding: 9px 10px;
}

#prep { width: 72px; text-align: center; }
input:focus { outline: 2px solid rgba(255, 255, 255, 0.4); outline-offset: 1px; }

.row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--s);
  padding: 0;
  cursor: pointer;
  opacity: 0.42;
}

.swatch[aria-pressed="true"] { opacity: 1; border-color: #fff; }

.row-tools { display: flex; gap: 4px; }

.icon-btn {
  appearance: none;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  font-size: 15px;
  cursor: pointer;
}

.icon-btn[disabled] { opacity: 0.25; }
.icon-btn.danger { color: #ff6b6d; }

.editor-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.ghost {
  appearance: none;
  flex: 1;
  padding: 12px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.ghost.danger { color: #ff6b6d; border-color: rgba(255, 107, 109, 0.4); }
.editor-head .ghost { flex: 0 0 auto; padding: 9px 18px; }

.hint {
  margin-top: 16px;
  font-size: 12px;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.4);
}

.hint code {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  padding: 1px 4px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 8px);
  z-index: 20;
  max-width: 84vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  backdrop-filter: blur(6px);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
