:root {
  color-scheme: light;
  --ground: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --control: #c4c9d1;
  --text: #111111;
  --muted: #5f6368;
  --primary: #1d1f20;
  --negative-bg: #ffedea;
  --negative-ink: #831c1e;
  --positive-bg: #dcfae5;
  --positive-ink: #04250e;
  --radius: 8px;
  --pad: 16px;
}
* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--ground);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 480px; margin: 0 auto; }
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) max(var(--pad), env(safe-area-inset-right)) 0 max(var(--pad), env(safe-area-inset-left));
}
.body { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 12px 0 20px; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
h1:focus { outline: none; }
h2 { font-size: 16px; font-weight: 600; line-height: 1.3; }
.muted { color: var(--muted); }
.center { text-align: center; font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }

.bar { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:focus-visible, .cell:focus-visible, .handle:focus-visible { outline: 3px solid #1d5fbf; outline-offset: 2px; }
button.text { min-height: 44px; padding: 0; font-weight: 500; }
button.link { padding: 12px 0; margin: -12px 0; color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
button.primary, button.secondary { flex: 1; min-height: 52px; border-radius: var(--radius); font-weight: 600; padding: 0 12px; }
button.primary { background: var(--primary); color: #fff; }
button.secondary { background: var(--surface); border: 1px solid var(--control); }
button:active { opacity: 0.75; }
button:disabled { opacity: 0.45; cursor: default; }
.actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  gap: 12px;
  padding: 12px 0 max(16px, env(safe-area-inset-bottom));
  background: var(--ground);
}

.cube { display: block; width: min(100%, 48dvh); aspect-ratio: 1; margin: 0 auto; }
.swatch { display: inline-block; flex: none; width: 20px; height: 20px; border: 1px solid #111; border-radius: 4px; }

.top-color { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; }
.stage { position: relative; width: min(100%, max(220px, 100dvh - 300px)); aspect-ratio: 1; margin: 0 auto; overflow: hidden; border-radius: var(--radius); background: #111; }
.stage video, .stage canvas, .stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage video { object-fit: cover; }
#camera-message { position: absolute; inset: 0; display: flex; align-items: center; padding: 32px; text-align: center; color: #fff; background: #111; }
#overlay polygon { fill: none; stroke: #fff; stroke-width: 8; }
#overlay .grid { stroke: #fff; stroke-width: 5; }
#overlay .under { stroke: #111; stroke-width: 14; }
#overlay .dot { stroke: #111; stroke-width: 6; }
.handle { touch-action: none; cursor: grab; }
.handle .hit { fill: transparent; }
.handle .knob { fill: #fff; stroke: #111; stroke-width: 8; }
.note { min-height: 24px; }

.status { padding: 12px; border-radius: var(--radius); background: var(--positive-bg); color: var(--positive-ink); }
.status.error { background: var(--negative-bg); color: var(--negative-ink); }
#faces { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.face { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.face p { font-size: 14px; color: var(--muted); line-height: 1.3; }
.cells { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; border-radius: 4px; background: #111; }
.cell { position: relative; aspect-ratio: 1; padding: 0; border-radius: 4px; font-weight: 700; color: #111; }
.cell:disabled { opacity: 1; }
.cell[data-color="R"], .cell[data-color="F"], .cell[data-color="B"] { color: #fff; }
.cell.bad { box-shadow: inset 0 0 0 3px #111, inset 0 0 0 5px #fff; }
.cell.selected { outline: 4px solid #1d5fbf; outline-offset: 1px; z-index: 1; }
.face-tools { display: flex; justify-content: space-between; font-size: 14px; }
.face-tools button { min-height: 44px; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.palette { display: grid; grid-template-columns: 1fr 1fr 1.35fr; gap: 8px; border-top: 1px solid var(--border); }
.palette button { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 10px; border: 1px solid var(--control); border-radius: var(--radius); background: var(--surface); font-size: 14px; white-space: nowrap; }

progress { display: block; width: 100%; height: 6px; border: 0; border-radius: 3px; overflow: hidden; background: var(--border); appearance: none; -webkit-appearance: none; }
progress::-webkit-progress-bar { background: var(--border); }
progress::-webkit-progress-value { background: var(--primary); }
progress::-moz-progress-bar { background: var(--primary); }
.move { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; min-height: 60px; }
#move-code { flex: none; font-size: 28px; line-height: 30px; font-weight: 600; color: var(--muted); }
#move-note { min-height: 48px; }
.hold { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px; font-weight: 600; font-size: 14px; }
.hold span { display: flex; align-items: center; gap: 8px; }
