:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2433; --muted: #6b7280;
  --border: #e3e5ea; --primary: #2f6fed; --accent: #0f9d74; --error: #d33;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14161b; --card: #1d2027; --text: #e8eaf0; --muted: #9aa1ad; --border: #2c3039; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, Segoe UI, sans-serif; }

/* ---------- Join screen ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.narrow { max-width: 380px; margin: 10vh auto; display: flex; flex-direction: column; gap: 12px; }
h1 { margin: 0 0 8px; font-size: 1.5rem; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
label.row { flex-direction: row; align-items: center; gap: 8px; }
label.inline { margin: 0; white-space: nowrap; }
label.inline input { width: auto; }

/* ---------- Session screen: one screen, no page scroll ---------- */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 10px; padding: 10px 16px 14px; max-width: 1600px; margin: 0 auto; }
.topbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.col { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.compact { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; }
/* Tutor controls: two short rows, so the answers get the rest of the screen. */
#tutorControls input, #tutorControls textarea, #tutorControls select { padding: 5px 8px; }
#tutorControls button { padding: 5px 10px; }
#questionInput { resize: none; min-height: 34px; max-height: 20vh; field-sizing: content; }
#micRow { flex-wrap: nowrap; gap: 6px; }
#topic { flex: 1; min-width: 80px; width: auto; }
.question-card { flex-shrink: 0; padding: 8px 14px; }
.question-card h2 { margin-bottom: 2px; }
.question { font-size: 1.15rem; font-weight: 600; white-space: pre-wrap; max-height: 16vh; overflow-y: auto; }
#answer { flex: 1; min-height: 60px; resize: none; }
#manualBox { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
#manualBox textarea { resize: vertical; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px; }

h2 { margin: 0 0 8px; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
input, textarea, select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
select { width: auto; }
textarea { resize: vertical; }
textarea[readonly] { opacity: .9; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
#micRow { margin-top: 0; }
button { font: inherit; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--primary); color: #fff; cursor: pointer; white-space: nowrap; }
button.accent { background: var(--accent); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.small-btn { padding: 4px 10px; font-size: .85rem; }
button:disabled { opacity: .45; cursor: default; }
button.recording { background: var(--error); color: #fff; border-color: var(--error); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .7; } }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.small a { color: var(--primary); }
#micStatus:empty, #topicLine:empty { display: none; }
.error { color: var(--error); min-height: 1.2em; margin: 0; }
.badge { font-size: .75rem; text-transform: none; letter-spacing: 0; margin-left: 6px; color: var(--accent); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .8rem; margin-left: 4px; background: var(--border); }
.pill.me { background: var(--primary); color: #fff; font-weight: 600; }

.ai h2 { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--text); margin-top: 14px; }
.ai h2:first-child { margin-top: 0; }
.ai pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow-x: auto; }
.ai code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }

/* ---------- History popup ---------- */
dialog { width: min(800px, calc(100vw - 32px)); max-height: 85vh; border: 1px solid var(--border); border-radius: 12px; background: var(--card); color: var(--text); padding: 16px; }
dialog::backdrop { background: rgb(0 0 0 / .4); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.hist { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.hist h3 { margin: 0 0 6px; font-size: 1rem; }

/* ---------- Small or short screens: fall back to normal scrolling ---------- */
@media (max-width: 900px), (max-height: 560px) {
  .app { height: auto; }
  .grid { grid-template-columns: 1fr; }
  #answer { min-height: 160px; }
  #micRow { flex-wrap: wrap; }
  .scroll { overflow: visible; }
  .grid .col:last-child .grow { min-height: 240px; }
}
.model-label { float: right; font-size: .75rem; text-transform: none; letter-spacing: 0; font-weight: 400; }
.file-btn { display: inline-flex; flex-direction: row; align-items: center; cursor: pointer; background: var(--primary); color: #fff; border-radius: 8px; padding: 8px 14px; font-size: 1rem; }
.file-btn input { display: none; }
button.has-resume { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.resume-text { white-space: pre-wrap; font: .85rem/1.5 ui-monospace, Menlo, monospace; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; max-height: 55vh; overflow-y: auto; margin: 10px 0 0; }
#resumeStatus { margin-top: 8px; }

/* Students don't see the answer column: give the question and answer the full width. */
.student-view .grid { grid-template-columns: minmax(0, 1fr); max-width: 900px; width: 100%; margin: 0 auto; }

/* Tutors don't see the student's answer box: controls and question share one short strip at the top,
   and the AI answer gets the full width and the rest of the height. */
.tutor-view .grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 10px; }
.tutor-view .grid > .col:first-child { flex-direction: row; align-items: stretch; }
.tutor-view #tutorControls, .tutor-view .question-card { flex: 1; min-width: 0; }
.tutor-view .question { max-height: 12vh; }
@media (max-width: 900px) {
  .tutor-view .grid > .col:first-child { flex-direction: column; }
}
