/* Class Screen — classroom display styles.
   Calm, high-contrast, large-type design meant to be read from across a room
   on a ClearTouch board or wall TV. Optimized for 1920x1080 and 3840x2160
   landscape, and degrades gracefully in a smaller browser window. */

:root {
  --bg: #0b1220;
  --bg-raised: #121b2e;
  --ink: #f5f7fb;
  --ink-dim: #a8b3c7;
  --accent: #38bdf8;
  --border: #243252;
  --danger: #f87171;
  --good: #34d399;

  --course-color: #38bdf8; /* overridden inline per course */

  /* Fluid type scale: min at a small window, max at 4K. The max bound is
     deliberately high (not ~1920px-sized) so text keeps growing in
     proportion to the screen all the way out to a 3840px-wide 4K display
     instead of flattening out at 1080p size. */
  --fs-target: clamp(2rem, 4.6vw, 11rem);
  --fs-assignment: clamp(1.4rem, 3vw, 7.5rem);
  --fs-meta: clamp(0.95rem, 1.3vw, 3.2rem);
  /* Timer/picker hero text is bounded by min(vw, vh) — not vw alone — so it
     can't outgrow the vertical space actually left under the header
     (especially the compact header, see .header.compact below) and get
     clipped by `overflow: hidden` on <body>. */
  --fs-timer: clamp(3rem, min(15vw, 22vh), 20rem);
  --fs-picker-name: clamp(2.5rem, min(11vw, 16vh), 16rem);
  --fs-eyebrow: clamp(0.8rem, 1vw, 2rem);

  /* Shrunk header sizing used while the Timer or Picker panel is open, so
     a long "I can..." target doesn't eat the room those panels need. */
  --fs-target-compact: clamp(1rem, 2vw, 2.4rem);
  --fs-assignment-compact: clamp(0.85rem, 1.3vw, 1.5rem);
  --fs-meta-compact: clamp(0.8rem, 1vw, 1.3rem);

  /* Assignment-panel logo height. Tuned to roughly match the assignment
     text block's own height in each mode (full vs. compact) — a fixed
     clamp rather than a CSS "stretch to sibling" trick, which broke badly
     here: the logo's own height is auto/content-driven (inside a flex
     column with no definite height), so a percentage height on the image
     fell back to its large intrinsic pixel size instead of matching text. */
  --logo-height: clamp(3.5rem, 7vw, 13rem);
  --logo-height-compact: clamp(1.6rem, 3vw, 3.5rem);

  --touch: clamp(44px, 4vw, 72px);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

button, select, input, textarea {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 4px solid var(--accent);
  outline-offset: 2px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ---------- Header ---------- */

.header {
  padding: clamp(1rem, 2vw, 2.5rem) clamp(1.25rem, 3vw, 3.5rem) clamp(0.75rem, 1.5vw, 1.5rem);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  /* Idle (not .compact): grow to fill the whole app height, since main
     collapses to near-nothing below it (see ".header:not(.compact) + .main"
     further down) — the target/assignment are the whole screen until the
     Timer or Picker is opened. */
  flex: 1 1 auto;
  min-height: 0;
  transition: padding 0.15s ease;
}

.header-meta {
  flex: 0 0 auto;
}

.content-fill {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* While the Timer or Picker panel is open: the target/assignment stay
   visible (per spec — never hidden), just much smaller and pinned to the
   top, so the panel that was actually opened has the rest of the screen. */
.header.compact {
  flex: 0 0 auto;
  padding: clamp(0.5rem, 1vw, 1rem) clamp(1.25rem, 3vw, 3.5rem) clamp(0.4rem, 0.8vw, 0.75rem);
}

.header.compact .content-fill {
  flex: 0 0 auto;
  justify-content: flex-start;
}

.header.compact .header-meta {
  font-size: var(--fs-meta-compact);
  margin-bottom: 0.3em;
}

.header.compact .clear-target {
  font-size: var(--fs-target-compact);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.header.compact .assignment-block {
  margin-top: 0.4em;
  padding-top: 0.4em;
}

.header.compact .assignment {
  font-size: var(--fs-assignment-compact);
}

.header.compact .additional-list {
  display: none;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.6em;
  flex-wrap: wrap;
  font-size: var(--fs-meta);
  color: var(--ink-dim);
  margin-bottom: clamp(0.5rem, 1.2vw, 1.2rem);
}

.header-meta .course-name {
  color: var(--course-color);
  font-weight: 700;
}

.dot {
  opacity: 0.5;
}

.badge {
  font-size: 0.7em;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.25em 0.7em;
  border-radius: 999px;
  text-transform: uppercase;
}

.badge-manual {
  background: #7c2d12;
  color: #fed7aa;
}

.badge-preview {
  background: #4c1d95;
  color: #e9d5ff;
}

.eyebrow {
  margin: 0;
  font-size: var(--fs-eyebrow);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  font-weight: 700;
}

.clear-target {
  margin: 0.1em 0 0;
  font-size: var(--fs-target);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.assignment-block {
  margin-top: clamp(0.6rem, 1.4vw, 1.4rem);
  border-top: 1px solid var(--border);
  padding-top: clamp(0.6rem, 1.4vw, 1.4rem);
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 2vw, 2rem);
}

/* display:flex above would otherwise override the `hidden` attribute's
   default display:none (author styles beat the UA stylesheet) — this bit
   the Teacher Panel overlay earlier for the same reason; same fix here. */
.assignment-block[hidden] {
  display: none;
}

.assignment-logo {
  height: var(--logo-height);
  width: auto;
  flex-shrink: 0;
  object-fit: contain;
}

.header.compact .assignment-logo {
  height: var(--logo-height-compact);
}

.assignment-text {
  flex: 1 1 auto;
  min-width: 0;
}

.assignment {
  margin: 0.1em 0 0;
  font-size: var(--fs-assignment);
  font-weight: 700;
  color: var(--ink);
}

.additional-list {
  margin: 0.5em 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em 1.2em;
  font-size: clamp(0.85rem, 1.3vw, 1.3rem);
  color: var(--ink-dim);
}

.additional-list li::before {
  content: "• ";
  opacity: 0.6;
}

/* ---------- Main / panels ---------- */

.main {
  flex: 1;
  position: relative;
  overflow: hidden;
  padding: clamp(1rem, 2vw, 2rem) clamp(1.25rem, 3vw, 3.5rem);
  display: flex;
  transition: flex-basis 0.15s ease;
}

/* Idle: header (target/assignment) fills the screen, so main collapses to
   just enough room for the small idle hint line above the toolbar. */
.header:not(.compact) + .main {
  flex: 0 0 auto;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}

.panel {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: clamp(0.75rem, 2vw, 2rem);
}

.panel[data-active="true"] {
  display: flex;
}

.idle-hint {
  color: var(--ink-dim);
  font-size: clamp(0.7rem, 0.9vw, 1rem);
  opacity: 0.65;
  margin: 0;
}

/* Timer */

.timer-display {
  font-size: var(--fs-timer);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer-display[data-done="true"] {
  color: var(--danger);
  animation: pulse 1s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .timer-display[data-done="true"] {
    animation: none;
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.timer-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em;
  justify-content: center;
}

.timer-custom {
  display: flex;
  align-items: center;
  gap: 0.6em;
  font-size: var(--fs-meta);
}

.timer-custom input[type="number"] {
  width: 5em;
  padding: 0.4em;
  font-size: 1em;
  border-radius: 0.5em;
  border: 1px solid var(--border);
  background: var(--bg-raised);
}

.timer-controls, .timer-adjust, .picker-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8em;
  justify-content: center;
}

.timer-done-msg {
  font-size: var(--fs-assignment);
  font-weight: 800;
  color: var(--danger);
}

/* Picker */

.picker-name {
  font-size: var(--fs-picker-name);
  font-weight: 800;
}

.picker-sub {
  color: var(--ink-dim);
  font-size: var(--fs-meta);
  min-height: 1.4em;
}

.picker-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: var(--fs-meta);
  color: var(--ink-dim);
}

.picker-roster {
  color: var(--ink-dim);
  font-size: var(--fs-meta);
}

.absence-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em;
  margin-top: 0.6em;
  max-width: 90vw;
}

.absence-list label {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 0.5em;
  padding: 0.4em 0.8em;
}

/* ---------- Buttons ---------- */

.btn {
  min-height: var(--touch);
  padding: 0.5em 1.1em;
  font-size: var(--fs-meta);
  font-weight: 600;
  background: var(--bg-raised);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 0.6em;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn:disabled:hover {
  border-color: var(--border);
}

.btn-lg {
  font-size: calc(var(--fs-meta) * 1.3);
  padding: 0.6em 1.6em;
  font-weight: 800;
}

/* ---------- Toolbar ---------- */

.toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.6em;
  flex-wrap: wrap;
  padding: 0.6em clamp(0.75rem, 2vw, 2rem);
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}

body[data-display-mode="true"] .toolbar {
  display: none;
}

/* Display Mode hides every interactive control, not just the toolbar —
   presets, start/pause/reset, ±1 min, mute, the Pick/Reset-cycle buttons,
   and the absence checklist all disappear. The countdown number and the
   picked student's name stay visible: that's the point of the mode (a
   clean student-facing view), not a reason to make the Timer/Picker
   unusable — a teacher exits Display Mode (3-tap corner or Escape) to
   operate them, same as any other control. */
body[data-display-mode="true"] .timer-presets,
body[data-display-mode="true"] .timer-custom,
body[data-display-mode="true"] .timer-controls,
body[data-display-mode="true"] .timer-adjust,
body[data-display-mode="true"] .picker-controls,
body[data-display-mode="true"] .picker-roster {
  display: none;
}

.tbtn {
  min-height: var(--touch);
  padding: 0.4em 0.9em;
  font-size: clamp(0.85rem, 1.1vw, 1.2rem);
  font-weight: 600;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 0.5em;
  cursor: pointer;
}

.tbtn[aria-pressed="true"] {
  background: var(--accent);
  color: #06202e;
  border-color: var(--accent);
}

.toolbar-spacer {
  flex: 1;
}

.period-select-wrap, .lesson-date-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: clamp(0.8rem, 1vw, 1.1rem);
  color: var(--ink-dim);
}

.period-select-wrap select,
.lesson-date-wrap input,
#overridePeriodSelect,
#activeScheduleSelect,
#rosterPeriodSelect {
  min-height: var(--touch);
  padding: 0.3em 0.6em;
  border-radius: 0.5em;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-size: 1em;
}

.exit-display-hotspot {
  position: fixed;
  top: 0;
  left: 0;
  width: 10vw;
  height: 10vh;
  min-width: 60px;
  min-height: 60px;
  background: transparent;
  border: none;
  z-index: 50;
  display: none;
}

body[data-display-mode="true"] .exit-display-hotspot {
  display: block;
}

/* ---------- Teacher panel ---------- */

.teacher-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  z-index: 100;
}

.teacher-overlay[hidden] {
  display: none;
}

.teacher-panel {
  width: min(680px, 92vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  padding: 1.25rem;
  overflow-y: auto;
  font-size: 1rem;
}

.teacher-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.teacher-tabs {
  display: flex;
  gap: 0.4em;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.ttab {
  min-height: var(--touch);
  padding: 0.4em 0.8em;
  border-radius: 0.5em;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  cursor: pointer;
}

.ttab[aria-selected="true"] {
  background: var(--accent);
  color: #06202e;
}

.ttab-panel label {
  display: block;
  margin: 0.75em 0 0.3em;
  font-weight: 600;
  color: var(--ink-dim);
}

.ttab-panel label.inline {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-weight: 400;
  color: var(--ink);
}

.ttab-panel select,
.ttab-panel input[type="text"],
.ttab-panel input[type="number"],
.ttab-panel textarea {
  width: 100%;
  padding: 0.5em;
  border-radius: 0.5em;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--ink);
  font-size: 1rem;
}

.ttab-panel textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.sample-warning {
  background: #78350f;
  color: #fde68a;
  padding: 0.75em 1em;
  border-radius: 0.5em;
  font-weight: 600;
}

.hint {
  color: var(--ink-dim);
  font-size: 0.9rem;
}

.row {
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin-top: 0.6em;
}

/* Specificity must beat ".ttab-panel input[type=text] { width:100% }" or
   the flex sizing below is silently ignored. */
.ttab-panel .row-add input[type="text"] {
  flex: 1 1 auto;
  width: auto;
}

.row-add .btn {
  flex-shrink: 0;
}

.save-msg {
  color: var(--good);
  font-size: 0.9rem;
}

.upcoming-list {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  margin-top: 0.5em;
}

.upcoming-item {
  border: 1px solid var(--border);
  border-radius: 0.5em;
  padding: 0.6em 0.8em;
}

.upcoming-item .ud {
  font-weight: 700;
  color: var(--accent);
}

#periodCourseMapEditor {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  margin-top: 0.5em;
}

.pcm-row {
  display: flex;
  align-items: center;
  gap: 0.6em;
}

.pcm-row span {
  width: 6em;
  color: var(--ink-dim);
}

.pcm-row select {
  flex: 1;
  padding: 0.4em;
  border-radius: 0.5em;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--ink);
}

/* ---------- Small-window safety ---------- */

@media (max-width: 640px) {
  .header-meta {
    gap: 0.4em;
  }
  .toolbar {
    justify-content: center;
  }
  .toolbar-spacer {
    display: none;
  }
}
