html, body.app-body { height: 100%; overflow: hidden; }
.app-body { display: flex; flex-direction: column; height: 100dvh; }

/* Top bar */
.topbar {
  position: relative; display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 12px 0 14px; flex-shrink: 0;
  background: var(--glass); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); z-index: 5;
}
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--gradient); opacity: 0.55; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-family: var(--display); font-weight: 800; font-size: 1.15rem; letter-spacing: -0.03em; }
.btn.tools {
  background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--gradient) border-box;
  border: 1.5px solid transparent; color: var(--ink);
}
.btn.tools:hover { box-shadow: var(--glow); }
.btn.tools .spark { background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: 1rem; }
.title-wrap { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; }
.title-input {
  min-width: 60px; max-width: 320px; width: 100%; border: 1px solid transparent; background: transparent;
  padding: 6px 8px; border-radius: 8px; font-weight: 600; text-overflow: ellipsis;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { border-color: var(--brand); outline: none; background: var(--surface); }
.save-status { color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.btn.account { background: var(--surface-2); color: var(--ink); padding: 0 10px 0 6px; gap: 8px; }
.btn.account:not(:has(.avatar)) { padding: 0 14px; }
.btn.account.is-pro .acct-label { background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 800; }
.show-sm { display: none; }

.share-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px; padding: 8px 14px; flex-wrap: wrap;
  background: var(--brand-soft); color: var(--ink); font-size: 0.9rem; border-bottom: 1px solid var(--line);
}

/* Workspace */
.workspace { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 380px; flex-shrink: 0; display: flex; flex-direction: column; background: var(--surface);
  border-right: 1px solid var(--line); min-height: 0;
}
.panel-tools { display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
/* On wide screens the wrapper is transparent to layout; on phones it becomes the one scroll area. */
.panel-scroll { display: contents; }
.expr-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.stage { position: relative; flex: 1; min-width: 0; background: var(--graph-bg); }
.stage canvas { display: block; touch-action: none; cursor: grab; }
.zoom-controls {
  position: absolute; top: 12px; right: 12px; display: grid; gap: 2px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm);
}

/* Expression rows */
.expr { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); position: relative; background: var(--surface); }
.expr.selected { background: color-mix(in srgb, var(--brand-soft) 45%, var(--surface)); }
.expr.selected::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--gradient); }
.expr-gutter { width: 44px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; background: var(--surface-2); border-right: 1px solid var(--line); }
.expr-idx { font-size: 0.7rem; color: var(--muted); font-weight: 600; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--c); background: var(--c); cursor: pointer; padding: 0;
  transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.12); }
.expr.is-hidden .swatch { background: transparent; }
.swatch.inactive { opacity: 0; pointer-events: none; }
.expr-main { flex: 1; min-width: 0; padding: 6px 4px 6px 10px; }
.expr-field { position: relative; min-height: 36px; display: flex; align-items: center; }
.expr-input {
  display: block; width: 100%; border: none; background: transparent; font-family: var(--mono); font-size: 0.98rem;
  padding: 8px 2px; outline: none; resize: none; overflow: hidden; line-height: 1.35;
  white-space: pre-wrap; overflow-wrap: anywhere; color: inherit;
}
.expr-tex {
  position: absolute; inset: 0; display: none; align-items: center; padding: 4px 2px; overflow-x: auto; overflow-y: hidden;
  background: inherit; font-size: 1.08rem; cursor: text; scrollbar-width: none;
}
.expr.has-tex:not(.editing) .expr-tex { display: flex; background: transparent; }
.expr.has-tex:not(.editing) .expr-input { color: transparent; caret-color: transparent; }
.expr-tex .katex { white-space: nowrap; }
/* Long expressions: while not editing, the rendered math sits in the normal flow and wraps onto more
   lines (KaTeX breaks after operators and relations) instead of being cut off at the panel edge. */
.expr.has-tex:not(.editing) .expr-field { display: block; padding: 4px 0; }
.expr.has-tex:not(.editing) .expr-input { position: absolute; inset: 0; opacity: 0; height: 100% !important; }
.expr.has-tex:not(.editing) .expr-tex { position: relative; inset: auto; display: block; min-height: 28px; padding: 2px; line-height: 1.5; scrollbar-width: thin; }
.expr.has-tex:not(.editing) .expr-tex .katex { white-space: normal; }
.expr-del { opacity: 0; align-self: center; margin-right: 4px; font-size: 1.2rem; }
.expr:hover .expr-del, .expr.selected .expr-del { opacity: 1; }
.expr-meta:empty { display: none; }
.expr-meta { padding: 0 2px 4px; display: grid; gap: 6px; }
.expr-error { display: flex; gap: 8px; align-items: flex-start; color: var(--danger); font-size: 0.82rem; font-weight: 600; }
.err-icon { display: inline-grid; place-items: center; width: 16px; height: 16px; flex-shrink: 0; border-radius: 50%; background: var(--danger); color: #fff; font-size: 0.7rem; margin-top: 2px; }
.expr-value { font-family: var(--mono); color: var(--ink-2); font-size: 0.9rem; text-align: right; padding-right: 6px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 0.8rem; }
.chip {
  height: 26px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 600; font-size: 0.8rem; color: var(--ink-2);
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.pro-chip { border-color: transparent; background: var(--brand-soft); color: var(--brand); }
.pro-tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px; vertical-align: 1px;
  background: var(--gradient); color: #fff; font-size: 0.62rem; font-weight: 800; letter-spacing: 0.04em; line-height: 1.5;
}
.pro-tag.on-gradient { background: rgb(255 255 255 / 0.25); }
.pro-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 12px; background: var(--gradient-soft); border: 1px solid var(--line-2); font-size: 0.9rem; font-weight: 600; }
.pro-note .pro-tag { margin: 0 4px 0 0; }

/* Sliders */
.slider-row { display: grid; grid-template-columns: 28px 64px 1fr 64px; align-items: center; gap: 6px; }
.slider-row .play { width: 28px; height: 28px; font-size: 0.75rem; background: var(--surface-2); }
.bound { height: 28px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); padding: 0 6px; font-size: 0.78rem; text-align: center; width: 100%; min-width: 0; }
.slider { width: 100%; accent-color: var(--brand); }

/* Color menu */
.color-menu {
  position: fixed; z-index: 40; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 10px; width: 184px;
}
.color-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.color-opt { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--surface); background: var(--c); cursor: pointer; box-shadow: 0 0 0 1px var(--line); }
.color-opt.on { box-shadow: 0 0 0 2px var(--ink); }
.menu-item { width: 100%; text-align: left; padding: 8px; border: none; background: none; border-radius: 8px; cursor: pointer; font-weight: 600; }
.menu-item:hover { background: var(--surface-2); }

/* Calculus lens */
.lens { position: relative; border-top: 1px solid var(--line); padding: 12px 14px; background: var(--surface); flex-shrink: 0; }
.lens-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.lens-title { font-weight: 800; }
.lens-swatch { width: 12px; height: 12px; border-radius: 50%; }
.lens-head .icon-btn { margin-left: auto; width: 28px; height: 28px; }
.lens-body { display: grid; gap: 8px; }
.lens-row { display: grid; gap: 6px; }
.lens-inline { display: flex; gap: 8px; align-items: center; padding-left: 44px; }
.lens-inline .slider { flex: 1; min-width: 60px; }
.lens-num { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); }
.lens-num input { width: 70px; height: 28px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); padding: 0 6px; }
.lens-result { font-size: 0.95rem; padding: 6px 10px; background: var(--surface-2); border-radius: 10px; overflow-x: auto; }
.lens-lock {
  position: absolute; inset: 40px 0 0; display: grid; place-content: center; text-align: center; gap: 6px; padding: 12px;
  background: color-mix(in srgb, var(--surface) 80%, transparent); backdrop-filter: blur(2px);
}
.lens-lock p { font-size: 0.85rem; color: var(--ink-2); margin: 0 0 4px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; font-size: 0.88rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.15s; flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: var(--shadow-sm); }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Keypad */
.keypad { border-top: 1px solid var(--line); padding: 8px; background: var(--surface-2); flex-shrink: 0; }
.keys { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.keys-nav { display: grid; grid-template-columns: 1fr 1fr 1fr 3fr; gap: 4px; margin-top: 4px; }
.key {
  height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-size: 0.88rem; font-weight: 600; padding: 0; touch-action: manipulation;
}
.key:hover { border-color: var(--brand); }
.key:active { background: var(--brand-soft); }
.key.num { background: color-mix(in srgb, var(--surface) 70%, var(--surface-2)); }
.key.enter { background: var(--brand); color: #fff; border-color: transparent; }

/* Analysis */
.analysis { display: grid; gap: 14px; }
.an-formulas { display: grid; gap: 8px; }
.an-formula { background: var(--surface-2); border-radius: 12px; padding: 8px 14px; overflow-x: auto; }
.an-formula .katex-display { margin: 4px 0; }
.an-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.an-section { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.an-section h3 { color: var(--muted); text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.08em; }
.an-section p { margin: 0 0 4px; }
.pt-list { margin: 0; padding-left: 18px; font-family: var(--mono); font-size: 0.88rem; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 10px; }
.steps li.indent { margin-left: 18px; list-style: circle; }
.step-rule { font-weight: 700; }
.step-note { color: var(--muted); font-size: 0.9rem; }
.step-tex { overflow-x: auto; }
.step-tex .katex-display { margin: 4px 0; text-align: left; }

/* Upgrade */
.upgrade-hero { text-align: center; margin-bottom: 10px; }
.upgrade-hero h2 { margin-top: 10px; }
.feature-list { list-style: none; padding: 0; margin: 0 0 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.feature-list li { display: flex; gap: 10px; align-items: flex-start; }
.f-icon { width: 30px; height: 30px; flex-shrink: 0; display: grid; place-items: center; border-radius: 9px; background: var(--brand-soft); }
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.plan { position: relative; border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: grid; gap: 6px; }
.plan.featured { border: 2px solid var(--brand); box-shadow: 0 10px 30px -18px var(--brand); }
.plan-flag { position: absolute; top: -11px; right: 14px; background: var(--gradient); color: #fff; font-size: 0.7rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; }
.plan-name { font-weight: 700; color: var(--muted); }
.plan-price { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }
.plan .btn { margin-top: 8px; }
.test-note { margin-top: 14px; text-align: center; font-size: 0.82rem; color: var(--muted); background: var(--surface-2); padding: 8px; border-radius: 10px; }

/* Lists & misc modals */
.graph-item { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.graph-open { flex: 1; display: grid; text-align: left; padding: 10px 6px; border: none; background: none; cursor: pointer; border-radius: 8px; min-width: 0; }
.graph-open:hover { background: var(--surface-2); }
.graph-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.limit-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 8px; background: var(--surface-2); border-radius: 12px; font-size: 0.88rem; font-weight: 600; }
.meter { flex: 1; min-width: 80px; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--gradient); }
.empty { padding: 24px 0; text-align: center; }
.share-row { display: flex; gap: 8px; margin: 14px 0; }
.share-url { flex: 1; min-width: 0; height: 36px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--surface-2); font-family: var(--mono); font-size: 0.85rem; }
.export-options { display: grid; gap: 10px; }
.export-opt { display: grid; gap: 2px; text-align: left; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.export-opt:hover { border-color: var(--brand); }
.example-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.example { display: grid; gap: 4px; text-align: left; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.example:hover { border-color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.ex-icon { font-size: 1.4rem; }
.big-icon { font-size: 2.4rem; }
.acct-card { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; }
.acct-card .badge { margin-left: auto; }
.acct-sub { margin: 14px 0 4px; font-size: 0.92rem; }
.account .btn-row { justify-content: flex-start; }
.danger-zone { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.danger-zone summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }
.menu-list { display: grid; gap: 4px; padding-top: 18px; }
.menu-row { text-align: left; padding: 12px; border-radius: 10px; border: none; background: none; font-weight: 600; cursor: pointer; }
.menu-row:hover { background: var(--surface-2); }

/* Responsive: stack panel over graph on phones/tablets in portrait */
@media (max-width: 900px) {
  .hide-sm { display: none !important; }
  .show-sm { display: inline-grid; }
  .panel { width: 320px; }
}
@media (max-width: 680px) {
  .hide-xs { display: none !important; }
  .brand-name, .save-status { display: none; }
  .topbar { gap: 6px; padding: 0 8px; }
  .workspace { flex-direction: column-reverse; }
  /* Panel = toolbar, one scrolling area (expressions, tables, lens), then the keypad below it.
     The keypad sits outside the scroll area so it can never cover the expression rows. */
  .panel { width: 100%; height: 48%; border-right: none; border-top: 1px solid var(--line); overflow: hidden; }
  .panel:has(> .keypad:not([hidden])) { height: 66%; }
  /* While typing on the keypad, the expression rows need the room more than a reminder banner
     (exam-mode notices stay). It comes back when the keypad is closed. */
  body:has(.keypad:not([hidden])) .notice-bar:not(.exam) { display: none; }
  .panel-scroll { display: block; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .expr-list { flex: none; overflow: visible; min-height: 96px; }
  .panel-scroll > .lens { max-height: none; overflow: visible; }
  .panel-tools { padding: 2px 8px; }
  .expr-gutter { padding: 6px 0; gap: 2px; width: 40px; }
  .expr-main { padding: 4px 4px 4px 8px; }
  .keypad { padding: 6px; }
  .keys { gap: 3px; }
  .keys-nav { gap: 3px; margin-top: 3px; }
  .stage { flex: 1; min-height: 0; }
  .plans { grid-template-columns: 1fr; }
  .modal { padding: 20px 16px; }
  .key { height: 28px; font-size: 0.8rem; }
  .expr-del { opacity: 1; }
}

/* ---- Lens additions ---- */
.lens { max-height: 55%; overflow-y: auto; }
.lens-sub { padding-left: 22px; border-left: 2px solid var(--line-2); margin-left: 16px; }
.lens-tag { font-size: 0.78rem; font-weight: 700; color: var(--muted); white-space: nowrap; min-width: 54px; }
select.input.mini { min-height: 28px; height: 28px; padding: 0 8px; font-size: 0.8rem; border-radius: 8px; width: auto; }
.lens-result .tex { display: block; }

/* ---- Study tools ---- */
.study-head { display: flex; align-items: center; gap: 10px; padding-right: 40px; margin-bottom: 14px; }
.study-head h2 { margin: 0; }
.tabs { display: flex; gap: 6px; padding: 4px; background: var(--surface-2); border-radius: 999px; margin-bottom: 18px; width: fit-content; max-width: 100%; overflow-x: auto; }
.tab { border: none; background: none; padding: 8px 16px; border-radius: 999px; font-weight: 650; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line-2); }
.tool-panel { display: grid; gap: 12px; }
.tool-row { display: flex; gap: 8px; align-items: center; }
.tool-row .input { flex: 1; min-width: 0; font-family: var(--mono); }
.tool-row.wrap { flex-wrap: wrap; }
.tool-out:empty { display: none; }
.tool-out { display: grid; gap: 12px; }
.tool-eq { background: var(--surface-2); border-radius: 14px; padding: 6px 14px; overflow-x: auto; }
.answer-box { display: grid; gap: 8px; padding: 14px 16px; border-radius: 16px; background: var(--gradient-soft); border: 1px solid var(--line-2); }
.answer-list { display: flex; flex-wrap: wrap; gap: 8px; }
.answer-chip { background: var(--surface); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2); }
.answer-box .btn { justify-self: start; }
.mode-chips { gap: 6px; }
.mode-chips .chip { min-height: 32px; }
.tool-stack { display: grid; gap: 10px; }
textarea.input.mono, .tool-stack .input { font-family: var(--mono); }
.pair-row { display: flex; align-items: center; gap: 10px; }
.pair-row .input { flex: 1; min-width: 0; }
.pair-label { font-size: 0.82rem; font-weight: 700; color: var(--muted); min-width: 52px; }
.matrix-editor { display: grid; gap: 10px; }
.matrix-wrap { display: flex; align-items: stretch; gap: 6px; width: fit-content; max-width: 100%; overflow-x: auto; padding: 2px; }
.matrix-wrap .bracket { width: 8px; border: 2px solid var(--ink-2); border-right: none; border-radius: 4px 0 0 4px; flex: none; }
.matrix-wrap .bracket.right { border: 2px solid var(--ink-2); border-left: none; border-radius: 0 4px 4px 0; }
.matrix-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), 64px); gap: 6px; padding: 4px 0; }
.matrix-grid .cell { width: 64px; min-width: 0; padding: 0 6px; text-align: center; font-family: var(--mono); }
/* Grid children default to min-width: auto, which lets one wide matrix push the modal sideways. */
.tool-panel > *, .tool-out > *, .answer-box > *, .answer-lines > *, .steps > li { min-width: 0; }
.answer-lines { display: grid; gap: 4px; }
.answer-line { background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; padding: 2px 12px; overflow-x: auto; }
.steps .step-tex, .steps .step-note { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
@media (max-width: 560px) {
  .matrix-grid { grid-template-columns: repeat(var(--cols, 2), 54px); }
  .matrix-grid .cell { width: 54px; }
  .pair-row { flex-direction: column; align-items: stretch; gap: 4px; }
}
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--brand); width: 16px; height: 16px; }

.practice-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.topic-chips .chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.practice-card { display: grid; gap: 12px; padding: 18px; border-radius: 18px; border: 1px solid var(--line-2); background: var(--surface-2); }
.practice-prompt { margin: 0; font-weight: 650; }
.practice-tex { font-size: 1.15rem; overflow-x: auto; }
.practice-actions { display: flex; gap: 8px; }
.feedback { display: grid; gap: 10px; }
.feedback:empty { display: none; }
.result { font-weight: 750; padding: 10px 14px; border-radius: 12px; }
.result.good { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.result.bad { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.solution { padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.feedback .btn.lime { justify-self: start; }

/* Hints before answers */
.ladder { display: grid; gap: 10px; min-width: 0; }
.ladder-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ladder-controls .check.small { font-size: 0.8rem; }
.steps li.hint-step { list-style: none; margin-left: -22px; padding: 8px 12px; border-radius: 12px; border: 1px dashed var(--line-2); background: var(--surface-2); }
.hint-box { display: grid; gap: 4px; padding: 10px 14px; border-radius: 12px; border: 1px dashed var(--line-2); background: var(--surface); }

/* Check my work */
.check-result { display: grid; gap: 10px; min-width: 0; }
.check-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.check-lines li { display: grid; grid-template-columns: 26px 1fr; gap: 8px; align-items: start; padding: 6px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); min-width: 0; }
.check-body { min-width: 0; }
.check-icon { width: 22px; height: 22px; margin-top: 8px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 0.8rem; background: var(--surface-2); color: var(--muted); }
.check-lines li.ok .check-icon { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.check-lines li.wrong { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.check-lines li.wrong .check-icon { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.check-lines li.warn { border-color: color-mix(in srgb, var(--amber) 50%, transparent); }
.check-lines li.warn .check-icon { background: color-mix(in srgb, var(--amber) 20%, transparent); color: var(--amber); }
.check-lines li.first { box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 35%, transparent); }

.photo-preview { position: relative; width: fit-content; }
.photo-preview img { max-height: 160px; max-width: 100%; border-radius: 12px; border: 1px solid var(--line-2); display: block; }
.photo-preview .icon-btn { position: absolute; top: 6px; right: 6px; background: var(--glass); }
.ai-answer { padding: 16px 18px; border-radius: 18px; background: var(--surface-2); border: 1px solid var(--line); line-height: 1.65; }
.math-text p:last-child { margin-bottom: 0; }
.display-math { overflow-x: auto; margin: 6px 0; }
.ai-exprs { display: grid; gap: 8px; }
.ai-expr { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line-2); }
.ai-expr code { font-family: var(--mono); font-weight: 600; }
.ai-expr .btn { margin-left: auto; }
.ai-exprs > .btn { justify-self: start; }
.locked { display: grid; justify-items: center; text-align: center; gap: 8px; padding: 22px; border-radius: 18px; background: var(--gradient-soft); border: 1px solid var(--line-2); }
.locked p { margin: 0; color: var(--ink-2); }
.locked-icon { font-size: 1.6rem; }
.legal-links { margin-top: 16px; text-align: center; color: var(--muted); }
.legal-links a { color: var(--muted); }

/* ---- Printable study sheet (analysis) ---- */
@media print {
  body.app-body { height: auto; overflow: visible; display: block; background: #fff; color: #000; }
  body.app-body > *:not(.overlay) { display: none !important; }
  .overlay { position: static; background: none; backdrop-filter: none; padding: 0; display: block; }
  .modal { width: 100% !important; max-height: none; overflow: visible; box-shadow: none; border: none; padding: 0; background: #fff; color: #000; }
  .modal-close, .no-print, .chips { display: none !important; }
  .an-formula, .an-section { background: #fff !important; border: 1px solid #ccc; break-inside: avoid; }
  .muted { color: #444 !important; }
}

/* ---- Installed app / native shells: keep clear of the notch and home indicator ---- */
.topbar { padding-top: env(safe-area-inset-top); height: calc(58px + env(safe-area-inset-top)); padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
.keypad { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
.native .expr-input, .native .input, .native textarea { font-size: 16px; } /* stops iOS zooming into focused inputs */
.native body { -webkit-user-select: none; user-select: none; }
.native input, .native textarea, .native .ai-answer, .native .tool-out { -webkit-user-select: text; user-select: text; }

/* Daily reminder (native apps) */
.reminder-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; }
input.input.mini { min-height: 32px; height: 32px; width: auto; padding: 0 10px; font-size: 0.85rem; border-radius: 9px; }

/* ---- Data tables ---- */
.tables { border-top: 1px solid var(--line); display: grid; gap: 10px; padding: 10px; background: var(--surface); }
.table-card { border: 1px solid var(--line-2); border-radius: 14px; padding: 10px; background: var(--surface-2); }
.table-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.table-head .icon-btn { width: 30px; height: 30px; font-size: 0.95rem; }
.table-swatch { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.table-name { flex: 1; min-width: 0; border: 1px solid transparent; background: transparent; font-weight: 700; padding: 4px 6px; border-radius: 8px; }
.table-name:focus { border-color: var(--brand); outline: none; background: var(--surface); }
.data-grid { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 0.88rem; }
.data-grid th { text-align: left; color: var(--muted); font-weight: 700; padding: 2px 6px; }
.data-grid td { padding: 2px; }
.data-grid td:last-child { width: 28px; }
.cell { width: 100%; height: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); padding: 0 8px; font-family: var(--mono); }
.cell:focus { border-color: var(--brand); outline: none; }
.cell.bad { border-color: var(--danger); }
.row-del { width: 26px; height: 26px; opacity: 0.5; }
.row-del:hover { opacity: 1; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }
.table-fit-result:empty { display: none; }
.table-fit-result { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--surface); overflow-x: auto; }
.fit-r2 { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }

/* ---- 3D view ---- */
.stage canvas#graph3d { display: block; touch-action: none; cursor: grab; }
.icon-btn.view3d { font-weight: 800; font-size: 0.8rem; background: var(--gradient); color: #fff; }

.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; }

/* ---- Live collaboration ---- */
.cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.live-cursor { position: absolute; left: 0; top: 0; transition: transform 60ms linear; }
.live-cursor::before { content: ''; position: absolute; left: -2px; top: -2px; width: 0; height: 0; border-left: 7px solid var(--c); border-top: 7px solid var(--c); border-right: 7px solid transparent; border-bottom: 7px solid transparent; transform: rotate(0deg); filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.35)); }
.live-cursor-name { position: absolute; left: 12px; top: 10px; background: var(--c); color: #fff; font-size: 0.72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.live-bar { position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-radius: 999px; background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--line-2); box-shadow: var(--shadow); z-index: 3; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 0 rgb(52 211 153 / 0.7); animation: live-pulse 1.8s infinite; }
@keyframes live-pulse { 70% { box-shadow: 0 0 0 8px rgb(52 211 153 / 0); } 100% { box-shadow: 0 0 0 0 rgb(52 211 153 / 0); } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } .live-cursor { transition: none; } }
.live-label { font-weight: 700; font-size: 0.85rem; }
.live-people { display: flex; }
.live-people .avatar.sm { width: 24px; height: 24px; font-size: 0.72rem; margin-left: -6px; border: 2px solid var(--surface); color: #fff; display: grid; place-items: center; border-radius: 50%; font-weight: 700; }
.live-people .avatar.sm:first-child { margin-left: 0; }
.collab-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-2); display: grid; gap: 8px; }
.collab-box h3 { margin: 0; font-size: 1rem; }

/* ---- Notices (exam mode, confirm email) ---- */
.notice-bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; font-size: 0.88rem; background: color-mix(in srgb, var(--brand) 14%, var(--surface)); border-bottom: 1px solid var(--line-2); }
.notice-bar > span { flex: 1; }
.notice-bar.exam { background: color-mix(in srgb, var(--amber) 22%, var(--surface)); }

/* ---- Progress dashboard ---- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 16px; padding: 14px; text-align: center; }
.stat-num { font-family: var(--display); font-size: 1.7rem; font-weight: 800; letter-spacing: -0.03em; }
.stat-label { color: var(--muted); font-size: 0.8rem; }
.section-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 20px 0 8px; }
.bars { display: grid; grid-template-columns: repeat(14, 1fr); gap: 5px; height: 120px; align-items: end; }
.bar-col { display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 4px; }
.bar { align-self: end; height: max(var(--h), 3px); border-radius: 6px 6px 3px 3px; background: linear-gradient(to top, var(--lime, #b6f24a) var(--ok), color-mix(in srgb, var(--brand) 55%, transparent) var(--ok)); }
.bar-day { font-size: 0.7rem; color: var(--muted); text-align: center; }
.skills { display: grid; gap: 10px; }
.skill-head { display: flex; justify-content: space-between; font-size: 0.92rem; margin-bottom: 4px; }
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line-2); overflow: hidden; }
.meter.small { height: 6px; width: 80px; }
.meter-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--pink)); border-radius: inherit; }
.meter-fill[data-weak="true"] { background: var(--amber); }
.review-cta { margin-top: 18px; padding: 14px; border-radius: 16px; background: color-mix(in srgb, var(--amber) 12%, transparent); border: 1px solid var(--line-2); display: grid; gap: 10px; }
.review-cta p { margin: 0; }
.review-tag { display: inline-block; font-size: 0.78rem; font-weight: 700; color: var(--amber); margin-bottom: 6px; }
.empty-state { text-align: center; padding: 20px 6px; display: grid; gap: 12px; justify-items: center; }
.assignment-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-radius: 14px; margin-bottom: 12px; background: color-mix(in srgb, var(--brand) 14%, transparent); border: 1px solid var(--line-2); }

/* ---- Classes ---- */
.class-section + .class-section { margin-top: 10px; }
.class-card { border: 1px solid var(--line-2); border-radius: 16px; padding: 14px; margin-bottom: 10px; background: var(--surface-2); display: grid; gap: 10px; }
.class-head { display: flex; align-items: center; gap: 10px; }
.class-head > div:first-child { flex: 1; min-width: 0; }
.badge.exam { background: color-mix(in srgb, var(--amber) 25%, transparent); color: var(--amber); }
.join-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 800; letter-spacing: 0.18em; font-size: 1.05rem; padding: 6px 10px; border-radius: 10px; border: 1px dashed var(--line-2); background: transparent; color: var(--ink); cursor: copy; }
.code-input { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 700; max-width: 160px; }
.assignments { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.assignment { display: flex; align-items: center; gap: 10px; }
.assignment > div:first-child { flex: 1; min-width: 0; }
.done-tick { color: #34d399; font-weight: 800; font-size: 1.2rem; width: 2rem; text-align: center; }
.exam-toggle { display: flex; gap: 10px; align-items: center; }
.assign-form { display: grid; gap: 8px; margin-top: 8px; }
.assign-form .num { max-width: 90px; }
.teach-new summary, .class-card summary { cursor: pointer; font-weight: 650; color: var(--brand-ink, var(--brand)); }
.table-scroll { overflow-x: auto; }
.roster-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.roster-table th, .roster-table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.roster-table th { color: var(--muted); font-weight: 650; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.roster-table td.complete { color: #34d399; font-weight: 700; }
.locked.exam { border-color: color-mix(in srgb, var(--amber) 40%, transparent); }

/* ---- Draw a curve ---- */
.draw-wrap { display: grid; gap: 10px; }
.draw-wrap h2 { margin: 0; }
.draw-pad { width: 100%; height: auto; aspect-ratio: 640 / 420; border-radius: 14px; border: 1px solid var(--line-2); touch-action: none; cursor: crosshair; background: #fff; }
@media (max-width: 560px) { .stat-num { font-size: 1.3rem; } .bars { height: 90px; } }
.danger-zone .input { margin: 8px 0; width: 100%; }

/* Parametric t / polar θ range under the selected row */
.range-row { align-items: center; }
.range-row .bound { width: 64px; flex: 0 0 64px; }
.bound.bad { border-color: var(--danger, #e5484d); }
