/* Math Translator – big, simple, works on phone, tablet and laptop */

:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #121826;
  --muted: #5b6475;
  --line: #d9dee8;
  --teacher: #1f5fbf;
  --teacher-soft: #e6eefb;
  --student: #0d7c66;
  --student-soft: #e2f4ef;
  --warn: #b35c00;
  --warn-soft: #fff1df;
  --danger: #b42318;
  --font: "Segoe UI", Roboto, "Noto Sans", "Noto Sans Hebrew", Arial, sans-serif;
  --math: "Cambria Math", "STIX Two Math", "Noto Serif", "Times New Roman", serif;
  --base: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --panel: #1a212d;
    --text: #eef1f6;
    --muted: #9aa4b5;
    --line: #2d3746;
    --teacher: #6ea2ff;
    --teacher-soft: #1b2a45;
    --student: #3fc7a6;
    --student-soft: #15342e;
    --warn: #ffb35c;
    --warn-soft: #3a2a14;
    --danger: #ff6b5e;
  }
}

body.size-normal { --base: 16px; }
body.size-large { --base: 19px; }
body.size-huge { --base: 23px; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--base);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 1.05em; font-weight: 600; }
.top .swap { color: var(--muted); }
.icon-btn {
  border: 0;
  background: transparent;
  font-size: 1.4em;
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
}
.icon-btn:active { background: var(--line); }

/* ---------- Chat ---------- */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 1.1em; }
.empty p { margin: 6px 0; }

.msg {
  max-width: 88%;
  border-radius: 16px;
  padding: 10px 14px;
  background: var(--panel);
  border: 2px solid var(--line);
}
.msg.teacher { align-self: flex-start; border-color: var(--teacher); background: var(--teacher-soft); border-top-left-radius: 4px; }
.msg.student { align-self: flex-end; border-color: var(--student); background: var(--student-soft); border-top-right-radius: 4px; }
.msg .who { font-size: 0.75em; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.msg .src { color: var(--muted); font-size: 0.85em; margin-bottom: 6px; white-space: pre-wrap; }
.msg .out { font-size: 1.35em; line-height: 1.45; white-space: pre-wrap; }
.msg .out[dir="rtl"], .msg .src[dir="rtl"] { text-align: right; }
.msg.pending .out { color: var(--muted); }
.msg .error { color: var(--danger); font-size: 0.9em; }
.msg.flagged { outline: 3px dashed var(--warn); outline-offset: 2px; }

.m { font-family: var(--math); unicode-bidi: isolate; direction: ltr; white-space: nowrap; }
.m i { font-style: italic; }
.mg { font-family: var(--math); unicode-bidi: isolate; }
.m .u { font-family: var(--font); font-size: 0.9em; }
.frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  font-size: 0.8em;
  line-height: 1.1;
  margin: 0 0.1em;
}
.frac .fn { border-bottom: 0.09em solid currentColor; padding: 0 0.15em; }
.frac .fd { padding: 0 0.15em; }

.box {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  direction: ltr;
}
.box .m {
  font-size: 1.6em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 12px;
}

.terms { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.8em;
}
.chip.missing { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.chip bdi { unicode-bidi: isolate; }

.actions { display: flex; justify-content: flex-end; gap: 4px; margin-top: 4px; }
.actions .icon-btn { font-size: 1.15em; min-width: 40px; min-height: 40px; }

/* ---------- Bottom ---------- */
.phrases-bar {
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 10px;
  font-size: 0.95em;
}
.sides {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}
.side { display: flex; gap: 6px; }
.mic {
  flex: 1;
  border: 0;
  border-radius: 18px;
  color: #fff;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.15);
}
.teacher .mic { background: var(--teacher); }
.student .mic { background: var(--student); }
@media (prefers-color-scheme: dark) { .mic { color: #0b0f15; } }
.mic:active { transform: scale(0.98); }
.mic-icon { width: 2.4em; height: 2.4em; display: block; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.25)); }
#composer-mic { display: flex; align-items: center; justify-content: center; }
#composer-mic .mic-icon { width: 1.9em; height: 1.9em; }
.mic-lang { font-weight: 700; font-size: 1.15em; letter-spacing: 0.03em; }
.mic-who { font-size: 0.8em; opacity: 0.9; }
.kbd {
  width: 52px;
  border: 2px solid var(--line);
  background: var(--bg);
  border-radius: 14px;
  font-size: 1.3em;
}

/* ---------- Sheets (panels that slide up) ---------- */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 10; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 10px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 -4px 20px rgb(0 0 0 / 0.2);
  max-width: 900px;
  margin: 0 auto;
}
.sheet.tall { height: 85dvh; }
.sheet[hidden], .backdrop[hidden], .toast[hidden] { display: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head > :first-child { flex: 1; font-weight: 600; }
.sheet-head input { font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }

#composer-text {
  width: 100%;
  font: inherit;
  font-size: 1.3em;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
#composer.fi #composer-text:focus { border-color: var(--teacher); outline: none; }
#composer.he #composer-text:focus { border-color: var(--student); outline: none; }
.status { min-height: 1.2em; color: var(--muted); font-size: 0.9em; }
.status.listening { color: var(--danger); font-weight: 600; }
.mathkeys { display: flex; flex-wrap: wrap; gap: 6px; direction: ltr; }
.mathkeys button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  font-family: var(--math);
  font-size: 1.2em;
}
.composer-actions { display: flex; gap: 10px; }
.big-btn {
  flex: 1;
  min-height: 56px;
  border-radius: 14px;
  border: 0;
  font-size: 1.3em;
  font-weight: 600;
}
.big-btn.primary { background: var(--teacher); color: #fff; }
#composer.he .big-btn.primary { background: var(--student); }
.big-btn.secondary { background: var(--bg); border: 2px solid var(--line); }
.big-btn.danger { background: transparent; border: 2px solid var(--danger); color: var(--danger); font-size: 1em; }
#composer-mic.listening { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

.tabs { display: flex; gap: 6px; }
.tab {
  border: 2px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 600;
}
.tab.active[data-speaker="teacher"] { border-color: var(--teacher); color: var(--teacher); }
.tab.active[data-speaker="student"] { border-color: var(--student); color: var(--student); }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li { border-bottom: 1px solid var(--line); }
.list button {
  width: 100%;
  text-align: start;
  background: transparent;
  border: 0;
  padding: 12px 6px;
  display: block;
}
.list .main { font-size: 1.05em; }
.list .sub { color: var(--muted); font-size: 0.9em; margin-top: 2px; }
.list .he { direction: rtl; text-align: right; }
.list .row3 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; align-items: baseline; }
.list .en { color: var(--muted); font-size: 0.85em; }
.list .mathline { grid-column: 1 / -1; font-size: 0.95em; }

#glossary-course { font: inherit; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }

#card-body .big { font-size: 1.6em; font-weight: 600; }
#card-body .he { direction: rtl; text-align: right; }
#card-body .mathline { font-size: 1.5em; margin: 10px 0; display: flex; gap: 16px; flex-wrap: wrap; }
#card-body .label { color: var(--muted); font-size: 0.8em; }
#card-body .note { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 10px; margin-top: 8px; }
#card-body .ex { margin-top: 8px; }

.settings { overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.settings .row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.settings .row select, .settings .row input[type="range"] { font: inherit; flex: 1; min-width: 140px; }
.settings input[type="checkbox"] { width: 24px; height: 24px; }
.settings .buttons { flex-direction: column; align-items: stretch; }
.small { color: var(--muted); font-size: 0.85em; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 140px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 20;
  max-width: 90vw;
  text-align: center;
}

/* Tablet and laptop: a bit more room */
@media (min-width: 700px) {
  .mic { min-height: 110px; }
  .msg { max-width: 75%; }
}
