/* =========================================================================
   Exam Timer — core styles
   Structure, typography, controls. Theme colours live in themes.css,
   layout variations in layouts.css.
   ========================================================================= */

:root {
  /* Sizing scale — multiplied by --font-scale (user adjustable) */
  --font-scale: 1;
  /* Countdown digit size. Overridden per-layout / in concurrent mode. */
  --cd-size: clamp(2.6rem, 9.5vw, 9rem);
  --clock-size: clamp(2rem, 7vw, 6rem);
  --title-size: clamp(1.6rem, 4.5vw, 4rem);

  /* Fallback palette (overridden per-theme in themes.css) */
  --bg: #0e1116;
  --bg-2: #171b22;
  --text: #f2f5f9;
  --text-dim: #9aa4b2;
  --accent: #3b82f6;
  --accent-2: #22d3ee;
  --track: rgba(255, 255, 255, 0.12);
  --panel-bg: #12161c;
  --panel-border: rgba(255, 255, 255, 0.1);
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;

  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --transition: 0.2s ease;
}

* { box-sizing: border-box; }

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

body.cursor-hidden { cursor: none; }

h1, h2, h3, h4 { margin: 0; font-weight: 700; }
button { font-family: inherit; }

/* ============================ PRESENTATION ============================ */
.presentation {
  position: relative;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: clamp(0.5rem, 1.5vh, 1.5rem);
  padding: clamp(1rem, 3vw, 3rem);
  padding-bottom: clamp(4.5rem, 9vh, 6.5rem); /* reserve room for the floating control bar */
  background:
    radial-gradient(120% 90% at 50% -10%, var(--bg-2), var(--bg) 70%);
  text-align: center;
}

/* Branding bar */
.brand-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 1px;
}
.brand-left { display: flex; align-items: center; gap: 0.9rem; }
.school-logo { max-height: clamp(2.4rem, 6vh, 5rem); max-width: 22vw; object-fit: contain; }
.logo-placeholder {
  display: grid; place-items: center;
  height: clamp(2.4rem, 6vh, 5rem); aspect-ratio: 1 / 1;
  border: 2px dashed var(--panel-border); border-radius: 10px;
  color: var(--text-dim); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em;
  opacity: 0.6;
}
.brand-text { text-align: left; }
.school-name { font-size: clamp(1rem, 2.2vw, 1.9rem); font-weight: 700; }
.school-name.is-placeholder { color: var(--text-dim); font-weight: 600; opacity: 0.6; font-style: italic; }
.department-name { font-size: clamp(0.75rem, 1.4vw, 1.1rem); color: var(--text-dim); }
.brand-right { text-align: right; }
.header-clock {
  font-size: clamp(1.1rem, 2.8vw, 2.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1.05;
}
.today-date { font-size: clamp(0.85rem, 1.8vw, 1.5rem); font-weight: 600; }
.academic-year { font-size: clamp(0.7rem, 1.3vw, 1rem); color: var(--text-dim); }

/* Exam heading */
.exam-head { display: flex; flex-direction: column; gap: 0.3rem; }
.exam-title {
  font-size: calc(var(--title-size) * var(--font-scale));
  line-height: 1.05;
  letter-spacing: -0.01em;
  color: var(--accent);
}
.exam-meta { font-size: clamp(0.9rem, 2vw, 1.8rem); color: var(--text); font-weight: 600; }
.exam-submeta { font-size: clamp(0.8rem, 1.5vw, 1.3rem); color: var(--text-dim); }

/* Stage: ring + countdown */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.6rem, 2vh, 1.6rem);
  min-height: 0;
}
/* Rounded-rectangle countdown frame with an animated progress border.
   The border geometry is sized to the frame in JS (layoutFrame). */
.timer-frame {
  position: relative;
  display: inline-grid;
  place-items: center;
  padding: clamp(0.7rem, 2.6vh, 1.9rem) clamp(1.4rem, 4vw, 3.4rem);
  margin: clamp(0.3rem, 1.5vh, 1rem) 0;
  min-width: min(42vw, 480px);
  max-width: 96vw;
}
.frame-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.frame-track { fill: none; stroke: var(--track); stroke-width: 8; }
.frame-progress {
  fill: none;
  stroke: var(--timer-color, var(--accent));
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s linear, stroke 0.3s ease;
}
.countdown-block { position: relative; display: grid; place-items: center; }
.countdown {
  font-size: calc(var(--cd-size) * var(--font-scale));
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: var(--text);
  transition: color 0.3s ease;
}
.countdown-label { font-size: clamp(0.8rem, 1.6vw, 1.4rem); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.15em; }

/* Progress bar */
.progress-wrap { display: flex; align-items: center; gap: 1rem; width: min(70vw, 900px); }
.progress-bar { flex: 1; height: clamp(8px, 1.4vh, 16px); background: var(--track); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.5s linear, background 0.3s; }
.progress-pct { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.5ch; }

/* Live clock */
.clock-block { display: flex; flex-direction: column; align-items: center; }
.live-clock {
  font-size: calc(var(--clock-size) * var(--font-scale));
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.clock-label { font-size: clamp(0.7rem, 1.3vw, 1.1rem); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.15em; }

/* ---- Concurrent exams grid (multiple subjects at the same time) ---- */
.single-view { display: flex; flex-direction: column; align-items: center; gap: clamp(0.6rem, 2vh, 1.6rem); }
.multi-stage { display: none; }
.presentation.has-concurrent .multi-stage {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: clamp(8px, 1.4vw, 18px);
  width: min(94vw, 1500px);
  margin: clamp(0.6rem, 2vh, 1.4rem) auto 0;
}
/* When a concurrent session is showing, shrink the headline timer to make
   room for the grid of subjects underneath it. */
.presentation.has-concurrent { --cd-size: clamp(1.8rem, 5.5vw, 4.5rem); }
.presentation.has-concurrent .schedule-strip { display: none; }

.mx-card {
  background: var(--bg-2);
  border: 1px solid var(--panel-border);
  border-top: 5px solid var(--accent);
  border-radius: 14px;
  padding: clamp(8px, 1.6vh, 18px) clamp(8px, 1.2vw, 16px);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-align: center; min-width: 0;
}
.mx-card.active-card { outline: 2px solid var(--accent); }
.mx-title { font-weight: 700; font-size: clamp(0.9rem, 1.5vw, 1.5rem); line-height: 1.1; }
.mx-sub { font-size: clamp(0.7rem, 1.05vw, 1rem); color: var(--text-dim); }
.mx-num {
  font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1;
  font-size: calc(clamp(1.8rem, 4.6vw, 4.2rem) * var(--font-scale));
  margin: 2px 0;
  transition: color 0.3s ease;
}
.mx-bar { width: 100%; height: clamp(6px, 0.9vh, 12px); background: var(--track); border-radius: 999px; overflow: hidden; }
.mx-fill { height: 100%; width: 0; transition: width 0.5s linear, background 0.3s; }
.mx-status { font-size: clamp(0.65rem, 0.95vw, 0.9rem); text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim); }
.mx-card.finished { border-color: var(--danger); animation: cardpulse 0.9s ease-in-out infinite; }
.mx-card.finished .mx-num, .mx-card.finished .mx-status { color: var(--danger); font-weight: 800; }
@keyframes cardpulse { 50% { background: rgba(239, 68, 68, 0.18); } }

/* Schedule strip */
.schedule-strip { display: none; }

/* Quick control bar */
.quick-bar {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 40;
  transition: opacity var(--transition);
}
.qb-btn {
  border: 1px solid var(--panel-border);
  background: var(--bg-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.qb-btn:hover { border-color: var(--accent); }
.qb-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
body.chrome-hidden .quick-bar { opacity: 0; pointer-events: none; }
body.chrome-hidden:hover .quick-bar,
body.chrome-hidden .quick-bar:hover { opacity: 1; pointer-events: auto; }

/* Project credit line */
.credit {
  position: fixed;
  bottom: 12px;
  left: 18px;
  font-size: clamp(0.72rem, 1vw, 1rem);
  color: var(--text-dim);
  opacity: 0.75;
  letter-spacing: 0.02em;
  z-index: 30;
  pointer-events: none;
}

/* Announcement overlay */
.announcement {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.82);
  z-index: 60;
  backdrop-filter: blur(4px);
  animation: fade 0.25s ease;
}
.announcement-text {
  font-size: clamp(2.5rem, 10vw, 11rem);
  font-weight: 800;
  color: #fff;
  padding: 2rem;
  text-align: center;
  line-height: 1.05;
}

/* Flash overlay for warnings / time up */
.flash-overlay { position: fixed; inset: 0; z-index: 50; pointer-events: none; background: var(--danger); }
.flash-overlay.flashing { animation: flash 0.7s steps(1) infinite; }
@keyframes flash { 50% { opacity: 0; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Expired state */
body.expired .countdown { color: var(--danger); }

/* ============================ PANEL / DRAWER ============================ */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 70; }
.panel {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: min(460px, 96vw);
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 80;
  display: flex;
  flex-direction: column;
}
.panel.open { transform: translateX(0); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--panel-border);
}
.panel-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.icon-btn { background: none; border: none; color: var(--text); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--bg-2); }

/* Tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  border: 1px solid var(--panel-border); background: var(--bg-2); color: var(--text-dim);
  padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
}
.tab.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.tab-pane h3 { margin: 18px 0 8px; font-size: 0.95rem; }
.tab-pane h4 { margin: 12px 0 6px; font-size: 0.82rem; color: var(--text-dim); }

/* Generic controls */
.btn {
  border: 1px solid var(--panel-border); background: var(--bg-2); color: var(--text);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 600; transition: var(--transition);
}
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 7px 11px; font-size: 0.85rem; }
.btn.tiny { padding: 5px 9px; font-size: 0.78rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn-group { display: flex; gap: 8px; align-items: center; }
.btn-group.right { justify-content: flex-end; margin-top: 14px; }
.btn-group.wrap { flex-wrap: wrap; }
.file-label { display: inline-flex; align-items: center; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hint { color: var(--text-dim); font-size: 0.8rem; margin: 6px 0; }

/* Forms */
label { font-size: 0.8rem; color: var(--text-dim); display: flex; flex-direction: column; gap: 4px; }
label.block { grid-column: 1 / -1; }
label.check, label.file-label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea {
  font-family: inherit; font-size: 0.9rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px 10px;
}
input[type="color"] { padding: 2px; height: 38px; }
input[type="range"] { padding: 0; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Exam list */
.exam-list, .warning-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.exam-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--panel-border); border-left: 5px solid var(--accent);
  border-radius: 10px; padding: 10px 12px;
}
.exam-item.active-exam { outline: 2px solid var(--accent); }
.exam-item[draggable="true"] { cursor: grab; }
.exam-item.dragging { opacity: 0.4; }
.exam-drag { color: var(--text-dim); cursor: grab; font-size: 1.1rem; }
.exam-info { flex: 1; text-align: left; min-width: 0; }
.exam-info .ei-title { font-weight: 700; font-size: 0.92rem; }
.exam-info .ei-sub { font-size: 0.78rem; color: var(--text-dim); }
.exam-actions { display: flex; gap: 4px; }
.exam-actions button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 1rem; padding: 3px 5px; border-radius: 6px; }
.exam-actions button:hover { color: var(--text); background: var(--bg); }

/* Warning list */
.warning-item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 10px; align-items: center; background: var(--bg-2); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px; }
.warning-item .w-time { display: flex; align-items: center; gap: 3px; font-weight: 700; font-variant-numeric: tabular-nums; }
.warning-item .w-time input { width: 3.2em; text-align: center; padding: 5px 4px; }
.warning-item .w-time .w-fixed { font-size: 0.8rem; color: var(--danger); }
.warning-item .w-opts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.75rem; align-items: center; }
.warning-item input[type="text"].w-msg { flex: 1; min-width: 120px; }
.warning-item select.w-soundsel { max-width: 150px; }

/* Sound messages library */
.sound-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sound-item { display: flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid var(--panel-border); border-radius: 10px; padding: 8px 10px; }
.sound-item .s-name { flex: 1; font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sound-item button { background: none; border: 1px solid var(--panel-border); color: var(--text); cursor: pointer; font-size: 0.9rem; padding: 4px 9px; border-radius: 8px; }
.sound-item button:hover { border-color: var(--accent); }
.sound-item .s-del { color: var(--danger); }

/* Chips */
.chip-list { list-style: none; margin: 6px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--panel-border); background: var(--bg-2); color: var(--text);
  border-radius: 999px; padding: 5px 11px; font-size: 0.8rem; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.quick-ann { margin-top: 8px; }

/* Theme + layout grids */
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme-swatch { border: 2px solid var(--panel-border); border-radius: 10px; padding: 10px 8px; cursor: pointer; font-size: 0.78rem; font-weight: 600; text-align: center; }
.theme-swatch.selected { border-color: var(--accent); }
.theme-dots { display: flex; gap: 4px; justify-content: center; margin-bottom: 6px; }
.theme-dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.2); }
.layout-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.layout-opt { border: 1px solid var(--panel-border); background: var(--bg-2); color: var(--text); border-radius: 10px; padding: 12px; cursor: pointer; font-weight: 600; }
.layout-opt.selected { border-color: var(--accent); background: var(--accent); color: #fff; }

/* Shortcuts list */
.shortcuts { list-style: none; padding: 0; margin: 8px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 0.85rem; }
kbd { background: var(--bg-2); border: 1px solid var(--panel-border); border-bottom-width: 2px; border-radius: 6px; padding: 1px 7px; font-family: inherit; font-size: 0.8rem; margin-right: 6px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: grid; place-items: center; z-index: 90; padding: 20px; }
.modal-card { background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: var(--radius); width: min(640px, 96vw); max-height: 92vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-body { padding: 18px; overflow-y: auto; }

/* Toast */
.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-weight: 600; z-index: 100; box-shadow: var(--shadow); animation: fade 0.2s ease;
}

/* Empty state */
.empty { color: var(--text-dim); text-align: center; padding: 20px; font-size: 0.85rem; }

/* Utility */
[hidden] { display: none !important; }

/* Print */
@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea { position: absolute; inset: 0; color: #000; background: #fff; padding: 24px; }
}
