/* ============================================================
   AI Prompt Minifier — style.css
   Pure CSS, no frameworks.
   Theme palettes are CSS custom properties: `:root` is the dark
   default (the original index.html colour language); the other
   palettes are activated with a class on <html> (see scripts/ui/theme.js).
   ============================================================ */

/* ---------------- Theme palettes (design tokens) ---------------- */

/* Dark — default, exact colours of the original single-file app */
:root {
    --bg: #121212;
    --pane: #181818;
    --panel: #242424;
    --panel-2: #2a2a2a;
    --title-bg: #1e1e1e;
    --border: #444444;
    --border-soft: #333333;
    --text: #e0e0e0;
    --text-soft: #cccccc;
    --muted: #aaaaaa;
    --faint: #8b8b8b;
    --input-bg: #333333;
    --placeholder: #9b9b9b;
    --accent: #0d6efd;
    --accent-hover: #0b5ed7;
    --accent-text: #66a3ff;
    --success: #1f7a38;
    --success-text: #28a745;
    --danger: #dc3545;
    --danger-text: #ef5a6a;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --focus-ring: var(--accent);
}

/* Light — cool neutral */
:root.light {
    --bg: #eef0f3;
    --pane: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #f1f3f5;
    --title-bg: #ffffff;
    --border: #cfd4dc;
    --border-soft: #dfe3e8;
    --text: #1f2328;
    --text-soft: #3c424a;
    --muted: #5f6771;
    --faint: #626a75;
    --input-bg: #ffffff;
    --placeholder: #626a75;
    --accent: #0b5ed7;
    --accent-hover: #0a52be;
    --accent-text: #0b5ed7;
    --success: #1f7a38;
    --success-text: #1f7a38;
    --danger: #c03444;
    --danger-text: #c03444;
    --shadow: 0 4px 12px rgba(31, 35, 40, 0.15);
    --focus-ring: var(--accent);
}

/* Midnight — deep blue dark */
:root.midnight {
    --bg: #0b1220;
    --pane: #101a2e;
    --panel: #16233c;
    --panel-2: #1b2a47;
    --title-bg: #13203a;
    --border: #2e3f5f;
    --border-soft: #24344f;
    --text: #dbe4f3;
    --text-soft: #b9c6de;
    --muted: #8fa2c0;
    --faint: #8fa2c0;
    --input-bg: #0f1a30;
    --placeholder: #93a7c9;
    --accent: #3272e0;
    --accent-hover: #2b62c9;
    --accent-text: #6ea8ff;
    --success: #1d7550;
    --success-text: #2eb872;
    --danger: #b83c4c;
    --danger-text: #ef5a6a;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Paper — warm sepia light */
:root.paper {
    --bg: #efe9dd;
    --pane: #f6f1e7;
    --panel: #fffdf8;
    --panel-2: #f3ecdf;
    --title-bg: #fffdf8;
    --border: #cfc4ad;
    --border-soft: #ded5c3;
    --text: #35302a;
    --text-soft: #4f473d;
    --muted: #6f6558;
    --faint: #6f6657;
    --input-bg: #fffdf8;
    --placeholder: #6d6455;
    --accent: #92400e;
    --accent-hover: #7c3a0d;
    --accent-text: #92400e;
    --success: #2f7d4f;
    --success-text: #2f7d4f;
    --danger: #c03444;
    --danger-text: #c03444;
    --shadow: 0 4px 12px rgba(53, 48, 42, 0.18);
    --focus-ring: var(--accent);
}

/* Nord — arctic blue-gray dark */
:root.nord {
    --bg: #2e3440;
    --pane: #3b4252;
    --panel: #434c5e;
    --panel-2: #4a5467;
    --title-bg: #333a46;
    --border: #4c566a;
    --border-soft: #434c5e;
    --text: #eceff4;
    --text-soft: #d5dbe7;
    --muted: #d0d8e2;
    --faint: #c2c9d4;
    --input-bg: #434c5e;
    --placeholder: #d0d8e2;
    --accent: #51749c;
    --accent-hover: #4a6d92;
    --accent-text: #aadde9;
    --success: #46633e;
    --success-text: #b2c898;
    --danger: #a8505c;
    --danger-text: #f0c8cd;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Dracula — purple/pink dark */
:root.dracula {
    --bg: #282a36;
    --pane: #191a21;
    --panel: #343746;
    --panel-2: #3c3f50;
    --title-bg: #21232d;
    --border: #6272a4;
    --border-soft: #44475a;
    --text: #f8f8f2;
    --text-soft: #dfe0ea;
    --muted: #b9c0dd;
    --faint: #a5acce;
    --input-bg: #343746;
    --placeholder: #b9c0dd;
    --accent: #bd93f9;
    --accent-hover: #ab80ee;
    --accent-text: #c9a9ff;
    --success: #50fa7b;
    --success-text: #50fa7b;
    --danger: #ff5555;
    --danger-text: #f79393;
    --on-accent: #282a36;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Alucard — cream + purple light */
:root.alucard {
    --bg: #fffbeb;
    --pane: #fffdf2;
    --panel: #ffffff;
    --panel-2: #fff8e1;
    --title-bg: #ffffff;
    --border: #e8dcbc;
    --border-soft: #f0e8d2;
    --text: #1f1f1f;
    --text-soft: #3a3a3a;
    --muted: #5c5648;
    --faint: #6b6557;
    --input-bg: #ffffff;
    --placeholder: #6b6557;
    --accent: #644ac9;
    --accent-hover: #563fb5;
    --accent-text: #644ac9;
    --success: #14710a;
    --success-text: #14710a;
    --danger: #cb3a2a;
    --danger-text: #cb3a2a;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(60, 60, 60, 0.18);
    --focus-ring: var(--accent);
}

/* Catppuccin Latte — pastel light */
:root.catppuccin-latte {
    --bg: #dce0e8;
    --pane: #eff1f5;
    --panel: #ffffff;
    --panel-2: #e6e9ef;
    --title-bg: #ffffff;
    --border: #acb0be;
    --border-soft: #cdd2dc;
    --text: #4c4f69;
    --text-soft: #565970;
    --muted: #5a5d71;
    --faint: #5c5f77;
    --input-bg: #ffffff;
    --placeholder: #6c6f85;
    --accent: #8839ef;
    --accent-hover: #742cd0;
    --accent-text: #7d33e0;
    --success: #2f7d30;
    --success-text: #2a6d29;
    --danger: #d20f39;
    --danger-text: #c20e34;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(60, 60, 60, 0.18);
    --focus-ring: var(--accent);
}

/* Catppuccin Frappé — soft lavender dark */
:root.catppuccin-frappe {
    --bg: #303446;
    --pane: #292c3c;
    --panel: #414559;
    --panel-2: #484d62;
    --title-bg: #2b2e40;
    --border: #626880;
    --border-soft: #51576d;
    --text: #c6d0f5;
    --text-soft: #b5bfe2;
    --muted: #b9bfd9;
    --faint: #b3b8cf;
    --input-bg: #414559;
    --placeholder: #b5bfe2;
    --accent: #babbf1;
    --accent-hover: #a4a9e4;
    --accent-text: #c4cbf5;
    --success: #a6d189;
    --success-text: #a6d189;
    --danger: #e78284;
    --danger-text: #efa9ab;
    --on-accent: #232634;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Catppuccin Macchiato — soft lavender dark */
:root.catppuccin-macchiato {
    --bg: #24273a;
    --pane: #1e2030;
    --panel: #363a4f;
    --panel-2: #3f4358;
    --title-bg: #262940;
    --border: #5b6078;
    --border-soft: #494d64;
    --text: #cad3f5;
    --text-soft: #b8c0e0;
    --muted: #a8b0cd;
    --faint: #a2a8c0;
    --input-bg: #363a4f;
    --placeholder: #b8c0e0;
    --accent: #c6a0f6;
    --accent-hover: #b28ce8;
    --accent-text: #d2b5fa;
    --success: #a6da95;
    --success-text: #a6da95;
    --danger: #ed8796;
    --danger-text: #f0a8b4;
    --on-accent: #181926;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Catppuccin Mocha — cozy low-contrast dark */
:root.catppuccin-mocha {
    --bg: #1e1e2e;
    --pane: #181825;
    --panel: #313244;
    --panel-2: #3a3b4e;
    --title-bg: #14141f;
    --border: #585b70;
    --border-soft: #45475a;
    --text: #cdd6f4;
    --text-soft: #bac2de;
    --muted: #a9b0ca;
    --faint: #979dbb;
    --input-bg: #313244;
    --placeholder: #a9b0ca;
    --accent: #cba6f7;
    --accent-hover: #b992ee;
    --accent-text: #ceabf7;
    --success: #a6e3a1;
    --success-text: #a6e3a1;
    --danger: #f38ba8;
    --danger-text: #f5a9bd;
    --on-accent: #11111b;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Tokyo Night — deep navy dark */
:root.tokyo-night {
    --bg: #1a1b26;
    --pane: #16161e;
    --panel: #292e42;
    --panel-2: #30354f;
    --title-bg: #1d1e2b;
    --border: #545c7e;
    --border-soft: #3b4261;
    --text: #c0caf5;
    --text-soft: #a9b1d6;
    --muted: #969ec4;
    --faint: #9297b8;
    --input-bg: #292e42;
    --placeholder: #a9b1d6;
    --accent: #7aa2f7;
    --accent-hover: #6490e8;
    --accent-text: #8fb0ff;
    --success: #9ece6a;
    --success-text: #9ece6a;
    --danger: #f7768e;
    --danger-text: #f98ba0;
    --on-accent: #1a1b26;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Tokyo Night Storm — navy dark */
:root.tokyo-night-storm {
    --bg: #24283b;
    --pane: #1f2335;
    --panel: #292e42;
    --panel-2: #30354f;
    --title-bg: #222638;
    --border: #545c7e;
    --border-soft: #3b4261;
    --text: #c0caf5;
    --text-soft: #a9b1d6;
    --muted: #969ec4;
    --faint: #9297b8;
    --input-bg: #292e42;
    --placeholder: #a9b1d6;
    --accent: #7aa2f7;
    --accent-hover: #6490e8;
    --accent-text: #8fb0ff;
    --success: #9ece6a;
    --success-text: #9ece6a;
    --danger: #f7768e;
    --danger-text: #f98ba0;
    --on-accent: #1f2335;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Tokyo Night Moon — purple-tinted dark */
:root.tokyo-night-moon {
    --bg: #222436;
    --pane: #1e2030;
    --panel: #2f334d;
    --panel-2: #373b58;
    --title-bg: #202231;
    --border: #545c7e;
    --border-soft: #3b4261;
    --text: #c8d3f5;
    --text-soft: #a8b2d8;
    --muted: #9fa6c9;
    --faint: #989dbf;
    --input-bg: #2f334d;
    --placeholder: #a8b2d8;
    --accent: #82aaff;
    --accent-hover: #6d95f0;
    --accent-text: #93b8ff;
    --success: #c3e88d;
    --success-text: #c3e88d;
    --danger: #ff757f;
    --danger-text: #ff8a92;
    --on-accent: #1e2030;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Tokyo Night Day — cool light */
:root.tokyo-night-day {
    --bg: #e4e8f4;
    --pane: #edf0f9;
    --panel: #f6f8fe;
    --panel-2: #e9edf8;
    --title-bg: #f6f8fe;
    --border: #b6bfd9;
    --border-soft: #cdd4e6;
    --text: #232a4d;
    --text-soft: #39406a;
    --muted: #4c5480;
    --faint: #5a6188;
    --input-bg: #ffffff;
    --placeholder: #5a6188;
    --accent: #2f54c0;
    --accent-hover: #2948a8;
    --accent-text: #2f54c0;
    --success: #2e6b1c;
    --success-text: #2e6b1c;
    --danger: #b32642;
    --danger-text: #b32642;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(60, 60, 60, 0.18);
    --focus-ring: var(--accent);
}

/* Gruvbox Dark — warm retro dark */
:root.gruvbox-dark {
    --bg: #282828;
    --pane: #32302f;
    --panel: #3c3836;
    --panel-2: #47413e;
    --title-bg: #302d2c;
    --border: #504945;
    --border-soft: #47413e;
    --text: #fbf1c7;
    --text-soft: #ebdbb2;
    --muted: #d5c4a1;
    --faint: #bdae93;
    --input-bg: #3c3836;
    --placeholder: #d5c4a1;
    --accent: #b84a0b;
    --accent-hover: #a03f09;
    --accent-text: #fe943d;
    --success: #79740e;
    --success-text: #b8bb26;
    --danger: #cc241d;
    --danger-text: #fd9184;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Gruvbox Light — warm retro light */
:root.gruvbox-light {
    --bg: #fbf1c7;
    --pane: #f2e5bc;
    --panel: #fbf1c7;
    --panel-2: #f8efcd;
    --title-bg: #fbf1c7;
    --border: #bdae93;
    --border-soft: #d5c4a1;
    --text: #282828;
    --text-soft: #3c3836;
    --muted: #504945;
    --faint: #665c54;
    --input-bg: #fbf1c7;
    --placeholder: #665c54;
    --accent: #b84a0b;
    --accent-hover: #a03f09;
    --accent-text: #9c3c09;
    --success: #66620c;
    --success-text: #66620c;
    --danger: #bf221b;
    --danger-text: #bf221b;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(60, 60, 60, 0.18);
    --focus-ring: var(--accent);
}

/* Solarized Dark — teal-slate dark */
:root.solarized-dark {
    --bg: #002b36;
    --pane: #073642;
    --panel: #0a3f4d;
    --panel-2: #0c424f;
    --title-bg: #04333e;
    --border: #586e75;
    --border-soft: #3a5560;
    --text: #eee8d5;
    --text-soft: #c5c0b0;
    --muted: #97a9af;
    --faint: #9fa8aa;
    --input-bg: #0a3f4d;
    --placeholder: #c5c0b0;
    --accent: #24749f;
    --accent-hover: #1e648c;
    --accent-text: #61ade4;
    --success: #557300;
    --success-text: #9bb41b;
    --danger: #dc322f;
    --danger-text: #f38783;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Solarized Light — warm cream light */
:root.solarized-light {
    --bg: #fdf6e3;
    --pane: #f4eeda;
    --panel: #fffdf4;
    --panel-2: #f7f2e2;
    --title-bg: #fffdf4;
    --border: #d5cba8;
    --border-soft: #e2dabc;
    --text: #073642;
    --text-soft: #1a4a58;
    --muted: #42596b;
    --faint: #526a76;
    --input-bg: #fffdf4;
    --placeholder: #526a76;
    --accent: #1a6db5;
    --accent-hover: #175f9e;
    --accent-text: #1a6db5;
    --success: #5f6c00;
    --success-text: #5f6c00;
    --danger: #c22b24;
    --danger-text: #c22b24;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(60, 60, 60, 0.18);
    --focus-ring: var(--accent);
}

/* Rosé Pine — muted plum dark */
:root.rose-pine {
    --bg: #191724;
    --pane: #1f1d2e;
    --panel: #26233a;
    --panel-2: #302c47;
    --title-bg: #151420;
    --border: #403d52;
    --border-soft: #322f45;
    --text: #e0def4;
    --text-soft: #c9c7e4;
    --muted: #9d9ab8;
    --faint: #928fa8;
    --input-bg: #26233a;
    --placeholder: #9d9ab8;
    --accent: #c4a7e7;
    --accent-hover: #b293d9;
    --accent-text: #d0b8f0;
    --success: #f6c177;
    --success-text: #f6c177;
    --danger: #eb6f92;
    --danger-text: #f093ac;
    --on-accent: #191724;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Rosé Pine Moon — muted plum dark */
:root.rose-pine-moon {
    --bg: #232136;
    --pane: #1f1d2e;
    --panel: #2a273f;
    --panel-2: #312e47;
    --title-bg: #201e31;
    --border: #44415a;
    --border-soft: #393552;
    --text: #e0def4;
    --text-soft: #c9c7e4;
    --muted: #9d9ab8;
    --faint: #928fa8;
    --input-bg: #2a273f;
    --placeholder: #9d9ab8;
    --accent: #c4a7e7;
    --accent-hover: #b293d9;
    --accent-text: #d0b8f0;
    --success: #f6c177;
    --success-text: #f6c177;
    --danger: #eb6f92;
    --danger-text: #f093ac;
    --on-accent: #1f1d2e;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Rosé Pine Dawn — soft cream light */
:root.rose-pine-dawn {
    --bg: #faf4ed;
    --pane: #fffaf3;
    --panel: #fffdf8;
    --panel-2: #f4ede8;
    --title-bg: #fffdf8;
    --border: #d8cfc4;
    --border-soft: #e5ded8;
    --text: #464261;
    --text-soft: #5a5675;
    --muted: #6d6984;
    --faint: #6c6980;
    --input-bg: #fffdf8;
    --placeholder: #6d6984;
    --accent: #7a55c0;
    --accent-hover: #6b499f;
    --accent-text: #7a55c0;
    --success: #8f5c00;
    --success-text: #8f5c00;
    --danger: #a5596f;
    --danger-text: #a5596f;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(60, 60, 60, 0.18);
    --focus-ring: var(--accent);
}

/* Ayu Dark — vivid dark */
:root.ayu-dark {
    --bg: #0d1017;
    --pane: #10141c;
    --panel: #141821;
    --panel-2: #1a2030;
    --title-bg: #0f1219;
    --border: #3a4560;
    --border-soft: #242d42;
    --text: #bfbdb6;
    --text-soft: #a9a7a0;
    --muted: #8d8b84;
    --faint: #83817a;
    --input-bg: #141821;
    --placeholder: #8d8b84;
    --accent: #59c2ff;
    --accent-hover: #41b2f5;
    --accent-text: #59c2ff;
    --success: #aad94c;
    --success-text: #aad94c;
    --danger: #f07178;
    --danger-text: #f58f95;
    --on-accent: #0d1017;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Ayu Mirage — vivid dark */
:root.ayu-mirage {
    --bg: #1f2430;
    --pane: #181c26;
    --panel: #282e3b;
    --panel-2: #2f3645;
    --title-bg: #1c212d;
    --border: #4a5468;
    --border-soft: #323947;
    --text: #cccac2;
    --text-soft: #b8b6ae;
    --muted: #a19f98;
    --faint: #9b9a94;
    --input-bg: #282e3b;
    --placeholder: #b8b6ae;
    --accent: #73d0ff;
    --accent-hover: #5cc2f5;
    --accent-text: #73d0ff;
    --success: #d5ff80;
    --success-text: #d5ff80;
    --danger: #f28779;
    --danger-text: #f7a294;
    --on-accent: #1f2430;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Ayu Light — cool light */
:root.ayu-light {
    --bg: #f8f9fa;
    --pane: #fcfcfc;
    --panel: #ffffff;
    --panel-2: #eef0f3;
    --title-bg: #ffffff;
    --border: #c9cdd2;
    --border-soft: #dde0e4;
    --text: #5c6166;
    --text-soft: #565b60;
    --muted: #50555a;
    --faint: #4a4f54;
    --input-bg: #ffffff;
    --placeholder: #5c6166;
    --accent: #22a4e6;
    --accent-hover: #1a92d0;
    --accent-text: #1473a6;
    --success: #5d8c00;
    --success-text: #4e7900;
    --danger: #e65050;
    --danger-text: #cb3131;
    --on-accent: #101418;
    --shadow: 0 4px 12px rgba(60, 60, 60, 0.18);
    --focus-ring: var(--accent);
}

/* One Dark Pro — VS Code standard dark */
:root.one-dark {
    --bg: #282c34;
    --pane: #21252b;
    --panel: #2c313a;
    --panel-2: #343b48;
    --title-bg: #252a31;
    --border: #4b5263;
    --border-soft: #3e4451;
    --text: #abb2bf;
    --text-soft: #a5adbc;
    --muted: #9ea6b6;
    --faint: #949cab;
    --input-bg: #2c313a;
    --placeholder: #98a0b0;
    --accent: #61afef;
    --accent-hover: #4d9de5;
    --accent-text: #66b1ef;
    --success: #98c379;
    --success-text: #98c379;
    --danger: #e8757e;
    --danger-text: #ea7b88;
    --on-accent: #282c34;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Kanagawa Dragon — warm ink dark */
:root.kanagawa-dragon {
    --bg: #1f1f28;
    --pane: #16161d;
    --panel: #2a2a37;
    --panel-2: #363644;
    --title-bg: #1a1a23;
    --border: #54546d;
    --border-soft: #363646;
    --text: #dcd7ba;
    --text-soft: #c8c093;
    --muted: #a3a18b;
    --faint: #9c9a85;
    --input-bg: #2a2a37;
    --placeholder: #a3a18b;
    --accent: #7e9cd8;
    --accent-hover: #6b8ccb;
    --accent-text: #8fadde;
    --success: #98bb6c;
    --success-text: #98bb6c;
    --danger: #e46876;
    --danger-text: #ee8792;
    --on-accent: #16161d;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --focus-ring: var(--accent);
}

/* Kanagawa Lotus — ink-on-parchment light */
:root.kanagawa-lotus {
    --bg: #f2ecbc;
    --pane: #e9e3b4;
    --panel: #f6f0c4;
    --panel-2: #eee8be;
    --title-bg: #f6f0c4;
    --border: #c9c29a;
    --border-soft: #d8d1ab;
    --text: #545464;
    --text-soft: #4a4a58;
    --muted: #64636b;
    --faint: #5f5e68;
    --input-bg: #f6f0c4;
    --placeholder: #64636b;
    --accent: #48638f;
    --accent-hover: #435d83;
    --accent-text: #48638f;
    --success: #4f6636;
    --success-text: #4f6636;
    --danger: #a83243;
    --danger-text: #a83243;
    --on-accent: #ffffff;
    --shadow: 0 4px 12px rgba(60, 60, 60, 0.18);
    --focus-ring: var(--accent);
}

/* ---------------- Base ---------------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    font-family: Arial, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s, color 0.3s;
}

button,
input,
select,
textarea {
    font-family: inherit;
}

::selection {
    background: var(--accent);
    color: var(--on-accent);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--faint);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.op-item:focus-visible,
.op-name:focus-visible,
.op-star:focus-visible,
.split-gutter:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 1px;
}

/* Contrast note (M27): every text/background pair in the palettes
   above meets WCAG AA (≥4.5:1). Where one hue cannot be both a
   background (behind white text) and readable text on dark surfaces,
   the roles are split into --accent/--accent-text, --success/
   --success-text, and --danger/--danger-text (the *-text tokens are
   the text roles). */

/* Reduced motion (M27, task 18; M34: OS preference only): the OS
   `prefers-reduced-motion` is honored natively (even before JS
   boots); ui/a11y.js mirrors it onto <html> so the app stays in
   step — apm-reduced-motion forces transitions OFF, apm-motion-full
   opts back IN when the OS prefers reduce. The former manual banner
   toggle was removed in M34. */
html.apm-reduced-motion *,
html.apm-reduced-motion *::before,
html.apm-reduced-motion *::after {
    transition: none !important;
    animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
    html:not(.apm-motion-full) *,
    html:not(.apm-motion-full) *::before,
    html:not(.apm-motion-full) *::after {
        transition: none !important;
        animation: none !important;
    }
}

/* ---------------- Toast (same look as the original app) ---------------- */

#toast {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: var(--on-accent);
    padding: 12px 24px;
    border-radius: 6px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: 1000;
    pointer-events: none;
    box-shadow: var(--shadow);
    min-width: 200px;
    text-align: center;
}

#toast.error {
    background: var(--danger);
}

/* ---------------- Top bar ---------------- */

#banner {
    flex: 0 0 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 12px;
    background: var(--title-bg);
    border-bottom: 1px solid var(--border);
}

#app-name {
    font-weight: bold;
    font-size: 15px;
    color: var(--text);
}

#app-tag {
    margin-left: 10px;
    font-size: 12px;
    color: var(--muted);
}

#banner-controls {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.banner-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.theme-label {
    font-size: 12px;
    color: var(--muted);
}

/* ---------------- Buttons & fields ---------------- */

.btn-ghost {
    padding: 5px 12px;
    font-size: 12px;
    color: var(--text-soft);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.btn-ghost:hover {
    border-color: var(--accent);
    color: var(--accent-text); /* accent as TEXT uses the AA text token */
}

.btn-ghost.danger:hover {
    border-color: var(--danger);
    color: var(--danger-text); /* danger as TEXT (white-on-danger keeps the bg token) */
}

/* Primary actions (Save / Load / modal Close / Confirm import): same
   metrics as btn-ghost (zero layout shift), accent-filled. */

.btn-primary {
    padding: 5px 12px;
    font-size: 12px;
    color: var(--on-accent);
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.field {
    padding: 6px 8px;
    font-size: 13px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.field:focus {
    border-color: var(--accent);
}

.save-select {
    min-width: 130px;
    max-width: 210px;
}

.theme-select {
    min-width: 105px;
}

/* ---------------- Workspace: three columns ---------------- */

#workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    /* Column-width defaults. scripts/ui/splits.js overrides
       --col-f/--col-r inline (persisted apm.ui.splits) and --peek-w
       (persisted apm.ui.peekWidth); the narrow-window media queries
       re-declare the defaults here for their breakpoints. */
    --col-f: 24%;
    --col-r: 26%;
    --peek-w: 26%;
}

#filters {
    flex: 0 0 var(--col-f, 24%);
    min-width: 220px;
    background: var(--pane);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

#recipe {
    flex: 0 0 var(--col-r, 26%);
    min-width: 250px;
    background: var(--pane);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

#io {
    flex: 1 1 0;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

/* Resizable left columns (expanded view only). The gutters are
   5px separators; scripts/ui/splits.js drives them (pointer drag,
   ArrowLeft/Right = ±10px, double-click resets both columns). The
   compact (rail) view hides them — the rails are never resizable.
   The hover-peek surface keeps its own right-edge handle (--peek-w),
   which never changes the 44px rails. */
.split-gutter {
    flex: 0 0 5px;
    width: 5px;
    cursor: col-resize;
    background: var(--border-soft);
    user-select: none;
    touch-action: none;
}

.split-gutter:hover,
.split-gutter.dragging {
    background: var(--accent);
}

/* Vertical I/O pane separators (inside #io; ALWAYS visible —
   the compact rail view doesn't touch #io). Drag, ArrowUp/Down = ±10px,
   double-click resets both panes — scripts/ui/splits.js. */
.pane-gutter {
    flex: 0 0 5px;
    height: 5px;
    cursor: row-resize;
    background: var(--border-soft);
    user-select: none;
    touch-action: none;
}

.pane-gutter:hover,
.pane-gutter.dragging {
    background: var(--accent);
}

#recipe {
    position: relative; /* anchor for the peek handle */
}

#recipe-peek-handle {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
    touch-action: none;
}

#recipe-peek-handle:hover {
    background: var(--accent);
    opacity: 0.6;
}

/* ---------------- Collapsed left columns (icon rail + hover peek) ----------------
   #workspace.left-collapsed: both left columns become 44px icon rails;
   hovering either one reveals the RECIPE for a settings-only peek
   (delete/reorder controls stay hidden — see the .rec-* rules below).
   The toggle + state live in scripts/ui/leftpane.js (apm.ui.leftCollapsed);
   the show/hide + hover behaviour below is pure CSS (no timers). */

.pane-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.left-rail {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    height: 100%;
    color: var(--muted);
}

.left-rail:hover {
    color: var(--text-soft);
}

.rail-glyph {
    font-size: 18px;
    line-height: 1;
}

.rail-label {
    writing-mode: vertical-rl;
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--faint);
}

#workspace.left-collapsed #filters,
#workspace.left-collapsed #recipe {
    flex: 0 0 44px;
    min-width: 44px;
}

/* Compact view is not resizable: the gutters disappear entirely. */
#workspace.left-collapsed .split-gutter {
    display: none;
}

#workspace.left-collapsed .pane-content {
    display: none;
}

#workspace.left-collapsed .left-rail {
    display: flex;
}

/* Hovering either collapsed column reveals the RECIPE only —
   the Filters column stays a rail. */
#workspace.left-collapsed #filters:hover ~ #recipe,
#workspace.left-collapsed #recipe:hover {
    flex: 0 0 var(--peek-w, 26%);
    min-width: 250px;
}

/* The peek surface's right-edge resize handle shows on peek only. */
#workspace.left-collapsed #filters:hover ~ #recipe #recipe-peek-handle,
#workspace.left-collapsed #recipe:hover #recipe-peek-handle {
    display: block;
}

#workspace.left-collapsed #filters:hover ~ #recipe .pane-content,
#workspace.left-collapsed #recipe:hover .pane-content {
    display: flex;
}

#workspace.left-collapsed #filters:hover ~ #recipe .left-rail,
#workspace.left-collapsed #recipe:hover .left-rail {
    display: none;
}

/* Collapsed = settings-only: no add/remove/reorder mid-session;
   the option values inside the recipe stay fully editable. */
#workspace.left-collapsed #recipe .rec-delete,
#workspace.left-collapsed #recipe .rec-handle,
#workspace.left-collapsed #recipe #clear-recipe {
    display: none;
}

/* ---------------- Pane titles ---------------- */

.pane-title {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 32px;
    padding: 4px 10px;
    background: var(--title-bg);
    border-bottom: 1px solid var(--border);
}

.pane-name {
    font-weight: bold;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
}

.count {
    margin-left: 5px;
    font-size: 11px;
    font-weight: normal;
    color: var(--muted);
}

.pane-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.io-info {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

/* The pos readout is left-anchored: it grows to the right, so the
   right-side counters/buttons never shift as it changes. */
.pane-title .io-pos {
    margin-right: auto;
}

.badge {
    font-size: 11px;
    font-weight: bold;
    color: var(--on-accent);
    background: var(--danger);
    padding: 2px 8px;
    border-radius: 10px;
}

/* M43 (✨7): worker status badge — a NEUTRAL pill (the red .badge is
   reserved for the "truncated" warning): how the last big run was
   settled (off-thread worker vs main-thread fallback). */
.worker-badge {
    background: var(--input-bg);
    color: var(--muted);
    border: 1px solid var(--border-soft);
}

/* ---------------- Column 1: filter palette ---------------- */

.pane-search {
    flex: 0 0 auto;
    padding: 8px;
}

#filter-search {
    width: 100%;
    padding: 7px 10px;
    font-size: 13px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
}

#filter-search::placeholder {
    color: var(--placeholder);
    opacity: 1;
}

.op-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
    padding: 0 0 8px;
}

.op-section {
    padding: 4px 8px 0;
}

.op-section:first-child {
    padding-top: 8px;
}

.op-section-name {
    display: block;
    margin: 0 2px 8px;
    /* M36: the header is a real <button> — reset the button chrome,
       keep the .pane-name typography (class rule still applies). */
    width: 100%;
    background: none;
    border: none;
    padding: 2px 0;
    font-family: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.op-section-name:hover {
    color: var(--accent-text); /* >=4.5:1 on the pane in all themes */
}

.op-section-name:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* M36: decorative collapse chevron (\u25BC expanded / \u25B6 collapsed). */
.op-chev {
    display: inline-block;
    margin-right: 6px;
    font-size: 11px;
    color: var(--muted);
}

.op-items {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* M36: the hidden attribute must win (same pattern as the other
   [hidden] overrides — see #output-body[hidden]). */
ul.op-items[hidden] {
    display: none;
}

.op-item {
    background: var(--panel);
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
    cursor: grab;
    user-select: none;
    transition: border-color 0.15s;
}

.op-item:hover {
    border-color: var(--accent);
}

.op-item:active {
    cursor: grabbing;
}

.op-item.dragging {
    opacity: 0.5;
}

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

.op-name {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    font: inherit;
    font-weight: bold;
    font-size: 13px;
    color: var(--text);
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
}

.op-name:hover {
    color: var(--accent-text);
}

.op-star {
    flex: 0 0 auto;
    font-size: 15px;
    line-height: 1;
    color: var(--muted);
    background: none;
    border: none;
    padding: 4px 6px; /* M47 (bug 22): >=24x24 hit target (was ~19x15) */
    min-width: 24px;
    min-height: 24px;
    margin: 0;
    cursor: pointer;
}

.op-star:hover {
    color: var(--text);
}

.op-star[aria-pressed="true"] {
    color: var(--accent-text);
}

.op-desc {
    margin-top: 3px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--muted);
}

/* ---------------- Column 1: presets ---------------- */

.preset-block {
    flex: 0 0 auto;
    padding: 10px 10px 4px;
    margin-top: 4px;
    border-top: 1px solid var(--border-soft);
}

.preset-block .pane-name {
    display: block;
    margin-bottom: 8px;
}

.preset-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.preset-btn {
    text-align: left;
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-soft);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.preset-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

/* ---------------- Column 2: recipe ---------------- */

.hint {
    flex: 0 0 auto;
    padding: 10px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--faint);
}

.hint-empty {
    flex: 0 0 auto;
    margin: 8px;
    padding: 16px 12px;
    text-align: center;
    font-size: 12px;
    line-height: 1.7;
    color: var(--faint);
    border: 1px dashed var(--border);
    border-radius: 6px;
}

.list-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    list-style: none;
    margin: 0;
    padding: 8px;
}

.rec-card {
    background: var(--panel);
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    margin-bottom: 8px;
    transition: border-color 0.15s;
}

.rec-card.dragging {
    opacity: 0.5;
}

.rec-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: grab;
    user-select: none;
}

.rec-head:active {
    cursor: grabbing;
}

.rec-handle {
    color: var(--faint);
    font-size: 14px;
    line-height: 1;
}

.rec-name {
    flex: 1;
    font-weight: bold;
    font-size: 13px;
    color: var(--text);
}

.rec-delete {
    background: none;
    border: none;
    padding: 0 4px;
    font-size: 16px;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    border-radius: 4px;
}

.rec-delete:hover {
    color: var(--danger-text);
}

/* M43 (U8): guaranteed >=24x24 hit areas for the small icon buttons
   (WCAG 2.5.5 target size) — the glyph stays centered in the box. */
.rec-eye,
.rec-delete,
.rec-move {
    min-width: 24px;
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* M43 (U9): the up/down move buttons (keyboard/touch reorder path). */
.rec-move {
    background: none;
    border: none;
    padding: 0 2px;
    font-size: 13px;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    border-radius: 4px;
}

.rec-move:hover {
    color: var(--text);
}

.rec-move:disabled {
    opacity: 0.35;
    cursor: default;
}

/* M43 (U9): kill double-tap zoom on touch so buttons and the
   double-click-add palette path don't fight the gesture. */
button,
.op-item {
    touch-action: manipulation;
}

.rec-eye {
    background: none;
    border: none;
    padding: 0 4px;
    font-size: 14px;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    border-radius: 4px;
}

.rec-eye:hover {
    color: var(--text);
}

/* Eye toggle OFF: the card stays (options intact) but reads as skipped. */
.rec-card.rec-off {
    opacity: 0.55;
}

.rec-skip-chip {
    font-size: 10px;
    line-height: 1.4;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    padding: 0 6px;
    white-space: nowrap;
}

.rec-desc {
    padding: 0 10px 8px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--muted);
}

.rec-options {
    display: flex;
    flex-direction: column; /* one option per row (M7) */
    align-items: stretch;
    gap: 8px;
    padding: 8px 10px 10px;
    border-top: 1px solid var(--border-soft);
}

.rec-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap; /* narrow-column fallback: wrap, don't overflow */
}

.rec-opt[hidden] {
    display: none; /* the hidden attribute must win over display:flex (same pattern as #save-modal[hidden]) */
}

.rec-options label {
    font-size: 12px;
    color: var(--text-soft);
}

.rec-options select,
.rec-options input {
    padding: 5px 8px;
    font-size: 12px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.rec-options input[type="number"] {
    width: 110px;
}

.rec-status {
    padding: 4px 10px 8px;
    font-size: 11px;
    line-height: 1.4;
    border-top: 1px solid var(--border-soft);
}

.rec-status.ok {
    color: var(--success-text);
}

.rec-status.none {
    color: var(--muted);
}

.rec-status.err {
    color: var(--danger-text);
}

.drop-indicator {
    height: 3px;
    margin: 0 2px;
    background: var(--accent);
    border-radius: 2px;
    pointer-events: none;
}

/* ---------------- Column 3: input / output ---------------- */
/* The three panes are vertically resizable — .pane-gutter
   separators between them; #io carries --pane-p (prefix) and --pane-i
   (input) and the output pane absorbs the remainder. The CSS defaults
   (18%/41%) keep the prefix visibly compact, as before. */

.io-pane {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Compact prefix block: visibly smaller than the full-size input/output panes. */
.prefix-pane {
    flex: 0 0 var(--pane-p, 18%);
    min-height: 60px;
}

#input-pane {
    flex: 0 0 var(--pane-i, 41%);
    min-height: 120px;
}

#output-pane {
    min-height: 120px;
}

.prefix-pane .io-body textarea {
    min-height: 52px;
}

.io-body {
    flex: 1;
    min-height: 0;
    display: flex;
    padding: 8px;
}

.io-body textarea {
    flex: 1;
    min-height: 0;
    width: 100%;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    resize: none;
    background: var(--panel);
    color: var(--text);
}

#output {
    background: var(--panel-2);
}

/* ---------------- File in (M22): drop target ---------------- */

.io-pane.drop-hover {
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
}

/* ---------------- Output pane: parts mode (M21) ---------------- */

.parts-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-top: 1px solid var(--border-soft);
}

.parts-label {
    font-size: 12px;
    color: var(--muted);
}

/* M43 (U14): the "Include marker in Copy" checkbox label. */
.parts-marker-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.parts-marker-label input {
    margin: 0;
}

/* M43 (U7): visually-hidden live region (screen-reader text that is
   never painted). */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

#parts-limit {
    width: 70px;
    padding: 2px 6px;
    font-size: 12px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.parts-view {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
}

/* The hidden attribute must beat these author display rules — same
   pattern as #save-modal[hidden] / .rec-opt[hidden] (M8 gotcha:
   author display:flex silently defeats [hidden]). M29: parts ON must
   actually hide the single textarea; parts OFF must actually hide the
   parts view. M35: the Part-limit bar is only shown when parts is ON
   (its .parts-bar display:flex would otherwise defeat [hidden]). */
#output-body[hidden],
#parts-view[hidden],
#parts-bar[hidden] {
    display: none;
}

.part-block {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    background: var(--panel-2);
}

.part-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-soft);
}

.part-label {
    font-size: 12px;
    font-weight: bold;
    color: var(--accent-text);
}

.part-sent {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    min-height: 24px; /* M47 (bug 22) bar: >=24px hit target (was ~13px) */
}

.part-sent-chk {
    margin: 0;
    cursor: pointer;
}

.part-text {
    flex: 1 1 auto;
    min-height: 56px;
    width: 100%;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    padding: 10px 12px;
    border: none;
    border-radius: 0 0 6px 6px;
    resize: vertical;
    background: var(--panel-2);
    color: var(--text);
}

#input::placeholder,
#output::placeholder {
    color: var(--placeholder);
    opacity: 1;
}

/* ---------------- Narrow windows ---------------- */

@media (max-width: 1100px) {
    /* Narrow-window defaults as custom props (same layout as the old
       literal flex-basis values). A persisted user width (inline on
       #workspace) intentionally wins; the min-widths stay the floor. */
    #workspace {
        --col-f: 21%;
        --col-r: 24%;
    }
}

@media (max-width: 900px) {
    #app-tag {
        display: none;
    }

    #workspace {
        --col-f: 22%;
        --col-r: 24%;
    }

    #filters {
        min-width: 185px;
    }

    #recipe {
        min-width: 205px;
    }

    #io {
        min-width: 250px;
    }
}

/* ---------------- Saves export / import modal + in-app dialog (M42) ----------------
   The #save-modal overlay and the #dlg confirm/prompt overlay share the
   same chrome; #dlg sits ABOVE the saves modal (z-index 60 > 50) so a
   dialog opened from inside the modal (overwrite / import-replace /
   delete) covers it. */

#save-modal, #dlg {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

#dlg {
    z-index: 60; /* above #save-modal: dialogs can open from inside it */
}

#save-modal[hidden], #dlg[hidden] {
    display: none;
}

#save-modal .modal-box, #dlg .modal-box {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-width: 640px;
    width: calc(100% - 48px);
    padding: 16px;
    box-shadow: var(--shadow);
}

#save-modal h2, #dlg h2 {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--text);
}

#save-modal .modal-hint, #dlg .modal-hint {
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--muted);
}

/* Dialog msgs wrap by default (pre-line keeps line breaks + single
   spaces); the shortcuts cheat sheet opts into `pre` (dlg-pre class,
   set by core/dialog.js) because it aligns its two columns with
   padding spaces that pre-line would collapse. */
#dlg .modal-hint {
    white-space: pre-line;
}
#dlg .modal-hint.dlg-pre {
    white-space: pre;
}

/* M47 (F8): the ≈ $ cost chip reads like the other header infos. */
.io-cost {
    font-size: 12px;
    padding: 1px 6px;
    font-weight: normal;
}

#saves-json {
    width: 100%;
    min-height: 180px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.5;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text);
    resize: vertical;
    box-sizing: border-box;
}

#save-modal .modal-row, #dlg .modal-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

#save-modal .modal-row .modal-hint, #dlg .modal-row .modal-hint {
    margin: 0;
    flex: 1;
    min-width: 160px;
}

/* ---------------- In-app confirm / prompt dialog (M42) ---------------- */

#dlg .modal-box {
    max-width: 440px;
}

#dlg .dlg-input {
    width: 100%;
    font: inherit;
    font-size: 13px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text);
    box-sizing: border-box;
}

#dlg .modal-row {
    justify-content: flex-end;
}

/* ---------------- Command palette (M24: Ctrl/Cmd+K, /) ---------------- */

#cmd-palette {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
    z-index: 60;
}

#cmd-palette[hidden] {
    display: none; /* the hidden attribute must win over display:flex */
}

#cmd-palette .cmd-box {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-width: 560px;
    width: calc(100% - 48px);
    padding: 12px;
    box-shadow: var(--shadow);
}

#cmd-input {
    width: 100%;
    font-size: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text);
    box-sizing: border-box;
}

#cmd-list {
    margin-top: 8px;
    max-height: 320px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cmd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.cmd-item:hover {
    background: var(--input-bg);
}

.cmd-item.active {
    background: var(--input-bg);
    outline: 1px solid var(--accent);
}

.cmd-item .cmd-group {
    flex: none;
    font-size: 11px;
    color: var(--muted);
}

.cmd-empty {
    padding: 10px;
    font-size: 12px;
    color: var(--muted);
}

#cmd-hint {
    margin: 8px 0 0;
    font-size: 11px;
    color: var(--muted);
    text-align: center;
}

/* ---------------- Mobile (M25): single-column stacked layout --------
   Pure CSS on the existing DOM (no JS state, no new storage keys).
   At ≤720px the three columns stack: Filters → Recipe →
   Prefix/Input/Output; the resize gutters disappear; the hover-based
   left-rail collapse is disabled (it needs a pointer); the workspace
   scrolls as one column. Desktop ( >720px) is untouched. */
@media (max-width: 720px) {
    /* M44 (U10): safe-area insets for notched phones — the viewport
       meta now requests viewport-fit=cover, so the UI must clear the
       notch (top/left/right, on the banner) and the home indicator
       (bottom, on the body). env() falls back to 0px where the OS
       defines no inset, so non-notched devices are unchanged. */
    body {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    #banner {
        flex: none;
        height: auto;
        flex-wrap: wrap;
        row-gap: 8px;
        padding: calc(8px + env(safe-area-inset-top, 0px))
                 calc(10px + env(safe-area-inset-right, 0px))
                 8px
                 calc(10px + env(safe-area-inset-left, 0px));
    }
    #banner-controls {
        gap: 8px;
        justify-content: flex-start;
    }
    /* Rail collapse is hover-based and useless on touch — out on mobile */
    #left-toggle {
        display: none;
    }

    #workspace {
        flex-direction: column;
        overflow-y: auto;
    }
    #workspace > .split-gutter {
        display: none;
    }
    #filters,
    #recipe {
        flex: none;
        min-width: 0;
        max-height: 46vh;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
    #io {
        flex: 1 1 auto;
        min-width: 0;
        min-height: 60vh;
    }
    /* 5px horizontal gutters are untouchable; the panes share space */
    #io .pane-gutter {
        display: none;
    }
    .io-body textarea {
        min-height: 90px;
    }
    /* A bit more touch room on the primary controls */
    .btn-ghost,
    .btn-primary {
        min-height: 36px;
    }

    /* The left-collapsed state (a per-browser setting) must not blank
       the sections on mobile — force the expanded state here, and keep
       the recipe's add/remove/reorder controls visible. */
    #workspace.left-collapsed #filters,
    #workspace.left-collapsed #recipe,
    #workspace.left-collapsed #filters:hover ~ #recipe,
    #workspace.left-collapsed #recipe:hover {
        flex: none;
        min-width: 0;
    }
    #workspace.left-collapsed .pane-content {
        display: flex;
    }
    #workspace.left-collapsed .left-rail {
        display: none;
    }
    #workspace.left-collapsed #recipe .rec-delete,
    #workspace.left-collapsed #recipe .rec-handle,
    #workspace.left-collapsed #recipe #clear-recipe {
        display: inline-block;
    }
    #workspace.left-collapsed #filters:hover ~ #recipe #recipe-peek-handle,
    #workspace.left-collapsed #recipe:hover #recipe-peek-handle,
    #recipe-peek-handle {
        display: none;
    }
}
