:root {
  --bg: #1a1a1a;
  --fg: #e0e0e0;
  --accent: #4a9eff;
  --warn: #ffb14a;
  --border: #3a3a3a;
  --danger: #ff6b6b;
  --panel-bg: #242424;
  --input-bg: #2a2a2a;
  --detail-bg: #2e2e2e;
}

[data-theme="light"] {
  --bg: #ffffff;
  --fg: #111111;
  --accent: #004aad;
  --warn: #dd8513;
  --border: #cccccc;
  --danger: #b00020;
  --panel-bg: #fafafa;
  --input-bg: #ffffff;
  --detail-bg: #f6f6f6;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: "Red Hat Display", sans-serif;
  font-optical-sizing: auto;
  background: var(--bg);
  color: var(--fg);
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
}

.header-logo {
  height: 2.5rem;
  max-width: 200px;
  object-fit: contain;
}

/* Exam in progress banner */
.exam-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-shrink: 0;
  padding: 0.45rem 1.5rem;
  background: #c62828;
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
}

.exam-banner[hidden] {
  display: none;
}

.fullscreen-mode .exam-banner {
  font-size: clamp(1.125rem, 3vw, 2.25rem);
  padding: 0.5625rem 1.5rem;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

button,
select,
input {
  font: inherit;
}

button {
  padding: 0.4rem 0.9rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}

button.secondary {
  background: var(--detail-bg);
  color: var(--fg);
  border: 1px solid var(--border);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

main {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  flex: 1;
  overflow: hidden;
}

/* Fullscreen mode - hide setup panel */
.fullscreen-mode main {
  grid-template-columns: 1fr;
}

.fullscreen-mode .panel {
  display: none;
}

.fullscreen-mode .live-clock {
  font-size: clamp(4rem, 10vw, 9rem);
}

.fullscreen-mode .clock-label {
  font-size: clamp(1rem, 2vw, 1.5rem);
  margin-top: 0.5rem;
}

.fullscreen-mode .display-panel {
  justify-content: flex-start;
  min-height: 100%;
}

.fullscreen-mode .live-clock-wrapper {
  flex: 0 0 clamp(9rem, 18vh, 12rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  
  .panel {
    max-height: 40vh;
  }
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  padding: 1rem 1.25rem;
  overflow-y: auto;
}

.panel h2 {
  margin-top: 0;
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

form {
  display: grid;
  gap: 0.75rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

input[type="text"],
input[type="number"],
input[type="time"],
select {
  padding: 0.35rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--fg);
}

input[readonly] {
  background: var(--detail-bg);
  color: var(--fg);
}

[data-theme="light"] input[type="time"] {
  color-scheme: light;
}

input[type="time"] {
  color-scheme: dark;
}

.input-with-action {
  display: flex;
  gap: 0.5rem;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.input-with-action input {
  flex: 1;
  min-width: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.field-row label {
  min-width: 0;
}

label.check-option {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.extra-time-group {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0.5rem 0.75rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  min-width: 0;
}

.extra-time-group legend {
  font-size: 0.9rem;
  padding: 0 0.3rem;
}

.timing-preview {
  display: grid;
  gap: 0.2rem;
  padding: 0.5rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 4px;
  background: var(--detail-bg);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.timing-preview-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.timing-preview-label {
  opacity: 0.7;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.display-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-radius: 16px;
  padding: 1.25rem 1.5rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.centre-info {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.centre-logo {
  max-height: 60px;
  max-width: 120px;
  object-fit: contain;
  margin-right: 1rem;
}

.centre-logo ~ div {
  text-align: right;
  margin-left: auto;
}

.centre-main {
  font-size: 1.4rem;
  font-weight: 60Ca0;
}

.centre-sub {
  font-size: 0.95rem;
  opacity: 0.85;
}

/* The clock and exam areas share remaining height; fullscreen assigns the clock a fixed footprint. */
.live-clock-wrapper {
  text-align: center;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.live-clock {
  font-size: clamp(2.5rem, 8vw, 4rem);
  line-height: 1;
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.clock-label {
  font-size: 0.9rem;
  color: var(--fg);
  opacity: 0.7;
  margin-top: 0.25rem;
}

.exam-details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

@media (max-width: 700px) {
  .exam-details-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .live-clock {
    font-size: clamp(2rem, 12vw, 3.5rem);
  }
}

@media (max-width: 480px) {
  header {
    padding: 0.5rem 1rem;
  }
  
  main {
    padding: 1rem;
    gap: 1rem;
  }
  
  .exam-details-grid {
    grid-template-columns: 1fr;
  }
}

.detail-item {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: var(--detail-bg);
  border: 1px solid var(--border);
}

.detail-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
  margin-bottom: 0.1rem;
}

.detail-value {
  font-size: 0.95rem;
  font-weight: 500;
  min-height: 1.2em;
}

.status-pill {
  padding: 0.2em 0.7em;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-pill.running {
  border-color: var(--warn);
  color: var(--warn);
}

.status-pill.idle {
  opacity: 0.7;
}

.small-note {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 0.3rem;
}

.warning {
  color: var(--danger);
}

/* Theme toggle switch */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.theme-toggle-label {
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border);
  border-radius: 24px;
  transition: background-color 0.2s ease;
}

.toggle-slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: var(--fg);
  border-radius: 50%;
  transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* Exams list */
.exams-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
}

/* Windowed (setup panel visible): the exams area may take more than its half when the cards
   need the room. The clock area keeps what it needs; its type size is never reduced. */
@media (min-width: 901px) {
  body:not(.fullscreen-mode) .live-clock-wrapper,
  body:not(.fullscreen-mode) .exams-list:not(.has-late-candidates) {
    min-height: min-content;
  }

  body:not(.fullscreen-mode).late-candidates-present .live-clock-wrapper {
    flex: 0 0 clamp(8rem, 15vh, 10rem);
  }
}

/* Each exam keeps its late candidates in the same column, including when columns wrap. */
.exams-list.has-late-candidates .exams-grid {
  --exam-rows: 3;
  grid-auto-rows: 1fr auto auto;
}

.exams-grid {
  --exam-cols: 1;
  display: grid;
  grid-template-columns: repeat(var(--exam-cols), minmax(0, 1fr));
  grid-auto-rows: 1fr auto;
  gap: 0.75rem 1rem;
  flex: 1 0 auto;
  /* All card text is sized in em, so this one multiplier (set by fitExamText in app.js) scales it together */
  font-size: calc(1rem * var(--exam-scale, 1));
}

.exams-grid[data-count="2"] { --exam-cols: 2; }
.exams-grid[data-count="3"] { --exam-cols: 3; }
.exams-grid[data-count="4"] { --exam-cols: 4; }

.exams-grid:not([data-count="1"]) .exam-card {
  padding: 0.75rem;
}

.exams-grid:not([data-count="1"]) .exam-card-details,
.exams-grid:not([data-count="1"]) .exam-card-footer {
  gap: 0.5rem;
}

/* Fewer columns when the display area is narrow, so each card stays readable */
@container (max-width: 760px) {
  .exams-grid[data-count="4"] { --exam-cols: 2; }
}

@container (max-width: 600px) {
  .exams-grid[data-count="3"] { --exam-cols: 2; }
}

@container (max-width: 440px) {
  .exams-grid[data-count] { --exam-cols: 1; }
}

.no-exams-message {
  text-align: center;
  padding: 2rem 1rem;
  opacity: 0.6;
  font-size: 0.95rem;
}

.exam-group {
  --exam-tint: hsl(var(--exam-hue, 210) 55% 60%);
  --exam-border: color-mix(in srgb, var(--border), var(--exam-tint) 45%);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-row: span var(--exam-rows, 2);
  grid-template-rows: subgrid;
  min-width: 0;
}

/* Shared details and footer rows align status pills; late candidates occupy a third row. */
.exam-card {
  background: color-mix(in srgb, var(--detail-bg), var(--exam-tint) 16%);
  border: 1px solid var(--exam-border);
  border-radius: 8px;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-row: span 2;
  grid-template-rows: subgrid;
}

/* The containers live on the inner blocks (not the card itself) because the card is a subgrid */
.exam-card-details,
.exam-card-footer {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  container-type: inline-size;
}

.exam-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.exam-title {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.exam-subject {
  font-size: 1.1em;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.exam-paper {
  font-size: 0.9em;
  opacity: 0.8;
}

.remove-exam-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  font-size: 1.5em;
  line-height: 1;
  padding: 0.2em 0.6em;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.remove-exam-btn:hover {
  background: var(--danger);
  color: white;
}

.exam-card-actions {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.late-exam-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 0.2em 0.6em;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.late-exam-btn svg {
  width: 1.25em;
  height: 1.25em;
}

.late-exam-btn:hover {
  background: var(--accent);
  color: white;
}

.late-candidates {
  display: grid;
  align-content: start;
  gap: 0.5rem;
  min-width: 0;
}

.late-candidate {
  display: grid;
  align-content: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.65rem 0.75rem;
  container-type: inline-size;
  background: color-mix(in srgb, var(--panel-bg), var(--exam-tint) 12%);
  border: 1px solid var(--exam-border);
  border-radius: 6px;
  font-size: clamp(1.35rem, 1.4vw, 1.65rem);
}

.late-candidate-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.late-candidate-name {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.late-candidate .exam-times {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8em), 1fr));
  gap: 0.2rem 0.4rem;
  font-size: 1.2rem;
}

.late-candidate .exam-time-item {
  flex-direction: row;
  align-items: baseline;
  gap: 0.25rem;
  white-space: nowrap;
}

.late-candidate .time-label {
  font-size: 0.75em;
  letter-spacing: 0.02em;
}

.late-candidate .exam-status {
  justify-content: flex-start;
  gap: 0.25rem;
}

.late-candidate .status-pill {
  padding: 0.12em 0.4em;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.late-tag {
  flex-shrink: 0;
  padding: 0.05em 0.45em;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.7em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.remove-late-btn {
  font-size: 1.1em;
  padding: 0.05em 0.45em;
}

.late-exam-summary {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  opacity: 0.8;
  overflow-wrap: anywhere;
}

#late-form {
  gap: 1rem;
}

.exam-times {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5em, 1fr));
  gap: 0.5rem;
  font-size: 0.9em;
}

.exam-time-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

/* 0.8333em of the 0.9em time text = the original 0.75rem label size */
.time-label {
  font-size: 0.8333em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
}

.time-value {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.exam-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.status-pill.complete {
  border-color: #4caf50;
  color: #4caf50;
  opacity: 0.8;
}

.status-pill.upcoming {
  border-color: var(--border);
  opacity: 0.8;
}

.exam-extra-times {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5em, 1fr));
  gap: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
  font-size: 0.9em;
}

.exam-extra-times .time-label {
  color: var(--accent);
  opacity: 1;
}

/* Narrow cards (several exams side by side): label and value share a line to save height.
   Thresholds are in em so they widen along with the text scale. */
@container (max-width: 25em) {
  .exam-times,
  .exam-extra-times {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }

  .exam-time-item {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    column-gap: 0.5rem;
  }

  .status-pill {
    text-align: center;
    padding: 0.2em 0.5em;
    font-size: 0.72em;
    letter-spacing: 0.04em;
  }
}

@container (max-width: 25rem) {
  .late-candidate {
    font-size: 1.1rem;
  }

  .late-candidate .exam-times {
    font-size: 1rem;
  }

  .late-candidate .status-pill {
    font-size: 0.75rem;
  }
}

/* Very narrow cards: buttons go above the title so the subject keeps the full width */
@container (max-width: 14.4em) {
  .exam-card-header {
    flex-direction: column-reverse;
    gap: 0.35rem;
  }

  .exam-title {
    flex: none;
  }

  .exam-card-actions {
    align-self: flex-end;
  }

  .exam-card-actions .remove-exam-btn {
    font-size: 1.2em;
    padding: 0.1em 0.5em;
  }
}

/* Settings Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 2rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.modal-close:hover {
  opacity: 1;
}

#settings-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#settings-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.95rem;
}

#settings-form input {
  padding: 0.5rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--fg);
  font-size: 1rem;
}

#settings-form .form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.file-note {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 0.25rem;
  display: block;
}

.logo-preview-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--detail-bg);
}

.logo-preview {
  max-width: 200px;
  max-height: 100px;
  object-fit: contain;
  border-radius: 4px;
}

.small-btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

.disclaimer-btn {
  width: 100%;
  font-size: 0.85rem;
}

/* The disclaimer opens from within Settings, so it has to sit above that modal */
#disclaimer-modal {
  z-index: 1100;
}

.disclaimer-content {
  line-height: 1.6;
}

.disclaimer-content p {
  margin: 0 0 1rem 0;
}

.disclaimer-content p:last-child {
  margin-bottom: 0;
}

