:root {
  color-scheme: dark;
  --bg: #0a0a0b;
  --surface: #141416;
  --fg: #f4f4f5;
  --soft: #d4d4d8;
  --muted: #a1a1aa;
  --line: #2a2a2e;
  --band: #1c1c1f;
  --warn: #f59e0b;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --info-size: min(3.6vw, 6vh);
  /* Starting size only: app.js enlarges the exam details to fill their space. */
  --exam-size: min(3.3vw, 5vh);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f6f6f7;
  --fg: #0a0a0b;
  --soft: #27272a;
  --muted: #52525b;
  --line: #e4e4e7;
  --band: #ededf0;
  --warn: #b45309;
}

/* With four or more exams, keep each to one line so they all fit. */
body[data-count="many"] .exams .paper { display: inline; margin-left: 0.6em; font-size: 0.8em; }

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Hide the cursor when nobody is using the mouse. */
body:not(.active):not(:has(dialog[open])) { cursor: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Display ---------- */

/* Centre number and date, then the clock, then the exam details from the top down. */
.display {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* never wider than the screen */
  grid-template-rows: auto 1fr 1.7fr;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4vw;
  padding: 3vh 5vw 0;
  font-size: var(--info-size);
}

.topbar strong { font-weight: 700; font-variant-numeric: tabular-nums; }
.date { margin-left: auto; text-align: right; font-weight: 700; }

/* Small capital labels name each item; the values next to or under them are large. */
.label,
.exams th {
  font-size: 0.55em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft);
}

.topbar .label { margin-right: 0.3em; }

.clock {
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0 5vw;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Fill the clock's row. The vw/vh size is a fallback for older browsers. */
.clock .time {
  font-size: min(23vw, 27vh);
  font-size: min(25cqw, 92cqh);
}

.clock-s,
.clock-ampm {
  font-size: 0.36em;
  font-weight: 600;
  color: var(--soft);
  letter-spacing: 0;
}

.clock-ampm { margin-left: 0.15em; }

.details {
  min-height: 0;
  padding: 3vh 5vw;
  border-top: 1px solid var(--line);
}

.exams { font-size: var(--exam-size); }

/* Each exam sits on its own shaded band so rows can be told apart from afar. */
.exams table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.2em;
}

.exams th {
  padding: 0 0 0.1em;
  text-align: left;
  vertical-align: bottom;
}

.exams td {
  padding: 0.25em 0;
  vertical-align: baseline;
  background: var(--band);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.exams th:first-child,
.exams td:first-child { padding-left: 0.45em; }
.exams th:last-child,
.exams td:last-child { padding-right: 0.45em; }
.exams td:first-child { border-radius: 0.15em 0 0 0.15em; }
.exams td:last-child { border-radius: 0 0.15em 0.15em 0; }

.exams .num {
  width: 1%;
  padding-left: 1em;
  text-align: right;
  white-space: nowrap;
}

/* One exam: its name is a heading and the times spread across the screen. */
.exams caption { padding: 0 0 0.25em 0.45em; text-align: left; }
.exams.single .num { width: auto; text-align: left; }

.exams .subject { font-weight: 700; white-space: nowrap; }
.exams.wrap .subject { white-space: normal; }
.exams .paper { display: block; font-size: 0.75em; font-weight: 600; color: var(--soft); white-space: nowrap; }
.exams .finish { font-weight: 800; }

.hint {
  margin: 0;
  font-size: 0.5em;
  color: var(--muted);
}

/* ---------- Corner buttons (shown while the mouse is in use) ---------- */

.corner-controls {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 8px;
  opacity: 0;
  transition: opacity 200ms ease;
}

body.active .corner-controls,
.corner-controls:has(:focus-visible) { opacity: 1; }

.icon-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover { color: var(--fg); }
.icon-button:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }

/* The theme button shows the theme it will switch to. */
:root[data-theme="dark"] .icon-moon,
:root[data-theme="light"] .icon-sun { display: none; }

.icon-button[data-warn]::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warn);
}

/* ---------- Setup dialog ---------- */

.setup {
  width: min(820px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
}

.setup::backdrop { background: rgb(0 0 0 / 0.55); }

.setup h2 { margin: 0 0 20px; font-size: 20px; font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); }

.setup input:not([type="radio"], [type="checkbox"]) {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  font: inherit;
}

.setup input:focus-visible,
.button:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }

.centre-field { max-width: 220px; margin-bottom: 20px; }

.exam-rows { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }

.exam-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr 11em 8em 5.5em auto;
  gap: 12px;
  align-items: end;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.with-button { display: flex; gap: 6px; }
.finish-field output { min-height: 38px; padding: 8px 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.finish-field .extra-finish { min-height: 0; padding: 0; font-size: 13px; font-weight: 500; color: var(--muted); }

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.button:hover { background: var(--surface); }
.button.small { padding: 8px 10px; }
.button.primary { border-color: var(--fg); background: var(--fg); color: var(--bg); font-weight: 600; }
.remove { color: var(--muted); }

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 20px 0 0;
  padding: 14px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.options legend { float: left; width: 100%; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.options label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.clock-status { min-height: 1.4em; margin: 16px 0 0; font-size: 13px; color: var(--muted); }
.clock-status.warn { color: var(--warn); font-weight: 600; }

.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

@media (max-width: 760px) {
  .exam-row { grid-template-columns: 1fr 1fr; }
  .subject-field { grid-column: 1 / -1; }
  .remove { justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  .corner-controls { transition: none; }
}
