/*
  Решатель — Blue Glass UI
  A single design system for phone, tablet and desktop.
  No external fonts or runtime UI dependencies.
*/
:root {
  color-scheme: light;
  --page: #eaf3ff;
  --page-2: #f7fbff;
  --ink: #10284d;
  --muted: #647d9f;
  --muted-2: #8ea3bf;
  --line: rgba(91, 139, 202, .20);
  --line-strong: rgba(77, 133, 207, .30);
  --panel: rgba(255, 255, 255, .70);
  --panel-strong: rgba(250, 253, 255, .92);
  --panel-soft: rgba(255, 255, 255, .46);
  --field: rgba(255, 255, 255, .82);
  --key: rgba(255, 255, 255, .82);
  --key-2: rgba(225, 239, 255, .92);
  --primary: #0878f9;
  --primary-2: #075bd7;
  --primary-3: #56a8ff;
  --primary-soft: rgba(8, 120, 249, .11);
  --green: #159b68;
  --green-bg: rgba(21, 155, 104, .10);
  --danger: #d94d61;
  --shadow: 0 24px 70px rgba(27, 83, 150, .13), 0 5px 16px rgba(31, 83, 142, .06), inset 0 1px 0 rgba(255,255,255,.92);
  --shadow-soft: 0 12px 32px rgba(27, 83, 150, .09), inset 0 1px 0 rgba(255,255,255,.90);
  --shadow-blue: 0 12px 28px rgba(0, 100, 235, .24);
  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius-md: 17px;
  --blur: 28px;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --page: #07152c;
  --page-2: #0a2146;
  --ink: #eef6ff;
  --muted: #a7bfdc;
  --muted-2: #7894b8;
  --line: rgba(155, 196, 244, .16);
  --line-strong: rgba(118, 177, 245, .28);
  --panel: rgba(13, 39, 78, .72);
  --panel-strong: rgba(9, 29, 61, .94);
  --panel-soft: rgba(106, 157, 220, .10);
  --field: rgba(4, 22, 49, .72);
  --key: rgba(31, 65, 111, .74);
  --key-2: rgba(42, 85, 143, .84);
  --primary: #2f91ff;
  --primary-2: #0867e8;
  --primary-3: #72bcff;
  --primary-soft: rgba(47, 145, 255, .16);
  --green: #54dda4;
  --green-bg: rgba(84, 221, 164, .12);
  --danger: #ff8291;
  --shadow: 0 28px 76px rgba(0, 0, 0, .30), 0 5px 18px rgba(0, 0, 0, .16), inset 0 1px 0 rgba(255,255,255,.09);
  --shadow-soft: 0 14px 36px rgba(0, 0, 0, .22), inset 0 1px 0 rgba(255,255,255,.08);
  --shadow-blue: 0 12px 30px rgba(0, 105, 255, .30);
}
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    color-scheme: dark;
    --page: #07152c; --page-2: #0a2146; --ink: #eef6ff;
    --muted: #a7bfdc; --muted-2: #7894b8;
    --line: rgba(155,196,244,.16); --line-strong: rgba(118,177,245,.28);
    --panel: rgba(13,39,78,.72); --panel-strong: rgba(9,29,61,.94); --panel-soft: rgba(106,157,220,.10);
    --field: rgba(4,22,49,.72); --key: rgba(31,65,111,.74); --key-2: rgba(42,85,143,.84);
    --primary: #2f91ff; --primary-2: #0867e8; --primary-3: #72bcff; --primary-soft: rgba(47,145,255,.16);
    --green: #54dda4; --green-bg: rgba(84,221,164,.12); --danger: #ff8291;
    --shadow: 0 28px 76px rgba(0,0,0,.30),0 5px 18px rgba(0,0,0,.16),inset 0 1px 0 rgba(255,255,255,.09);
    --shadow-soft: 0 14px 36px rgba(0,0,0,.22),inset 0 1px 0 rgba(255,255,255,.08);
    --shadow-blue: 0 12px 30px rgba(0,105,255,.30);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; scroll-behavior: smooth; background: var(--page); }
body {
  min-width: 320px; min-height: 100vh; min-height: 100dvh; margin: 0; color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(ellipse at 10% 0%, rgba(52, 145, 255, .19), transparent 36rem),
    radial-gradient(ellipse at 91% 13%, rgba(105, 178, 255, .16), transparent 34rem),
    radial-gradient(ellipse at 52% 100%, rgba(28, 118, 236, .10), transparent 42rem),
    linear-gradient(140deg, var(--page), var(--page-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
html[data-theme="dark"] body,
html[data-theme="system"] body { background-color: var(--page); }
body::before, body::after { content: ""; position: fixed; z-index: -1; pointer-events: none; border-radius: 50%; }
body::before { width: 34rem; height: 34rem; top: 5%; right: -15rem; background: radial-gradient(circle, rgba(47,145,255,.14), transparent 70%); }
body::after { width: 36rem; height: 36rem; bottom: -17rem; left: -14rem; background: radial-gradient(circle, rgba(0,105,255,.10), transparent 70%); }
button, input, textarea { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(8,120,249,.42); outline-offset: 3px; }
button:disabled { opacity: .48; cursor: not-allowed; }

/* Main frame and brand */
.app-shell { width: min(100% - 48px, 1360px); margin: 0 auto; padding: 28px 0 36px; min-height: 100vh; min-height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 4px 4px 22px; }
.brand-lockup { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-copy h1 { margin: 0; font-size: clamp(1.55rem, 2.4vw, 2.12rem); line-height: 1.08; font-weight: 780; letter-spacing: -.055em; }
.brand-copy p { margin: 6px 0 0; color: var(--muted); font-size: .84rem; letter-spacing: .01em; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .75rem; white-space: nowrap; }
.status i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #e6ac42; box-shadow: 0 0 0 4px rgba(230,172,66,.12); }
.status.ready i { background: #25bd79; box-shadow: 0 0 0 4px rgba(37,189,121,.13); }
.status.error i { background: #ed6573; box-shadow: 0 0 0 4px rgba(237,101,115,.13); }
.icon-button { display: grid; place-items: center; flex: 0 0 46px; width: 46px; min-height: 46px; border-radius: 15px; font-size: 1.15rem; }
.install-btn { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: auto; min-width: 112px; min-height: 46px; padding: 0 15px; border-radius: 14px; color: var(--primary); font-size: .82rem; font-weight: 750; line-height: 1; white-space: nowrap; }
button[hidden], [hidden] { display: none !important; }
.icon-button:hover, .install-btn:hover { transform: translateY(-1px); border-color: var(--line-strong); }

/* Desktop navigation */
.primary-nav { display: flex; align-items: center; gap: 7px; width: fit-content; margin: 0 0 22px; padding: 6px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-soft); -webkit-backdrop-filter: blur(26px) saturate(175%); backdrop-filter: blur(26px) saturate(175%); box-shadow: var(--shadow-soft); }
.nav-pill { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 42px; padding: 0 21px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: .88rem; font-weight: 700; cursor: pointer; transition: .18s ease; }
.nav-pill:hover { color: var(--ink); background: var(--panel); }
.nav-pill.active { color: #fff; background: linear-gradient(115deg, var(--primary), var(--primary-2)); box-shadow: var(--shadow-blue); }
.nav-glyph { font-size: 1.08rem; line-height: 1; }
.main-content { min-height: 50vh; }
.workspace-grid { display: grid; grid-template-columns: minmax(330px, .86fr) minmax(0, 1.14fr); align-items: start; gap: 22px; }
.workspace-grid.is-welcome { grid-template-columns: minmax(0,1fr); }
.workspace-grid.is-welcome .input-column { width: min(820px,100%); margin-inline: auto; }
.workspace-grid.is-welcome .result-column { display: none; }
.input-column, .result-column { display: flex; flex-direction: column; gap: 17px; min-width: 0; }
.panel { position: relative; isolation: isolate; border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--panel); -webkit-backdrop-filter: blur(var(--blur)) saturate(175%); backdrop-filter: blur(var(--blur)) saturate(175%); box-shadow: var(--shadow); }
.panel::before { content: ""; position: absolute; z-index: -1; inset: 0; border-radius: inherit; pointer-events: none; background: linear-gradient(145deg, rgba(255,255,255,.32), transparent 42%, rgba(64,145,235,.035)); }
html[data-theme="dark"] .panel::before { background: linear-gradient(145deg, rgba(255,255,255,.09), transparent 46%, rgba(29,128,255,.05)); }
html[data-theme="system"] .panel::before { background: linear-gradient(145deg, rgba(255,255,255,.32), transparent 42%, rgba(64,145,235,.035)); }
@media (prefers-color-scheme: dark) { html[data-theme="system"] .panel::before { background: linear-gradient(145deg, rgba(255,255,255,.09), transparent 46%, rgba(29,128,255,.05)); } }

/* Input card */
.input-card { padding: 23px; overflow: visible; transition: box-shadow .22s ease, border-color .22s ease; }
.input-card.keyboard-open { border-color: rgba(8,120,249,.38); box-shadow: 0 26px 70px rgba(19,91,178,.18), 0 0 0 3px rgba(8,120,249,.08), inset 0 1px 0 rgba(255,255,255,.88); }
.input-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 2px 13px; }
.input-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.input-title label, .verify-card > label { color: var(--muted); font-size: .72rem; font-weight: 850; letter-spacing: .12em; }
.input-symbol { color: var(--primary); font-size: 1.12rem; }
.keyboard-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-soft); color: var(--primary); font-size: .74rem; font-weight: 750; cursor: pointer; transition: .18s ease; }
.keyboard-toggle:hover, .keyboard-toggle[aria-expanded="true"] { border-color: var(--line-strong); background: var(--primary-soft); }
.keyboard-toggle > span:first-child { font-size: 1rem; }
.expression-shell { position: relative; display: flex; align-items: center; min-height: 92px; padding: 14px 56px 14px 19px; border: 1px solid var(--line-strong); border-radius: 23px; background: var(--field); box-shadow: inset 0 2px 9px rgba(20,66,120,.045), 0 8px 22px rgba(16,71,138,.045); }
#taskInput { display: block; width: 100%; min-height: 52px; max-height: 180px; resize: vertical; padding: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: clamp(1.55rem, 2.6vw, 2.25rem); line-height: 1.48; letter-spacing: .005em; }
#taskInput::placeholder { color: var(--muted-2); font-family: inherit; font-size: 1.02rem; }
#taskInput:focus-visible { outline: none; }
.clear-expression { position: absolute; top: 50%; right: 13px; display: grid; place-items: center; width: 34px; height: 34px; transform: translateY(-50%); border: 1px solid var(--line); border-radius: 50%; background: var(--key-2); color: var(--muted); font-size: 1.36rem; line-height: 1; cursor: pointer; }
.power-editor { display: flex; width: min(220px,100%); margin: 12px 0 0 auto; gap: 8px; }
.power-editor input { min-width: 0; flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--field); }
.power-editor button { width: 42px; border: 0; border-radius: 12px; color: #fff; font-weight: 800; background: linear-gradient(125deg, var(--primary), var(--primary-2)); box-shadow: var(--shadow-blue); cursor: pointer; }

/* AI entry point and empty state */
.welcome-note { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 250px; padding: 27px 22px 21px; text-align: center; }
.welcome-icon { display: grid; place-items: center; width: 68px; height: 68px; border: 1px solid rgba(255,255,255,.56); border-radius: 23px; color: #fff; font-size: 2.25rem; background: linear-gradient(145deg, #36a5ff, #0878f9 58%, #0755cf); box-shadow: var(--shadow-blue), inset 0 1px 0 rgba(255,255,255,.45); }
.welcome-note > strong { font-size: 1rem; letter-spacing: -.015em; }
.welcome-note > p { max-width: 340px; margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.55; }
.welcome-tip { display: flex; align-items: flex-start; gap: 10px; width: min(100%, 410px); margin-top: 5px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel-soft); text-align: left; }
.welcome-tip > span { color: var(--primary); font-size: 1.12rem; }
.welcome-tip b { font-size: .78rem; }
.welcome-tip p { margin: 4px 0 0; color: var(--muted); font-size: .73rem; line-height: 1.45; }
/* Result area */
.results { display: grid; grid-template-columns: minmax(215px, .78fr) minmax(0, 1.22fr); grid-template-areas: "answer steps" "verify steps" "clarify clarify"; align-items: start; gap: 14px; }
.answer-card { grid-area: answer; position: relative; min-height: 138px; overflow: hidden; padding: 19px 22px 17px; border-color: rgba(8,120,249,.20); background: linear-gradient(130deg, rgba(222,241,255,.94), var(--panel) 62%, rgba(255,255,255,.46)); }
html[data-theme="dark"] .answer-card { background: linear-gradient(130deg, rgba(10,91,169,.38), var(--panel) 64%, rgba(43,111,190,.13)); }
.answer-head { display: flex; align-items: center; justify-content: space-between; }
.answer-label { display: flex; align-items: center; gap: 9px; color: var(--green); font-size: .98rem; font-weight: 780; }
.answer-dot { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: #fff; background: linear-gradient(135deg, #3dd99a, #129765); box-shadow: 0 4px 13px rgba(21,155,104,.22); font-weight: 850; }
.answer-text { overflow-wrap: anywhere; margin: 0 25px; color: var(--ink); text-align: center; font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: clamp(2.1rem, 3.8vw, 2.8rem); line-height: 1.45; }
.copy-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: var(--panel-soft); font-size: 1.25rem; cursor: pointer; }
.verify-card { grid-area: verify; padding: 16px 18px 14px; }
.verify-card > label { display: block; margin-bottom: 9px; }
.verify-row { display: flex; gap: 8px; }
.verify-row input, .verify-row input::placeholder, .settings-input::placeholder { color: var(--muted-2); }
.verify-feedback { min-height: 0; margin: 0; font-size: .78rem; }
.verify-feedback:not(:empty) { margin-top: 9px; }
.verify-feedback.correct { color: var(--green); }
.verify-feedback.incorrect { color: var(--danger); }
.steps-panel { grid-area: steps; padding: 19px; }
.steps-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.steps-title { display: flex; align-items: center; gap: 9px; }
.steps-title > span { color: var(--primary); font-size: 1.2rem; }
.steps-heading h2 { margin: 0; font-size: 1.03rem; letter-spacing: -.025em; }
.step-count { color: var(--muted); font-size: .73rem; }
.steps-list { display: grid; gap: 9px; }
.step-card { display: grid; grid-template-columns: 35px minmax(0,1fr); align-items: start; column-gap: 11px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel-soft); cursor: pointer; transition: border-color .16s ease, background .16s ease, transform .16s ease; }
.step-card:hover, .step-card.selected { border-color: rgba(8,120,249,.38); background: var(--primary-soft); }
.step-card:active { transform: scale(.995); }
.step-top { display: flex; justify-content: center; grid-row: span 2; }
.step-number { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; color: #fff; background: linear-gradient(145deg, var(--primary), var(--primary-2)); box-shadow: 0 5px 12px rgba(0,105,230,.18); font-weight: 800; }
.step-caption { display: none; }
.step-formula { padding-top: 2px; color: var(--ink); font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: 1.08rem; font-weight: 650; overflow-wrap: anywhere; }
.step-explanation { margin-top: 5px; color: var(--muted); font-size: .77rem; line-height: 1.5; }
.explain-basic { align-self: flex-start; margin-top: 13px; }
.clarify-bar { grid-area: clarify; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px 20px; align-items: center; padding: 17px 19px 14px; }
.clarify-copy { display: flex; flex-direction: column; gap: 4px; }
.clarify-copy strong { font-size: .9rem; }
.clarify-copy span { color: var(--muted); font-size: .75rem; }
.clarify-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.button { min-height: 43px; padding: 0 15px; border: 1px solid var(--line); border-radius: 13px; font-size: .80rem; font-weight: 730; cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, background .16s ease; }
.button-secondary { color: var(--primary); background: var(--panel-strong); box-shadow: var(--shadow-soft); }
.button-primary { color: #fff; border-color: transparent; background: linear-gradient(115deg, #1689ff, #075bd7); box-shadow: 0 8px 22px rgba(0,100,230,.25), inset 0 1px 0 rgba(255,255,255,.30); }
.button-quiet { color: var(--muted); background: var(--panel-soft); }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0) scale(.99); }
.ai-usage-row { display: flex; grid-column: 1 / -1; justify-content: flex-start; align-items: center; gap: 12px; margin-top: 1px; padding-top: 10px; border-top: 1px solid var(--line); }
.ai-quota { color: var(--muted); font-size: .72rem; }
.text-action { border: 0; background: transparent; color: var(--primary); font-size: .74rem; font-weight: 760; cursor: pointer; }

/* History */
.history-page { max-width: 1080px; margin: 0 auto; }
.history-panel { padding: 27px; }
.history-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.eyebrow { color: var(--primary); font-size: .67rem; font-weight: 850; letter-spacing: .14em; }
.history-heading h2 { margin: 6px 0 5px; font-size: 1.55rem; letter-spacing: -.045em; }
.history-heading p { margin: 0; color: var(--muted); font-size: .81rem; }
.history-back { margin-top: 13px; }
.history-list { display: grid; gap: 9px; }
.history-empty { margin: 0; padding: 30px 14px; border: 1px dashed var(--line-strong); border-radius: 16px; color: var(--muted); text-align: center; font-size: .85rem; }
.history-item { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 5px 15px; width: 100%; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel-soft); text-align: left; cursor: pointer; transition: .16s ease; }
.history-item:hover { border-color: var(--line-strong); background: var(--primary-soft); }
.history-task { overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; font-family: "Cambria Math", Georgia, serif; font-size: 1.04rem; }
.history-answer { color: var(--primary); font-weight: 760; }
.history-item small { color: var(--muted-2); font-size: .68rem; }
.app-footer { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-top: 28px; padding: 14px 7px 0; border-top: 1px solid var(--line); }
.app-footer > span:last-child { color: var(--muted-2); font-size: .72rem; }
.mobile-nav { display: none; }

/* Floating math keyboard */
.keyboard-backdrop { position: fixed; z-index: 1040; inset: 0; background: rgba(4, 21, 47, .28); -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px); animation: backdropIn .18s ease both; }
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
.math-keyboard { position: fixed; z-index: 1050; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); width: min(900px, calc(100vw - 48px)); max-height: min(76vh, 760px); overflow: auto; margin: 0; padding: 18px 19px 15px; transform: translateX(-50%); border: 1px solid var(--line-strong); border-radius: 27px; background: var(--panel-strong); -webkit-backdrop-filter: blur(36px) saturate(185%); backdrop-filter: blur(36px) saturate(185%); box-shadow: 0 30px 90px rgba(2, 28, 65, .28), 0 8px 28px rgba(0, 94, 215, .12), inset 0 1px 0 rgba(255,255,255,.65); animation: keyboardUp .24s cubic-bezier(.2,.8,.2,1) both; }
@keyframes keyboardUp { from { opacity: 0; transform: translate(-50%, 24px) scale(.985); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
.keyboard-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.keyboard-tabs { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); flex: 1 1 auto; min-width: 0; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-soft); }
.keyboard-tab { display: flex; min-width: 0; min-height: 44px; padding: 3px 4px; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; border-radius: 999px; color: var(--muted); background: transparent; font-size: .76rem; line-height: 1; font-weight: 730; white-space: nowrap; cursor: pointer; }
.keyboard-tab span { display: block; margin: 0; font-size: .63rem; line-height: 1.1; white-space: nowrap; }
.keyboard-tab.active { color: #fff; background: linear-gradient(115deg, var(--primary), var(--primary-2)); box-shadow: 0 6px 17px rgba(0,100,230,.22); }
.keyboard-hide { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: var(--panel-soft); font-size: 1.25rem; cursor: pointer; }
.keyboard-page.active { display: block; }
.keypad-main { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 8px; }
.math-key { min-width: 0; min-height: 48px; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); background: var(--key); box-shadow: 0 4px 13px rgba(12,66,128,.07), inset 0 1px 0 rgba(255,255,255,.76); font-size: 1.15rem; font-weight: 650; cursor: pointer; touch-action: manipulation; transition: transform .11s ease, background .14s ease, border-color .14s ease; }
.math-key:hover { border-color: var(--line-strong); background: var(--key-2); }
.math-key:active { transform: scale(.96); }
.key-operator, .key-bracket { color: var(--primary); }
.key-variable { color: #0878f9; }
html[data-theme="dark"] .key-variable { color: #76baff; }
.key-utility { color: var(--muted); }
.keyboard-functions { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 8px; margin-top: 9px; }
.function-key { min-height: 42px; color: var(--primary); font-size: .96rem; }
.keypad-letters { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 7px; }
.keypad-letters .math-key { min-height: 43px; }
.keyboard-letter-functions { grid-template-columns: repeat(6,minmax(0,1fr)); }
.keyboard-symbol-functions { grid-template-columns: repeat(5,minmax(0,1fr)); }
.interval-template-key { grid-column: span 2; font-size: .82rem; letter-spacing: -.02em; }
.keyboard-symbol-functions .math-key { min-height: 43px; }
.keyboard-interval-templates { grid-template-columns: repeat(2,minmax(0,1fr)); }
.keyboard-function-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
.keyboard-graph-templates { grid-template-columns: repeat(3,minmax(0,1fr)); }
.keyboard-section-label { margin: 8px 2px 2px; color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .02em; }
.keyboard-note { margin: 9px 2px 0; color: var(--muted); font-size: .70rem; line-height: 1.45; }
.keyboard-actions { margin-top: 12px; }
.keyboard-solve { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 49px; padding: 0 18px; border: 0; border-radius: 15px; color: #fff; background: linear-gradient(110deg, #1689ff, #075bd7); box-shadow: 0 8px 20px rgba(0,100,230,.24); font-size: .96rem; font-weight: 780; cursor: pointer; }
.keyboard-solve span:last-child { font-size: 1.25rem; }
.keyboard-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 9px; color: var(--muted-2); font-size: .70rem; }
.keyboard-bottom-actions { display: flex; gap: 8px; }
.keyboard-newline, .keyboard-clear { padding: 5px 7px; border: 0; color: var(--muted); background: transparent; font-size: .71rem; cursor: pointer; }

/* Startup / dialogs */
.startup-screen { position: fixed; z-index: 1000; inset: 0; display: grid; place-items: center; padding: 22px; color: var(--ink); background: radial-gradient(ellipse at 50% 32%, rgba(55,151,255,.18), transparent 27rem), linear-gradient(140deg,var(--page),var(--page-2)); transition: opacity .45s ease, visibility .45s ease; }
.startup-screen.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.startup-content { display: flex; align-items: center; flex-direction: column; width: min(360px,100%); text-align: center; }
.startup-logo { display: block; width: 88px; height: 88px; margin: 0 0 18px; border-radius: 23px; filter: drop-shadow(0 12px 24px rgba(8, 92, 205, .20)); animation: startupLogoFloat 2.8s ease-in-out infinite; }
@keyframes startupLogoFloat { 50% { transform: translateY(-4px); } }
@keyframes float { 50% { transform: translateY(-5px); } }
.startup-name { font-size: 1.7rem; font-weight: 820; letter-spacing: -.045em; }
.startup-tagline { margin-top: 5px; color: var(--muted); font-size: .85rem; }
.startup-loader { width: 220px; height: 6px; margin-top: 27px; overflow: hidden; border-radius: 10px; background: var(--primary-soft); }
.startup-loader span { display: block; width: 42%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #63b8ff, #0878f9); animation: loading 1.4s ease-in-out infinite; }
@keyframes loading { from { transform: translateX(-110%); } to { transform: translateX(250%); } }
.startup-status { margin-top: 12px; color: var(--muted); font-size: .75rem; }
.startup-retry, .startup-continue { margin-top: 11px; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: 12px; color: var(--primary); background: var(--panel-strong); cursor: pointer; }
.modal { position: fixed; z-index: 1200; inset: 0; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4,18,40,.43); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.modal-card, .settings-card { position: relative; width: min(620px,100%); max-height: min(88vh, 900px); overflow: auto; padding: 26px; border: 1px solid var(--line-strong); border-radius: 26px; background: var(--panel-strong); -webkit-backdrop-filter: blur(38px) saturate(180%); backdrop-filter: blur(38px) saturate(180%); box-shadow: 0 30px 90px rgba(3,24,55,.30); }
.modal-close { position: absolute; top: 14px; right: 14px; display: grid; place-items: center; width: 37px; height: 37px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: var(--panel-soft); font-size: 1.3rem; cursor: pointer; }
.modal-card h2, .settings-header h2 { margin: 6px 44px 16px 0; font-size: 1.42rem; letter-spacing: -.035em; }
.modal-body { color: var(--ink); line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-notice { margin: 16px 0; color: var(--muted); font-size: .77rem; line-height: 1.5; }
.modal-done { min-width: 130px; }
.settings-card { width: min(720px,100%); }
.settings-header { position: relative; padding-right: 35px; }
.settings-section { padding: 18px 0; border-top: 1px solid var(--line); }
.settings-section h3 { margin: 0 0 6px; font-size: 1rem; }
.settings-section > p { margin: 0 0 14px; color: var(--muted); font-size: .81rem; line-height: 1.5; }
.theme-options { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; }
.theme-option { display: flex; align-items: center; flex-direction: column; gap: 8px; padding: 12px 8px; border: 1px solid var(--line); border-radius: 16px; color: var(--muted); background: var(--panel-soft); font-size: .78rem; font-weight: 720; cursor: pointer; }
.theme-option.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px rgba(8,120,249,.08); }
.theme-preview { display: grid; place-items: center; width: 100%; height: 56px; border-radius: 11px; font-size: 1.35rem; }
.theme-preview-system { color: #fff; background: linear-gradient(90deg,#f4f9ff 50%,#0b2145 50%); text-shadow: 0 1px 3px rgba(0,0,0,.25); }
.theme-preview-light { color: #0878f9; background: linear-gradient(135deg,#fff,#dceeff); }
.theme-preview-dark { color: #8cc8ff; background: linear-gradient(135deg,#174b89,#06142c); }
.settings-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-top: 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: .72rem; }
.toast { position: fixed; z-index: 1300; left: 50%; bottom: 24px; max-width: min(90vw,520px); padding: 12px 17px; transform: translate(-50%,18px); border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: var(--panel-strong); -webkit-backdrop-filter: blur(28px); backdrop-filter: blur(28px); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .22s ease; text-align: center; font-size: .80rem; }
.toast.show { transform: translate(-50%,0); opacity: 1; }

/* Tablet — comfortable single workspace, with the same floating keyboard. */
@media (max-width: 1080px) {
  .app-shell { width: min(100% - 36px, 920px); }
  .workspace-grid { grid-template-columns: minmax(0,1fr); gap: 18px; }
  .input-column, .result-column { gap: 16px; }
  .welcome-note { min-height: 220px; }
  .results { grid-template-columns: minmax(245px,.8fr) minmax(0,1.2fr); }
}
@media (min-width: 721px) and (max-width: 1080px) {
  .primary-nav { display: none; }
  .mobile-nav { position: fixed; z-index: 500; right: 22px; bottom: max(14px,env(safe-area-inset-bottom)); left: 22px; display: grid; grid-template-columns: repeat(2,1fr); gap: 7px; width: min(420px,calc(100% - 44px)); margin: 0 auto; padding: 8px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel-strong); -webkit-backdrop-filter: blur(28px) saturate(180%); backdrop-filter: blur(28px) saturate(180%); box-shadow: 0 18px 48px rgba(6,43,89,.18), inset 0 1px 0 rgba(255,255,255,.72); }
  .mobile-nav-item { display: flex; min-height: 50px; align-items: center; justify-content: center; flex-direction: column; gap: 3px; border: 0; border-radius: 15px; color: var(--muted); background: transparent; cursor: pointer; }
  .mobile-nav-item > span { font-size: 1.12rem; line-height: 1.1; }
  .mobile-nav-item small { font-size: .68rem; font-weight: 680; }
  .mobile-nav-item.active { color: var(--primary); background: var(--primary-soft); }
  .app-shell { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
  .app-footer { display: none; }
  body.keyboard-is-open { overflow: hidden; }
  body.keyboard-is-open .mobile-nav { transform: translateY(130%); opacity: 0; pointer-events: none; }
}

/* Phone */
@media (max-width: 720px) {
  :root { --blur: 18px; }
  body { background-attachment: scroll; }
  .app-shell { width: 100%; min-height: 100dvh; padding: max(13px,env(safe-area-inset-top)) max(13px,env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(13px,env(safe-area-inset-left)); }
  .topbar { gap: 10px; padding: 3px 1px 17px; }
  .brand-lockup { gap: 10px; }
  .brand-copy h1 { font-size: 1.38rem; }
  .brand-copy p { margin-top: 3px; font-size: .68rem; }
  .top-actions { gap: 6px; }
  #topEngineStatus { display: none; }
  .icon-button { width: 39px; min-height: 39px; border-radius: 13px; }
  .install-btn { min-width: 92px; min-height: 39px; padding: 0 10px; font-size: .70rem; border-radius: 12px; }
  .primary-nav { display: none; }
  .workspace-grid { display: flex; flex-direction: column; gap: 14px; }
  .input-column, .result-column { width: 100%; gap: 13px; }
  .input-card { padding: 15px; border-radius: 23px; }
  .input-card-head { margin: 0 1px 10px; }
  .input-title { gap: 7px; }
  .input-title label { font-size: .65rem; }
  .keyboard-toggle { min-height: 32px; padding: 0 9px; font-size: .68rem; }
  .expression-shell { min-height: 73px; padding: 9px 45px 9px 13px; border-radius: 18px; }
  #taskInput { min-height: 48px; font-size: 1.48rem; }
  #taskInput::placeholder { font-size: .88rem; }
  .clear-expression { right: 9px; width: 30px; height: 30px; }
  .welcome-note { width: 100%; min-height: 0; padding: 19px 14px 15px; border-radius: 23px; }
  .welcome-icon { width: 55px; height: 55px; border-radius: 18px; font-size: 1.85rem; }
  .welcome-note > strong { font-size: .94rem; }
  .welcome-note > p { font-size: .75rem; }
  .welcome-tip { padding: 10px 12px; }
  .results { display: flex; flex-direction: column; gap: 10px; width: 100%; min-width: 0; }
  .results > * { width: 100%; min-width: 0; flex: 0 0 auto; }
  .answer-card, .verify-card, .steps-panel, .clarify-bar { border-radius: 22px; }
  .answer-card { min-height: 110px; padding: 13px 15px 11px; }
  .answer-label { font-size: .90rem; }
  .answer-dot { width: 25px; height: 25px; }
  .answer-text { margin: 0 18px; font-size: 2.35rem; }
  .copy-btn { width: 33px; height: 33px; }
  .verify-card { padding: 14px; }
  .verify-row { width: 100%; min-width: 0; }
  .verify-row input { width: 0; flex: 1 1 0; }
  .verify-row .button { flex: 0 0 auto; padding-inline: 12px; }
  .steps-panel { padding: 14px; }
  .step-card { grid-template-columns: 32px minmax(0,1fr); padding: 10px; border-radius: 14px; }
  .step-formula { font-size: 1rem; }
  .clarify-bar { display: block; padding: 15px; }
  .clarify-actions { display: grid; grid-template-columns: 1fr; margin-top: 11px; }
  .clarify-actions .button { width: 100%; }
  .ai-usage-row { align-items: flex-start; margin-top: 11px; }
  .history-page { width: 100%; }
  .history-panel { padding: 16px; border-radius: 22px; }
  .history-heading { align-items: flex-start; flex-direction: column; }
  .history-heading h2 { font-size: 1.35rem; }
  .history-item { grid-template-columns: minmax(0,1fr); gap: 4px; padding: 12px 13px; }
  .app-footer { display: none; }
  .mobile-nav { position: fixed; z-index: 500; right: max(11px,env(safe-area-inset-right)); bottom: max(8px,env(safe-area-inset-bottom)); left: max(11px,env(safe-area-inset-left)); display: grid; grid-template-columns: repeat(2,1fr); gap: 5px; padding: 7px; border: 1px solid var(--line); border-radius: 21px; background: var(--panel-strong); -webkit-backdrop-filter: blur(30px) saturate(185%); backdrop-filter: blur(30px) saturate(185%); box-shadow: 0 16px 44px rgba(6,43,89,.18), inset 0 1px 0 rgba(255,255,255,.72); transition: transform .22s ease, opacity .22s ease; }
  .mobile-nav-item { display: flex; min-height: 48px; align-items: center; justify-content: center; flex-direction: column; gap: 3px; border: 0; border-radius: 14px; color: var(--muted); background: transparent; cursor: pointer; }
  .mobile-nav-item > span { font-size: 1.08rem; line-height: 1.1; }
  .mobile-nav-item small { font-size: .65rem; font-weight: 690; }
  .mobile-nav-item.active { color: var(--primary); background: var(--primary-soft); }
  body.keyboard-is-open { overflow: hidden; }
  body.keyboard-is-open .mobile-nav { transform: translateY(130%); opacity: 0; pointer-events: none; }
  .keyboard-backdrop { background: rgba(4,18,42,.35); }
  .math-keyboard { left: max(8px,env(safe-area-inset-left)); right: max(8px,env(safe-area-inset-right)); bottom: max(8px,env(safe-area-inset-bottom)); width: auto; max-height: min(74dvh, 610px); -webkit-backdrop-filter: blur(24px) saturate(175%); backdrop-filter: blur(24px) saturate(175%); padding: 13px 12px calc(11px + env(safe-area-inset-bottom)); transform: none; border-radius: 23px; }
  @keyframes keyboardUp { from { opacity: 0; transform: translateY(24px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
  .keyboard-head { margin-bottom: 9px; }
  .keyboard-tab { min-height: 35px; padding: 0 12px; font-size: .74rem; }
  .keyboard-hide { width: 34px; height: 34px; }
  .keypad-main { gap: 6px; }
  .math-key { min-height: 45px; border-radius: 12px; font-size: 1.02rem; }
  .keyboard-functions { gap: 6px; margin-top: 7px; }
  .function-key { min-height: 37px; font-size: .86rem; }
  .keypad-letters { gap: 5px; }
  .keypad-letters .math-key { min-height: 39px; }
  .keyboard-note { font-size: .65rem; }
  .keyboard-section-label { font-size: .64rem; }
  .keyboard-actions { margin-top: 9px; }
  .keyboard-solve { min-height: 44px; }
  .keyboard-bottom { align-items: flex-start; font-size: .64rem; }
  .input-hint { display: none; }
  .keyboard-newline, .keyboard-clear { padding: 4px 5px; font-size: .64rem; }
  .modal { padding: 11px; }
  .modal-card, .settings-card { max-height: 92dvh; padding: 20px 16px; border-radius: 22px; -webkit-backdrop-filter: blur(24px) saturate(175%); backdrop-filter: blur(24px) saturate(175%); }
  .settings-footer { align-items: flex-start; flex-direction: column; }
  .theme-options { gap: 7px; }
  .theme-option { padding: 9px 5px; font-size: .69rem; }
  .theme-preview { height: 45px; }
    .toast { bottom: calc(82px + env(safe-area-inset-bottom)); }
}
@media (max-width: 370px) {
  .app-shell { padding-right: 10px; padding-left: 10px; }
  .brand-copy p { display: none; }
  .top-actions { gap: 5px; }
  .input-card { padding: 12px; }
  .keypad-main, .keyboard-functions { gap: 5px; }
  .math-key { min-height: 42px; }
  .keyboard-tab { padding-inline: 2px; font-size: .65rem; }
  .keyboard-tab span { font-size: .54rem; }
  .keyboard-head { gap: 6px; }
  .keyboard-tabs { gap: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}


/* Desktop keyboard: a side drawer that leaves the equation field visible. */
@media (min-width: 1081px) {
  /* On laptops/desktops the drawer sits beside the workspace, never over the equation. */
  body.keyboard-is-open .app-shell {
    width: min(calc(100vw - 460px), 1360px);
    margin-left: max(20px, calc((100vw - 1780px) / 2));
    margin-right: auto;
    transition: width .24s cubic-bezier(.2,.8,.2,1), margin .24s cubic-bezier(.2,.8,.2,1);
  }
  .keyboard-backdrop {
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    pointer-events: none;
  }
  .math-keyboard {
    top: 104px;
    right: max(20px, calc((100vw - 1780px) / 2));
    bottom: 24px;
    left: auto;
    width: min(410px, 36vw);
    max-height: none;
    overflow-y: auto;
    transform: none;
    border-radius: 25px;
    animation: keyboardSideIn .24s cubic-bezier(.2,.8,.2,1) both;
  }
  @keyframes keyboardSideIn {
    from { opacity: 0; transform: translateX(28px) scale(.985); }
    to { opacity: 1; transform: translateX(0) scale(1); }
  }
}

/* Minimal in-app identity: app name only; the PWA icon remains separate. */
.brand-lockup { gap: 0; }
.brand-copy h1 { letter-spacing: -.045em; }


/* R59: keep the complete expression editor visible while the custom keyboard is open.
   The editor is promoted above the backdrop on every form factor; the keyboard
   remains a bottom sheet on touch devices and a side dock on desktop. */
.input-card.keyboard-open {
  position: fixed !important;
  z-index: 1060 !important;
  margin: 0 !important;
  max-height: min(220px, 30dvh);
  overflow: auto;
  overscroll-behavior: contain;
}
.input-card.keyboard-open .expression-shell {
  min-height: 66px;
  max-height: min(150px, 20dvh);
}
.input-card.keyboard-open #taskInput {
  min-height: 48px;
  max-height: min(128px, 18dvh);
  overflow-y: auto;
  overflow-wrap: anywhere;
}
.input-card.keyboard-open .input-hint { display: none; }

/* Touch layouts: hide secondary chrome while typing and pin the expression
   above the bottom-sheet keyboard so it cannot be covered by the keys. */
@media (max-width: 1080px) {
  body.keyboard-is-open .topbar,
  body.keyboard-is-open .primary-nav { display: none !important; }
  body.keyboard-is-open .input-card.keyboard-open {
    top: max(8px, env(safe-area-inset-top)) !important;
    left: max(12px, env(safe-area-inset-left)) !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    width: auto !important;
    max-width: 920px;
    max-height: min(190px, 27dvh);
    margin-inline: auto !important;
    padding: 12px 14px;
    border-radius: 20px;
  }
  body.keyboard-is-open .input-card.keyboard-open .input-card-head { margin-bottom: 7px; }
  body.keyboard-is-open .input-card.keyboard-open .expression-shell { min-height: 58px; padding-block: 6px; }
  body.keyboard-is-open .math-keyboard {
    max-height: min(54dvh, 500px);
    bottom: max(8px, env(safe-area-inset-bottom));
  }
  body.keyboard-is-open .keyboard-backdrop { background: rgba(4,18,42,.28); }
  body.keyboard-is-open .welcome-note,
  body.keyboard-is-open .result-column { visibility: hidden; }
}

/* Phones: a little more compact to preserve a clear gap between the input
   line and the keyboard, including short landscape viewports. */
@media (max-width: 720px) {
  body.keyboard-is-open .input-card.keyboard-open {
    left: max(8px, env(safe-area-inset-left)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    padding: 10px 12px;
    max-height: min(166px, 25dvh);
  }
  body.keyboard-is-open .input-card.keyboard-open .input-title label { font-size: .62rem; }
  body.keyboard-is-open .input-card.keyboard-open .expression-shell { min-height: 54px; }
  body.keyboard-is-open .input-card.keyboard-open #taskInput { min-height: 42px; font-size: 1.35rem; }
  body.keyboard-is-open .math-keyboard { max-height: min(54dvh, 460px); }
}

/* Desktop: the editor is fixed in the left workspace; the keyboard docks on
   the right. Neither surface covers the other, even on shorter laptop screens. */
@media (min-width: 1081px) {
  body.keyboard-is-open .input-card.keyboard-open {
    top: 104px !important;
    left: max(20px, calc((100vw - 1780px) / 2)) !important;
    right: auto !important;
    width: min(calc(100vw - 490px), 1360px) !important;
    max-width: calc(100vw - 490px);
    max-height: min(220px, 32dvh);
  }
  body.keyboard-is-open .math-keyboard {
    top: 104px;
    right: max(20px, calc((100vw - 1780px) / 2));
    bottom: 20px;
    width: min(410px, 36vw);
    max-height: none;
  }
  body.keyboard-is-open .welcome-note,
  body.keyboard-is-open .result-column { visibility: hidden; }
}

@media (max-height: 560px) {
  body.keyboard-is-open .math-keyboard { max-height: 54dvh; }
  body.keyboard-is-open .math-keyboard .math-key { min-height: 34px; }
  body.keyboard-is-open .math-keyboard .function-key { min-height: 30px; }
}

@media (max-height: 560px) and (max-width: 1080px) {
  body.keyboard-is-open .math-keyboard { max-height: 46dvh; }
  body.keyboard-is-open .input-card.keyboard-open { max-height: 38dvh; }
}


/* R60: keep install actions correctly sized and aligned on all screens. */
.top-actions { flex: 0 0 auto; min-width: 0; }
.install-btn { box-sizing: border-box; align-self: center; }
@media (min-width: 721px) and (max-width: 1080px) {
  .topbar { gap: 14px; }
  .top-actions { gap: 8px; }
  .install-btn { min-width: 104px; min-height: 42px; }
}
@media (max-width: 720px) {
  .topbar { align-items: center; }
  .brand-lockup { flex: 1 1 auto; min-width: 0; }
  .top-actions { gap: 6px; }
  .install-btn { min-width: 88px; min-height: 39px; padding-inline: 9px; font-size: .69rem; }
}
@media (max-width: 360px) {
  .brand-copy p { display: none; }
  .brand-copy h1 { font-size: 1.25rem; }
  .install-btn { min-width: 82px; padding-inline: 7px; font-size: .66rem; }
  .icon-button { flex-basis: 37px; width: 37px; min-height: 37px; }
}

/* Читаемое оформление ИИ-объяснений и формул */
.modal-body { white-space: normal; line-height: 1.72; }
.modal-body p { margin: 0 0 13px; }
.modal-body h3 { margin: 20px 0 10px; font-size: 1.04rem; line-height: 1.35; color: var(--ink); }
.modal-body .explanation-math { overflow-x: auto; max-width: 100%; padding: 10px 4px; margin: 8px 0 14px; text-align: center; }
.modal-body .explanation-list-item { padding-left: 4px; }
.modal-body mjx-container { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
