:root {
  --page: #e9ecf1;
  --surface: #ffffff;
  --teacher: #3f3cbb;
  --student: #9a6206;
  --text: #151a23;
  --border: rgba(21, 26, 35, 0.12);
  --danger: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0e1118;
    --surface: #171c26;
    --teacher: #8a87f5;
    --student: #f0b64a;
    --text: #eef1f6;
    --border: rgba(238, 241, 246, 0.14);
  }
}

:root[data-theme="dark"] {
  --page: #0e1118;
  --surface: #171c26;
  --teacher: #8a87f5;
  --student: #f0b64a;
  --text: #eef1f6;
  --border: rgba(238, 241, 246, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page);
  color: var(--text);
  font-family: 'Archivo', system-ui, sans-serif;
}

.mono {
  font-family: 'Azeret Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.screen { display: none; flex: 1; flex-direction: column; gap: 16px; max-width: 480px; margin: 0 auto; width: 100%; }
.screen.active { display: flex; }

h1 { font-size: 1.1rem; font-weight: 600; margin: 0; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 8px; }

label { display: block; font-size: 0.85rem; margin-bottom: 4px; opacity: 0.8; }

select, input[type="email"], input[type="text"], input[type="password"] {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.field { margin-bottom: 14px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  margin-bottom: 4px;
}
.checkbox-row input { width: 18px; height: 18px; }
.field.missing select, .field.missing input { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 0.8rem; margin-top: 4px; display: none; }
.field.missing .field-error { display: block; }

button {
  font-family: inherit;
  font-size: 1rem;
  border-radius: 10px;
  border: none;
  padding: 14px;
  cursor: pointer;
}

.btn-primary { background: var(--teacher); color: white; font-weight: 600; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-row { display: flex; gap: 10px; }
.btn-row button { flex: 1; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chip button { padding: 0; border: none; background: none; color: inherit; font-size: 1rem; line-height: 1; cursor: pointer; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.resume-banner { border: 1px solid var(--teacher); }

/* Recording screen */
#screen-recording { gap: 12px; }

.rec-header { display: flex; justify-content: space-between; align-items: baseline; }
.rec-header .room { opacity: 0.7; font-size: 0.9rem; }

.class-clock { text-align: center; font-size: 1.8rem; }

.ratio-bar {
  height: 34px;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  border: 1px solid var(--border);
}
.ratio-bar .seg { flex: none; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 600; color: white; transition: width 0.3s ease; white-space: nowrap; overflow: hidden; }
.ratio-bar .seg.teacher { background: var(--teacher); }
.ratio-bar .seg.student { background: var(--student); }

.tap-button {
  flex: 1;
  min-height: 40vh;
  border-radius: 20px;
  border: none;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
}
.tap-button.teacher { background: var(--teacher); }
.tap-button.student { background: var(--student); }
.tap-button.paused { background: #5a5f6b; }
.tap-button .who { font-size: 1.6rem; font-weight: 700; }
.tap-button .turn-time { font-size: 2.4rem; }
.tap-button .next { font-size: 0.9rem; opacity: 0.85; }

.controls-row { display: flex; gap: 10px; }
.controls-row button { flex: 1; }

.sync-indicator { font-size: 0.75rem; opacity: 0.6; text-align: center; }

/* Summary */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-grid .stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.stat .label { font-size: 0.75rem; opacity: 0.7; }
.stat .value { font-size: 1.3rem; }
.stat .value.teacher { color: var(--teacher); }
.stat .value.student { color: var(--student); }

.timeline-strip { height: 24px; border-radius: 6px; overflow: hidden; display: flex; border: 1px solid var(--border); }
.timeline-strip .seg.teacher { background: var(--teacher); }
.timeline-strip .seg.student { background: var(--student); }

.turn-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; }
.turn-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); font-size: 0.85rem; }
.turn-row .who.teacher { color: var(--teacher); font-weight: 600; }
.turn-row .who.student { color: var(--student); font-weight: 600; }
.mode-toggle { display: flex; gap: 4px; }
.mode-toggle button { padding: 4px 8px; font-size: 0.75rem; }
.mode-toggle button.active { background: var(--teacher); color: white; }

.top-bar { display: flex; justify-content: space-between; align-items: center; }
.link-btn { background: none; border: none; color: var(--text); opacity: 0.7; text-decoration: underline; padding: 4px; font-size: 0.85rem; }

.hint { font-size: 0.85rem; opacity: 0.7; }

/* Modal (replaces window.confirm/prompt everywhere) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  max-width: 360px;
  width: 100%;
}
.modal-message { margin: 0 0 16px; font-size: 1rem; line-height: 1.4; }
.modal-input { margin-bottom: 16px; }
.modal-actions button { flex: 1; }

.manage-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border, rgba(128,128,128,0.25)); }
.manage-row span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.manage-row button { padding: 6px 10px; font-size: 0.85rem; }

.history-row { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left; padding: 12px; margin-bottom: 8px; background: none; border: 1px solid rgba(128,128,128,0.35); border-radius: 8px; color: inherit; font: inherit; }
.history-row span { font-size: 0.85rem; opacity: 0.7; }
