/* Imbuer — an Excel-style spreadsheet with a Radii Office soul!
   Theme tokens first, then chrome (title bar, ribbon, formula bar), the grid,
   the selection overlays and their animations, menus, dialogs and panels! */

:root {
    --accent: #6bc702;
    --accent-d: #3f7f00;
    --accent-l: #eefbe0;
    --accent-ring: rgba(104, 199, 2, 0.35);
    --title-bg: #6bc702;
    /* Glossy buttons = the original Imbuer sidebar's lit-up button style! */
    --gel-a: #98f838;
    --gel-b: #54c702;
    --gel-border: #b2fc7d;
    --gel-glow: rgba(104, 199, 2, 0.35);
    --title-text: #ffffff;
    --ribbon-bg: #f7f7f7;
    --ribbon-line: #dadada;
    --ui-bg: #f3f3f3;
    --ui-text: #252525;
    --ui-dim: #6b6b6b;
    --hover: #e6e6e6;
    --on: #e3f7cf;
    --menu-bg: #ffffff;
    --menu-line: #e1e1e1;
    --field-bg: #ffffff;
    --field-line: #c6c6c6;
    --grid-bg: #ffffff;
    --cell-bg: #ffffff;
    --cell-text: #1b1b1b;
    --grid-line: #e2e2e2;
    --hdr-bg: #f5f5f5;
    --hdr-line: #d6d6d6;
    --hdr-text: #4a4a4a;
    --hdr-on-bg: #eaf9d9;
    --hdr-on-text: #3f7f00;
    --hdr-full-bg: #cdeeaa;
    --sel-fill: rgba(107, 199, 2, 0.12);
    --sel-line: rgba(92, 184, 0, 0.6);
    --font-ui: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    --font-cell: Aptos, Calibri, Carlito, "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    --spring: cubic-bezier(0.2, 0.9, 0.25, 1.18);
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    color-scheme: light;
}

body.dark {
    --accent: #7ee21c;
    --accent-d: #a6f25a;
    --accent-l: #2a3b1a;
    --accent-ring: rgba(126, 226, 28, 0.4);
    --title-bg: #4f9a00;
    --ribbon-bg: #262626;
    --ribbon-line: #3a3a3a;
    --ui-bg: #1f1f1f;
    --ui-text: #e8e8e8;
    --ui-dim: #a3a3a3;
    --hover: #383838;
    --on: #2f4420;
    --menu-bg: #2b2b2b;
    --menu-line: #3d3d3d;
    --field-bg: #1e1e1e;
    --field-line: #4a4a4a;
    --grid-bg: #1e1e1e;
    --cell-bg: #1e1e1e;
    --cell-text: #e6e6e6;
    --grid-line: #353535;
    --hdr-bg: #2a2a2a;
    --hdr-line: #3e3e3e;
    --hdr-text: #bdbdbd;
    --hdr-on-bg: #2c3f1c;
    --hdr-on-text: #b5f57a;
    --hdr-full-bg: #3d5a22;
    --sel-fill: rgba(126, 226, 28, 0.13);
    --sel-line: rgba(126, 226, 28, 0.6);
    color-scheme: dark;
}

body.no-grid { --grid-line: transparent; }

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

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

body {
    font-family: var(--font-ui);
    font-size: 13px;
    color: var(--ui-text);
    background: var(--ui-bg);
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

.ico { width: 18px; height: 18px; flex: none; display: block; }

/* ---------- Title bar ---------- */
#titlebar {
    height: 38px;
    flex: none;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 10px;
    background: var(--title-bg);
    color: var(--title-text);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 30;
}

.tb-left { display: flex; align-items: center; gap: 10px; }
.tb-logo { width: 22px; height: 22px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25)); }
.qat { display: flex; gap: 2px; }

.qbtn {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.12s;
}
.qbtn:hover { background: rgba(255, 255, 255, 0.16); }
.qbtn:active { transform: scale(0.9); }
.qbtn:disabled { opacity: 0.45; cursor: default; background: transparent; }
.qbtn .ico { width: 17px; height: 17px; }

.tb-title { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#book-name {
    background: transparent;
    border: 1px solid transparent;
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    padding: 3px 6px;
    border-radius: 4px;
    width: auto;
    min-width: 6ch;
    max-width: min(36vw, 340px);
    text-align: right;
    field-sizing: content;
}
#book-name:hover { border-color: rgba(255, 255, 255, 0.35); }
#book-name:focus { outline: none; background: rgba(255, 255, 255, 0.95); color: #1b1b1b; text-align: left; }

.tb-saved { font-size: 11.5px; opacity: 0.75; margin-left: 6px; padding: 1px 7px; border-radius: 10px; background: rgba(255, 255, 255, 0.14); }
.tb-saved.blip { animation: blip 0.45s var(--ease); }

.tb-right { display: flex; justify-content: flex-end; }
.cmd-search { position: relative; display: flex; align-items: center; width: min(360px, 100%); }
.cmd-search > .ico { position: absolute; left: 9px; width: 15px; height: 15px; opacity: 0.85; pointer-events: none; }
#cmd-search {
    width: 100%;
    height: 26px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    padding: 0 10px 0 30px;
    font-size: 12.5px;
    transition: background 0.2s, box-shadow 0.2s;
}
#cmd-search::placeholder { color: rgba(255, 255, 255, 0.82); }
#cmd-search:focus { outline: none; background: #fff; color: #1b1b1b; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); }
.cmd-search:focus-within > .ico { color: #555; }
#cmd-results { position: absolute; top: 30px; left: 0; right: 0; color: var(--ui-text); }
#cmd-results small { display: block; color: var(--ui-dim); font-size: 11px; }
#cmd-results .m-item.kb { background: var(--hover); }

/* ---------- Ribbon ---------- */
#ribbon-tabs {
    height: 32px;
    flex: none;
    display: flex;
    align-items: stretch;
    gap: 2px;
    padding: 0 8px;
    background: var(--ribbon-bg);
    position: relative;
    z-index: 20;
}

.rtab {
    border: 0;
    background: transparent;
    padding: 0 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--ui-text);
    border-radius: 5px 5px 0 0;
    transition: color 0.15s, background 0.15s;
}
.rtab:hover { background: var(--hover); }
.rtab.on { color: var(--accent-d); font-weight: 600; }
.rtab.file { background: var(--accent); color: #fff; margin: 4px 6px 4px 0; border-radius: 5px; padding: 0 14px; font-weight: 600; }
.rtab.file:hover { background: var(--accent-d); }
body.dark .rtab.file:hover { background: linear-gradient(180deg, #b4fb6c 0%, #62d40a 100%); }

#tab-ink {
    position: absolute;
    bottom: 2px;
    height: 3px;
    border-radius: 3px;
    background: var(--accent);
    transition: left 0.32s var(--spring), width 0.32s var(--spring);
    pointer-events: none;
}

.rtab-collapse {
    margin-left: auto;
    border: 0;
    background: transparent;
    width: 30px;
    border-radius: 5px;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--ui-dim);
    transition: transform 0.25s var(--spring), background 0.15s;
}
.rtab-collapse:hover { background: var(--hover); }
body.ribbon-min .rtab-collapse { transform: rotate(180deg); }

#ribbon {
    flex: none;
    height: 98px;
    background: var(--ribbon-bg);
    border-bottom: 1px solid var(--ribbon-line);
    overflow-x: auto;
    overflow-y: hidden;
    position: relative;
    z-index: 15;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: height 0.25s var(--ease);
    scrollbar-width: thin;
}
body.ribbon-min #ribbon { height: 0; border-bottom: 0; }

.rpanel { display: none; height: 100%; padding: 4px 6px 0; gap: 0; }
.rpanel.on { display: flex; }
.rpanel.panel-in, .panel-in { animation: panelIn 0.24s var(--ease); }

@keyframes panelIn {
    from { opacity: 0; transform: translateY(-5px); }
}

.rgroup {
    display: flex;
    flex-direction: column;
    flex: none;
    padding: 0 5px;
    position: relative;
}
.rgroup::after {
    content: "";
    position: absolute;
    right: 0;
    top: 6px;
    bottom: 8px;
    width: 1px;
    background: var(--ribbon-line);
}

.rg-body { flex: 1; display: flex; align-items: center; gap: 2px; }
.rg-body.col { flex-direction: column; align-items: flex-start; justify-content: center; gap: 4px; }
.rg-body .row { display: flex; align-items: center; gap: 2px; }
.rg-label { font-size: 11px; color: var(--ui-dim); text-align: center; padding: 1px 0 4px; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 1px; justify-content: center; }
.rsep { width: 1px; height: 18px; background: var(--ribbon-line); margin: 0 3px; }

.rb {
    border: 1px solid transparent;
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    color: var(--ui-text);
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    transition: background 0.14s, border-color 0.14s, transform 0.1s;
}
.rb:hover, .split-arrow:hover { background: var(--hover); }
.rb:active { transform: scale(0.94); }
.rb.on, .rb.menu-on, .split-arrow.menu-on { background: var(--on); border-color: var(--accent-ring); }
.rb:disabled { opacity: 0.45; cursor: default; }

.rb.big {
    flex-direction: column;
    justify-content: flex-start;
    min-width: 44px;
    height: 70px;
    padding: 5px 4px 3px;
    gap: 3px;
    font-size: 12px;
    line-height: 1.12;
    text-align: center;
}
.rb.big .ico, .rb.big .glyph { width: 30px; height: 30px; }
.rb.big:hover .ico { animation: iconHop 0.4s var(--spring); }

@keyframes iconHop {
    40% { transform: translateY(-3px); }
}

.rb.sm { height: 23px; padding: 0 6px 0 4px; font-size: 12.5px; }
.rb.sm .ico { width: 16px; height: 16px; }
.rb.ic { width: 25px; height: 25px; justify-content: center; padding: 0; }
.rb.ic .ico { width: 17px; height: 17px; }

.glyph { font-style: normal; font-weight: 700; font-size: 15px; width: 17px; text-align: center; line-height: 1; display: inline-grid; place-items: center; font-family: Georgia, "Times New Roman", serif; }
.glyph.it { font-style: italic; font-family: Georgia, serif; }
.glyph.sm { font-size: 13px; font-family: var(--font-ui); }
.rb.big .glyph { font-size: 22px; }
.glyph.fx { font-style: italic; font-family: Georgia, serif; color: var(--accent); }
.glyph.sigma { font-family: var(--font-ui); color: var(--accent); }
.glyph.sigma.big { font-size: 26px; }
.rb s.glyph { font-size: 13px; font-family: var(--font-ui); }

.split { display: inline-flex; align-items: stretch; border-radius: 5px; }
.split:hover { box-shadow: inset 0 0 0 1px var(--ribbon-line); }
.split.big { flex-direction: column; }
.split.big .rb.big { height: 50px; border-radius: 5px 5px 0 0; }
.split.big .split-arrow { height: 20px; width: 100%; border-radius: 0 0 5px 5px; }
.split-arrow {
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    font-size: 9px;
    color: var(--ui-dim);
    padding: 0 3px;
    border-radius: 0 5px 5px 0;
    transition: background 0.14s;
}
.split.ic .rb.ic { border-radius: 5px 0 0 5px; width: 24px; }
.split.sm .rb.sm { border-radius: 5px 0 0 5px; }

.color-btn { position: relative; flex-direction: column; gap: 0; }
.color-btn .ico, .color-btn .glyph { width: 16px; height: 15px; }
.color-btn .cbar { display: block; width: 16px; height: 4px; border-radius: 1px; margin-top: 1px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }

.combo {
    display: inline-flex;
    align-items: stretch;
    height: 24px;
    border: 1px solid var(--field-line);
    border-radius: 4px;
    background: var(--field-bg);
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.combo:hover { border-color: #9a9a9a; }
.combo:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }
.combo input { border: 0; outline: 0; background: transparent; width: 112px; padding: 0 6px; font-size: 12.5px; }
.combo.narrow input { width: 34px; }
.combo.wide input { width: 100px; cursor: default; }
.combo-arrow { border: 0; border-left: 1px solid transparent; background: transparent; width: 18px; font-size: 9px; color: var(--ui-dim); cursor: pointer; }
.combo-arrow:hover { background: var(--hover); }

.rcheck { display: flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer; padding: 1px 6px; border-radius: 4px; }
.rcheck:hover { background: var(--hover); }
.rcheck input { accent-color: var(--accent); margin: 0; }

.kd-btn .ico { color: #b44fe8; }
.rb.kd-btn:hover .ico { animation: sparkleSpin 0.7s var(--spring); }

@keyframes sparkleSpin {
    50% { transform: rotate(20deg) scale(1.15); }
}

/* ---------- Formula bar ---------- */
#formula-row {
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 5px 8px;
    background: var(--ui-bg);
    border-bottom: 1px solid var(--ribbon-line);
    position: relative;
    z-index: 10;
}
body.no-fbar #formula-row { display: none; }

.name-box-wrap { display: flex; height: 26px; border: 1px solid var(--field-line); border-radius: 4px; background: var(--field-bg); overflow: hidden; }
.name-box-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }
#name-box { width: 96px; border: 0; outline: 0; background: transparent; padding: 0 8px; font-size: 13px; }

.fx-btns { display: flex; align-items: center; height: 26px; gap: 1px; color: var(--ui-dim); }
.fx-btns button { border: 0; background: transparent; width: 24px; height: 24px; border-radius: 4px; cursor: pointer; color: var(--ui-dim); font-size: 13px; transition: background 0.15s, color 0.15s; }
.fx-btns button:hover { background: var(--hover); color: var(--ui-text); }
#fx-cancel, #fx-enter { opacity: 0.35; pointer-events: none; }
body.is-editing #fx-cancel, body.is-editing #fx-enter { opacity: 1; pointer-events: auto; }
body.is-editing #fx-cancel:hover { color: #c42b1c; }
body.is-editing #fx-enter:hover { color: var(--accent); }
#fx-insert i { font-family: Georgia, serif; font-style: italic; font-weight: 700; }

#fbar-wrap { flex: 1; position: relative; min-width: 0; display: flex; }
#formula-input, #fbar-hl {
    width: 100%;
    height: 26px;
    border: 1px solid var(--field-line);
    border-radius: 4px;
    background: var(--field-bg);
    padding: 4px 30px 4px 8px;
    font-family: var(--font-cell);
    font-size: 13.5px;
    line-height: 16px;
    white-space: pre;
    overflow: hidden;
    resize: none;
    margin: 0;
    transition: height 0.2s var(--ease), border-color 0.15s, box-shadow 0.15s;
}
#formula-input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }
#fbar-hl { position: absolute; inset: 0; pointer-events: none; border-color: transparent; background: transparent; color: var(--cell-text); z-index: 1; }
#formula-input.hl-on { color: transparent; caret-color: var(--cell-text); background: var(--field-bg); }
body.fbar-tall #formula-input, body.fbar-tall #fbar-hl { height: 84px; white-space: pre-wrap; overflow: auto; }
#fbar-expand { position: absolute; right: 3px; top: 3px; width: 22px; height: 20px; border: 0; background: transparent; border-radius: 3px; cursor: pointer; color: var(--ui-dim); z-index: 2; display: grid; place-items: center; transition: transform 0.25s var(--spring); }
#fbar-expand:hover { background: var(--hover); }
#fbar-expand .ico { width: 14px; height: 14px; }
body.fbar-tall #fbar-expand { transform: rotate(180deg); }

/* ---------- Grid ---------- */
#grid-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    position: relative;
    background: var(--grid-bg);
    outline: none;
    scrollbar-width: thin;
}

#grid-inner { position: relative; }
#grid-inner.sheet-in { animation: sheetIn 0.32s var(--ease); }

@keyframes sheetIn {
    from { opacity: 0; transform: translateX(14px); }
}

#grid {
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    font-family: var(--font-cell);
    font-size: calc(13px * var(--z, 1));
    color: var(--cell-text);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

#grid th, #grid td { padding: 0; margin: 0; }

#grid td {
    border-right: 1px solid var(--grid-line);
    border-bottom: 1px solid var(--grid-line);
    cursor: cell;
    overflow: visible;
    position: relative;
}

#grid thead th {
    position: sticky;
    top: 0;
    z-index: 7;
    background: var(--hdr-bg);
    color: var(--hdr-text);
    font-family: var(--font-ui);
    font-weight: 400;
    font-size: calc(12px * var(--z, 1));
    border-right: 1px solid var(--hdr-line);
    border-bottom: 1px solid var(--hdr-line);
    text-align: center;
    cursor: s-resize;
    transition: background 0.15s, color 0.15s, box-shadow 0.18s;
}
#grid thead th.corner { left: 0; z-index: 9; cursor: se-resize; }
.corner-tri { position: absolute; right: 3px; bottom: 3px; border: 5px solid transparent; border-right-color: #b9b9b9; border-bottom-color: #b9b9b9; }
#grid thead th.corner:hover .corner-tri { border-right-color: var(--accent); border-bottom-color: var(--accent); }

#grid th.rh {
    position: sticky;
    left: 0;
    z-index: 6;
    background: var(--hdr-bg);
    color: var(--hdr-text);
    font-family: var(--font-ui);
    font-weight: 400;
    font-size: calc(11.5px * var(--z, 1));
    border-right: 1px solid var(--hdr-line);
    border-bottom: 1px solid var(--hdr-line);
    text-align: center;
    cursor: e-resize;
    transition: background 0.15s, color 0.15s, box-shadow 0.18s;
}

#grid thead th.on { background: var(--hdr-on-bg); color: var(--hdr-on-text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
#grid th.rh.on { background: var(--hdr-on-bg); color: var(--hdr-on-text); font-weight: 600; box-shadow: inset -2px 0 0 var(--accent); }
#grid th.full { background: var(--hdr-full-bg) !important; }
#grid thead th:not(.corner):hover, #grid th.rh:hover { background: var(--hover); }
#grid thead th.on:hover, #grid th.rh.on:hover { background: var(--hdr-full-bg); }
#grid th.frz-edge { box-shadow: inset -2px 0 0 #9d9d9d; }
#grid th.rh.frz-edge { box-shadow: inset 0 -2px 0 #9d9d9d; }

.rz { position: absolute; z-index: 2; }
.rz-c { top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; }
.rz-r { left: 0; bottom: -4px; height: 8px; width: 100%; cursor: row-resize; }
.rz:hover::after { content: ""; position: absolute; background: var(--accent); border-radius: 2px; }
.rz-c:hover::after { left: 3px; top: 15%; bottom: 15%; width: 2px; }
.rz-r:hover::after { top: 3px; left: 15%; right: 15%; height: 2px; }

body.no-heads #grid thead th, body.no-heads #grid th.rh { font-size: 0; border: 0; padding: 0; overflow: hidden; }
body.no-heads .rz { display: none; }

/* Hidden rows & columns collapse to nothing */
#grid tr.hr > * { font-size: 0; border-bottom-width: 0; overflow: hidden; }
#grid tr.hr .cv, #grid tr.hr .flt-btn, #grid tr.hr .rz { display: none; }
#grid .hc { font-size: 0 !important; border-right-width: 0 !important; overflow: hidden !important; }
#grid .hc .cv, #grid .hc .flt-btn, #grid .hc .rz { display: none; }
#grid thead th.hc + th:not(.hc) { box-shadow: inset 2px 0 0 #9d9d9d; }

/* Cell content: a flex box so alignment matches Excel */
.cv {
    display: flex;
    height: calc(var(--rh) - 1px);
    width: 100%;
    padding: 0 calc(4px * var(--z, 1)) calc(1px * var(--z, 1));
    overflow: hidden;
    align-items: flex-end;
    line-height: 1.25;
    pointer-events: none;
}
.cv.v-top { align-items: flex-start; padding-top: 2px; }
.cv.v-middle { align-items: center; }
.cv.a-left { justify-content: flex-start; text-align: left; }
.cv.a-center { justify-content: center; text-align: center; }
.cv.a-right { justify-content: flex-end; text-align: right; }
.cv.spill { overflow: visible; }
.ct { flex: none; white-space: pre; }
td.wrap .ct { white-space: pre-wrap; overflow-wrap: anywhere; flex: 1 1 auto; min-width: 0; }
.ct code { font-family: "JetBrains Mono", monospace; font-size: 0.92em; background: rgba(127, 127, 127, 0.14); padding: 0 3px; border-radius: 3px; }
.ct .kd-strike { text-decoration: line-through; }
.cf-ico { margin-right: 4px; font-size: 0.9em; display: inline-block; }
body.show-formulas #grid td .ct { font-family: "JetBrains Mono", monospace; font-size: 0.88em; }

td.has-note::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    border-style: solid;
    border-width: 0 7px 7px 0;
    border-color: transparent #d13438 transparent transparent;
    pointer-events: none;
}

/* Checkboxes in cells */
.xcb {
    pointer-events: auto;
    width: calc(15px * var(--z, 1));
    height: calc(15px * var(--z, 1));
    border: 1.5px solid #8a8a8a;
    border-radius: 4px;
    display: inline-grid;
    place-items: center;
    background: var(--cell-bg, #fff);
    cursor: pointer;
    margin-bottom: 2px;
    transition: background 0.18s, border-color 0.18s, transform 0.15s var(--spring);
}
.xcb:hover { border-color: var(--accent); transform: scale(1.12); }
.xcb svg { width: 85%; height: 85%; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.xcb.on { background: var(--accent); border-color: var(--accent); }
.xcb.on svg { opacity: 1; stroke-dasharray: 14; stroke-dashoffset: 0; animation: tick 0.32s var(--ease); }

@keyframes tick {
    from { stroke-dashoffset: 14; }
}

/* Filter buttons in header cells */
.flt-btn {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: calc(17px * var(--z, 1));
    height: calc(17px * var(--z, 1));
    border: 1px solid #b9b9b9;
    border-radius: 3px;
    background: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    z-index: 2;
    transition: transform 0.15s var(--spring), border-color 0.15s;
}
.flt-btn:hover { border-color: var(--accent); transform: scale(1.1); }
.flt-btn svg { width: 72%; height: 72%; fill: none; stroke: #444; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.flt-btn.on { background: var(--accent-l); border-color: var(--accent); }
.flt-btn.on svg { fill: var(--accent); stroke: var(--accent); }
td.flt-head .cv { padding-right: calc(22px * var(--z, 1)); }

.spark { display: block; overflow: visible; }
.spk-ln { stroke-dasharray: 1; stroke-dashoffset: 0; }
td.fx-in .spk-ln, td.fx-pop .spk-ln { animation: draw 0.8s var(--ease) both; stroke-dashoffset: 1; }

/* ---------- Selection overlays ---------- */
#ov { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#ov.snap *, #ov.snap { transition: none !important; }

#sel-active {
    position: absolute;
    border: 2px solid var(--accent);
    border-radius: 1px;
    z-index: 3;
    transition: left var(--glide, 0.16s) var(--spring), top var(--glide, 0.16s) var(--spring), width var(--glide, 0.16s) var(--spring), height var(--glide, 0.16s) var(--spring);
}
#sel-active.in-range { border-width: 1px; border-color: var(--sel-line); }
#sel-active.land { animation: glow 0.5s var(--ease); }
#sel-active.land::after {
    content: "";
    position: absolute;
    inset: -2px;
    border: 2px solid var(--accent);
    border-radius: 3px;
    animation: lockOn 0.42s var(--ease) forwards;
}

@keyframes lockOn {
    0% { transform: scale(1.45); opacity: 0; }
    35% { opacity: 0.85; }
    100% { transform: scale(1); opacity: 0; }
}

@keyframes glow {
    0% { box-shadow: 0 0 0 5px var(--accent-ring), 0 0 14px var(--accent-ring); }
    100% { box-shadow: 0 0 0 0 transparent, 0 0 0 transparent; }
}

.sel-trail {
    position: absolute;
    border: 2px solid var(--accent);
    border-radius: 2px;
    background: var(--sel-fill);
    animation: trail 0.42s var(--ease) forwards;
}

.comet {
    position: absolute;
    height: 4px;
    margin-top: -2px;
    transform-origin: 0 50%;
    border-radius: 4px;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, var(--accent-ring) 40%, var(--accent));
    box-shadow: 0 0 10px var(--accent-ring);
    animation: comet 0.5s var(--ease) forwards;
}
.comet::after {
    content: "";
    position: absolute;
    right: -5px;
    top: -3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px 3px var(--accent-ring);
}

@keyframes comet {
    0% { clip-path: inset(0 100% 0 0); opacity: 1; }
    45% { clip-path: inset(0 0 0 0); opacity: 1; }
    100% { clip-path: inset(0 0 0 100%); opacity: 0; }
}

#grid td.fx-tick { animation: tick2 0.42s var(--ease); }

@keyframes tick2 {
    0% { box-shadow: inset 0 0 0 999px rgba(104, 199, 2, 0.24); }
    100% { box-shadow: inset 0 0 0 999px rgba(104, 199, 2, 0); }
}

@keyframes trail {
    0% { opacity: 0.55; }
    100% { opacity: 0; transform: scale(0.55); }
}

#sel-range {
    position: absolute;
    background: var(--sel-fill);
    border: 2px solid var(--accent);
    overflow: hidden;
    z-index: 1;
    transition: left var(--glide, 0.16s) var(--spring), top var(--glide, 0.16s) var(--spring), width var(--glide, 0.16s) var(--spring), height var(--glide, 0.16s) var(--spring);
}
#ov.dragging #sel-range, #ov.dragging #sel-active { transition-duration: 0.07s; transition-timing-function: linear; }
#sel-range.shine::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 25%, rgba(255, 255, 255, 0.7) 50%, transparent 75%);
    transform: translateX(-110%);
    animation: shine 0.75s var(--ease) forwards;
}
body.dark #sel-range.shine::after { background: linear-gradient(105deg, transparent 25%, rgba(140, 255, 190, 0.22) 50%, transparent 75%); }

@keyframes shine {
    to { transform: translateX(110%); }
}

.sel-extra {
    position: absolute;
    background: var(--sel-fill);
    border: 1px solid var(--sel-line);
    transition: left 0.16s var(--spring), top 0.16s var(--spring), width 0.16s var(--spring), height 0.16s var(--spring);
}
.sel-extra.bloom { animation: bloom 0.38s var(--spring); }

@keyframes bloom {
    from { transform: scale(0.5); opacity: 0; }
}

#fill-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border: 1.5px solid var(--cell-bg, #fff);
    border-radius: 1px;
    pointer-events: auto;
    cursor: crosshair;
    z-index: 5;
    transition: left var(--glide, 0.16s) var(--spring), top var(--glide, 0.16s) var(--spring), transform 0.15s var(--spring);
}
#fill-handle:hover { transform: scale(1.6); }
#ov.dragging #fill-handle { transition: none; }

#sel-edges { position: absolute; z-index: 4; transition: left var(--glide, 0.16s) var(--spring), top var(--glide, 0.16s) var(--spring), width var(--glide, 0.16s) var(--spring), height var(--glide, 0.16s) var(--spring); }
#ov.dragging #sel-edges { display: none; }
#sel-edges i { position: absolute; pointer-events: auto; cursor: move; }
#sel-edges .e-t { left: 0; right: 0; top: -3px; height: 5px; }
#sel-edges .e-b { left: 0; right: 6px; bottom: -3px; height: 5px; }
#sel-edges .e-l { top: 0; bottom: 0; left: -3px; width: 5px; }
#sel-edges .e-r { top: 0; bottom: 6px; right: -3px; width: 5px; }

#fill-preview {
    position: absolute;
    border: 2px dashed #6b6b6b;
    background: rgba(104, 199, 2, 0.05);
    border-radius: 1px;
    transition: left 0.08s, top 0.08s, width 0.08s var(--ease), height 0.08s var(--ease);
}

#move-ghost {
    position: absolute;
    border: 3px solid var(--sel-line);
    background: rgba(104, 199, 2, 0.07);
    border-radius: 2px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
    transition: left 0.1s var(--spring), top 0.1s var(--spring);
}
#move-ghost.copy::after {
    content: "+";
    position: absolute;
    right: -11px;
    top: -11px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 14px;
    line-height: 1;
}
body.moving, body.moving * { cursor: move !important; }
body.painting #grid-inner, body.painting #grid td { cursor: copy; }

#copy-ants {
    position: absolute;
    z-index: 2;
    background-image:
        linear-gradient(90deg, var(--accent) 50%, transparent 50%),
        linear-gradient(90deg, var(--accent) 50%, transparent 50%),
        linear-gradient(0deg, var(--accent) 50%, transparent 50%),
        linear-gradient(0deg, var(--accent) 50%, transparent 50%);
    background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
    background-size: 8px 2px, 8px 2px, 2px 8px, 2px 8px;
    background-position: 0 0, 0 100%, 0 0, 100% 0;
    animation: ants 0.45s linear infinite;
}

@keyframes ants {
    to { background-position: 8px 0, -8px 100%, 0 -8px, 100% 8px; }
}

.ripple-host { position: absolute; overflow: hidden; z-index: 0; }
.ripple-host i {
    position: absolute;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: radial-gradient(circle, rgba(104, 199, 2, 0.32) 0%, rgba(104, 199, 2, 0.14) 45%, transparent 70%);
    animation: ripple 0.55s var(--ease) forwards;
}

@keyframes ripple {
    to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

.fx-poof {
    position: absolute;
    background: rgba(209, 52, 56, 0.16);
    border: 1px solid rgba(209, 52, 56, 0.45);
    animation: poof 0.5s var(--ease) forwards;
}

@keyframes poof {
    to { opacity: 0; transform: scale(0.94); filter: blur(3px); }
}

.fx-pulse {
    position: absolute;
    border: 2px solid var(--accent);
    animation: pulseRing 0.55s var(--ease) forwards;
}

@keyframes pulseRing {
    0% { box-shadow: 0 0 0 0 var(--accent-ring); opacity: 1; }
    100% { box-shadow: 0 0 0 9px transparent; opacity: 0; }
}

.fly-block {
    position: absolute;
    z-index: 8;
    pointer-events: none;
    transition: transform 0.46s var(--spring);
    filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.2));
}
.fly-block.row { background: var(--cell-bg); box-shadow: 0 0 0 1px var(--grid-line); filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.16)); }
.fly-block.go { transition: transform 0.46s var(--spring); }
.fly-cell { position: absolute; overflow: hidden; font-family: var(--font-cell); color: var(--cell-text); }
.fly-cell .cv { height: 100%; }
td.ghosted > * { opacity: 0; }

.ref-box {
    position: absolute;
    border: 2px solid var(--rc);
    background: color-mix(in srgb, var(--rc) 9%, transparent);
    border-radius: 1px;
    animation: refIn 0.26s var(--spring);
}
.ref-box::after { content: ""; position: absolute; right: -4px; bottom: -4px; width: 6px; height: 6px; background: var(--rc); border: 1px solid #fff; }

@keyframes refIn {
    from { transform: scale(0.85); opacity: 0; }
}

.trace-box { position: absolute; border: 2px dashed var(--rc); background: color-mix(in srgb, var(--rc) 10%, transparent); animation: refIn 0.3s var(--spring) backwards; }
.trace-svg { position: absolute; left: 0; top: 0; overflow: visible; }
.trace-svg path[stroke] { fill: none; stroke-width: 2; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 0.7s var(--ease) forwards; }

@keyframes draw {
    to { stroke-dashoffset: 0; }
}

#resize-guide { position: absolute; z-index: 9; background: var(--accent); pointer-events: none; }
#resize-guide.col { width: 2px; height: 100vh; }
#resize-guide.row { height: 2px; width: 100vw; }

#drag-tip {
    position: absolute;
    z-index: 12;
    pointer-events: none;
    background: #fffbe6;
    color: #1b1b1b;
    border: 1px solid #c8b66b;
    border-radius: 3px;
    padding: 2px 7px;
    font-size: 12px;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* ---------- Cell animations ---------- */
#grid td.fx-flash { animation: cellFlash 0.9s var(--ease); }
#grid td.fx-in { animation: cellTint 0.7s var(--ease) backwards; animation-delay: inherit; }
#grid td.fx-in .ct { animation: cellIn 0.48s var(--spring) backwards; animation-delay: inherit; }
#grid td.fx-pop .ct { animation: cellPop 0.45s var(--spring) backwards; animation-delay: inherit; }
#grid td.fx-pop { animation: cellTint 0.6s var(--ease) backwards; animation-delay: inherit; }

@keyframes cellFlash {
    0% { box-shadow: inset 0 0 0 999px rgba(255, 210, 0, 0.42); }
    100% { box-shadow: inset 0 0 0 999px rgba(255, 210, 0, 0); }
}

@keyframes cellTint {
    0% { box-shadow: inset 0 0 0 999px rgba(104, 199, 2, 0.2); }
    100% { box-shadow: inset 0 0 0 999px rgba(104, 199, 2, 0); }
}

@keyframes cellIn {
    from { opacity: 0; transform: translateY(7px) scale(0.88); }
}

@keyframes cellPop {
    0% { transform: scale(0.65); opacity: 0.2; }
    60% { transform: scale(1.12); }
    100% { transform: none; }
}

/* ---------- In-cell editor ---------- */
#editor-wrap {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 6;
    width: 2px;
    height: 2px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    font-family: var(--font-cell);
    font-size: calc(13px * var(--z, 1));
    color: var(--cell-text);
}
#editor-wrap.on {
    height: auto;
    overflow: visible;
    opacity: 1;
    pointer-events: auto;
    background: var(--cell-bg);
    box-shadow: 0 0 0 2px var(--accent), 0 8px 22px rgba(0, 0, 0, 0.16);
    border-radius: 1px;
}
#editor-wrap.on.pop-in { animation: edPop 0.2s var(--spring); }
#editor-wrap.away { display: none; }

@keyframes edPop {
    from { transform: scale(0.94); opacity: 0.5; }
}

#cell-editor, #editor-hl {
    display: block;
    width: 100%;
    min-height: inherit;
    margin: 0;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    font: inherit;
    color: inherit;
    padding: calc(3px * var(--z, 1)) calc(4px * var(--z, 1)) 0;
    line-height: 1.3;
    white-space: pre;
    overflow: hidden;
}
#editor-hl { position: absolute; inset: 0; pointer-events: none; }
#editor-wrap.wrap #cell-editor, #editor-wrap.wrap #editor-hl { white-space: pre-wrap; overflow-wrap: anywhere; }
#editor-wrap.a-right #cell-editor { text-align: right; }
#editor-wrap.a-center #cell-editor { text-align: center; }
#cell-editor.hl-on { color: transparent; caret-color: var(--cell-text); }
#cell-editor::selection, #formula-input::selection { background: rgba(104, 199, 2, 0.28); }
.hl-layer .tk-fn { font-weight: 600; }
.hl-layer .tk-str { color: #b5470b; }
.hl-layer .tk-num { color: #0b7a4b; }
.hl-layer .tk-err { color: #c42b1c; font-weight: 600; }
body.dark .hl-layer .tk-str { color: #f0a36b; }
body.dark .hl-layer .tk-num { color: #7bd6a4; }

#edit-measure { position: absolute; left: -9999px; top: -9999px; white-space: pre; visibility: hidden; }

/* ---------- Charts ---------- */
#charts-layer { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 5; }
.chart-obj {
    position: absolute;
    background: var(--cell-bg);
    border: 1px solid #d4d4d4;
    border-radius: 9px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s, transform 0.2s var(--spring);
    font-family: var(--font-ui);
}
body.dark .chart-obj { border-color: #3d3d3d; }
.chart-obj:hover { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14); }
.chart-obj.sel { box-shadow: 0 0 0 2px var(--accent), 0 12px 30px rgba(0, 0, 0, 0.16); }
.chart-obj.dragging { transform: scale(1.015) rotate(-0.4deg); box-shadow: 0 0 0 2px var(--accent), 0 20px 40px rgba(0, 0, 0, 0.25); cursor: grabbing; transition: transform 0.2s var(--spring), box-shadow 0.2s; }
.chart-obj.animate { animation: chartIn 0.45s var(--spring); }
.chart-obj.leaving { animation: chartOut 0.2s var(--ease) forwards; }

@keyframes chartIn {
    from { transform: scale(0.85) translateY(10px); opacity: 0; }
}

@keyframes chartOut {
    to { transform: scale(0.8); opacity: 0; }
}

.chart-head { height: 32px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; color: var(--ui-text); cursor: grab; padding: 0 12px; overflow: hidden; white-space: nowrap; }
.chart-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 8px 8px; cursor: grab; }
.chart-body svg { display: block; overflow: visible; font-family: var(--font-ui); }
.chart-stats { flex: none; height: 20px; font-size: 11px; color: var(--ui-dim); text-align: center; font-family: "JetBrains Mono", monospace; animation: fadeIn 0.4s var(--ease); }
.chart-tools {
    position: absolute;
    right: 0;
    top: -42px;
    display: none;
    gap: 2px;
    padding: 3px;
    background: var(--menu-bg);
    border: 1px solid var(--menu-line);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}
.chart-obj.sel .chart-tools { display: flex; animation: menuIn 0.18s var(--ease); }
.chart-tools button { width: 30px; height: 30px; border: 0; background: transparent; border-radius: 6px; display: grid; place-items: center; cursor: pointer; transition: background 0.14s, transform 0.12s; }
.chart-tools button:hover { background: var(--hover); }
.chart-tools button:active { transform: scale(0.9); }
.chart-tools button.on { background: var(--on); }
.chart-tools .ct-sep { width: 1px; background: var(--menu-line); margin: 4px 2px; }
.chart-rz { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; border-radius: 3px; background: var(--cell-bg); border: 2px solid var(--accent); cursor: nwse-resize; display: none; }
.chart-obj.sel .chart-rz { display: block; }

.chart-body .bar, .chart-body .slice, .chart-body .dot { transition: filter 0.15s, opacity 0.15s; }
.chart-body .bar:hover, .chart-body .slice:hover, .chart-body .dot:hover { filter: brightness(1.15) saturate(1.1); }
.chart-obj.animate .bar { transform-box: fill-box; transform-origin: 50% 100%; animation: growY 0.7s var(--spring) backwards; animation-delay: calc(var(--i) * 32ms); }
.chart-obj.animate .bar.neg { transform-origin: 50% 0; }
.chart-obj.animate .bar.h { transform-origin: 0 50%; animation-name: growX; }
.chart-obj.animate .bar.h.neg { transform-origin: 100% 50%; }
.chart-obj.animate .ln { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.1s var(--ease) forwards; }
.chart-obj.animate .area { transform-box: fill-box; transform-origin: 50% 100%; animation: growY 0.9s var(--ease) backwards; }
.chart-obj.animate .dot { transform-box: fill-box; transform-origin: center; animation: dotIn 0.42s var(--spring) backwards; animation-delay: calc(0.35s + var(--i) * 35ms); }
.chart-obj.animate .sweep { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1s cubic-bezier(0.3, 0.7, 0.3, 1) forwards; }
.chart-obj.animate .slice-lbl, .chart-obj.animate .legend { animation: fadeIn 0.45s 0.7s var(--ease) backwards; }

@keyframes growY {
    from { transform: scaleY(0); }
}

@keyframes growX {
    from { transform: scaleX(0); }
}

@keyframes dotIn {
    from { transform: scale(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
}

/* ---------- Footer: sheet tabs + status bar ---------- */
#footer { flex: none; background: var(--ui-bg); border-top: 1px solid var(--ribbon-line); }

#sheet-bar { height: 32px; display: flex; align-items: stretch; gap: 4px; padding: 0 6px; }
.sheet-nav { display: flex; align-items: center; gap: 1px; }
.sheet-nav button { width: 22px; height: 24px; border: 0; background: transparent; border-radius: 4px; color: var(--ui-dim); font-size: 9px; cursor: pointer; }
.sheet-nav button:hover { background: var(--hover); }
#sheet-tabs { position: relative; display: flex; align-items: stretch; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; max-width: calc(100% - 120px); }
#sheet-tabs::-webkit-scrollbar { display: none; }

.stab {
    position: relative;
    border: 0;
    background: transparent;
    padding: 0 18px;
    font-size: 13px;
    color: var(--ui-text);
    cursor: pointer;
    white-space: nowrap;
    border-right: 1px solid var(--ribbon-line);
    transition: background 0.15s, color 0.15s, transform 0.3s var(--spring);
}
.stab:hover { background: var(--hover); }
.stab.on { background: var(--cell-bg); color: var(--accent-d); font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }
.stab::before { content: ""; position: absolute; left: 6px; right: 6px; top: 0; height: 3px; border-radius: 0 0 3px 3px; background: var(--tab, transparent); }
.stab.tab-in { animation: tabIn 0.38s var(--spring); }
.stab.tab-out { animation: tabOut 0.18s var(--ease) forwards; }
.stab.drop-here { box-shadow: inset 3px 0 0 var(--accent); }
body.tab-dragging, body.tab-dragging * { cursor: grabbing !important; }
.stab-edit { border: 1px solid var(--accent); border-radius: 3px; margin: 3px 2px; padding: 0 8px; font-size: 13px; background: var(--field-bg); outline: none; box-shadow: 0 0 0 2px var(--accent-ring); }

@keyframes tabIn {
    from { transform: translateY(100%) scale(0.8); opacity: 0; }
}

@keyframes tabOut {
    to { transform: translateY(100%); opacity: 0; }
}

#sheet-ink { position: absolute; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); transition: left 0.34s var(--spring), width 0.34s var(--spring); pointer-events: none; z-index: 1; }

#add-sheet { align-self: center; width: 26px; height: 26px; border-radius: 50%; border: 0; background: transparent; font-size: 18px; color: var(--ui-dim); cursor: pointer; transition: background 0.15s, transform 0.25s var(--spring), color 0.15s; }
#add-sheet:hover { background: var(--hover); color: var(--accent); transform: rotate(90deg); }

#status-bar {
    height: 25px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 10px;
    font-size: 12px;
    color: var(--ui-dim);
    border-top: 1px solid var(--ribbon-line);
}
#status-mode { min-width: 40px; color: var(--ui-text); }
#status-info { color: var(--accent-d); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status-bar .grow { flex: 1; }
#status-stats { display: flex; gap: 16px; white-space: nowrap; }
#status-stats b { color: var(--ui-text); font-weight: 600; }
#status-stats.blip span { animation: blip 0.4s var(--ease) backwards; }
#status-stats.blip span:nth-child(2) { animation-delay: 0.03s; }
#status-stats.blip span:nth-child(3) { animation-delay: 0.06s; }
#status-stats.blip span:nth-child(4) { animation-delay: 0.09s; }
#status-stats.blip span:nth-child(5) { animation-delay: 0.12s; }

@keyframes blip {
    from { opacity: 0; transform: translateY(4px); }
}

.zoom-ctl { display: flex; align-items: center; gap: 4px; }
.zoom-ctl button { border: 0; background: transparent; color: var(--ui-dim); width: 20px; height: 20px; border-radius: 4px; cursor: pointer; font-size: 14px; }
.zoom-ctl button:hover { background: var(--hover); color: var(--ui-text); }
#zoom-label { width: auto; padding: 0 4px; font-size: 12px; min-width: 42px; }
#zoom-slider { width: 110px; accent-color: var(--accent); }

/* ---------- Menus ---------- */
.menu {
    position: fixed;
    z-index: 1000;
    min-width: 190px;
    max-height: 80vh;
    overflow: auto;
    background: var(--menu-bg);
    border: 1px solid var(--menu-line);
    border-radius: 9px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.08);
    padding: 4px;
    font-size: 13px;
    color: var(--ui-text);
}
.menu.pop { animation: menuIn 0.15s var(--ease); }
.menu.closing { animation: menuOut 0.1s var(--ease) forwards; pointer-events: none; }

@keyframes menuIn {
    from { opacity: 0; transform: scale(0.96) translateY(-4px); }
}

@keyframes menuOut {
    to { opacity: 0; transform: scale(0.98); }
}

.m-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 5px 10px 5px 6px;
    border-radius: 5px;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s;
}
.m-item:hover, .m-item:focus-visible { background: var(--hover); outline: none; }
.m-item:disabled { opacity: 0.45; cursor: default; background: transparent; }
.m-item.checked .m-label { font-weight: 600; }
.m-ico { width: 18px; display: inline-grid; place-items: center; flex: none; color: var(--ui-dim); }
.m-ico .ico { width: 16px; height: 16px; }
.m-check { color: var(--accent); font-weight: 700; }
.m-label { flex: 1; display: flex; align-items: center; gap: 4px; overflow: hidden; text-overflow: ellipsis; }
.m-kbd { margin-left: auto; padding-left: 18px; font-size: 11.5px; color: var(--ui-dim); }
.m-arrow { margin-left: auto; padding-left: 12px; color: var(--ui-dim); }
.m-sep { height: 1px; background: var(--menu-line); margin: 4px 2px; }
.m-head { font-size: 11px; font-weight: 700; color: var(--ui-dim); padding: 7px 10px 3px; }
.nf-name { flex: 1; }
.nf-sample { color: var(--ui-dim); font-size: 12px; margin-left: 16px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.menu-numFormats { min-width: 300px; }
.menu-fonts { max-height: 60vh; }

.pal { padding: 6px 6px 4px; width: 234px; }
.pal-auto { display: flex; align-items: center; gap: 8px; width: 100%; border: 1px solid var(--menu-line); background: transparent; border-radius: 5px; padding: 5px 8px; margin-bottom: 6px; cursor: pointer; }
.pal-auto:hover { background: var(--hover); }
.pal-none { width: 16px; height: 16px; border: 1px solid #999; background: linear-gradient(135deg, transparent 45%, #d13438 45%, #d13438 55%, transparent 55%); }
.pal-head { font-size: 11px; font-weight: 700; color: var(--ui-dim); margin: 4px 0; }
.pal-grid { display: grid; grid-template-columns: repeat(10, 18px); gap: 2px 4px; }
.pal-grid.gel { grid-template-columns: repeat(8, 22px); gap: 5px; }
.pal-sw { width: 18px; height: 18px; border: 1px solid rgba(0, 0, 0, 0.14); border-radius: 3px; cursor: pointer; padding: 0; transition: transform 0.12s var(--spring), box-shadow 0.12s; position: relative; }
.pal-sw.top { margin-bottom: 4px; }
.pal-sw:hover { transform: scale(1.3); z-index: 1; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); }
.gelsw { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.8), 0 1px 2px rgba(0, 0, 0, 0.2); }
.pal-more { display: flex; align-items: center; gap: 8px; padding: 6px 6px 4px; margin-top: 6px; border-top: 1px solid var(--menu-line); cursor: pointer; position: relative; border-radius: 5px; }
.pal-more:hover { background: var(--hover); }
.pal-more input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.pal-rain { width: 16px; height: 16px; border-radius: 50%; background: conic-gradient(#ff3b30, #ff9500, #ffcc00, #34c759, #00c7be, #007aff, #af52de, #ff3b30); }

.gal { padding: 6px; width: 560px; max-width: calc(100vw - 24px); max-height: 72vh; overflow: auto; }
.gal-head { font-size: 11.5px; font-weight: 700; color: var(--ui-dim); margin: 8px 2px 5px; }
.gal-head:first-child { margin-top: 2px; }
.gal-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.gal-item {
    height: 30px;
    border: 1px solid var(--menu-line);
    border-radius: 5px;
    background: var(--cell-bg);
    font-family: var(--font-cell);
    font-size: 12.5px;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding: 0 7px;
    transition: transform 0.15s var(--spring), box-shadow 0.15s;
}
.gal-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }
.gal-grid.tbl { grid-template-columns: repeat(5, 1fr); }
.tbl-item { border: 1px solid var(--menu-line); background: #fff; border-radius: 6px; padding: 6px; cursor: pointer; transition: transform 0.15s var(--spring), box-shadow 0.15s; }
.tbl-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }
.tt { display: grid; gap: 1px; justify-content: center; }
.tt i { display: flex; gap: 1px; }
.tt b { width: 16px; height: 7px; }

.sym-grid { display: grid; grid-template-columns: repeat(9, 30px); gap: 3px; padding: 4px; }
.sym-grid button { width: 30px; height: 30px; border: 1px solid var(--menu-line); background: transparent; border-radius: 5px; font-size: 16px; cursor: pointer; transition: transform 0.12s var(--spring); }
.sym-grid button:hover { background: var(--hover); transform: scale(1.15); }

.cf-sw { display: inline-block; width: 18px; height: 13px; border-radius: 2px; border: 1px solid rgba(0, 0, 0, 0.12); margin-right: 4px; flex: none; }
.cf-sw.wide { width: 42px; }
.cf-sw.txt { width: auto; padding: 0 5px; height: 18px; line-height: 16px; font-size: 11px; }
.cf-icons { display: inline-flex; gap: 2px; width: 46px; font-size: 12px; }

.flt-pop { min-width: 250px; }
.flt-menu { padding: 2px; }
.flt-search { width: calc(100% - 8px); margin: 4px; height: 28px; border: 1px solid var(--field-line); border-radius: 5px; padding: 0 8px; background: var(--field-bg); outline: none; }
.flt-search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }
.flt-list { max-height: 220px; overflow: auto; border: 1px solid var(--menu-line); border-radius: 5px; margin: 4px; padding: 4px; }
.flt-list label { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.flt-list label:hover { background: var(--hover); }
.flt-list small { margin-left: auto; color: var(--ui-dim); padding-left: 10px; }
.flt-list input { accent-color: var(--accent); }
.flt-foot { display: flex; justify-content: flex-end; gap: 6px; padding: 6px 4px 2px; }

/* Autocomplete & argument tips */
#ac-list { width: 330px; padding: 3px; z-index: 1100; }
.ac-item { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: transparent; padding: 4px 8px; border-radius: 5px; cursor: pointer; text-align: left; }
.ac-item b { font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--accent-d); }
.ac-item span { font-size: 11.5px; color: var(--ui-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ac-item.on, .ac-item:hover { background: var(--on); }
.ac-foot { font-size: 10.5px; color: var(--ui-dim); padding: 3px 8px 1px; border-top: 1px solid var(--menu-line); margin-top: 2px; }
#arg-tip {
    position: fixed;
    z-index: 1100;
    background: var(--menu-bg);
    border: 1px solid var(--menu-line);
    border-radius: 5px;
    padding: 3px 9px;
    font-size: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: "JetBrains Mono", monospace;
    animation: menuIn 0.12s var(--ease);
}
#arg-tip u { text-decoration: none; font-weight: 700; color: var(--accent-d); background: var(--accent-l); border-radius: 3px; padding: 0 2px; }

/* ---------- Dialogs ---------- */
.dlg-back {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.3);
    display: grid;
    place-items: center;
    animation: fadeIn 0.16s var(--ease);
    padding: 16px;
}
.dlg-back.closing { animation: fadeOut 0.16s var(--ease) forwards; }
.dlg-back.closing .dlg { animation: dlgOut 0.16s var(--ease) forwards; }

@keyframes fadeOut {
    to { opacity: 0; }
}

.dlg {
    width: 400px;
    max-width: 100%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: var(--menu-bg);
    color: var(--ui-text);
    border-radius: 12px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
    animation: dlgIn 0.26s var(--spring);
}

@keyframes dlgIn {
    from { transform: scale(0.9) translateY(12px); opacity: 0; }
}

@keyframes dlgOut {
    to { transform: scale(0.95); opacity: 0; }
}

.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; font-size: 15.5px; font-weight: 600; }
.dlg-x { border: 0; background: transparent; width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; cursor: pointer; color: var(--ui-dim); }
.dlg-x:hover { background: var(--hover); color: var(--ui-text); }
.dlg-body { padding: 4px 16px 12px; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--menu-line); }
.dlg-btn { min-width: 84px; height: 31px; padding: 0 14px; border: 1px solid var(--field-line); background: var(--field-bg); border-radius: 6px; cursor: pointer; transition: background 0.14s, transform 0.1s, box-shadow 0.14s; }
.dlg-btn:hover { background: var(--hover); }
.dlg-btn:active { transform: scale(0.96); }
.dlg-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.dlg-btn.primary:hover { background: var(--accent-d); box-shadow: 0 3px 10px var(--accent-ring); }
body.dark .dlg-btn.primary:hover { background: linear-gradient(180deg, #b4fb6c 0%, #62d40a 100%); }
.dlg-btn.danger.primary { background: #c42b1c; border-color: #c42b1c; }
.dlg-text { margin: 6px 0 10px; line-height: 1.45; }
.dlg-hint { margin: 8px 0 0; font-size: 12px; color: var(--ui-dim); line-height: 1.4; }
.dlg-field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 12.5px; }
.dlg-field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.dlg-field.inline input { width: 120px; }
.dlg-input, .dlg select, .dlg-field select {
    height: 31px;
    border: 1px solid var(--field-line);
    border-radius: 6px;
    background: var(--field-bg);
    padding: 0 9px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.dlg-input:focus, .dlg select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }
.dlg-input.tiny { width: 50px; height: 26px; }
.dlg-check { display: flex; align-items: center; gap: 7px; margin: 8px 0; cursor: pointer; }
.dlg input[type=checkbox], .dlg input[type=radio] { accent-color: var(--accent); }
.dlg-row { display: flex; align-items: center; gap: 8px; }
.dlg-row .dlg-input { flex: 1; }
.radio-col { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.radio-col label, .radio-row label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.radio-row { display: flex; gap: 18px; margin: 8px 0; }
.cf-preview { margin-top: 10px; padding: 8px; border: 1px dashed var(--field-line); border-radius: 6px; text-align: center; font-family: var(--font-cell); transition: background 0.2s, color 0.2s; }
.sort-row { display: grid; grid-template-columns: 64px 1fr 1fr; gap: 8px; align-items: center; margin: 10px 0; }

.fc-grid { display: grid; grid-template-columns: 150px 1fr; gap: 14px; }
.fc-list { display: flex; flex-direction: column; border: 1px solid var(--menu-line); border-radius: 6px; padding: 3px; max-height: 300px; overflow: auto; }
.fc-opt { border: 0; background: transparent; text-align: left; padding: 5px 8px; border-radius: 4px; cursor: pointer; }
.fc-opt:hover { background: var(--hover); }
.fc-opt.on { background: var(--on); font-weight: 600; }
.fc-sample-label { font-size: 11.5px; color: var(--ui-dim); }
.fc-sample { margin: 4px 0 10px; padding: 8px 10px; border: 1px solid var(--menu-line); border-radius: 6px; font-family: var(--font-cell); font-size: 15px; min-height: 38px; }

.if-top { display: flex; gap: 8px; }
.if-top .dlg-input { flex: 1; }
.if-list { margin-top: 10px; height: 220px; overflow: auto; border: 1px solid var(--menu-line); border-radius: 6px; padding: 3px; }
.if-item { display: flex; justify-content: space-between; width: 100%; border: 0; background: transparent; padding: 5px 9px; border-radius: 4px; cursor: pointer; text-align: left; }
.if-item b { font-family: "JetBrains Mono", monospace; font-size: 12.5px; }
.if-item span { color: var(--ui-dim); font-size: 11.5px; }
.if-item:hover { background: var(--hover); }
.if-item.on { background: var(--on); }
.if-desc { margin-top: 10px; min-height: 54px; }
.if-desc code { font-family: "JetBrains Mono", monospace; font-size: 12.5px; color: var(--accent-d); }
.if-desc p { margin: 4px 0 0; color: var(--ui-dim); }

.cf-list { display: flex; flex-direction: column; gap: 4px; min-height: 60px; }
.cf-row { display: grid; grid-template-columns: 60px 1fr auto auto auto; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--menu-line); border-radius: 6px; animation: blip 0.25s var(--ease); }
.cf-row em { color: var(--ui-dim); font-style: normal; font-size: 12px; }
.cf-row button { border: 0; background: transparent; width: 26px; height: 26px; border-radius: 5px; cursor: pointer; display: grid; place-items: center; color: var(--ui-dim); }
.cf-row button:hover:not(:disabled) { background: var(--hover); color: var(--ui-text); }
.cf-row button:disabled { opacity: 0.3; }
.cf-row .ico { width: 15px; height: 15px; }

.help-tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--menu-line); }
.help-tabs button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--ui-dim); }
.help-tabs button.on { color: var(--accent-d); border-bottom-color: var(--accent); font-weight: 600; }
.help-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.help-cards div { border: 1px solid var(--menu-line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.help-cards span { color: var(--ui-dim); font-size: 12.5px; line-height: 1.45; }
.help-cards code, .help-keys code { font-family: "JetBrains Mono", monospace; font-size: 11.5px; background: rgba(127, 127, 127, 0.14); padding: 1px 4px; border-radius: 3px; }
.help-keys { width: 100%; border-collapse: collapse; }
.help-keys td { padding: 5px 4px; border-bottom: 1px solid var(--menu-line); }
.help-keys td:last-child { text-align: right; }
.help-keys kbd { font-family: var(--font-ui); font-size: 12px; background: var(--ui-bg); border: 1px solid var(--field-line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; }
.help-fns { margin-top: 8px; max-height: 340px; overflow: auto; }
.help-fns div { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 6px 2px; border-bottom: 1px solid var(--menu-line); }
.help-fns code { font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--accent-d); }
.help-fns span { grid-column: 1; color: var(--ui-dim); font-size: 12px; }
.help-fns em { grid-row: 1; grid-column: 2; font-size: 11px; color: var(--ui-dim); font-style: normal; }

/* ---------- Find panel ---------- */
#find-panel {
    position: fixed;
    top: 178px;
    right: 22px;
    width: 350px;
    z-index: 900;
    background: var(--menu-bg);
    border: 1px solid var(--menu-line);
    border-radius: 11px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
    padding: 10px 12px 12px;
}
#find-panel.pop, .pop { animation: dlgIn 0.24s var(--spring); }
#find-panel.closing { animation: dlgOut 0.15s var(--ease) forwards; }
.fp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.fp-tabs { display: flex; gap: 2px; }
.fp-tabs button { border: 0; background: transparent; padding: 4px 10px; border-radius: 5px; cursor: pointer; color: var(--ui-dim); }
.fp-tabs button.on { background: var(--on); color: var(--accent-d); font-weight: 600; }
.fp-x { border: 0; background: transparent; width: 26px; height: 26px; border-radius: 5px; cursor: pointer; display: grid; place-items: center; color: var(--ui-dim); }
.fp-x:hover { background: var(--hover); }
.fp-row { display: grid; grid-template-columns: 86px 1fr; align-items: center; margin: 6px 0; font-size: 12.5px; }
.fp-row input { height: 29px; border: 1px solid var(--field-line); border-radius: 5px; padding: 0 8px; background: var(--field-bg); outline: none; }
.fp-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }
.fp-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 8px 0; font-size: 12.5px; }
.fp-opts label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.fp-opts input { accent-color: var(--accent); }
.fp-btns { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.fp-btns button { height: 28px; padding: 0 10px; border: 1px solid var(--field-line); background: var(--field-bg); border-radius: 5px; cursor: pointer; }
.fp-btns button:hover { background: var(--hover); }
.fp-btns button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.fp-rep-btns { display: flex; gap: 6px; }
#fp-results p { margin: 8px 0 0; font-size: 12.5px; }
.fp-none { color: #c42b1c; }
.fp-count { color: var(--accent-d); }
#fp-results.shake { animation: shake 0.35s; }

@keyframes shake {
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.fp-list { max-height: 180px; overflow: auto; margin-top: 6px; border: 1px solid var(--menu-line); border-radius: 6px; }
.fp-list button { display: grid; grid-template-columns: 70px 50px 1fr; gap: 6px; width: 100%; border: 0; border-bottom: 1px solid var(--menu-line); background: transparent; padding: 4px 8px; text-align: left; cursor: pointer; font-size: 12px; }
.fp-list button:hover { background: var(--hover); }
.fp-list em { color: var(--ui-dim); font-style: normal; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- Notes ---------- */
.note-pop {
    position: fixed;
    z-index: 800;
    width: 220px;
    background: #fff9d6;
    color: #2a2a2a;
    border: 1px solid #e0cf7a;
    border-radius: 4px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    padding: 6px 8px 8px;
}
.note-pop::before { content: ""; position: absolute; left: -8px; top: 10px; border: 4px solid transparent; border-right-color: #e0cf7a; border-right-width: 8px; border-left-width: 0; }
.note-author { font-size: 11px; font-weight: 700; color: #8a7b28; margin-bottom: 2px; }
#note-text { width: 100%; height: 86px; border: 0; background: transparent; resize: vertical; outline: none; font-size: 12.5px; line-height: 1.4; font-family: var(--font-ui); }
.note-pop.editing { box-shadow: 0 0 0 2px #d6b800, 0 8px 22px rgba(0, 0, 0, 0.2); }

/* ---------- Toast ---------- */
#toast {
    position: fixed;
    left: 50%;
    bottom: 72px;
    transform: translate(-50%, 16px) scale(0.96);
    background: #262626;
    color: #fff;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    z-index: 3000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    transition: opacity 0.22s, transform 0.3s var(--spring);
    max-width: calc(100vw - 40px);
    text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---------- Backstage ---------- */
#backstage { position: fixed; inset: 0; z-index: 1500; display: flex; background: var(--cell-bg); color: var(--ui-text); }
#backstage.bs-in { animation: bsIn 0.28s var(--ease); }
#backstage.bs-out { animation: bsOut 0.2s var(--ease) forwards; }

@keyframes bsIn {
    from { opacity: 0; transform: translateX(-28px); }
}

@keyframes bsOut {
    to { opacity: 0; transform: translateX(-20px); }
}

.bs-nav { width: 220px; flex: none; background: var(--title-bg); color: #fff; display: flex; flex-direction: column; padding: 10px 0; }
.bs-nav button { display: flex; align-items: center; gap: 12px; border: 0; background: transparent; color: #fff; padding: 11px 22px; font-size: 14px; cursor: pointer; text-align: left; transition: background 0.15s, padding 0.2s var(--spring); }
.bs-nav button:hover { background: rgba(255, 255, 255, 0.12); padding-left: 26px; }
.bs-nav button.on { background: rgba(255, 255, 255, 0.2); font-weight: 600; }
.bs-nav .bs-back { margin-bottom: 12px; font-size: 13px; opacity: 0.9; }
.bs-nav .grow { flex: 1; }
.bs-body { flex: 1; overflow: auto; padding: 34px 52px; }
.bs-body h1 { font-size: 30px; font-weight: 600; margin: 0 0 24px; }
.bs-body h2 { font-size: 17px; font-weight: 600; margin: 34px 0 12px; }
.tpl-row { display: flex; flex-wrap: wrap; gap: 18px; }
.tpl { width: 176px; border: 0; background: transparent; text-align: left; cursor: pointer; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.tpl b { font-size: 13.5px; margin-top: 4px; }
.tpl span { font-size: 12px; color: var(--ui-dim); line-height: 1.35; }
.tpl-thumb {
    height: 112px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--a), color-mix(in srgb, var(--a) 55%, #000));
    display: grid;
    place-items: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: transform 0.25s var(--spring), box-shadow 0.25s;
    overflow: hidden;
    position: relative;
}
.tpl-thumb svg { width: 74px; height: 46px; }
.tpl-thumb::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 255, 255, 0.25), transparent 45%); }
.tpl-thumb.blank { background: #fff; border: 1px solid #d4d4d4; }
.tpl-grid { width: 100%; height: 100%; background-image: linear-gradient(#e6e6e6 1px, transparent 1px), linear-gradient(90deg, #e6e6e6 1px, transparent 1px); background-size: 34px 16px; }
.tpl:hover .tpl-thumb { transform: translateY(-5px) scale(1.02); box-shadow: 0 12px 26px rgba(0, 0, 0, 0.2); }
.bs-card, .bs-about { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--menu-line); border-radius: 10px; max-width: 560px; }
.bs-card img, .bs-about img { width: 36px; height: 36px; }
.bs-card div, .bs-about div { display: flex; flex-direction: column; gap: 3px; }
.bs-card span, .bs-about span { color: var(--ui-dim); font-size: 12.5px; }
.bs-actions { display: flex; flex-wrap: wrap; gap: 14px; }
.bs-big { width: 230px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 16px; border: 1px solid var(--menu-line); border-radius: 10px; background: transparent; cursor: pointer; text-align: left; transition: transform 0.2s var(--spring), box-shadow 0.2s, border-color 0.2s; }
.bs-big .ico { width: 26px; height: 26px; color: var(--accent); }
.bs-big span { color: var(--ui-dim); font-size: 12.5px; line-height: 1.4; }
.bs-big:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12); border-color: var(--accent); }
.bs-note { color: var(--ui-dim); margin-top: 20px; }
.bs-opts { display: flex; flex-direction: column; gap: 6px; max-width: 520px; }
.bs-opt { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--menu-line); border-radius: 8px; cursor: pointer; }
.bs-opt:hover { background: var(--hover); }
.bs-opt input { accent-color: var(--accent); margin-top: 3px; }
.bs-opt span { display: flex; flex-direction: column; gap: 2px; }
.bs-opt em { font-style: normal; color: var(--ui-dim); font-size: 12px; }
.bs-danger { display: inline-flex; align-items: center; gap: 8px; border: 1px solid #c42b1c; color: #c42b1c; background: transparent; padding: 8px 14px; border-radius: 6px; cursor: pointer; }
.bs-danger:hover { background: #c42b1c; color: #fff; }
.bs-danger .ico { width: 16px; height: 16px; }

/* ---------- Keydown toolbar (kept from classic Imbuer, refreshed) ---------- */
#aero-selection-toolbar.aero-floating-bar {
    position: fixed;
    display: none;
    align-items: center;
    gap: 4px;
    z-index: 1200;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(240, 249, 255, 0.95) 100%);
    border: 1px solid #cfd8e3;
    border-radius: 10px;
    padding: 4px 6px;
    box-shadow: 0 10px 28px rgba(2, 60, 120, 0.22), inset 0 1px 0 #fff;
}
#aero-selection-toolbar.show { display: flex; }
#aero-selection-toolbar.pop { animation: dlgIn 0.24s var(--spring); }
#aero-selection-toolbar.cells::before {
    content: "Whole cells";
    font-size: 10.5px;
    font-weight: 700;
    color: #6b7c8f;
    padding: 0 4px;
}

.style-bar-btn {
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: bold;
    color: #334155;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0 1px 0 #fff;
    transition: transform 0.12s var(--spring);
}
.style-bar-btn:hover { background: #e2e8f0; color: var(--accent); transform: translateY(-1px); }
.style-bar-divider { width: 1px; height: 18px; background: #cbd5e1; margin: 0 4px; }
.aero-dropdown { position: relative; display: inline-block; }
.highlight-grid-menu {
    display: none;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 6px;
    padding: 8px !important;
    background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%) !important;
    border: 1px solid #b6c2d1 !important;
    border-radius: 10px !important;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22), inset 0 1px 0 #fff !important;
    min-width: 150px !important;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 1205;
    max-height: 320px;
    overflow: auto;
}
.aero-dropdown.active .highlight-grid-menu { display: grid !important; animation: menuIn 0.15s var(--ease); }
.chip-grid-menu { grid-template-columns: repeat(4, 1fr) !important; min-width: 180px !important; }
.color-swatch-item, .chip-swatch-item {
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s var(--spring);
}
.color-swatch-item:hover, .chip-swatch-item:hover, .effect-swatch-item:hover { transform: scale(1.14); }

/* ---------- Misc ---------- */
body.drop-on::after {
    content: "Drop to open!";
    position: fixed;
    inset: 12px;
    border: 3px dashed var(--accent);
    border-radius: 18px;
    background: rgba(104, 199, 2, 0.08);
    display: grid;
    place-items: center;
    font-size: 26px;
    font-weight: 600;
    color: var(--accent);
    z-index: 4000;
    pointer-events: none;
    animation: fadeIn 0.15s;
}

/* =====================================================================
   SOUL! Radii Office gel touches that show up in BOTH layouts!
   (Glossy gel buttons, a glowing JetBrains Mono brand, glass panels...)
   ===================================================================== */
:root { --font-brand: "JetBrains Mono", ui-monospace, Menlo, monospace; }

#titlebar {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.02) 52%, rgba(0, 0, 0, 0.05) 100%), var(--title-bg);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 1px 0 rgba(0, 0, 0, 0.12);
}
.tb-brand {
    font-family: var(--font-brand);
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.2px;
    color: #fff;
    text-shadow: 0 0 10px rgba(160, 255, 120, 0.65), 0 1px 1px rgba(0, 0, 0, 0.3);
    margin-left: 4px;
    user-select: none;
}

/* The File tab is a little gel pill! */
.rtab.file {
    background: linear-gradient(180deg, var(--gel-a) 0%, var(--gel-b) 100%);
    border: 1px solid var(--gel-border);
    box-shadow: 0 4px 12px var(--gel-glow), inset 0 1px 2px #fff;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}
.rtab.file:hover { background: linear-gradient(180deg, #b4fb6c 0%, #62d40a 100%); }
body.dark .rtab.file:hover { background: linear-gradient(180deg, #b4fb6c 0%, #62d40a 100%); }

/* Ribbon buttons light up like glass when you hover them! */
.rb:hover, .split-arrow:hover {
    background: linear-gradient(180deg, #ffffff 0%, var(--accent-l) 100%);
    border-color: #c9f0a0;
    box-shadow: inset 0 1px 0 #fff, 0 1px 3px rgba(104, 199, 2, 0.14);
}
body.dark .rb:hover, body.dark .split-arrow:hover {
    background: linear-gradient(180deg, #3d4a42 0%, #2c3530 100%);
    border-color: #4c6253;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
#tab-ink, #sheet-ink { background: linear-gradient(90deg, var(--gel-a), var(--gel-b)); box-shadow: 0 0 6px var(--accent-ring); }

/* Gel primary buttons in dialogs! */
.dlg-btn.primary, .fp-btns button.primary {
    background: linear-gradient(180deg, var(--gel-a) 0%, var(--gel-b) 100%);
    border-color: var(--gel-border);
    box-shadow: 0 4px 12px var(--gel-glow), inset 0 1px 2px #fff;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.dlg-btn.primary:hover { background: linear-gradient(180deg, #b4fb6c 0%, #62d40a 100%); }
body.dark .dlg-btn.primary:hover { background: linear-gradient(180deg, #b4fb6c 0%, #62d40a 100%); }
.dlg-btn.danger.primary { background: linear-gradient(180deg, #f87171 0%, #dc2626 100%); border-color: #fecaca; box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3), inset 0 1px 2px #fff; }
.dlg-head { font-family: var(--font-brand); font-weight: 800; font-size: 14.5px; }

/* Glassy toast with a glowing rim! */
#toast {
    background: linear-gradient(180deg, rgba(58, 64, 60, 0.94) 0%, rgba(26, 30, 28, 0.94) 100%);
    border: 1px solid rgba(120, 248, 56, 0.35);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 14px rgba(104, 199, 2, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* The "Ready" mode is a tiny gel chip! */
#status-mode {
    min-width: 0;
    padding: 1px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(180deg, var(--gel-a) 0%, var(--gel-b) 100%);
    border: 1px solid var(--gel-border);
    box-shadow: 0 2px 6px var(--gel-glow), inset 0 1px 2px #fff;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}

/* The active sheet tab gets a glossy sheen! */
.stab.on { background-image: linear-gradient(180deg, rgba(255, 255, 255, 0) 40%, rgba(104, 199, 2, 0.07) 100%); }

/* Backstage (File) nav: a Bitbook-style gel sidebar! */
.bs-nav {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 100%), linear-gradient(180deg, #5cb800 0%, #3a7500 100%);
    padding: 12px 10px;
    gap: 4px;
    box-shadow: 5px 0 25px rgba(0, 0, 0, 0.12);
}
.bs-nav button { border-radius: 8px; padding: 10px 14px; font-family: var(--font-brand); font-weight: 700; font-size: 13px; border: 1px solid transparent; }
.bs-nav button:hover { padding-left: 18px; border-color: rgba(255, 255, 255, 0.2); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12); }
.bs-nav button.on {
    background: linear-gradient(180deg, var(--gel-a) 0%, var(--gel-b) 100%);
    color: #fff;
    border-color: var(--gel-border);
    box-shadow: 0 4px 12px var(--gel-glow), inset 0 1px 2px #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.bs-body h1 { font-family: var(--font-brand); font-weight: 800; }
.bs-body h2.first { margin-top: 0; }

/* Layout picker cards in Settings! */
.lay-cards { display: flex; flex-wrap: wrap; gap: 16px; }
.lay-card {
    width: 250px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 10px 10px 14px;
    border: 2px solid var(--menu-line);
    border-radius: 14px;
    background: transparent;
    cursor: pointer;
    text-align: left;
    position: relative;
    transition: transform 0.22s var(--spring), border-color 0.2s, box-shadow 0.2s;
}
.lay-card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12); }
.lay-card.on { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.lay-card.on::after {
    content: "✓";
    position: absolute;
    top: -9px;
    right: -9px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    background: linear-gradient(180deg, var(--gel-a) 0%, var(--gel-b) 100%);
    border: 1px solid var(--gel-border);
    box-shadow: 0 2px 8px var(--gel-glow), inset 0 1px 2px #fff;
    animation: tabIn 0.35s var(--spring);
}
.lay-card b { font-family: var(--font-brand); font-size: 14px; margin-top: 4px; padding: 0 4px; }
.lay-card span { color: var(--ui-dim); font-size: 12.5px; line-height: 1.4; padding: 0 4px; }
.lay-thumb { width: 100%; height: 128px; border-radius: 9px; position: relative; overflow: hidden; border: 1px solid rgba(0, 0, 0, 0.12); }
.lay-thumb i { position: absolute; display: block; }
.lay-excel { background: #fff; }
.lay-excel .lt-side, .lay-excel .lt-orb { display: none; }
.lay-excel .lt-bar { left: 0; right: 0; top: 0; height: 30px; background: linear-gradient(#6bc702 0 12px, #f7f7f7 12px); border-bottom: 1px solid #dadada; }
.lay-excel .lt-grid { left: 0; right: 0; top: 31px; bottom: 0; background: linear-gradient(#f5f5f5 0 9px, transparent 9px), repeating-linear-gradient(90deg, transparent 0 31px, #e2e2e2 31px 32px), repeating-linear-gradient(transparent 0 11px, #e2e2e2 11px 12px); }
.lay-classic { background: radial-gradient(circle at 60% 40%, #1e293b 0%, #0f172a 100%); }
.lay-classic .lt-side { left: 0; top: 0; bottom: 0; width: 52px; background: linear-gradient(90deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.06)); border-right: 1px solid rgba(255, 255, 255, 0.25); }
.lay-classic .lt-side::before { content: ""; position: absolute; left: 7px; right: 7px; top: 10px; height: 8px; border-radius: 3px; background: #dfffc8; box-shadow: 0 0 6px #8cf84c, 0 16px 0 rgba(255, 255, 255, 0.25), 0 28px 0 rgba(255, 255, 255, 0.25), 0 40px 0 rgba(255, 255, 255, 0.25); }
.lay-classic .lt-bar { left: 62px; right: 10px; top: 9px; height: 16px; border-radius: 5px; background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(220, 238, 250, 0.8)); }
.lay-classic .lt-grid { left: 62px; right: 10px; top: 32px; bottom: 8px; border-radius: 6px; background: linear-gradient(#8ef02e 0 10px, transparent 10px), linear-gradient(90deg, #e9eef3 0 12px, transparent 12px), repeating-linear-gradient(90deg, transparent 0 27px, #d5dde6 27px 28px), repeating-linear-gradient(transparent 0 11px, #d5dde6 11px 12px), #f8fafc; }
.lay-classic .lt-orb { width: 46px; height: 46px; left: 26px; bottom: -14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, rgba(190, 255, 140, 0.7), rgba(104, 199, 2, 0.15) 60%, transparent 72%); }

/* Switching layouts melts the app away and back! */
#app { transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), filter 0.2s var(--ease); }
#app.layout-out { opacity: 0; transform: scale(0.985); filter: blur(3px); }
#app.layout-in { animation: layoutIn 0.36s var(--spring); }
@keyframes layoutIn { from { opacity: 0; transform: scale(1.012); } }

/* =====================================================================
   IMBUER CLASSIC LAYOUT! The original glassy Imbuer look: navy backdrop,
   gel orbs, a glass sidebar, lime gel headers and JetBrains Mono!
   ===================================================================== */
#orbs, #classic-side { display: none; }

body.layout-classic {
    --accent: #6bc702;
    --accent-d: #3f7f00;
    --accent-l: #eefbe0;
    --accent-ring: rgba(104, 199, 2, 0.35);
    --on: #e3f7cf;
    --hover: #eef6e6;
    --grid-line: rgba(203, 213, 225, 0.75);
    --hdr-on-text: #3f7f00;
    --sel-fill: rgba(120, 248, 56, 0.14);
    --sel-line: rgba(92, 184, 0, 0.6);
    --font-ui: "JetBrains Mono", ui-monospace, Menlo, monospace;
    --font-cell: "JetBrains Mono", ui-monospace, Menlo, monospace;
    --glass: linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(240, 249, 255, 0.88) 100%);
    --glass-line: rgba(255, 255, 255, 0.9);
    --side-w: 250px;
    background: radial-gradient(circle at 50% 50%, #1e293b 0%, #0f172a 100%);
    font-size: 12.5px;
}
body.layout-classic.dark {
    --accent: #7ee21c;
    --accent-d: #a6f25a;
    --accent-ring: rgba(126, 226, 28, 0.35);
    --on: #2f4420;
    --hover: #2c3a2a;
    --hdr-on-text: #b5f57a;
    --sel-fill: rgba(126, 226, 28, 0.13);
    --sel-line: rgba(126, 226, 28, 0.6);
    --grid-line: rgba(71, 85, 105, 0.55);
    --glass: linear-gradient(180deg, rgba(30, 41, 59, 0.92) 0%, rgba(15, 23, 42, 0.9) 100%);
    --glass-line: rgba(148, 163, 184, 0.28);
    background: radial-gradient(circle at 50% 50%, #131c2c 0%, #070b14 100%);
}

/* Drifting gel orbs, like Bitbook's! */
body.layout-classic #orbs { display: block; position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; animation: fadeIn 0.6s; }
#orbs i {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 32% 28%, rgba(220, 255, 190, 0.55) 0%, rgba(120, 220, 40, 0.22) 38%, rgba(30, 60, 20, 0.08) 66%, transparent 72%);
    box-shadow: inset -6px -10px 24px rgba(0, 0, 0, 0.25);
    animation: orbDrift 22s ease-in-out infinite alternate;
}
#orbs i:nth-child(1) { width: 120px; height: 120px; left: 22%; top: 8%; }
#orbs i:nth-child(2) { width: 64px; height: 64px; left: 30%; top: 62%; animation-duration: 17s; animation-delay: -6s; }
#orbs i:nth-child(3) { width: 180px; height: 180px; right: -40px; bottom: 6%; animation-duration: 27s; filter: hue-rotate(60deg); }
#orbs i:nth-child(4) { width: 42px; height: 42px; right: 18%; top: 4%; animation-duration: 14s; animation-delay: -3s; filter: hue-rotate(110deg); }
#orbs i:nth-child(5) { width: 90px; height: 90px; left: 55%; bottom: -30px; animation-duration: 20s; animation-delay: -11s; filter: hue-rotate(160deg); }
@keyframes orbDrift {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(24px, -30px) scale(1.06); }
    100% { transform: translate(-18px, 16px) scale(0.96); }
}

/* The glass sidebar! */
body.layout-classic #classic-side { display: flex; }
.aero-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--side-w, 250px);
    z-index: 50;
    flex-direction: column;
    gap: 10px;
    padding: 22px 14px 16px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.05) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 5px 0 25px rgba(0, 0, 0, 0.15);
    font-family: var(--font-brand);
    transition: transform 0.36s cubic-bezier(0.1, 0.9, 0.2, 1);
    animation: sideIn 0.45s cubic-bezier(0.1, 0.9, 0.2, 1);
}
@keyframes sideIn { from { transform: translateX(-100%); } }
body.side-collapsed .aero-sidebar { transform: translateX(-100%); }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 14px; }
.side-brand img { width: 28px; height: 28px; filter: drop-shadow(0 0 8px rgba(120, 248, 56, 0.55)); }
.side-brand h2 { margin: 0; color: #fff; font-size: 1.5rem; font-weight: 900; text-shadow: 0 0 10px rgba(120, 248, 56, 0.6); }
.side-label { color: rgba(255, 255, 255, 0.55); font-size: 11px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; padding: 8px 8px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.12); padding-bottom: 6px; }
.pad-stack { display: flex; flex-direction: column; gap: 8px; }
.pad-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-family: var(--font-brand);
    font-weight: 700;
    font-size: 13.5px;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.pad-btn .ico { width: 16px; height: 16px; }
.pad-btn:hover {
    background: linear-gradient(180deg, #98f838 0%, #54c702 100%);
    border-color: #b2fc7d;
    box-shadow: 0 4px 12px rgba(104, 199, 2, 0.35), inset 0 1px 2px #fff;
    transform: translateY(-1px);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.pad-btn:active { transform: translateY(1px); box-shadow: 0 2px 6px rgba(104, 199, 2, 0.2); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.side-act { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, 0.15); background: transparent; color: #cbd5e1; font-family: var(--font-brand); font-weight: 700; font-size: 12.5px; cursor: pointer; transition: all 0.2s; }
.side-act .ico { width: 15px; height: 15px; }
.side-act:hover { background: rgba(255, 255, 255, 0.1); color: #fff; border-color: rgba(255, 255, 255, 0.4); }
#side-latch {
    position: absolute;
    top: 50%;
    right: -26px;
    width: 24px;
    height: 60px;
    margin-top: -30px;
    padding: 0;
    display: grid;
    place-items: center;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-left: none;
    border-radius: 0 8px 8px 0;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    transition: background 0.2s;
}
#side-latch:hover { background: linear-gradient(90deg, rgba(152, 248, 56, 0.5), rgba(84, 199, 2, 0.3)); }
#side-latch .ico { width: 16px; height: 16px; transition: transform 0.36s var(--spring); }
body.side-collapsed #side-latch .ico { transform: rotate(180deg); }

/* The workspace floats as glass cards beside the sidebar! */
body.layout-classic #app {
    position: relative;
    z-index: 1;
    margin-left: var(--side-w);
    padding: 8px 22px 10px 30px;
    transition: margin-left 0.36s cubic-bezier(0.1, 0.9, 0.2, 1), opacity 0.2s var(--ease), transform 0.2s var(--ease), filter 0.2s var(--ease);
}
body.layout-classic.side-collapsed #app { margin-left: 8px; }

body.layout-classic #titlebar { background: transparent; box-shadow: none; padding: 0 2px; height: 40px; }
body.layout-classic .tb-logo, body.layout-classic .tb-brand { display: none; }
body.layout-classic .qbtn { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.18); }
body.layout-classic .qbtn:hover { background: linear-gradient(180deg, #98f838 0%, #54c702 100%); border-color: #b2fc7d; }
body.layout-classic #book-name { font-family: var(--font-brand); font-weight: 800; }
body.layout-classic .tb-saved { font-family: var(--font-brand); }
body.layout-classic #cmd-search { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.2); }

/* Ribbon tabs + ribbon = one glass toolbar card! */
body.layout-classic #ribbon-tabs {
    background: var(--glass);
    border: 2px solid var(--glass-line);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
    padding: 0 8px;
    height: 34px;
}
body.layout-classic #ribbon {
    background: var(--glass);
    border: 2px solid var(--glass-line);
    border-top: 1px solid rgba(92, 184, 0, 0.18);
    border-radius: 0 0 12px 12px;
    box-shadow: 0 8px 25px rgba(104, 199, 2, 0.18), inset 0 -1px 2px rgba(255, 255, 255, 0.6);
}
body.layout-classic.ribbon-min #ribbon-tabs { border-bottom: 2px solid var(--glass-line); border-radius: 12px; }
body.layout-classic .rtab { font-weight: 700; font-size: 12.5px; color: #3b4a5a; }
body.layout-classic.dark .rtab { color: #cbd5e1; }
body.layout-classic .rtab.on { color: var(--accent-d); }
body.layout-classic .rtab.file, body.layout-classic .lay-card.on::after, body.layout-classic .dlg-btn.primary, body.layout-classic .fp-btns button.primary, body.layout-classic #status-mode {
    background: linear-gradient(180deg, var(--gel-a) 0%, var(--gel-b) 100%);
    border-color: var(--gel-border);
    box-shadow: 0 4px 12px var(--gel-glow), inset 0 1px 2px #fff;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
body.layout-classic #tab-ink, body.layout-classic #sheet-ink { background: linear-gradient(90deg, #9bf838, #5bb100); box-shadow: 0 0 8px rgba(120, 248, 56, 0.6); }
body.layout-classic .rb:hover, body.layout-classic .split-arrow:hover {
    background: linear-gradient(180deg, #a2f838 0%, #78c702 100%);
    border-color: #b2fc7d;
    color: #fff;
    box-shadow: 0 3px 10px rgba(104, 199, 2, 0.3), inset 0 1px 2px rgba(255, 255, 255, 0.8);
}
body.layout-classic .rb.on { background: linear-gradient(180deg, #f2ffe4, #d8f7b8); border-color: #9fdc5c; }
body.layout-classic.dark .rb.on { background: linear-gradient(180deg, #3a5226, #2b3d1c); border-color: #5e8a2c; }
body.layout-classic .rg-label { font-weight: 700; letter-spacing: 0.3px; }
body.layout-classic .rb.sm span, body.layout-classic .rb.big span { font-size: 12px; }
body.layout-classic .combo, body.layout-classic .name-box-wrap { border-radius: 8px; border-color: #a5d8f3; box-shadow: inset 0 1px 1px #fff, 0 1px 3px rgba(14, 165, 233, 0.12); }

/* Formula bar: a glass pill with a lime badge! */
body.layout-classic #formula-row {
    margin-top: 10px;
    background: var(--glass);
    border: 2px solid var(--glass-line);
    border-radius: 10px;
    padding: 5px 8px;
    box-shadow: 0 4px 15px rgba(107, 199, 2, 0.15), inset 0 1px 2px rgba(255, 255, 255, 0.7);
}
body.layout-classic #name-box { font-weight: 800; color: #5fa700; }
body.layout-classic.dark #name-box { color: #a6f25a; }
body.layout-classic #formula-input { border-radius: 8px; }

/* The grid: a rounded glass sheet with lime gel column headers! */
body.layout-classic #grid-scroll {
    margin-top: 10px;
    border: 2px solid var(--glass-line);
    border-radius: 12px;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.3), inset 0 1px 2px #fff;
}
body.layout-classic #grid thead th {
    background: linear-gradient(180deg, #9bf838 0%, #6bc702 100%);
    color: #fff;
    font-family: var(--font-brand);
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    border-right-color: rgba(255, 255, 255, 0.4);
    border-bottom-color: rgba(62, 120, 0, 0.45);
}
body.layout-classic #grid thead th.corner { background: linear-gradient(180deg, #64c702 0%, #62a103 100%); }
body.layout-classic .corner-tri { border-right-color: rgba(255, 255, 255, 0.7); border-bottom-color: rgba(255, 255, 255, 0.7); }
body.layout-classic #grid thead th:not(.corner):hover { background: linear-gradient(180deg, #b4fb6c 0%, #7fd80e 100%); }
body.layout-classic #grid thead th.on { background: linear-gradient(180deg, #74d80a 0%, #4b9600 100%); color: #fff; box-shadow: inset 0 -3px 0 #e8ffd0; }
body.layout-classic #grid thead th.on:hover { background: linear-gradient(180deg, #6bc702 0%, #3f8200 100%); }
body.layout-classic #grid th.rh {
    background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
    color: #67a103;
    font-family: var(--font-brand);
    font-weight: 800;
    border-right-color: #cbd5e1;
    border-bottom-color: #d8dee6;
}
body.layout-classic.dark #grid th.rh { background: linear-gradient(180deg, #243145 0%, #1b2536 100%); color: #9be25a; border-right-color: #334155; border-bottom-color: #2b3647; }
body.layout-classic #grid th.rh:hover { background: linear-gradient(180deg, #f5ffe9 0%, #e1f6c9 100%); }
body.layout-classic.dark #grid th.rh:hover { background: linear-gradient(180deg, #2c3d27 0%, #22301e 100%); }
body.layout-classic #grid th.rh.on { background: linear-gradient(180deg, #e9fdd2 0%, #cff3a6 100%); color: #3f7f00; box-shadow: inset -3px 0 0 #6bc702; }
body.layout-classic.dark #grid th.rh.on { background: linear-gradient(180deg, #34501f 0%, #2a4019 100%); color: #c4f78f; }
body.layout-classic #grid th.full { background: linear-gradient(180deg, #5aae00 0%, #3f8200 100%) !important; color: #fff; }
body.layout-classic #grid th.rh.full { color: #fff; }

/* Footer: gel pill sheet tabs floating on the navy! */
body.layout-classic #footer { background: transparent; border-top: 0; margin-top: 6px; }
body.layout-classic #sheet-bar { padding: 0; gap: 6px; }
body.layout-classic .sheet-nav button { color: #cbd5e1; }
body.layout-classic .sheet-nav button:hover { background: rgba(255, 255, 255, 0.1); }
body.layout-classic .stab {
    margin: 3px 3px;
    padding: 0 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    font-family: var(--font-brand);
    font-weight: 700;
    font-size: 12.5px;
}
body.layout-classic .stab:hover { background: rgba(255, 255, 255, 0.16); }
body.layout-classic .stab.on {
    background: linear-gradient(180deg, #98f838 0%, #54c702 100%);
    border-color: #b2fc7d;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 3px 10px rgba(104, 199, 2, 0.35), inset 0 1px 2px #fff;
}
body.layout-classic #sheet-ink { display: none; }
body.layout-classic #add-sheet { color: #cbd5e1; border: 1px solid rgba(255, 255, 255, 0.2); }
body.layout-classic #add-sheet:hover { background: linear-gradient(180deg, #98f838 0%, #54c702 100%); color: #fff; }
body.layout-classic #status-bar { border-top: 0; color: #94a3b8; font-family: var(--font-brand); font-size: 11.5px; }
body.layout-classic #status-stats b { color: #e2e8f0; }
body.layout-classic #status-info { color: #a6f25a; }
body.layout-classic #zoom-label, body.layout-classic #status-bar button { color: #cbd5e1; }

/* Menus and dialogs become glass too! */
body.layout-classic .menu { background: var(--glass); border: 2px solid var(--glass-line); border-radius: 12px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.7); }
body.layout-classic .m-item:hover { background: linear-gradient(180deg, #a2f838 0%, #78c702 100%); color: #fff; }
body.layout-classic .dlg { background: var(--glass); border: 2px solid var(--glass-line); border-radius: 14px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
body.layout-classic .dlg-head { color: #5fa700; text-transform: uppercase; letter-spacing: 0.5px; font-size: 13px; }
body.layout-classic.dark .dlg-head { color: #a6f25a; }

/* Backstage in Classic: the navy glass sidebar look! */
body.layout-classic #backstage { background: radial-gradient(circle at 60% 40%, #f8fafc 0%, #e8eef5 100%); }
body.layout-classic.dark #backstage { background: radial-gradient(circle at 60% 40%, #1e293b 0%, #0f172a 100%); }
body.layout-classic .bs-nav { background: linear-gradient(90deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.02) 100%), radial-gradient(circle at 50% 30%, #1e293b 0%, #0f172a 100%); }
body.layout-classic .bs-nav button.on { background: linear-gradient(180deg, #98f838 0%, #54c702 100%); color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }

@media (max-width: 760px) {
    body.layout-classic { --side-w: 220px; }
    body.layout-classic #app { margin-left: 8px; padding: 6px 8px 8px 30px; }
    body.layout-classic:not(.side-collapsed) #classic-side { box-shadow: 10px 0 40px rgba(0, 0, 0, 0.5); }
}

body.no-anim *, body.no-anim *::before, body.no-anim *::after {
    animation: none !important;
    transition: none !important;
}

@media (max-width: 760px) {
    .cmd-search { display: none; }
    .tb-brand { display: none; }
    #name-box { width: 64px; }
    #status-stats .opt { display: none; }
    #zoom-slider { display: none; }
    .bs-nav { width: 64px; }
    .bs-nav button { font-size: 0; padding: 12px 20px; }
    .bs-nav button .ico { width: 22px; height: 22px; }
    .bs-body { padding: 24px 20px; }
}

/* Online pictures reuse the chart frame but have no chart tools! */
.chart-obj[data-kind="image"] .chart-tools [data-ct],
.chart-obj[data-kind="image"] .chart-tools [data-ca="data"],
.chart-obj[data-kind="image"] .chart-tools .ct-sep { display: none; }

/* ---- the "more styles" menu in the Keydown bar ---- */
.kd-more-menu { display: none; flex-direction: column; gap: 8px; width: 280px; }
.aero-dropdown.active .kd-more-menu { display: flex !important; }
.kd-more-pick { font: 600 12px var(--font, system-ui); padding: 6px 8px; border-radius: 8px; border: 1px solid #b6c2d1; background: #fff; color: #1e293b; }
.kd-more-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
