:root {
 color-scheme: light;
 font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
 color: #212529;
 background: #f8f9fa;
 --muted: #6c757d;
 --line: #dee2e6;
 --teal: #0d6efd;
 --amber: #855b0b;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
main { max-width: 1200px; margin: auto; padding: 28px 24px; display: grid; grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); gap: 20px; }
header, .wake-status, .lock-panel, .model { grid-column: 1 / -1; }
header { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 4px 0 8px; }
.eyebrow { margin: 0 0 8px; font-size: 14px; font-weight: 700; letter-spacing: .7px; color: #0d6efd; }
h1 { margin: 0; font-size: clamp(24px, 3.5vw, 32px); line-height: 1.25; font-weight: 600; letter-spacing: -.6px; }
header label { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
#disc-count { width: 76px; }
p { font-size: 13px; line-height: 1.6; }
.panel { min-width: 0; align-self: start; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.panel-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 16px; line-height: 1.35; font-weight: 600; }
.panel-head > span { font-size: 10px; letter-spacing: .3px; color: var(--muted); }
button, input, select { font: inherit; font-size: 14px; color: #212529; border: 1px solid #ced4da; border-radius: 6px; -webkit-tap-highlight-color: transparent; }
button { padding: 10px 14px; background: #fff; cursor: pointer; line-height: 1.4; touch-action: manipulation; transition: background-color .12s, border-color .12s; }
button:hover:not(:disabled) { background: #e9ecef; border-color: #adb5bd; }
button:active:not(:disabled) { background: #dee2e6; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: #0d6efd; border-color: #0d6efd; color: #fff; font-weight: 600; }
.primary:hover:not(:disabled) { background: #0b5ed7; border-color: #0a58ca; }
.primary:active:not(:disabled) { background: #0a58ca; }
input, select { max-width: 100%; background: #fff; padding: 10px 12px; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #86b7fe; outline-offset: 2px; border-color: #0d6efd; }
.panel-toggle { min-height: 48px; padding: 8px 12px; flex-shrink: 0; font-size: 12px; background: #f8f9fa; }
.is-collapsed .panel-head { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }
.help { font-size: 11px; color: var(--muted); margin: 14px 0 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Lock library */
.lock-panel { padding: 16px 20px; }
.lock-panel.is-collapsed { padding-top: 10px; padding-bottom: 10px; }
.lock-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lock-fields label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.lock-fields input, .lock-fields select { min-width: 0; width: 100%; min-height: 44px; font-size: 16px; }
.lock-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.lock-actions button { min-height: 44px; }
#lock-summary { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; letter-spacing: 0; }

/* Model and playback */
.model canvas { display: block; width: 100%; height: 390px; touch-action: none; cursor: grab; background: #fff; }
.model-caption { display: flex; justify-content: space-between; gap: 16px; padding: 12px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.model-caption span:first-child { color: var(--amber); }
.model > .help { margin: 10px 18px 12px; }
.workspace-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--line); background: #f8f9fa; }
.workspace-controls button { min-height: 48px; }
.workspace-controls > span { flex: 1; font-size: 12px; color: var(--muted); }
.pick-order { padding: 10px 18px; border-top: 1px solid var(--line); }
.order-units { font-weight: 400; color: var(--muted); }
.pick-order h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
#pick-order { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
#pick-order li { padding: 3px 6px; border: 1px solid #ffe69c; background: #fff9e6; border-radius: 5px; font-size: 12px; }
#pick-order li.latest-step { background: #d1e7dd; border-color: #198754; box-shadow: inset 0 0 0 1px #198754; color: #0f5132; font-weight: 600; }
#workspace-command-status { margin: 8px 0 0; padding: 8px 10px; border: 1px solid #badbcc; border-radius: 5px; font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
#workspace-command-status[data-status=success] { background: #d1e7dd; color: #0f5132; }
#workspace-command-status[data-status=error] { background: #f8d7da; border-color: #f1aeb5; color: #842029; }
#pick-order .false-step { border-color: #b6d4fe; background: #eaf2ff; }
#picking-status { margin: 8px 0 0; font-size: 11px; color: var(--muted); }
.model-details { border-top: 1px solid var(--line); }
.model-details summary { cursor: pointer; padding: 8px 18px; font-size: 11px; color: var(--muted); }
.model-details .help { margin: 10px 18px 12px; }

/* Manual input */
.touch-panel { padding: 18px; }
.touch-panel .panel-head > span { display: none; }
.touch-row { display: grid; grid-template-columns: 44px 52px minmax(0, 1fr) 52px; align-items: center; gap: 8px; margin-top: 8px; max-width: 440px; }
.touch-row > span, .touch-row > label { font-size: 13px; color: var(--muted); }
.touch-row button, .touch-row input, .touch-row select { min-height: 48px; }
.touch-row button { padding: 8px; font-size: 20px; background: #f8f9fa; }
.touch-row input, .touch-row select { text-align: center; width: 100%; min-width: 0; padding: 10px; font-size: 18px; }
.touch-row input::-webkit-inner-spin-button { -webkit-appearance: none; }
.touch-row:focus-within > label, .touch-row:focus-within > span { color: #0a58ca; font-weight: 600; }
.touch-actions { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; max-width: 440px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.touch-actions button { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; font-size: 13px; padding: 10px 6px; }
.touch-actions svg { width: 18px; height: 18px; flex: 0 0 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#touch-reset, #voice-start[aria-pressed="true"], #picking-stop { color: #b02a37; border-color: #e0b8bc; }
#touch-reset:hover:not(:disabled), #voice-start[aria-pressed="true"]:hover, #picking-stop:hover:not(:disabled) { background: #f8d7da; }
#touch-status { font-size: 12px; color: #495057; margin: 10px 0 0; line-height: 1.4; }
.touch-help { margin-top: 8px; }
.touch-kind { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; margin: 6px 0; max-width: 440px; cursor: pointer; touch-action: manipulation; font-size: 13px; }
.touch-kind small { display: inline-block; margin-left: 6px; font-size: 11px; color: var(--muted); }
.touch-kind input { position: absolute; opacity: 0; width: 1px; height: 1px; padding: 0; margin: 0; }
.switch-track { position: relative; display: block; flex: 0 0 48px; width: 48px; height: 26px; border: 1px solid #adb5bd; border-radius: 20px; background: #ced4da; }
.switch-track::before { content: ""; position: absolute; width: 18px; height: 18px; top: 3px; left: 3px; background: #fff; border-radius: 50%; transition: transform .12s; }
.touch-kind input:checked + .switch-track { background: #0d6efd; border-color: #0d6efd; }
.touch-kind input:checked + .switch-track::before { transform: translateX(22px); }
.touch-kind input:focus-visible + .switch-track { outline: 3px solid #86b7fe; outline-offset: 3px; }

/* Voice controls and observations */
.voice-panel { padding: 18px 20px; }
.voice-panel.is-collapsed { padding-top: 12px; padding-bottom: 12px; }
#voice-summary { font-size: 10px; letter-spacing: 0; text-align: right; max-width: 180px; }
.voice-controls, .voice-entry { display: flex; gap: 8px; flex-wrap: wrap; }
.voice-controls button { min-height: 48px; }
#voice-start { min-height: 48px; flex-shrink: 0; }
#voice-start[aria-pressed="true"] { background: #fff; }
.wake-status { margin: -12px 0 0; font-size: 11px; }
.voice-entry input { flex: 1; min-width: 0; }
#mic-input { min-width: 0; font-size: 12px; }
.voice-controls #mic-input { flex: 1; min-width: 160px; }
.mic-level { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 12px; margin: 12px 0; }
.mic-level meter { width: 140px; max-width: 40%; height: 14px; accent-color: #0d6efd; }
.voice-phase { border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; margin-top: 16px; background: #f8f9fa; font-size: 15px; font-weight: 600; color: var(--muted); }
.voice-phase[data-phase=listening] { background: #d1e7dd; color: #0f5132; border-color: #badbcc; }
.voice-phase[data-phase=hearing] { background: #cff4fc; color: #055160; border-color: #b6effb; }
.voice-phase[data-phase=transcribing] { background: #fff3cd; color: #664d03; border-color: #ffecb5; }
.voice-phase[data-phase=preparing] { color: #664d03; }
#voice-status { color: #495057; min-height: 22px; }
#command-status { color: #0a58ca; }
#gate-notebook { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.gate-card { border: 1px solid #ffe69c; background: #fff9e6; border-radius: 6px; padding: 12px; min-width: 175px; }
.gate-card strong { color: #664d03; font-size: 13px; }
.gate-card p { margin: 5px 0 10px; font-size: 11px; color: var(--muted); }
.gate-card button { min-height: 36px; font-size: 11px; padding: 6px 10px; }
.false-gate-card { background: #eaf2ff; border-color: #b6d4fe; }
.false-gate-card strong { color: #084298; }

@media (max-width: 900px) {
 html { scroll-padding-top: calc(var(--workspace-height, 400px) + 20px); }
 main { grid-template-columns: minmax(0, 1fr); }
 header { order: 0; }
 .wake-status { order: 1; }
 .lock-panel { order: 2; }
 .model { order: 3; position: sticky; top: 8px; z-index: 5; box-shadow: 0 3px 12px #00000012; }
 .model:has(.model-details[open]), .model.is-tall { position: static; }
 .model canvas { height: clamp(110px, min(28svh, calc(100svh - var(--workspace-extra-height, 220px) - 100px)), 280px); }
 .workspace-controls { padding: 8px 10px; gap: 6px; }
 .workspace-controls button { min-height: 48px; padding: 8px 10px; font-size: 12px; }
 .workspace-controls #voice-summary { flex-basis: 100%; max-width: none; text-align: left; }
 .pick-order { padding: 8px 10px; }
 .pick-order h2 { margin-bottom: 6px; }
 #pick-order li { font-size: 11px; }
 #picking-status { max-height: 32px; overflow: auto; }
 .model-details summary { padding: 8px 10px; }
 .voice-panel { order: 4; }
 .touch-panel { order: 5; }
}
@media (max-width: 600px) {
 body { padding-bottom: env(safe-area-inset-bottom); }
 main { padding: 18px 12px; gap: 14px; }
 header { align-items: start; gap: 12px; }
 header label { flex-direction: column; align-items: start; gap: 5px; font-size: 12px; }
 h1 { font-size: 24px; }
 .eyebrow { font-size: 12px; }
 .lock-panel { padding: 12px; }
 .lock-panel .panel-head h2 { font-size: 14px; }
 .lock-fields { grid-template-columns: 1fr; }
 .lock-actions button { flex: 1; }
 #lock-summary { max-width: 90px; font-size: 10px; }

 .model-caption { padding: 10px 12px; gap: 10px; font-size: 10px; }
 .workspace-controls button { flex: 1; }
 .touch-panel { padding: 14px; }
 .touch-panel .panel-head { margin-bottom: 6px; padding-bottom: 8px; }
 .touch-panel .panel-head h2 { font-size: 14px; }
 .touch-panel .panel-head > span { display: none; }
 .panel-toggle { padding: 8px 10px; font-size: 12px; }
 .touch-panel.is-collapsed { padding-top: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
 .touch-panel.is-collapsed .panel-head { margin-bottom: 0; padding-bottom: 0; }
 .touch-row, .touch-actions, .touch-kind { max-width: 420px; margin-left: auto; margin-right: auto; }
 .touch-row { margin-top: 6px; grid-template-columns: 44px 52px minmax(0, 1fr) 52px; }
 .touch-actions { margin-top: 10px; padding-top: 10px; }
 .touch-actions button { flex-direction: column; gap: 2px; min-height: 58px; padding: 7px 4px; font-size: 13px; }
 .touch-actions svg { width: 17px; height: 17px; flex-basis: 17px; }
 .touch-help { font-size: 10px; }
 .voice-panel { padding: 16px; }
 .voice-panel .panel-head { flex-wrap: wrap; }
 .voice-panel .panel-head h2 { flex: 1; }
 .voice-controls #mic-input { flex-basis: 100%; min-height: 48px; font-size: 16px; }
 .voice-entry input { font-size: 16px; min-height: 48px; }
 #voice-start { padding: 8px 10px; font-size: 12px; }
 #voice-summary { flex: 1; }
 .voice-entry { flex-direction: column; }
 .voice-entry input { width: 100%; }
 .gate-card { flex: 1; }
}
@media (max-width: 900px) and (max-height: 500px) {
 .model { top: 4px; }
 .model canvas { height: 120px; }
}
@media (prefers-reduced-motion: reduce) {
 button, .switch-track::before { transition: none; }
}
