/* DM Sans, bundled with the app (SIL Open Font License, see fonts/OFL-DM-Sans.txt), so no request goes to Google. */
@font-face { font-family: "DM Sans"; font-style: normal; font-display: swap; font-weight: 100 1000;
  src: url("fonts/dm-sans-latin-wght-normal.woff2") format("woff2-variations"), url("fonts/dm-sans-latin-wght-normal.woff2") format("woff2"); }
/* F*ckDeck — app shell
   Calm cream base, ink text, grape as the single accent, lime only for live speed,
   butter only for the cap marker, tomato only for STOP. */
:root {
  --bg: #FFF6EC; --surface: #FFFFFF; --sunk: #F6EBDD; --line: #EADFD2; --line-2: #DDCFBF;
  --ink: #22172E; --muted: #625870; --faint: #7A7085;
  --grape: #6B3DF4; --grape-ink: #4F25D6; --grape-soft: #EEE8FF;
  --lime: #C6F36B; --butter: #FFD54A; --tomato: #D92D20;
  --c-tender: #E98BB0; --c-goon: #1F8A8A; --c-tease: #F2B705; --c-hypno: #6B3DF4;  --c-rough: #E2543B;
  --player-h: 92px; --r: 14px;
  --on-ink: #FFFFFF;        /* text on an ink-filled pill/button */
  --bar: #22172E;           /* player bar, dark in both themes */
  --dark: #22172E;          /* text on butter/lime fills */
  --dial-speed: #6B3DF4;
  --banner-bg: #FFF1C9; --banner-line: #F3D47A; --banner-ink: #6B5300;
  --h1-bg: #E9F7EF; --h1-ink: #1F7A4A; --h2-bg: #EEF0FF; --h2-ink: #3B3FB0;
  --h3-bg: #FFF1DA; --h3-ink: #8A5300; --h4-bg: #FFE6E1; --h4-ink: #B42B12;
  --shadow: #22172E55;
  --accent-text: #5A2EE0;   /* purple used as text */
  color-scheme: light;
}
/* Night (default): dark first, lime = live speed, butter = cap, red = STOP. */
:root[data-theme="night"] {
  --bg: #15111B; --surface: #1E1827; --sunk: #2A2236; --line: #352B44; --line-2: #76698A;
  --ink: #F5F0FA; --muted: #B4A9C2; --faint: #8F84A0;
  --grape: #7A4DFF; --grape-ink: #8E66FF; --grape-soft: #2E2445;
  --tomato: #D92D20;
  --on-ink: #15111B; --bar: #0E0A13; --dial-speed: #C6F36B;
  --banner-bg: #3A2F12; --banner-line: #6B5520; --banner-ink: #FFE08A;
  --h1-bg: #7EE0A81F; --h1-ink: #7EE0A8; --h2-bg: #A9B4FF1F; --h2-ink: #A9B4FF;
  --h3-bg: #FFC56B1F; --h3-ink: #FFC56B; --h4-bg: #FF9A851F; --h4-ink: #FF9A85;
  --shadow: #00000099;
  --accent-text: #A98BFF;
  color-scheme: dark;
}
* { box-sizing: border-box; min-width: 0; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); overflow: hidden;
  font: 15px/1.45 "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--grape); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
kbd { font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 2px 5px; border-radius: 5px; border: 1px solid var(--line-2); background: var(--surface); color: var(--muted); }

/* ---------- buttons & inputs ---------- */
button.primary, #ePlay, #tPlay, #crSave, #calStart, #saveSettings {
  background: var(--grape); color: #fff; font-weight: 700; padding: 10px 18px; border-radius: 999px; min-height: 42px; }
button.primary:hover, #ePlay:hover, #tPlay:hover, #crSave:hover { background: var(--grape-ink); }
button.quiet, .ghost, button.small { background: var(--surface); border: 1px solid var(--line-2); padding: 8px 14px; border-radius: 999px; font-weight: 600; min-height: 38px; }
button.quiet:hover, .ghost:hover { border-color: var(--ink); }
.ghost.on, button.small.on, .seg-toggle button.on { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
button:disabled { opacity: .4; cursor: default; }
input[type=text], input:not([type]), input[type=number], input[type=password], select, textarea {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 11px; }
textarea { width: 100%; resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--grape); height: 28px; }
input[type=file] { font-size: 14px; width: 100%; padding: 10px; border: 1px dashed var(--line-2); border-radius: 10px; background: var(--surface); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.sub { color: var(--muted); font-size: 14px; }
.label { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row.tight { margin-top: 6px; gap: 6px; } .row.between { justify-content: space-between; } .row.end { justify-content: flex-end; } .row.center { justify-content: center; }
.grow { flex: 1; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); height: calc(100vh - var(--player-h)); }
.side { display: flex; flex-direction: column; gap: 18px; padding: 22px 16px 16px; border-right: 1px solid var(--line); background: var(--bg); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.01em; padding: 0 8px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cdefs%3E%3ClinearGradient id='g1' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop offset='0' stop-color='%238F68FF'/%3E%3Cstop offset='1' stop-color='%235F33E6'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='512' height='512' rx='114' fill='url%28%23g1%29'/%3E%3Cpath d='M256 256L256.0 106.0M256 256L385.9 181.0M256 256L385.9 331.0M256 256L256.0 406.0M256 256L126.1 331.0M256 256L126.1 181.0' fill='none' stroke='%23FFF6EC' stroke-width='74' stroke-linecap='round'/%3E%3C/svg%3E") center/100% no-repeat; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav > button { display: flex; align-items: center; gap: 10px; text-align: left; padding: 9px 10px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.nav > button:hover { background: var(--sunk); color: var(--ink); }
.nav > button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 0 var(--line-2), 0 0 0 1px var(--line); }
.ico { width: 20px; text-align: center; color: var(--faint); }
.nav > button.on .ico { color: var(--accent-text); }
.nav-sep { height: 1px; background: var(--line); margin: 8px 6px; }
.subnav { display: flex; flex-direction: column; margin: 2px 0 6px 30px; }
.subnav button { text-align: left; padding: 5px 8px; border-radius: 8px; font-size: 13.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.subnav button:hover { color: var(--ink); background: var(--sunk); }
.subnav i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.device { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.dev-line { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: #22C55E; box-shadow: 0 0 0 3px #22C55E33; }
.main { overflow-y: auto; padding: 30px 40px 48px; scroll-behavior: smooth; }
.banner { background: var(--banner-bg); border: 1px solid var(--banner-line); color: var(--banner-ink); padding: 10px 14px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; }
.page-head, .tab .sec { margin: 0 0 18px; display: block; }
.page-head h1, .tab .sec h1, .tab .sec h2 { margin: 0; font-size: 30px; font-weight: 850; letter-spacing: -.025em; line-height: 1.1; }
.page-head p, .tab .sec span { display: block; margin: 6px 0 0; color: var(--muted); font-size: 15px; max-width: 64ch; }
.tab { max-width: 1180px; }

/* ---------- scene grid ---------- */
#lengthBar { gap: 6px; margin: 0 0 22px; padding: 10px 12px; border-radius: var(--r); background: var(--sunk); }
#lengthBar .label { margin: 0 6px 0 2px; }
#lengthBar button { min-height: 32px; padding: 5px 12px; font-size: 13.5px; }
#lengthBar #lenCustom { width: 78px; padding: 6px 8px; text-align: center; font-size: 13.5px; }
#lengthBar #lenNote { flex-basis: 100%; font-size: 13px; color: var(--muted); margin: 2px 2px 0; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
#sceneGrid .cat-head { font-size: 19px; font-weight: 800; letter-spacing: -.01em; margin: 26px 0 0; display: flex; align-items: center; gap: 10px; scroll-margin-top: 20px; }
#sceneGrid .cat-head:first-child { margin-top: 0; }
#sceneGrid .cat-head::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--cat, var(--grape)); }
.pat { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 16px 16px 14px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
.pat::before { content: ""; position: absolute; left: -1px; right: -1px; top: -1px; height: 5px; border-radius: var(--r) var(--r) 0 0; background: var(--cat, var(--line-2)); }
.pat:hover { border-color: var(--line-2); box-shadow: 0 6px 20px -12px var(--shadow); transform: translateY(-1px); }
.pat.playing { border-color: var(--grape); box-shadow: 0 0 0 2px var(--grape); }
.pat.playing::after { content: "Playing"; position: absolute; top: 14px; right: 14px; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: #fff; background: var(--grape); padding: 3px 8px; border-radius: 999px; }
.pat h3 { margin: 4px 0 0; font-size: 17px; font-weight: 800; letter-spacing: -.01em; padding-right: 64px; }
.pat .sub { font-size: 13.5px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 38px; }
.pat canvas { width: 100%; height: 40px; margin: 4px 0 0; background: transparent; }
.pat > .tags:nth-child(5) { display: none; }
.pat .tags { font-size: 12.5px; color: var(--faint); }
.pat .row { margin-top: 4px; gap: 6px; }
.pat .row button { min-height: 32px; padding: 5px 12px; font-size: 13px; }
.pat .row button:first-child { background: var(--ink); color: var(--on-ink); border: 0; border-radius: 999px; font-weight: 700; }

/* ---------- mode panels ---------- */
.mode-panel > *:not(.sec) { max-width: 860px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 18px; padding: 20px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.form-grid label { font-size: 13px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.form-grid label.inline { flex-direction: row; align-items: center; color: var(--ink); }
label.inline { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; }
label.inline input[type=range] { width: 140px; }
.tempo { display: flex; align-items: center; justify-content: center; gap: 28px; padding: 26px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.tempo-num { font-size: 72px; font-weight: 850; letter-spacing: -.04em; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.tempo-num small { display: block; font-size: 13px; font-weight: 600; letter-spacing: 0; color: var(--muted); margin-top: 6px; }
button.big { width: 60px; height: 60px; border-radius: 50%; font-size: 28px; padding: 0; }
.media-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.pane { padding: 18px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.pane input[type=file] { margin-top: 8px; }
.seg-toggle { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--sunk); margin-bottom: 10px; }
.seg-toggle button { padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.readout { display: flex; align-items: baseline; gap: 8px; font-size: 44px; font-weight: 850; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin-top: 8px; }
.readout small { font-size: 13px; font-weight: 600; letter-spacing: 0; color: var(--muted); }
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--sunk); color: var(--muted); align-self: center; }
.pill[data-s=locked] { background: #E6F9D0; color: #2F6B00; } .pill[data-s=holding] { background: var(--banner-bg); color: var(--banner-ink); }
.conf { height: 6px; border-radius: 3px; background: var(--sunk); overflow: hidden; margin: 10px 0; }
#rConf { height: 100%; width: 0; background: var(--grape); transition: width .3s; }
#videoScene { margin-top: 16px; }
#mediaStatus { margin-top: 12px; }
video { width: 100%; max-height: 420px; margin-top: 14px; border-radius: var(--r); background: #000; }
video.audio-only { max-height: 54px; background: transparent; }
#mediaCanvas, #edCanvas { width: 100%; margin-top: 10px; border-radius: 10px; background: var(--sunk); }
.steps { list-style: none; padding: 0; margin: 14px 0 0; counter-reset: s; }
.steps li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 6px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); counter-increment: s; }
.steps li::before { content: counter(s); width: 22px; height: 22px; border-radius: 50%; background: var(--sunk); font-size: 12px; font-weight: 700; display: grid; place-items: center; flex: none; }
.steps input[type=number] { width: 70px; }
.subhead { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 8px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.scroll { overflow-x: auto; }
table.segs { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13.5px; background: var(--surface); border-radius: var(--r); overflow: hidden; }
.segs th { text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 8px; background: var(--sunk); }
.segs td { padding: 6px 8px; border-top: 1px solid var(--line); }
.segs input, .segs select { padding: 6px 8px; font-size: 13.5px; width: 100%; }
.segs input[type=number] { width: 74px; } .segs input:not([type]) { min-width: 96px; }

.manual-card { max-width: 640px; padding: 28px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.manual-read { font-size: 64px; font-weight: 850; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.manual-read small { font-size: 14px; font-weight: 600; letter-spacing: 0; color: var(--muted); margin-left: 8px; }
.presets { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.presets button, .focus-presets button { min-height: 48px; border-radius: 12px; background: var(--sunk); font-weight: 800; font-size: 16px; }
.presets button:hover, .focus-presets button:hover { background: var(--grape-soft); color: var(--grape-ink); }

/* ---------- player bar ---------- */
.player { position: fixed; left: 0; right: 0; bottom: 0; height: var(--player-h); z-index: 20; display: grid; align-items: center; gap: 18px;
  grid-template-columns: minmax(200px, 1.25fr) auto auto auto auto auto; padding: 0 18px 0 24px; background: var(--bar); color: #fff; }
.np { overflow: hidden; }
.np-top { display: flex; gap: 10px; align-items: baseline; font-size: 12px; color: #B9AFC6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-kicker { font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.np-name { font-size: 18px; font-weight: 800; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-phase { font-size: 13.5px; color: var(--lime); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 19px; }
.progress { height: 3px; border-radius: 2px; background: #ffffff22; margin-top: 6px; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: var(--lime); }
.transport { display: flex; gap: 6px; }
.tbtn { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 62px; padding: 8px 10px; border-radius: 12px; background: #ffffff10; font-weight: 700; font-size: 13px; }
.tbtn:hover { background: #ffffff1f; }
.tbtn kbd { background: transparent; border-color: #ffffff33; color: #B9AFC6; font-size: 12px; }
.tbtn.on { background: var(--butter); color: var(--dark); }
.tbtn.accent { background: var(--grape); }
.tbtn.accent:hover { background: var(--grape-ink); }
.speed { display: grid; grid-template-columns: auto auto auto; grid-template-rows: auto auto; align-items: center; column-gap: 10px; }
.round { width: 38px; height: 38px; border-radius: 50%; background: #ffffff14; font-size: 20px; font-weight: 700; color: #fff; }
.round:hover { background: #ffffff26; }
.round.wide { width: auto; padding: 0 14px; font-size: 13px; }
.speed-read { text-align: center; min-width: 76px; line-height: 1; }
#speedNum { font-size: 34px; font-weight: 850; letter-spacing: -.03em; color: var(--lime); font-variant-numeric: tabular-nums; }
.speed-read small { font-size: 15px; font-weight: 700; color: var(--lime); }
.speed-sub { font-size: 12px; color: #B9AFC6; margin-top: 3px; white-space: nowrap; }
.meter { grid-column: 1 / -1; position: relative; height: 5px; border-radius: 3px; background: #ffffff1a; margin-top: 8px; }
#meterFill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 3px; background: var(--lime); }
#meterCap { position: absolute; top: -4px; width: 2px; height: 13px; background: var(--butter); border-radius: 1px; left: 60%; }
.capbox { width: 130px; font-size: 12px; color: #B9AFC6; }
.capbox b { color: var(--butter); }
.capbox input { accent-color: var(--butter); height: 22px; }
.stop { height: 64px; min-width: 132px; padding: 0 22px; border-radius: 16px; background: var(--tomato); color: #fff; font-weight: 900; font-size: 22px; letter-spacing: .04em;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; box-shadow: 0 0 0 3px #FF4B3340; }
.stop:hover { filter: brightness(1.06); }
.stop small { font-size: 12px; font-weight: 700; letter-spacing: .06em; opacity: 1; margin-top: 4px; }

/* ---------- focus view ---------- */
.focus { position: fixed; inset: 0 0 var(--player-h) 0; z-index: 15; background: var(--bg); padding: 32px 48px; overflow: auto; }
.focus-close { position: absolute; top: 20px; right: 24px; }
.focus-grid { display: grid; grid-template-columns: minmax(280px, 440px) minmax(0, 1fr); gap: 48px; align-items: center; height: 100%; max-width: 1200px; margin: 0 auto; }
.focus-dial { position: relative; aspect-ratio: 1; }
.focus-dial svg { width: 100%; height: 100%; }
.focus-speed { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#focusSpeed { font-size: clamp(80px, 10vw, 140px); font-weight: 900; letter-spacing: -.05em; line-height: .9; font-variant-numeric: tabular-nums; }
.focus-speed small { font-size: 15px; font-weight: 700; color: var(--muted); margin-top: 6px; }
.focus-kicker { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.focus-name { font-size: clamp(36px, 5vw, 64px); font-weight: 900; letter-spacing: -.035em; line-height: 1.02; margin-top: 4px; }
.focus-phase { font-size: 22px; font-weight: 700; color: var(--accent-text); margin: 10px 0 16px; min-height: 30px; }
#focusChips { margin-bottom: 18px; }
#focusChips span { padding: 6px 12px; border-radius: 999px; background: var(--sunk); font-size: 13.5px; font-weight: 600; color: var(--muted); }
#focusChips span.done { color: var(--faint); text-decoration: line-through; }
#focusChips span.now { background: var(--ink); color: var(--on-ink); }
#liveCanvas { width: 100%; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.focus-presets { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.focus-presets span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-right: 4px; }
.focus-presets button { min-width: 64px; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 20px; padding: 26px 28px; width: min(720px, 94vw); max-height: 88vh; background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px var(--shadow); }
dialog::backdrop { background: #0E0A13AA; }
dialog h2 { margin: 0 0 14px; font-size: 24px; font-weight: 850; letter-spacing: -.02em; }
dialog h3 { margin: 18px 0 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; margin: 8px 0; }
dialog label b { color: var(--accent-text); }
.set-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; }
.set-grid h3:first-child { margin-top: 0; }
.keys { font-size: 13.5px; color: var(--muted); line-height: 2; margin: 0; }
.log { font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); max-height: 140px; overflow-y: auto; white-space: pre-wrap; background: var(--sunk); border-radius: 10px; padding: 10px 12px; }
.cal-step { display: flex; flex-direction: column; gap: 4px; margin: 14px 0; font-size: 18px; font-weight: 700; }
.tapbtn { width: 100%; height: 120px; border-radius: 18px; background: var(--grape); color: #fff; font-size: 22px; font-weight: 800; transition: transform .08s; }
.tapbtn.flash { transform: scale(.97); filter: brightness(1.2); }

/* ---------- smaller screens ---------- */
@media (max-width: 1180px) {
  .player { grid-template-columns: minmax(140px, 1fr) auto auto auto auto auto; gap: 12px; }
  .capbox { width: 100px; }
  #focusBtn { display: none; }
  .tbtn kbd { display: none; }
  .tbtn { min-width: 52px; }
}
@media (max-width: 860px) {
  :root { --player-h: 206px; }
  body { overflow: auto; }
  .app { display: block; height: auto; padding-bottom: var(--player-h); }
  .side { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; align-items: center; border-right: 0; border-bottom: 1px solid var(--line);
    padding: 10px 12px; gap: 8px; position: sticky; top: 0; z-index: 10; overflow: visible; }
  .brand { font-size: 15px; }
  .nav { grid-column: 1 / -1; grid-row: 2; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  .nav > button { flex: none; white-space: nowrap; padding: 7px 12px; }
  .subnav, .nav-sep, .ico { display: none; }
  .device { grid-column: 2; grid-row: 1; margin: 0; flex-direction: row; padding: 0; border: 0; background: none; align-items: center; gap: 6px; }
  .device button { min-height: 34px; padding: 5px 12px; font-size: 13px; }
  .dev-line span:last-child { display: none; }
  .main { overflow: visible; padding: 20px 16px 40px; }
  .media-grid, .set-grid, .focus-grid { grid-template-columns: 1fr; }
  .player { grid-template-columns: 1fr auto; grid-template-rows: auto auto auto; padding: 10px 12px; height: var(--player-h); gap: 8px 10px; }
  .np { grid-column: 1 / -1; } .transport { overflow-x: auto; } #focusBtn { display: none; }
  .speed { grid-column: 1; grid-row: 3; } .capbox { grid-column: 2; grid-row: 3; width: 120px; }
  .stop { grid-column: 2; grid-row: 2; }
  .side-foot .donate { display: none; }
  .phone-note:not(.hidden) { display: block; }
  .stop { height: 56px; min-width: 110px; }
  .focus { padding: 20px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* ---- filters + card meta ---- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 14px; }
.filter-bar input[type=search] { flex: 0 1 320px; min-width: 200px; padding: 10px 14px; border-radius: 999px; }
.filter-bar .frow { flex-basis: 100%; }
.frow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.frow .label { margin: 0 6px 0 0; min-width: 72px; }
.fchip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); font-size: 13px; font-weight: 600; min-height: 30px; }
.fchip:hover { border-color: var(--ink); }
.fchip.on { background: var(--grape); border-color: var(--grape); color: #fff; }
.fclear { grid-column: 3; grid-row: 1 / span 2; font-size: 13px; color: var(--muted); text-decoration: underline; padding: 6px; }
.pat .meta, #sdMeta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: -2px; }
.pat .meta span, #sdMeta span { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--sunk); color: var(--muted); }
.pat .meta .heat.h1, #sdMeta .heat.h1 { background: var(--h1-bg); color: var(--h1-ink); } .pat .meta .heat.h2, #sdMeta .heat.h2 { background: var(--h2-bg); color: var(--h2-ink); }
.pat .meta .heat.h3, #sdMeta .heat.h3 { background: var(--h3-bg); color: var(--h3-ink); } .pat .meta .heat.h4, #sdMeta .heat.h4 { background: var(--h4-bg); color: var(--h4-ink); }
.pat .meta .fmt, #sdMeta .fmt { background: transparent; border: 1px solid var(--line-2); color: var(--ink); }
.empty { color: var(--muted); padding: 24px 0; }
@media (max-width: 860px) { .filter-bar { grid-template-columns: 1fr; } .filter-bar input[type=search] { grid-row: auto; } .fclear { grid-column: auto; grid-row: auto; justify-self: start; } }

/* footer of sidebar: donate + about */
.side-foot { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; }
.donate { display: block; text-align: center; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; text-decoration: none; }
.donate:hover { border-color: var(--grape); color: var(--accent-text); }
.linkish { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; padding: 2px; cursor: pointer; }
/* 18+ gate */
.gate { position: fixed; inset: 0; z-index: 1000; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.gate[hidden] { display: none; }
.gate-card { max-width: 460px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: 0 10px 40px rgba(34,23,46,.08); }
.gate-card h2 { margin: 18px 0 8px; }
.btnlink { display: inline-flex; align-items: center; text-decoration: none; color: var(--ink); }
#aboutDlg { max-width: 560px; }

#lostDlg { max-width: 480px; border-top: 6px solid var(--tomato, #FF4B33); }
#lostDlg h2 { color: var(--tomato, #FF4B33); margin-top: 0; }

/* idle: transport controls are quiet until something plays */
body.is-idle .transport .tbtn, .transport .tbtn:disabled { opacity: 1; color: #8F84A0; background: #ffffff0a; }
body.is-idle .transport .tbtn.accent { background: transparent; }
/* filters fold away behind one button */
.ftoggle { justify-self: start; }
.filter-bar:not(.open) .frow, .filter-bar:not(.open) .fclear { display: none; }
.fsort { justify-self: start; min-height: 38px; border-radius: 999px; padding: 0 14px; }
/* start here */
#setupDlg { max-width: 620px; }
.steps { list-style: none; counter-reset: st; padding: 0; margin: 14px 0; display: grid; gap: 12px; }
.steps li { counter-increment: st; display: grid; grid-template-columns: 30px 1fr auto auto; gap: 10px; align-items: start; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.steps li::before { content: counter(st); width: 26px; height: 26px; border-radius: 50%; background: var(--grape-soft); color: var(--accent-text); font-weight: 800; display: grid; place-items: center; font-size: 13px; }
.steps .hint { margin: 4px 0 0; }
.steps input[type=range] { width: 220px; }
.st { font-size: 13px; font-weight: 700; color: var(--muted); align-self: center; white-space: nowrap; }
.st.ok { color: #2E8B57; } .st.bad { color: var(--tomato); }
.safety { background: var(--sunk); border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.5; margin-bottom: 14px; }
.phone-note { display: none; position: sticky; top: 0; z-index: 11; background: var(--butter); color: var(--dark); padding: 8px 14px; font-size: 13px; font-weight: 600; }
.side-foot #setupBtn { width: 100%; }
@media (max-width: 860px) { .steps li { grid-template-columns: 30px 1fr; } .steps li > button, .steps li > .st { grid-column: 2; justify-self: start; } .steps input[type=range] { width: 100%; } }
@media (max-width: 860px) {
  .side-foot { grid-column: 1 / -1; flex-direction: row; gap: 14px; align-items: center; padding: 0; }
  .side-foot #setupBtn { width: auto; min-height: 0; padding: 2px; border: 0; background: none; font-size: 13px; text-decoration: underline; color: var(--muted); }
}

/* create */
.cr-folder { margin: 0 0 16px; }
.cr-folder p { margin: 0 0 8px; }
.cr-meta { display: grid; grid-template-columns: 1.2fr 2fr auto auto; gap: 12px; align-items: end; margin-bottom: 12px; }
.cr-meta label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.cr-meta label.inline { display: flex; align-items: center; gap: 6px; padding-bottom: 10px; }
.cr-kinks { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.cr-table-wrap { overflow-x: auto; margin-bottom: 8px; }
.cr-table { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
.cr-table th { text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 0 6px; }
.cr-table td { padding: 0 4px; }
.cr-table input, .cr-table select { width: 100%; min-width: 0; }
.cr-table td:nth-child(1) input { min-width: 110px; }
.cr-table td:nth-child(5) select, .cr-table td:nth-child(6) select { min-width: 160px; }
.cr-table input[type=number] { width: 80px; }
.cr-table td.acts { white-space: nowrap; }
#crCanvas { width: 100%; margin: 10px 0 4px; border-radius: 10px; background: var(--sunk); }
.cr-mine { list-style: none; padding: 0; display: grid; gap: 6px; }
.cr-mine li { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.cr-mine .grow { flex: 1; font-weight: 700; }
button.danger { color: var(--tomato); }
@media (max-width: 860px) { .cr-meta { grid-template-columns: 1fr; } }

/* edge trainer visuals */
.edge-viz { display: grid; gap: 16px; margin-top: 18px; }
.edge-live { display: grid; grid-template-columns: 150px 1fr; gap: 22px; align-items: center; padding: 20px 22px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.el-ring { position: relative; width: 150px; height: 150px; }
.el-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.el-ring-bg { fill: none; stroke: var(--sunk); stroke-width: 10; }
.el-ring-fg { fill: none; stroke: var(--grape); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .25s linear, stroke .3s; stroke-dasharray: 327; stroke-dashoffset: 327; }
.edge-live[data-stage="rest"] .el-ring-fg { stroke: #1F8A8A; }
.edge-live[data-stage="hold"] .el-ring-fg { stroke: var(--butter); }
.edge-live[data-stage="finish"] .el-ring-fg { stroke: var(--tomato); }
.el-ring-txt { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.el-count { font-size: 42px; font-weight: 850; line-height: 1; font-variant-numeric: tabular-nums; }
.el-unit { font-size: 12px; color: var(--muted); font-weight: 600; }
.el-stage { font-size: 30px; font-weight: 850; letter-spacing: -.02em; }
.el-next { color: var(--muted); margin: 4px 0 12px; }
.el-dots { display: flex; gap: 8px; margin-bottom: 14px; min-height: 14px; }
.el-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--sunk); border: 2px solid var(--line-2); }
.el-dot.done { background: var(--grape); border-color: var(--grape); }
.el-dot.now { border-color: var(--grape); animation: elPulse 1.4s ease-in-out infinite; }
@keyframes elPulse { 50% { box-shadow: 0 0 0 5px var(--grape-soft); } }
.el-bar { position: relative; height: 10px; border-radius: 999px; background: var(--sunk); overflow: visible; }
.el-bar-fill { height: 100%; border-radius: 999px; background: var(--grape); width: 0; transition: width .15s linear; }
.el-bar-peak { position: absolute; top: -4px; width: 3px; height: 18px; border-radius: 2px; background: var(--ink); left: 0; }
.el-speed { margin-top: 6px; }
.edge-live[data-stage="idle"] .el-bar, .edge-live[data-stage="idle"] .el-speed { display: none; }
.edge-map { width: 100%; height: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 8px; }
.em-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 5; }
.em-area { fill: var(--grape-soft); opacity: .55; }
.em-area.done { opacity: 1; }
.em-line { fill: none; stroke: var(--line-2); stroke-width: 2.5; stroke-linejoin: round; }
.em-line.done { stroke: var(--grape); }
.em-head { stroke: var(--ink); stroke-width: 2; }
.em-peak { fill: var(--grape); }
.em-label { font-size: 12px; font-weight: 700; fill: var(--ink); }
.em-axis { font-size: 11px; fill: var(--muted); font-weight: 600; }
@media (max-width: 860px) { .edge-live { grid-template-columns: 1fr; justify-items: center; text-align: center; } .el-dots { justify-content: center; } }

#phaseLine.alert { color: var(--butter); font-weight: 800; }

.t-live { text-align: center; color: var(--muted); font-weight: 600; margin-top: 18px; }
.t-live.on { color: var(--accent-text); font-size: 18px; }

dialog label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; }
dialog label.check input { width: 18px; height: 18px; margin: 0; }
.activity { margin-top: 16px; }
.activity summary { cursor: pointer; font-weight: 700; padding: 6px 0; }

.cr-table input.len { width: 80px; }
.cr-table input.bad { border-color: var(--tomato); }

.edge-presets { margin: 0 0 12px; flex-wrap: wrap; align-items: center; }
.edge-presets .label, .cr-kinks .label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-right: 4px; }
.empty { display: grid; justify-items: start; gap: 8px; color: var(--muted); }
.empty p { margin: 0; }
@media (max-width: 860px) {
  #tab-edge .form-grid { grid-template-columns: 1fr 1fr; gap: 8px 12px; }
  .edge-presets .fchip { font-size: 13px; }
}

.em-warm { fill: var(--butter); opacity: .25; }

/* ===== Phone layout (overrides the earlier phone rules) =====
   Closed: a slim mini player — what's playing, the speed, a Controls button and a big STOP.
   Controls open the full-screen view with every control at thumb height. */
@media (max-width: 860px) {
  :root { --player-h: calc(78px + env(safe-area-inset-bottom)); }
  body.focus-on { --player-h: calc(214px + env(safe-area-inset-bottom)); }
  .side { padding-top: calc(10px + env(safe-area-inset-top)); }
  .player { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  body:not(.focus-on) .player { grid-template-columns: minmax(0, 1fr) auto auto auto; grid-template-rows: auto; gap: 8px; }
  body:not(.focus-on) .np { grid-column: 1; }
  body:not(.focus-on) .np-top { display: none; }
  body:not(.focus-on) .transport, body:not(.focus-on) .capbox, body:not(.focus-on) #spDown, body:not(.focus-on) #spUp, body:not(.focus-on) .meter { display: none; }
  body:not(.focus-on) .speed { grid-column: 2; grid-row: 1; display: block; }
  body:not(.focus-on) .speed-sub { display: none; }
  body:not(.focus-on) #speedNum { font-size: 28px; }
  #focusBtn { display: inline-flex; min-height: 44px; padding: 0 14px; }
  body:not(.focus-on) #focusBtn { grid-column: 3; grid-row: 1; }
  body:not(.focus-on) .stop { grid-column: 4; grid-row: 1; height: 54px; min-width: 96px; }
  /* open: full controls */
  body.focus-on .player { grid-template-columns: 1fr auto; grid-template-rows: auto auto auto; }
  body.focus-on #focusBtn { grid-column: 2; grid-row: 1; }
  body.focus-on .transport { grid-column: 1; grid-row: 2; display: flex; gap: 6px; }
  body.focus-on .transport .tbtn { flex: 1; min-height: 52px; }
  body.focus-on .stop { grid-column: 2; grid-row: 2 / span 2; height: auto; min-height: 112px; min-width: 104px; }
  body.focus-on .speed { grid-column: 1; grid-row: 3; }
  body.focus-on .capbox { display: none; }
  .focus { padding: calc(18px + env(safe-area-inset-top)) 18px 18px; }
  .focus-grid { gap: 18px; height: auto; }
  .focus-grid > :first-child { max-width: 260px; margin: 0 auto; }
  .focus .focus-cap { display: block; }
  .tbtn kbd { display: none; }
  /* Create: each step becomes a small card */
  .cr-table thead { display: none; }
  .cr-table, .cr-table tbody { display: block; }
  .cr-table tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 10px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
  .cr-table td { padding: 0; display: grid; gap: 3px; }
  .cr-table td::before { content: attr(data-label); font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
  .cr-table td:nth-child(1) { grid-column: 1 / -1; }
  .cr-table td:nth-child(5), .cr-table td:nth-child(6) { grid-column: span 3; }
  .cr-table td.acts { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 6px; }
  .cr-table td.acts::before { content: none; }
  .cr-table input[type=number], .cr-table input.len { width: 100%; }
  .cr-table td:nth-child(5) select, .cr-table td:nth-child(6) select { min-width: 0; }
  /* bigger touch targets */
  .fchip, .chip { min-height: 38px; }
  button, select, input { font-size: 16px; } /* 16px stops iPhone zooming into inputs */
}
/* A cap slider inside the full-screen view, for phones (the player's cap is hidden there). */
.focus-cap { display: none; margin-top: 18px; }
.focus-cap input { width: 100%; }

/* Create: graph with step marks and a test playhead; playing step; help under movement */
.cr-graph { position: relative; margin: 10px 0 4px; }
.cr-graph #crCanvas { margin: 0; }
.cr-head { position: absolute; top: 0; height: 90px; width: 2px; background: var(--ink); border-radius: 2px; transition: left .2s linear; }
.cr-marks { position: relative; height: 22px; }
.cr-marks span { position: absolute; top: 4px; font-size: 11px; font-weight: 700; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 5px; border-left: 2px solid var(--line-2); box-sizing: border-box; }
.cr-table tr.now td { background: var(--grape-soft); }
.cr-table tr.now td:first-child { border-radius: 10px 0 0 10px; } .cr-table tr.now td:last-child { border-radius: 0 10px 10px 0; }
.move-help { display: block; color: var(--muted); font-size: 11.5px; margin-top: 3px; line-height: 1.3; }
#crTest.on { background: var(--ink); color: var(--on-ink); }
.cr-folder { margin: 6px 0 10px; }
@media (max-width: 860px) { .cr-table tr.now { background: var(--grape-soft); } .cr-table tr.now td { background: none; } }

/* phone full-controls layout fix */
@media (max-width: 860px) {
  body.focus-on { --player-h: calc(250px + env(safe-area-inset-bottom)); }
  body.focus-on .player { grid-template-rows: auto auto auto; align-content: start; }
  body.focus-on .np { grid-column: 1; grid-row: 1; }
  body.focus-on .np-top { display: none; }
  body.focus-on #focusBtn { grid-column: 2; grid-row: 1; align-self: center; }
  body.focus-on .transport { grid-row: 2; }
  body.focus-on .speed { grid-row: 3; justify-self: start; }
  body.focus-on .stop { grid-row: 2 / span 2; }
  #focusBtn { background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; font-weight: 700; }
  .focus-close { display: none; }
}
/* step action buttons: compact so all four fit */
.cr-table td.acts { display: flex; gap: 4px; }
.cr-table td.acts button { width: 34px; height: 34px; min-height: 34px; padding: 0; display: inline-grid; place-items: center; }
.cr-table td:nth-child(5) select, .cr-table td:nth-child(6) select { min-width: 140px; }
@media (max-width: 860px) {
  body.focus-on .transport .tbtn { display: grid; place-content: center; text-align: center; }
  #focusBtn { height: 44px; align-items: center; justify-content: center; padding: 0 16px; }
}
.cr-table td:nth-child(5) select, .cr-table td:nth-child(6) select { min-width: 168px; }
.cr-table td:nth-child(3) input, .cr-table td:nth-child(4) input { width: 66px; }

/* STOP inside every dialog (dialogs cover the player bar) */
.dlg-stopbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: flex-end; margin: -4px -4px 8px 0; pointer-events: none; }
.dlg-stop { pointer-events: auto; min-height: 48px; min-width: 96px; padding: 0 18px; border: 0; border-radius: 14px;
  background: var(--tomato); color: #fff; font: inherit; font-weight: 900; font-size: 18px; letter-spacing: .04em; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.dlg-stop:hover { filter: brightness(1.06); }
.dlg-stop:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* Touch screens have no keyboard: hide key hints on controls */
@media (hover: none) and (pointer: coarse) {
  .tbtn kbd, .stop small, #tTap kbd, .keys { display: none; }
}

/* Scene details */
#sceneDlg .meta { margin: -6px 0 10px; }
.sd-desc { font-size: 16px; line-height: 1.5; margin: 0 0 12px; }
.sd-curve { width: 100%; height: 110px; display: block; }
.sd-phases { margin: 0; padding-left: 20px; line-height: 1.7; }
#sdExtra { display: contents; }
.pat { cursor: pointer; }
body.is-preview #modeLabel { color: var(--sun, #FFC94D); }

.notices summary { cursor: pointer; font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 8px; }
.notices pre.licence { white-space: pre-wrap; font-size: 11px; line-height: 1.45; background: var(--sunk); padding: 10px 12px; border-radius: 10px; max-height: 220px; overflow: auto; }

/* Focus dial colours follow the theme (SVG attributes are overridden by CSS) */
#dTrack { stroke: var(--line); } #dLimit { stroke: var(--sunk); } #dSpeed { stroke: var(--dial-speed); } #dCap { stroke: var(--ink); }
:root[data-theme="night"] .pill[data-s=locked] { background: #C6F36B1F; color: #C6F36B; }

.banner a, .banner .linkish { color: inherit; font-weight: 700; text-decoration: underline; }

.fcount { color: var(--muted); font-size: 13px; font-weight: 600; }

/* Skip link: hidden until focused */
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--grape); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 700; }
.skip:focus { top: 12px; }
.player:focus { outline: 3px solid var(--grape); outline-offset: -3px; }
/* Form-control borders need 3:1 against their background (decorative borders keep --line) */
:root { --control-line: #8C7D6C; } :root[data-theme="night"] { --control-line: #76698A; }
input[type=text], input:not([type]), input[type=number], input[type=search], select, textarea, .fchip, button.quiet, .ghost { border-color: var(--control-line); }
.st.bad { color: #B42318; } :root[data-theme="night"] .st.bad { color: #FF9A85; }
.st.ok { color: #1F7A4A; } :root[data-theme="night"] .st.ok { color: #7EE0A8; }
