/* ==========================================================================
   Ascent Academia · Exam Clock
   Sizes are expressed in viewport units so the layout scales cleanly from a
   laptop screen up to a 4K projector / TV.
   ========================================================================== */

/* Manrope (SIL Open Font License), bundled so the clock works offline */
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/manrope-latin-var.woff2") format("woff2");
}

/* ---------- Brand ----------
   Ascent Academia violet, taken from the official logo files in brand/. */
:root {
  --brand: #8c68ac;
  --brand-light: #b597d3;
  --brand-lighter: #d9c8ea;
  --brand-deep: #5b3f78;

  --font: "Manrope", "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --radius: clamp(10px, 1.1vmin, 28px);
  --gutter: clamp(16px, 3vmin, 96px);
}

/* Midnight (default): deep aubergine, built for projectors */
:root,
[data-clock-theme="dark"] {
  --bg: #120d19;
  --bg-2: #1c1526;
  --glow-1: rgba(140, 104, 172, .26);
  --glow-2: rgba(91, 63, 120, .30);
  --fg: #f6f2fb;
  --fg-muted: #b3a6c4;
  --logo: #ffffff;
  --accent: var(--brand-light);
  --accent-2: var(--brand);
  --accent-fg: #170f20;
  --reading: #f2b766;
  --warn: #f59a5b;
  --danger: #f2727a;
  --surface: rgba(255, 255, 255, .06);
  --surface-2: rgba(255, 255, 255, .11);
  --border: rgba(217, 200, 234, .16);
  --track: rgba(255, 255, 255, .09);
  --shadow: 0 30px 80px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* Daylight: for bright rooms and front projectors */
[data-clock-theme="light"] {
  --bg: #f8f5fb;
  --bg-2: #efe8f5;
  --glow-1: rgba(140, 104, 172, .18);
  --glow-2: rgba(181, 151, 211, .22);
  --fg: #1b1224;
  --fg-muted: #5e5070;
  --logo: var(--brand);
  --accent: #74529a;
  --accent-2: var(--brand);
  --accent-fg: #ffffff;
  --reading: #a55a06;
  --warn: #bf4d0c;
  --danger: #b4232f;
  --surface: rgba(91, 63, 120, .06);
  --surface-2: rgba(91, 63, 120, .11);
  --border: rgba(91, 63, 120, .20);
  --track: rgba(91, 63, 120, .12);
  --shadow: 0 30px 80px rgba(60, 35, 90, .18);
  color-scheme: light;
}

/* High contrast: maximum legibility from the back of the room */
[data-clock-theme="contrast"] {
  --bg: #000000;
  --bg-2: #000000;
  --glow-1: transparent;
  --glow-2: transparent;
  --fg: #ffffff;
  --fg-muted: #ffffff;
  --logo: #ffffff;
  --accent: #e2d0f7;
  --accent-2: #e2d0f7;
  --accent-fg: #000000;
  --reading: #00e5ff;
  --warn: #ffea00;
  --danger: #ff5c5c;
  --surface: #000000;
  --surface-2: #1a1a1a;
  --border: #ffffff;
  --track: #3a3a3a;
  --shadow: none;
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  transition: background-color .6s var(--ease-in-out), color .6s var(--ease-in-out);
}

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

.skip-link {
  position: absolute; left: 12px; top: -100px; z-index: 100;
  padding: 10px 16px; border-radius: 8px;
  background: var(--accent); color: var(--accent-fg); font-weight: 600;
}
.skip-link:focus { top: 12px; }

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

/* ---------- App shell ---------- */

.app {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  padding: var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  isolation: isolate;
  /* The ambient background is larger than the screen; never let it scroll */
  overflow: hidden;
  overflow: clip;
}

/* Slow, subtle ambient background */
.app::before {
  content: "";
  position: absolute; inset: -20%;
  z-index: -1;
  background:
    radial-gradient(40% 50% at 20% 25%, var(--glow-1), transparent 70%),
    radial-gradient(45% 55% at 80% 75%, var(--glow-2), transparent 70%),
    linear-gradient(160deg, var(--bg), var(--bg-2));
  animation: drift 40s var(--ease-in-out) infinite alternate;
}

@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(2%, 1%, 0) scale(1.05); }
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2vmin;
  min-height: 6vmin;
}

.brand {
  display: flex;
  align-items: center;
  max-width: 100%;
  gap: 1.6vmin;
  min-width: 0;
}

.brand-logo {
  display: block;
  height: clamp(40px, 7vmin, 190px);
  width: auto;
  color: var(--logo);
  flex: none;
  transition: color .6s var(--ease-in-out);
}

.brand-divider {
  align-self: stretch;
  width: 2px;
  margin-block: .6vmin;
  border-radius: 2px;
  background: var(--border);
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.brand-kicker {
  font-size: clamp(11px, 1.5vmin, 40px);
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent);
}

.exam-name {
  font-size: clamp(18px, 3.4vmin, 92px);
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Long titles glide sideways to show the whole title, then glide back.
   JS sets --title-shift and --title-duration only when the title overflows. */
.exam-name-inner { display: inline-block; }
.exam-name.is-scrolling {
  text-overflow: clip;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 1.2em), transparent);
          mask-image: linear-gradient(90deg, #000 calc(100% - 1.2em), transparent);
}
.exam-name.is-scrolling .exam-name-inner {
  animation: title-scroll var(--title-duration, 12s) ease-in-out infinite;
}
@keyframes title-scroll {
  0%, 15%   { transform: translateX(0); }
  45%, 60%  { transform: translateX(var(--title-shift, 0)); }
  90%, 100% { transform: translateX(0); }
}

/* Centre the two text lines on the logo by the letters themselves: trim each
   line box to cap height and baseline, so empty space above the capitals and
   below the baseline doesn't push the text off-centre. */
@supports (text-box: trim-both cap alphabetic) {
  .brand-text { gap: clamp(5px, .9vmin, 24px); }
  .brand-kicker,
  .exam-name,
  .exam-name-inner { text-box: trim-both cap alphabetic; }
  /* Keep room for ascenders and descenders (e.g. the y in "Physics"), which
     the clipping for long titles would otherwise cut off */
  .exam-name { padding-block: .15em .3em; margin-block: -.15em -.3em; }
}

.controls {
  display: flex;
  gap: clamp(6px, 1vmin, 24px);
  flex-wrap: wrap;
  justify-content: flex-end;
  transition: opacity .5s var(--ease-in-out), transform .5s var(--ease-out);
}

/* Controls fade away when the mouse is idle so the projected screen stays clean */
.app.idle .controls,
.app.idle .shortcut-hint {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}
.app.idle { cursor: none; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .5em;
  font: inherit;
  font-size: clamp(14px, 1.7vmin, 40px);
  font-weight: 600;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .7em 1.2em;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background-color .2s, transform .2s var(--ease-out), border-color .2s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.96); }
.btn svg { width: 1.25em; height: 1.25em; fill: currentColor; flex: none; }
.btn[hidden] { display: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

.btn-danger,
.btn-danger:hover {
  background: var(--danger);
  color: var(--bg);
  border-color: transparent;
}

.icon-btn { padding: .7em; }

/* ---------- Stage / clock ---------- */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  gap: 2vmin;
}

.phase-pill {
  display: inline-flex;
  align-items: center;
  gap: .6em;
  padding: .45em 1.1em;
  border-radius: 999px;
  font-size: clamp(14px, 2.8vmin, 76px);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--phase-color, var(--accent));
  background: color-mix(in srgb, var(--phase-color, var(--accent)) 14%, transparent);
  border: 2px solid color-mix(in srgb, var(--phase-color, var(--accent)) 45%, transparent);
  animation: pill-in .4s var(--ease-out);
  transition: color .3s var(--ease-in-out), background-color .3s var(--ease-in-out), border-color .3s var(--ease-in-out);
}
.phase-pill[hidden] { display: none; }
.phase-dot {
  width: .6em; height: .6em;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.75); }
}
@keyframes pill-in {
  from { opacity: 0; transform: translateY(-6px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.phase-reading  { --phase-color: var(--reading); }
.phase-writing  { --phase-color: var(--accent); }
.phase-upcoming { --phase-color: var(--accent-2); }
.phase-paused   { --phase-color: var(--warn); }
.phase-finished { --phase-color: var(--danger); }
.phase-warning  { --phase-color: var(--warn); }

.clock-wrap {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: center;
}

.clock {
  --clock-size: min(19.5vw, 40vh);
  display: flex;
  align-items: center;
  font-size: var(--clock-size);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: -.02em;
  line-height: 1;
  color: var(--fg);
  transition: font-size .8s var(--ease-out), color .6s;
  user-select: none;
}

.app.exam-on .clock { --clock-size: min(17vw, 30vh); }

.clock .digit {
  position: relative;
  display: inline-block;
  width: .62em;
  height: 1.08em;
  overflow: hidden;
  text-align: center;
}

.clock .digit > span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform, opacity;
}

.clock .digit > .in {
  animation: digit-in .55s var(--ease-out) both;
}
.clock .digit > .out {
  animation: digit-out .55s var(--ease-out) both;
}

@keyframes digit-in {
  from { transform: translateY(55%) scale(.92); opacity: 0; filter: blur(.04em); }
  to   { transform: none; opacity: 1; filter: none; }
}
@keyframes digit-out {
  from { transform: none; opacity: 1; filter: none; }
  to   { transform: translateY(-55%) scale(.92); opacity: 0; filter: blur(.04em); }
}

.clock .sep {
  display: inline-block;
  width: .3em;
  text-align: center;
  color: var(--fg-muted);
  transform: translateY(-.06em);
}

.clock .secs { color: var(--accent); }

.ampm {
  font-size: calc(var(--clock-size, 19vw) * .2);
  font-weight: 600;
  color: var(--fg-muted);
  margin-left: .4em;
  letter-spacing: .05em;
}
.ampm:empty { display: none; }

.date {
  margin: 0;
  font-size: clamp(16px, 3.4vmin, 92px);
  font-weight: 500;
  color: var(--fg-muted);
  letter-spacing: .02em;
}
.date[hidden] { display: none; }

.sync-badge {
  margin: 0;
  font-size: clamp(11px, 1.4vmin, 36px);
  font-weight: 600;
  color: var(--fg-muted);
  opacity: .8;
}
.sync-badge[hidden] { display: none; }
.sync-status { margin: 0; line-height: 1.45; color: var(--fg-muted); }
#sync-now { font-size: .95em; }

/* Pulse the whole clock briefly when a milestone fires */
.app.flash .clock { animation: clock-flash 1s var(--ease-out); }
/* Colour only: a blurred text-shadow on the giant digits is expensive to paint */
@keyframes clock-flash {
  20% { color: var(--accent); }
}

/* ---------- Exam panel ---------- */

.exam-panel {
  display: flex;
  flex-direction: column;
  gap: 2.2vmin;
  padding: 2.4vmin 3vmin 2.2vmin;
  border-radius: calc(var(--radius) * 1.6);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: panel-in .9s var(--ease-out);
}
.exam-panel[hidden] { display: none; }

@keyframes panel-in {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1.3fr 1.3fr 1fr;
  gap: 2vmin;
  align-items: end;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: .3vmin;
  min-width: 0;
}
.stat:nth-child(2), .stat:nth-child(3) { align-items: center; text-align: center; }
.stat:last-child { align-items: flex-end; text-align: right; }
.stat[hidden] { display: none; }

.stat-label {
  font-size: clamp(11px, 1.8vmin, 48px);
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.stat-value {
  font-size: clamp(18px, 4.4vmin, 120px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.stat-strong .stat-value {
  font-size: clamp(22px, 6.6vmin, 180px);
}

#stat-remaining-wrap.is-warning .stat-value { color: var(--warn); }
#stat-remaining-wrap.is-danger .stat-value { color: var(--danger); animation: soft-blink 1.6s ease-in-out infinite; }
@keyframes soft-blink { 50% { opacity: .55; } }

.progress {
  position: relative;
  height: clamp(10px, 1.6vmin, 44px);
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.progress-reading,
.progress-fill {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 0;
  border-radius: inherit;
  transition: width 1s linear, background-color .6s;
}
.progress-reading {
  background: repeating-linear-gradient(
    -45deg,
    color-mix(in srgb, var(--reading) 70%, transparent) 0 8px,
    color-mix(in srgb, var(--reading) 45%, transparent) 8px 16px);
}
.progress-fill {
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  box-shadow: 0 0 1.6vmin color-mix(in srgb, var(--accent) 45%, transparent);
}
.progress.is-warning .progress-fill { background: linear-gradient(90deg, var(--warn), var(--warn)); }
.progress.is-danger .progress-fill  { background: linear-gradient(90deg, var(--danger), var(--danger)); }

.progress-ticks { position: absolute; inset: 0; }
.progress-ticks i {
  position: absolute;
  top: 18%; bottom: 18%;
  width: 2px;
  margin-left: -1px;
  background: var(--bg);
  opacity: .65;
  border-radius: 2px;
}

.milestones {
  position: relative;
  height: clamp(14px, 2vmin, 52px);
  font-size: clamp(10px, 1.5vmin, 40px);
  font-weight: 600;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.milestones span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
  transition: color .4s, opacity .4s;
  opacity: .7;
}
.milestones span.passed { color: var(--accent); opacity: 1; }
.milestones span:first-child { transform: none; }
.milestones span:last-child  { transform: translateX(-100%); }

/* ---------- Announcement banner ---------- */

.announce {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 50;
  visibility: hidden;
}
/* A plain translucent scrim: a full-screen backdrop blur has to be recomputed
   every frame while the clock ticks underneath, which made the banner stutter. */
.announce::before {
  content: "";
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  opacity: 0;
  transition: opacity .18s var(--ease-in-out);
  will-change: opacity;
}

.announce.show { visibility: visible; pointer-events: auto; cursor: pointer; }
.announce.show::before { opacity: 1; transition-duration: .22s; }
/* Keep the layer visible while the exit animation plays */
.announce.hiding { visibility: visible; }

.announce-dismiss {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .6em;
  margin-top: 2.4vmin;
  padding: .55em 1.2em;
  font: inherit;
  font-size: clamp(13px, 1.8vmin, 48px);
  font-weight: 700;
  color: var(--fg-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.announce-dismiss:hover { color: var(--fg); background: var(--surface-2); }
.app.idle .announce-dismiss { opacity: .55; }

.announce-card {
  position: relative;
  min-width: min(80vw, 60vmin);
  max-width: 88vw;
  padding: 5vmin 7vmin;
  border-radius: calc(var(--radius) * 2.4);
  background: var(--bg-2);
  border: 3px solid var(--announce-color, var(--accent));
  box-shadow: var(--shadow), 0 0 8vmin color-mix(in srgb, var(--announce-color, var(--accent)) 35%, transparent);
  text-align: center;
  opacity: 0;
  overflow: hidden;
  will-change: transform, opacity;
}
.announce.show .announce-card { opacity: 1; animation: card-in .38s var(--ease-out) both; }
.announce.hiding .announce-card { animation: card-out .18s var(--ease-in-out) both; }
/* Back-to-back announcements swap in place instead of fading the overlay */
.announce.show.swap .announce-card { animation: card-swap .3s var(--ease-out) both; }
@keyframes card-in {
  from { opacity: 0; transform: translateY(2.5vh) scale(.94); }
  to   { opacity: 1; transform: none; }
}
@keyframes card-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: scale(.97); }
}
@keyframes card-swap {
  from { transform: scale(.96); }
  to   { transform: none; }
}

.announce-ring {
  position: absolute;
  left: 50%; top: 50%;
  width: 20vmin; height: 20vmin;
  margin: -10vmin 0 0 -10vmin;
  border-radius: 50%;
  border: .6vmin solid var(--announce-color, var(--accent));
  opacity: 0;
  will-change: transform, opacity;
}
.announce.show .announce-ring { animation: ring 1.8s var(--ease-out) .08s 2; }
@keyframes ring {
  from { transform: scale(.4); opacity: .6; }
  to   { transform: scale(6); opacity: 0; }
}

.announce-kicker {
  position: relative;
  font-size: clamp(14px, 2.6vmin, 70px);
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--announce-color, var(--accent));
}
.announce-title {
  position: relative;
  margin-top: 1.2vmin;
  font-size: clamp(30px, 9vmin, 250px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -.01em;
}
.announce-sub {
  position: relative;
  margin-top: 1.6vmin;
  font-size: clamp(16px, 3.4vmin, 90px);
  font-weight: 500;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.announce-sub:empty { display: none; }

.announce.tone-reading  { --announce-color: var(--reading); }
.announce.tone-warning  { --announce-color: var(--warn); }
.announce.tone-danger   { --announce-color: var(--danger); }
.announce.tone-info     { --announce-color: var(--accent-2); }

/* ---------- Finished state ---------- */

.app.finished .clock .secs { color: var(--danger); }

/* ---------- Shortcut hint ---------- */

.shortcut-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gutter) * .35);
  transform: translateX(-50%);
  font-size: clamp(11px, 1.3vmin, 32px);
  color: var(--fg-muted);
  white-space: nowrap;
  transition: opacity .5s var(--ease-in-out), transform .5s var(--ease-out);
}
.app.exam-on .shortcut-hint { display: none; }
kbd {
  font: inherit;
  font-weight: 700;
  padding: .1em .45em;
  border: 1px solid var(--border);
  border-radius: .35em;
  background: var(--surface);
}

/* ---------- Settings side panel ---------- */

.settings {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: min(480px, 100vw);
  max-width: 100vw;
  height: 100%;
  max-height: 100%;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 22px 0 0 22px;
  color: var(--fg);
  background: var(--bg-2);
  box-shadow: var(--shadow);
  font-size: 16px;
  overflow: hidden;
}
.settings[open] { animation: panel-slide-in .5s var(--ease-out); }
.settings.closing { animation: panel-slide-out .32s var(--ease-in-out) forwards; }
.settings::backdrop {
  /* Light scrim so the clock stays readable while settings are open */
  background: rgba(10, 6, 16, .35);
  animation: scrim-in .4s var(--ease-out);
}
.settings.closing::backdrop { animation: scrim-out .32s var(--ease-in-out) forwards; }

@keyframes panel-slide-in {
  from { transform: translateX(100%); }
  to   { transform: none; }
}
@keyframes panel-slide-out {
  from { transform: none; }
  to   { transform: translateX(100%); }
}
@keyframes scrim-in  { from { opacity: 0; } }
@keyframes scrim-out { to { opacity: 0; } }

@media (max-width: 520px) {
  .settings { border-radius: 0; border-left: 0; }
}

@media (min-width: 2400px) {
  .settings { font-size: 24px; width: min(760px, 100vw); }
}

.settings form {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.settings-head h2 { margin: 0; font-size: 1.35em; font-weight: 800; }
.settings-head .btn { font-size: 1em; }

.settings fieldset {
  margin: 0;
  padding: 12px 24px 16px;
  border: 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.settings fieldset:first-child { border-top: 0; }
.settings legend {
  float: left;
  width: 100%;
  padding: 8px 0 2px;
  font-size: .8em;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; min-width: 0; }
.field small { font-weight: 400; color: var(--fg-muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 560px) { .field-row, .field-row-3 { grid-template-columns: 1fr; } }

.timing-group { display: flex; flex-direction: column; gap: 14px; }
.timing-group[hidden] { display: none; }
.field-note { margin: 0; font-size: .9em; color: var(--fg-muted); line-height: 1.4; }

.timing-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600;
  line-height: 1.4;
}
.timing-summary:empty { display: none; }
.timing-summary.is-error { color: var(--danger); border-color: var(--danger); }

.tl-note {
  font-size: .8em;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.tl-row {
  display: grid;
  grid-template-columns: auto 5.2em 1fr auto;
  align-items: baseline;
  gap: 10px;
}
.tl-dot {
  width: .7em;
  height: .7em;
  border-radius: 50%;
  background: var(--tl-color, var(--accent));
  align-self: center;
}
.tl-row.reading { --tl-color: var(--reading); }
.tl-row.writing { --tl-color: var(--accent); }
.tl-name { color: var(--fg-muted); font-weight: 700; }
.tl-time {
  font-size: 1.3em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
  white-space: nowrap;
}
.tl-time .tl-arrow { color: var(--fg-muted); font-weight: 600; margin-inline: .3em; }
.tl-len { color: var(--fg-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.settings input[type="time"].time-lg {
  font-size: 1.4em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .03em;
  min-height: 56px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 9px 12px;
  border-radius: 9px;
  text-align: center;
  font-weight: 700;
  color: var(--fg-muted);
  transition: background-color .2s, color .2s;
}
.segmented input:checked + span { background: var(--accent); color: var(--accent-fg); }
.segmented input:focus-visible + span { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.settings input[type="text"],
.settings input[type="number"],
.settings input[type="time"],
.settings select {
  font: inherit;
  font-weight: 500;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}
.settings select option { background: var(--bg-2); color: var(--fg); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-block;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  transition: background-color .2s, color .2s, border-color .2s;
}
.chip input:checked + span {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
}
.chip input:focus-visible + span { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  cursor: pointer;
  min-height: 32px;
}
.toggle input {
  width: 22px; height: 22px;
  accent-color: var(--accent);
  flex: none;
}

.settings-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}
.settings-foot .btn { font-size: 1em; }

/* Start mode shows only what's needed to set up an exam */
.settings.start-mode [data-section="settings-only"] { display: none; }

/* ---------- Exit exam confirmation ---------- */

.confirm {
  width: min(460px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--fg);
  background: var(--bg-2);
  box-shadow: var(--shadow);
  font-size: 16px;
}
.confirm[open] { animation: confirm-in .35s var(--ease-out); }
.confirm::backdrop { background: rgba(10, 6, 16, .55); }
@keyframes confirm-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.confirm h2 { margin: 0 0 8px; font-size: 1.35em; font-weight: 800; }
.confirm p { margin: 0 0 22px; color: var(--fg-muted); line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.confirm-actions .btn { font-size: 1em; }
@media (min-width: 2400px) { .confirm { font-size: 24px; width: min(680px, calc(100vw - 32px)); } }

.noscript {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg); color: var(--fg);
  font-size: 4vmin; text-align: center; padding: 5vmin;
}

/* ---------- Small screens (phones, portrait) ---------- */

@media (max-aspect-ratio: 1/1) {
  .clock { --clock-size: 15.5vw; }
  .app.exam-on .clock { --clock-size: 15vw; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(n) { align-items: flex-start; text-align: left; }
  .stat:nth-child(even) { align-items: flex-end; text-align: right; }
  .topbar { flex-wrap: wrap; }
  .controls { justify-content: flex-start; }
  .shortcut-hint { display: none; }
}

@media (max-width: 760px) {
  .milestones { display: none; }
}

@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  .exam-panel { padding: 1.5vmin 2vmin; gap: 1.2vmin; }
  .milestones { display: none; }
}

/* ---------- Motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  html:not([data-motion="full"]) *,
  html:not([data-motion="full"]) *::before,
  html:not([data-motion="full"]) *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
html[data-motion="reduced"] *,
html[data-motion="reduced"] *::before,
html[data-motion="reduced"] *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}
