/* ==========================================================================
   Jonah's Super Calculator — styles
   ========================================================================== */

:root {
  --bg: #f4f6f9;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #e8edff 0%, transparent 60%),
             radial-gradient(900px 500px at 100% 0%, #e6f7f4 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --surface-3: #e8ebf1;
  --border: #e0e4ec;
  --border-strong: #cdd3df;
  --text: #131722;
  --muted: #667085;
  --faint: #98a2b3;
  --accent: #4a63e7;
  --accent-hover: #3d54d1;
  --accent-soft: #eaeeff;
  --accent-text: #ffffff;
  --ok: #0f9d58;
  --warn: #d98207;
  --err: #d92d20;
  --err-soft: #fdecea;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .07), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, .16);
  --radius: 14px;
  --radius-sm: 10px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --header-h: 60px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0e1016;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #1a2040 0%, transparent 60%),
             radial-gradient(900px 500px at 100% 0%, #13302c 0%, transparent 55%);
  --surface: #171a22;
  --surface-2: #1e222c;
  --surface-3: #272c38;
  --border: #272c37;
  --border-strong: #39404f;
  --text: #e9ecf3;
  --muted: #98a2b3;
  --faint: #6d7686;
  --accent: #7189ff;
  --accent-hover: #8a9dff;
  --accent-soft: #1d2440;
  --accent-text: #0b0d13;
  --ok: #35c17c;
  --warn: #f0a83c;
  --err: #ff6b63;
  --err-soft: #2c1a1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .38);
  --shadow-lg: 0 24px 56px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0e1016;
    --bg-grad: radial-gradient(1200px 600px at 15% -10%, #1a2040 0%, transparent 60%),
               radial-gradient(900px 500px at 100% 0%, #13302c 0%, transparent 55%);
    --surface: #171a22;
    --surface-2: #1e222c;
    --surface-3: #272c38;
    --border: #272c37;
    --border-strong: #39404f;
    --text: #e9ecf3;
    --muted: #98a2b3;
    --faint: #6d7686;
    --accent: #7189ff;
    --accent-hover: #8a9dff;
    --accent-soft: #1d2440;
    --accent-text: #0b0d13;
    --ok: #35c17c;
    --warn: #f0a83c;
    --err: #ff6b63;
    --err-soft: #2c1a1c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .38);
    --shadow-lg: 0 24px 56px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Several components below set display on classes that also get toggled with
   the hidden attribute, and a class rule would otherwise win. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

code {
  font-family: var(--mono);
  font-size: .92em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .05em .35em;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  height: var(--header-h);
  padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex; align-items: center; gap: 9px;
  color: var(--text); text-decoration: none; white-space: nowrap;
  font-size: 15px; letter-spacing: -.015em;
}
.brand b { font-weight: 700; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); stroke-width: 1.6; }
.brand-mark rect { fill: color-mix(in srgb, var(--accent) 12%, transparent); }

.tabs {
  display: flex; align-items: center; gap: 4px;
  flex: 1 1 auto; justify-content: center;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 14px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab svg { width: 17px; height: 17px; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-on { background: var(--accent-soft); color: var(--accent); }

.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; padding: 0;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.small svg { width: 17px; height: 17px; }

.ico-moon { display: none; }
html[data-theme="dark"] .ico-sun { display: none; }
html[data-theme="dark"] .ico-moon { display: block; }
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] .ico-sun { display: none; }
  html[data-theme="auto"] .ico-moon { display: block; }
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 11px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font: inherit; font-size: 12.5px; font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.chip svg { width: 14px; height: 14px; }
.chip.is-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.chip.is-blocked { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--border)); background: var(--err-soft); }

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px 0; gap: 8px; }
  .brand-text { display: none; }
  .tabs { order: 3; width: 100%; justify-content: flex-start; padding-bottom: 8px; }
  .topbar-actions { margin-left: auto; }
}

/* ------------------------------------------------------------------ main */

main { max-width: 1320px; margin: 0 auto; padding: 20px 16px 48px; }

.panel[hidden] { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 4px 0 10px;
}
.side-head:not(:first-child) { margin-top: 20px; }
.side-head h2 {
  font-size: 11.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint);
}

.hint { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.muted { color: var(--muted); }

/* --------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; min-height: 38px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn-accent {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

.input {
  width: 100%; padding: 9px 11px; min-height: 40px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14.5px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.input.mono { font-family: var(--mono); }
.input.tiny { width: 74px; min-width: 0; }
textarea.input { min-height: 88px; resize: vertical; line-height: 1.5; }
select.input { appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.field-inline { flex-direction: row; align-items: center; gap: 8px; }
.field-inline > span { white-space: nowrap; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 11px; margin-bottom: 16px; max-width: 100%; overflow-x: auto;
}
.seg-btn {
  padding: 7px 14px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 13.5px; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.seg-btn.is-on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.example-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.example {
  padding: 4px 10px; border: 1px dashed var(--border-strong); border-radius: 999px;
  background: transparent; color: var(--muted);
  font-family: var(--mono); font-size: 12px; cursor: pointer;
}
.example:hover { border-style: solid; color: var(--accent); border-color: var(--accent); }

/* ------------------------------------------------------------ calculator */

.calc-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1000px) {
  .calc-layout { grid-template-columns: minmax(0, 1fr) minmax(380px, 480px); }
}

.display-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.mode-pills, .mem-row { display: flex; align-items: center; gap: 6px; }

.pill {
  padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font: inherit; font-size: 11.5px; font-weight: 650; letter-spacing: .04em; cursor: pointer;
}
.pill:hover { color: var(--text); }
.pill.is-on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.pill-static { cursor: default; }

.mini {
  padding: 4px 8px; border: 1px solid transparent; border-radius: 7px;
  background: var(--surface-2); color: var(--muted);
  font: inherit; font-size: 11.5px; font-weight: 650; cursor: pointer;
}
.mini:hover { background: var(--surface-3); color: var(--text); }
.mem-flag { font-size: 11.5px; font-weight: 700; color: var(--accent); }

.expr-input {
  display: block; width: 100%; padding: 6px 2px; border: 0; resize: none; overflow: hidden;
  background: transparent; color: var(--text);
  font-family: var(--mono); font-size: clamp(20px, 4.4vw, 28px); line-height: 1.35;
  letter-spacing: -.01em;
}
.expr-input:focus { outline: none; }
.expr-input::placeholder { color: var(--faint); font-size: 15px; font-family: var(--sans); }

.preview-row {
  display: flex; align-items: baseline; gap: 8px; min-height: 24px;
  color: var(--faint); font-family: var(--mono); font-size: 15px;
}
.preview-eq { opacity: .55; }
.preview-value { overflow-wrap: anywhere; }

.result-block { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.result-main { display: flex; align-items: flex-start; gap: 8px; }
.result-value {
  flex: 1; font-family: var(--mono); font-size: clamp(22px, 5vw, 32px); font-weight: 600;
  line-height: 1.25; overflow-wrap: anywhere; color: var(--text);
}
.result-alt { margin-top: 6px; font-family: var(--mono); font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.result-alt b { color: var(--accent); font-weight: 600; }

.error-line {
  margin-top: 10px; padding: 9px 11px; border-radius: var(--radius-sm);
  background: var(--err-soft); color: var(--err); font-size: 13px;
  border: 1px solid color-mix(in srgb, var(--err) 25%, transparent);
}

/* keypad */
.keypad { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .keypad { grid-template-columns: 1fr 1fr; } }

.keypad-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }

.key {
  display: inline-grid; place-items: center;
  min-height: 50px; padding: 4px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 17px; font-weight: 550; font-family: var(--mono);
  cursor: pointer; user-select: none;
  transition: background .12s, transform .05s, color .12s;
}
.key:hover { background: var(--surface-3); }
.key:active { transform: translateY(1px); }
.key-fn { font-size: 14.5px; font-weight: 600; color: var(--muted); background: var(--surface); }
.key-fn:hover { color: var(--text); }
.key-op { color: var(--accent); font-size: 19px; }
.key-util { color: var(--muted); font-size: 14px; }
.key-eq { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-size: 20px; }
.key-eq:hover { background: var(--accent-hover); }
.key-toggle.is-on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.key svg { width: 19px; height: 19px; }

.fn-library { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.fn-library-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.fn-library-body { max-height: 260px; overflow-y: auto; }
.fn-group-title {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--faint); margin: 10px 0 6px;
}
.fn-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.fn-chip {
  padding: 4px 9px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface-2); color: var(--text);
  font-family: var(--mono); font-size: 12.5px; cursor: pointer;
}
.fn-chip:hover { border-color: var(--accent); color: var(--accent); }
.fn-chip small { color: var(--faint); font-family: var(--sans); }

/* ----------------------------------------------------------------- graph */

.graph-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 940px) {
  .graph-layout { grid-template-columns: 330px minmax(0, 1fr); align-items: start; }
}

.graph-side { max-height: calc(100vh - var(--header-h) - 60px); overflow-y: auto; }
@media (max-width: 939px) { .graph-side { order: 2; max-height: none; } }

.fn-list { display: flex; flex-direction: column; gap: 7px; }
.fn-row { display: flex; align-items: center; gap: 7px; }
.fn-swatch {
  flex: 0 0 auto; width: 26px; height: 26px; padding: 0;
  border: 1px solid var(--border-strong); border-radius: 8px; cursor: pointer;
  position: relative; background: var(--surface-2);
}
.fn-swatch::after {
  content: ""; position: absolute; inset: 5px; border-radius: 3px; background: var(--c);
}
.fn-swatch.is-off::after { opacity: .22; }
.fn-input { flex: 1 1 auto; min-width: 0; font-family: var(--mono); font-size: 13.5px; min-height: 36px; padding: 7px 9px; }
.fn-input.has-error { border-color: var(--err); }
.fn-del { flex: 0 0 auto; }
.fn-error { font-size: 11.5px; color: var(--err); margin: -3px 0 2px 33px; }

.window-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.window-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); }
.window-grid .input { min-height: 34px; padding: 6px 8px; font-size: 13px; font-family: var(--mono); }

.analyze-out { margin-top: 10px; font-size: 13px; }
.analyze-out:empty { display: none; }
.analyze-item {
  display: flex; justify-content: space-between; gap: 10px; padding: 5px 0;
  border-bottom: 1px dashed var(--border); font-family: var(--mono); font-size: 12.5px;
}
.analyze-item:last-child { border-bottom: 0; }
.analyze-title { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); margin-bottom: 4px; }
.analyze-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; }
.analyze-table th, .analyze-table td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.analyze-table th { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }

.graph-canvas-card { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.canvas-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.readout {
  font-family: var(--mono); font-size: 12.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.canvas-tools { display: flex; gap: 2px; flex: 0 0 auto; }

.canvas-wrap {
  position: relative; width: 100%;
  height: min(66vh, 620px); min-height: 320px;
  border-radius: var(--radius-sm); overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
  touch-action: none;
}
#graph-canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }

/* ------------------------------------------------------- solve / algebra */

.stack-layout { display: flex; flex-direction: column; gap: 16px; max-width: 900px; margin: 0 auto; }
.solve-body { display: flex; flex-direction: column; gap: 14px; }
.solve-controls { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.solve-controls .field-inline { align-items: center; }
.solve-controls select { min-width: 110px; }
.solve-controls .btn { margin-left: auto; min-width: 120px; }

.cas-ops { display: flex; flex-wrap: wrap; gap: 7px; margin: 14px 0 12px; }
.cas-ops .btn { flex: 0 1 auto; }
.cas-ops .btn.is-on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.cas-args { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }

.result-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.result-head h2 { font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.result-out { display: flex; flex-direction: column; gap: 10px; }

.res-line {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
}
.res-label { flex: 0 0 auto; font-size: 12px; font-weight: 650; color: var(--faint); min-width: 62px; padding-top: 3px; }
.res-value { flex: 1 1 auto; font-family: var(--mono); font-size: 16px; overflow-wrap: anywhere; }
.res-value sup { font-size: .72em; }
.res-approx { display: block; margin-top: 3px; font-size: 13px; color: var(--muted); }
.res-note { font-size: 13px; color: var(--muted); }
.res-error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 25%, transparent); color: var(--err); }
.res-steps { margin: 0; padding-left: 18px; font-size: 13.5px; color: var(--muted); line-height: 1.8; }
.res-steps code { font-size: 12.5px; }

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- convert */

.convert-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 900px) { .convert-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1180px) { .convert-layout { grid-template-columns: 1.2fr 1fr 1fr; } }

.convert-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; align-items: end; }
@media (min-width: 560px) { .convert-grid { grid-template-columns: 1fr 1fr auto 1fr; } }
.icon-btn.swap { align-self: end; margin-bottom: 2px; border: 1px solid var(--border); }

.convert-result {
  margin-top: 14px; padding: 14px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--text);
  font-family: var(--mono); font-size: clamp(17px, 3.6vw, 22px); font-weight: 600;
  overflow-wrap: anywhere;
}

.base-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 480px) { .base-grid { grid-template-columns: 1fr 1fr; } }

.const-list { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.const-item {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  padding: 7px 9px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); text-align: left;
  font: inherit; cursor: pointer;
}
.const-item:hover { background: var(--surface-2); }
.const-sym { font-family: var(--mono); font-weight: 650; min-width: 46px; color: var(--accent); }
.const-name { flex: 1; font-size: 13px; color: var(--muted); }
.const-val { font-family: var(--mono); font-size: 12.5px; color: var(--faint); }

/* --------------------------------------------------------------- history */

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
  width: min(400px, 92vw);
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .22s ease;
}
.drawer.is-open { transform: translateX(0); }
.drawer[hidden] { display: none; }

.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; }
.drawer-head h2 { font-size: 16px; }
.drawer-actions { display: flex; gap: 2px; }
.drawer-tools { display: flex; gap: 8px; padding: 0 14px 12px; border-bottom: 1px solid var(--border); }
.drawer-tools .input { min-height: 36px; font-size: 13.5px; }
.drawer-tools select { flex: 0 0 116px; }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 8px; }
.drawer-foot {
  display: flex; justify-content: space-between; padding: 10px 14px;
  border-top: 1px solid var(--border); font-size: 12px; color: var(--faint);
}

.hist-item {
  display: block; width: 100%; text-align: left; position: relative;
  padding: 9px 34px 9px 11px; margin-bottom: 4px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.hist-item:hover { background: var(--surface-2); border-color: var(--border); }
.hist-top { display: flex; align-items: center; gap: 7px; margin-bottom: 3px; }
.hist-kind {
  font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 5px; background: var(--surface-3); color: var(--muted);
}
.hist-kind[data-kind="calc"] { background: var(--accent-soft); color: var(--accent); }
.hist-kind[data-kind="solve"] { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.hist-kind[data-kind="algebra"] { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.hist-time { font-size: 11px; color: var(--faint); margin-left: auto; }
.hist-expr { font-family: var(--mono); font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.hist-result { font-family: var(--mono); font-size: 14.5px; font-weight: 600; overflow-wrap: anywhere; margin-top: 2px; }
.hist-del {
  position: absolute; top: 7px; right: 6px; opacity: 0; transition: opacity .15s;
}
.hist-item:hover .hist-del, .hist-del:focus { opacity: 1; }
.hist-empty { padding: 40px 20px; text-align: center; color: var(--faint); font-size: 13.5px; }

.scrim {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 13, 20, .38); backdrop-filter: blur(1.5px);
  opacity: 0; transition: opacity .22s;
}
.scrim.is-open { opacity: 1; }
.scrim[hidden] { display: none; }

/* ---------------------------------------------------------- toast/dialog */

.toast-host {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  padding: 10px 16px; border-radius: 999px;
  background: var(--text); color: var(--surface);
  font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-md);
  animation: toast-in .2s ease;
}
.toast.is-warn { background: var(--warn); color: #1a1205; }
.toast.is-err { background: var(--err); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.dialog {
  width: min(680px, 94vw); max-height: 86vh; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(10, 13, 20, .45); backdrop-filter: blur(2px); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
.dialog-body { padding: 18px; overflow-y: auto; max-height: calc(86vh - 60px); font-size: 14px; line-height: 1.65; }
.dialog-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin: 20px 0 8px; }
.dialog-body h3:first-child { margin-top: 0; }
.dialog-body table { width: 100%; border-collapse: collapse; }
.dialog-body td { padding: 5px 8px 5px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.dialog-body td:first-child { width: 44%; }
.dialog-body p { margin: 0 0 10px; color: var(--muted); }

@media print { .topbar, .drawer, .scrim, .toast-host, .keypad-card { display: none !important; } }
