/* data-theme is "light" or "dark": the system's theme, or the one the toolbar's theme button chose. */
:root {
  color-scheme: light;
  --page: #ffffff;
  --chrome: #ececee;
  --chrome-border: #d3d3d8;
  --pane: #f7f7f9;
  --text: #1d1d22;
  --secondary: #6f6f78;
  --accent: #0a6cdf;
  --danger: #c4312f;
  --button-hover: #0000000f;
  --button-active: #0000001c;
  --tile-border: #00000014;
  --tint-blue: #dde9f4;
  --tint-rose: #efe2ea;
  --tint-green: #e3eedd;
  --tint-violet: #e6e3f2;
  --tint-amber: #f3ead8;
  --vt-slot: #c6e4fb;
  --vt-slot-active: #9ccff5;
  --vt-caret: var(--text);
  --line-rule: #d6d8ea;
  --tile-w: 56px;
  --tile-h: 48px;
  --bottom-height: 280px;
  font: 13px -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #1f1f22;
  --chrome: #2c2c30;
  --chrome-border: #3f3f45;
  --pane: #262629;
  --text: #ececf0;
  --secondary: #a0a0aa;
  --accent: #4b9bff;
  --danger: #ff8a85;
  --button-hover: #ffffff14;
  --button-active: #ffffff24;
  --tile-border: #ffffff12;
  --tint-blue: #2b3846;
  --tint-rose: #3d2f38;
  --tint-green: #2f3a2c;
  --tint-violet: #34314a;
  --tint-amber: #3e3627;
  --vt-slot: #2a4865;
  --vt-slot-active: #3b6d99;
  --line-rule: #3c3e4e;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--page); color: var(--text); -webkit-user-select: none; user-select: none; }
button, select, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(80px, 1fr) 5px auto var(--bottom-height); height: 100vh; }

/* Equation canvas */
#canvas { position: relative; overflow: auto; background: var(--page); cursor: text; }
#field-host { display: flex; flex-direction: column; min-height: 100%; padding: 10px 22px 40px; }
/* One field per line, each on its own dotted rule. */
math-field {
  /* The page disables text selection; MathLive needs it to place the caret where you click. */
  -webkit-user-select: text; user-select: text;
  display: block; width: 100%; min-height: 1.6em; padding: 6px 2px 8px;
  border: 0; border-bottom: 1px dotted var(--line-rule); outline: none; background: transparent;
  color: var(--text); font-size: 40px;
  --caret-color: var(--text);
  --selection-background-color: #b4d5fe;
  --selection-color: inherit;
  --contains-highlight-background-color: transparent;
  --smart-fence-color: #8f8f99;
}
math-field::part(menu-toggle), math-field::part(virtual-keyboard-toggle) { display: none; }
math-field::part(container) { padding: 0; }
:root[data-theme="dark"] math-field { --selection-background-color: #2d5a8c; }
#greek-indicator {
  position: absolute; top: 10px; right: 14px; padding: 2px 8px; border-radius: 10px;
  background: var(--accent); color: white; font-size: 11px; font-weight: 600; pointer-events: none;
}

#splitter { cursor: row-resize; background: var(--chrome); border-top: 1px solid var(--chrome-border); }

/* Toolbar */
#toolbar {
  display: flex; align-items: center; gap: 4px; padding: 3px 10px 5px;
  background: var(--chrome); border-bottom: 1px solid var(--chrome-border);
}
#toolbar .group { display: flex; align-items: center; gap: 1px; padding-right: 7px; margin-right: 3px; border-right: 1px solid var(--chrome-border); }
#toolbar .group:last-of-type { border-right: 0; }
#toolbar .spacer { flex: 1; }
#toolbar button {
  height: 26px; min-width: 28px; padding: 0 5px; border: 0; border-radius: 5px;
  background: transparent; display: inline-flex; align-items: center; justify-content: center;
}
#toolbar button:hover { background: var(--button-hover); }
#toolbar button:active { background: var(--button-active); }
#toolbar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
#toolbar .glyph { font: 16px "Times New Roman", Times, serif; }
#toolbar .bold { font-weight: 700; }
#toolbar .italic { font-style: italic; }
#toolbar .text { font: 600 12px "Times New Roman", Times, serif; letter-spacing: -.02em; }
#font-size { height: 22px; margin-left: 4px; border: 1px solid var(--chrome-border); border-radius: 5px; background: var(--page); padding: 0 4px; }
.color { display: inline-flex; width: 26px; height: 22px; margin-left: 4px; border-radius: 5px; overflow: hidden; border: 1px solid var(--chrome-border); }
.color input { width: 40px; height: 32px; margin: -6px -8px; border: 0; padding: 0; background: none; }

.segmented { display: flex; padding: 2px; border-radius: 7px; background: var(--button-hover); }
.segmented button { height: 22px !important; padding: 0 12px !important; font-size: 12px; }
.segmented button[aria-selected="true"] { background: var(--page) !important; box-shadow: 0 1px 2px #0000002a; }

/* Bottom pane */
#bottom { min-height: 0; min-width: 0; background: var(--pane); }
#symbols-pane, #code-pane { display: flex; flex-direction: column; height: 100%; min-width: 0; }

#tabs {
  display: flex; gap: 2px; padding: 5px 10px 0; overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
  border-bottom: 1px solid var(--chrome-border);
}
#tabs::-webkit-scrollbar { display: none; }
#tabs button {
  flex-shrink: 0; height: 32px; min-width: 70px; padding: 0 14px; border: 1px solid transparent; border-bottom: 0;
  border-radius: 7px 7px 0 0; background: transparent; color: var(--secondary);
  display: inline-flex; align-items: center; justify-content: center;
}
#tabs button { font-size: 14px; }
#tabs button svg { max-height: 21px; max-width: 70px; overflow: visible; }
#tabs button:hover { color: var(--text); background: var(--button-hover); }
#tabs button[aria-selected="true"] { color: var(--text); background: var(--page); border-color: var(--chrome-border); margin-bottom: -1px; }

/* Every category side by side, four rows each, in one sideways-scrolling strip. */
#strip {
  flex: 1; display: flex; align-items: flex-start; gap: 16px; padding: 12px 14px 14px;
  overflow-x: auto; overflow-y: hidden; background: var(--page); scroll-padding: 0 10px;
}
.group {
  flex: none; display: grid; grid-template-columns: repeat(var(--columns), var(--tile-w));
  grid-template-rows: repeat(4, var(--tile-h)); gap: 1px; padding: 1px; border-radius: 7px; background: var(--tile-border);
}
.group[data-tint="blue"] { --tint: var(--tint-blue); }
.group[data-tint="rose"] { --tint: var(--tint-rose); }
.group[data-tint="green"] { --tint: var(--tint-green); }
.group[data-tint="violet"] { --tint: var(--tint-violet); }
.group[data-tint="amber"] { --tint: var(--tint-amber); }
.tile {
  position: relative; width: 100%; height: 100%; border: 0; padding: 6px 7px 13px;
  background: var(--tint); color: var(--text); font-size: 16px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.group .tile:first-child { border-top-left-radius: 6px; }
.tile:hover { filter: brightness(.95); }
.tile:active { filter: brightness(.88); }
:root[data-theme="dark"] .tile:hover { filter: brightness(1.2); } :root[data-theme="dark"] .tile:active { filter: brightness(1.35); }
.tile svg { max-width: 100%; max-height: 100%; width: auto; height: auto; }
/* Integrals, large operators, matrices: tiles two rows tall and half again as wide, display style. */
.group.large {
  grid-template-columns: repeat(var(--columns), calc(var(--tile-w) * 1.5));
  grid-template-rows: repeat(2, calc(var(--tile-h) * 2 + 1px));
}
.group.large .tile { font-size: 20px; padding: 8px 9px 15px; }
/* The shortcut sits in its own strip along the bottom edge, below the glyph's padding box. */
.tile .key {
  position: absolute; left: 2px; right: 3px; bottom: 1px; text-align: right;
  font: 600 9px/11px -apple-system, sans-serif; color: var(--secondary); pointer-events: none;
}

#code-pane { display: flex; flex-direction: column; height: 100%; }

#code-pane { background: var(--page); }
#code-wrap { position: relative; flex: 1; min-height: 0; }
#code, #code-mirror {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; border: 0; padding: 12px 16px;
  font: 14px/1.55 "SF Mono", Menlo, monospace; tab-size: 2; white-space: pre-wrap; overflow-wrap: break-word;
}
#code {
  resize: none; outline: none; overflow: auto;
  background: transparent; color: var(--text); -webkit-user-select: text; user-select: text;
}
#code-mirror { overflow: hidden; color: transparent; background: var(--page); pointer-events: none; }
/* Matching brackets: in the LaTeX code, and in the equation (.vt-match on the delimiters' elements). */
#code-mirror mark { color: transparent; background: var(--bracket-match); border-radius: 2px; }
:root { --bracket-match: #f6d77a; }
:root[data-theme="dark"] { --bracket-match: #6b5a1e; }
#code-status { padding: 5px 16px 7px; min-height: 26px; font-size: 11px; color: var(--secondary); border-top: 1px solid var(--chrome-border); background: var(--pane); }
#code-status.error { color: var(--danger); }

/* Command candidates (typing \name), like an input method's candidate bar */
#candidates { position: fixed; z-index: 30; pointer-events: none; }
.cand-preedit {
  position: fixed; padding: 0 2px; background: var(--page); color: #2f6fe4;
  font: 400 var(--preedit-size, 30px)/1.15 "Times New Roman", Times, serif; white-space: nowrap;
}
.cand-list {
  position: fixed; display: flex; pointer-events: auto; border-radius: 4px; overflow: hidden;
  box-shadow: 0 6px 20px #00000038; border: 1px solid #00000030;
}
.cand { display: flex; flex-direction: column; min-width: 46px; border: 0; padding: 0; background: none; cursor: default; }
.cand + .cand { border-left: 1px solid #ffffff55; }
.cand-label {
  padding: 3px 7px; background: #6b4518; color: #fff; white-space: nowrap;
  font: 13px/1.3 -apple-system, "Helvetica Neue", sans-serif;
}
.cand-glyph {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 5px 8px;
  background: #f3e6ea; color: #17191d; font-size: 18px;
}
.cand-glyph svg { max-height: 40px; max-width: 120px; }
.cand.current .cand-label { background: #8d5c1f; }
.cand.current .cand-glyph, .cand:hover .cand-glyph { background: #e7d1d9; }
.cand-more { display: flex; align-items: center; padding: 0 7px; background: #6b4518; color: #fff; font-size: 12px; }
:root[data-theme="dark"] .cand-preedit { color: #6ea8ff; }
:root[data-theme="dark"] .cand-glyph { background: #3a2f36; color: #ececf0; }
:root[data-theme="dark"] .cand.current .cand-glyph, :root[data-theme="dark"] .cand:hover .cand-glyph { background: #4a3a44; }

/* Popovers */
.popover {
  position: fixed; z-index: 20; min-width: 120px; padding: 5px; border-radius: 8px;
  background: var(--page); border: 1px solid var(--chrome-border); box-shadow: 0 8px 28px #00000033;
}
#export-menu button { display: block; width: 100%; text-align: left; padding: 4px 10px; border: 0; border-radius: 4px; background: none; }
#export-menu button:hover { background: var(--accent); color: white; }
#recorder { padding: 10px 14px; text-align: center; }
.recorder-title { font-weight: 600; margin-bottom: 4px; }
.recorder-keys { font-size: 18px; margin: 6px 0; }
.recorder-hint { font-size: 11px; color: var(--secondary); }

/* Shortcuts sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-start; justify-content: center; background: #0000002a; }
.sheet {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); margin-top: 20px; display: flex; flex-direction: column;
  border-radius: 12px; background: var(--pane); border: 1px solid var(--chrome-border); box-shadow: 0 18px 50px #00000040;
}
.sheet header { display: flex; align-items: center; gap: 12px; padding: 14px 16px 4px; }
.sheet h1 { flex: 1; margin: 0; font-size: 14px; }
.sheet input[type="search"] { width: 160px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--chrome-border); background: var(--page); }
.sheet-hint { margin: 2px 16px 8px; color: var(--secondary); font-size: 11px; }
#shortcut-list { flex: 1; overflow: auto; margin: 0 12px; border: 1px solid var(--chrome-border); border-radius: 8px; background: var(--page); }
.shortcut-row { display: grid; grid-template-columns: 64px 1fr auto 24px; align-items: center; gap: 8px; padding: 4px 8px; border-bottom: 1px solid var(--chrome-border); }
.shortcut-row:last-child { border-bottom: 0; }
.shortcut-row .glyph { display: flex; justify-content: center; font-size: 14px; }
.shortcut-row .glyph svg { max-width: 60px; max-height: 30px; }
.shortcut-row .name { color: var(--secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.keycap { min-width: 70px; padding: 2px 10px; border: 1px solid var(--chrome-border); border-radius: 5px; background: var(--pane); font-size: 13px; }
.keycap.recording { border-color: var(--accent); color: var(--accent); }
.remove { border: 0; background: none; color: var(--secondary); font-size: 15px; }
.remove:hover { color: var(--danger); }
.sheet footer { display: flex; gap: 8px; padding: 12px 16px 14px; }
.sheet footer .spacer { flex: 1; }
.sheet footer button { padding: 3px 14px; border-radius: 6px; border: 1px solid var(--chrome-border); background: var(--page); }
.sheet footer .primary { background: var(--accent); color: white; border-color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-height) + 56px); transform: translateX(-50%) translateY(8px);
  padding: 6px 14px; border-radius: 14px; background: #000000c0; color: white; font-size: 12px;
  opacity: 0; transition: opacity .18s, transform .18s; pointer-events: none;
}
#toast.visible { opacity: 1; transform: translateX(-50%); }

/* The web edition (a browser, without the app) has no PDF export. */
.web-edition #export-menu [data-format="pdf"] { display: none; }
