:root {
  color-scheme: light;
  --ink: #1a1a1a;
  --bg: #f7f6f3;
  --line: #b7b1a6;
  --muted: #5c564e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 28px 16px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft JhengHei", "PingFang HK", "Noto Sans CJK HK", sans-serif;
  font-size: 18px;
  line-height: 1.4;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.exam { margin: auto 0; }

button, input, textarea {
  font: inherit;
  color: var(--ink);
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  height: 96px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.school {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.exam { text-align: center; }

body[data-view="settings"] .exam { margin: 0; }

.subject {
  margin: 18px 0 0;
  font-size: clamp(3.2rem, 8vw, 7rem);
  font-weight: 650;
  line-height: 1.1;
}

.subject.is-placeholder { color: var(--muted); font-weight: 500; }

.slot {
  margin: 10px 0 0;
  font-size: clamp(2.2rem, 5vw, 4rem);
}

.extended, .phase {
  margin: 10px 0 0;
  font-size: clamp(1.8rem, 3.6vw, 3rem);
}

.clock {
  margin: 4px 0 16px;
  font-size: clamp(7.5rem, 26vw, 18rem);
  font-weight: 650;
  letter-spacing: -0.04em;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.btn {
  min-height: 48px;
  padding: 0.55rem 1.2rem;
  border: 1px solid var(--ink);
  background: #fff;
  cursor: pointer;
}

.btn-primary {
  background: var(--ink);
  color: #fff;
}

.top-actions .btn {
  min-height: 44px;
  font-size: 1rem;
}

.confirm {
  max-width: 44rem;
  margin: 16px auto 0;
  padding: 12px 16px;
  border: 1px solid currentColor;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.confirm p {
  flex: 1 1 100%;
  margin: 0;
}

.error, .warn-note {
  margin: 12px auto 0;
  max-width: 44rem;
  text-align: center;
}

.settings { margin-top: 28px; }

.settings-inner, .settings form { max-width: 960px; margin: 0 auto; }

fieldset {
  margin: 0 0 18px;
  padding: 12px 16px 16px;
  border: 1px solid var(--line);
}

legend { padding: 0 6px; font-weight: 650; }

label { display: block; }

label span, .prompt-row span {
  display: block;
  margin-bottom: 4px;
  font-size: 0.95rem;
}

input, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #8d877c;
  background: #fff;
}

textarea { resize: vertical; }

.pair, .triple {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.pair { grid-template-columns: 1fr 1fr; }
.triple { grid-template-columns: 1fr 1fr 1fr; }

.prompt-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.settings-actions { justify-content: flex-start; margin-top: 4px; }

.help, footer p {
  margin: 0 0 12px;
  color: var(--muted);
}

footer {
  padding-top: 20px;
  text-align: center;
}

footer p { margin: 0; font-size: 0.95rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

body[data-view="settings"] .clock {
  font-size: clamp(3.5rem, 10vw, 6rem);
}

body[data-view="settings"] .subject {
  margin-top: 12px;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

body[data-phase="warn"] { background: #f3d27a; }

body[data-phase="ended"] {
  background: #6f1d1d;
  color: #fff;
}

body[data-phase="ended"] .help,
body[data-phase="ended"] footer p,
body[data-phase="ended"] .subject.is-placeholder {
  color: #f3d7d7;
}

body[data-phase="ended"] .btn {
  background: #fff;
  color: #1a1a1a;
  border-color: #fff;
}

body[data-phase="ended"] .btn-primary {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

body[data-phase="ended"] :focus-visible { outline-color: #fff; }

@media (max-width: 800px) {
  body { padding: 16px; }

  .pair, .triple, .prompt-row { grid-template-columns: 1fr; }

  .logo { height: 64px; }

  .top { align-items: center; }
}
