/* Space Grotesk (SIL Open Font License), latin subset, self-hosted so the
   timer works offline and behind school web filters. */
@font-face {
  font-family: 'Space Grotesk';
  font-weight: 300 700;
  font-display: swap;
  src: url(../fonts/space-grotesk.woff2) format('woff2');
}

:root {
  --ink: #ffffff;
  --paper: #f2eee6;
  --text: #1c2128;
  --muted: #5e646c;
  --line: #d6d0c4;
  font-family: 'Space Grotesk', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #16202a; color: #fff; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
kbd {
  font: 600 0.85em/1 'Space Grotesk', ui-monospace, monospace;
  padding: 0.15em 0.4em;
  background: #e4ded2;
  border-bottom: 2px solid #cfc7b8;
}

#viewport { position: fixed; inset: 0; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- The clock ---------- */
#clock {
  position: fixed;
  left: 5vw; top: 7vh;
  z-index: 10;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  transition: opacity 0.6s;
}
#time {
  font-size: 27vh;
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.035em;
  white-space: nowrap;
  text-shadow: 0 0.4vh 3vh var(--glow, rgba(0, 0, 0, 0.35));
  transform-origin: 0 60%;
}
#bar {
  position: relative;
  height: 0.7vh;
  margin: 2.2vh 0 0 0.6vh;
  background: color-mix(in srgb, var(--ink) 25%, transparent);
}
#bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0;
  background: var(--ink);
}
#status {
  margin: 1.6vh 0 0 0.6vh;
  min-height: 1.3em;
  font-size: 3vh;
  font-weight: 500;
  letter-spacing: 0.01em;
  opacity: 0.85;
}
body.paused #time { opacity: 0.45; }

/* Last ten seconds: one big number that drops in each second */
body.final #time { font-size: 46vh; line-height: 0.85; }
body.final #bar, body.final #status { visibility: hidden; }
#time.tick { animation: tick 0.9s cubic-bezier(.2, .7, .3, 1); }
@keyframes tick { from { transform: scale(1.18); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }

/* At zero the theme's word takes the clock's place */
body.done #time { font-size: 17vh; font-weight: 600; letter-spacing: -0.02em; animation: arrive 0.9s cubic-bezier(.2, .7, .3, 1); }
body.done #bar { visibility: hidden; }
@keyframes arrive { from { transform: translateY(3vh); opacity: 0; } to { transform: none; opacity: 1; } }
#ending-buttons { display: none; gap: 1.2vh; margin: 2.4vh 0 0 0.6vh; }
body.done.settled #ending-buttons { display: flex; animation: arrive 0.6s ease-out; }
#ending-buttons button {
  border: 0;
  padding: 1.3vh 2.4vh;
  font-size: 2.4vh; font-weight: 600;
  background: rgba(16, 22, 30, 0.55);
  color: #fff;
  backdrop-filter: blur(6px);
}
#ending-buttons button:first-child { background: var(--ink); color: var(--ink-on, #10161e); }
#ending-buttons button:hover { filter: brightness(1.12); }

/* ---------- Toolbar: bottom right, out of the way ---------- */
#toolbar {
  position: fixed;
  right: 2vw; bottom: 2.4vh;
  z-index: 10;
  display: flex; gap: 2px;
  transition: opacity 0.6s;
}
body.idle #toolbar { opacity: 0; }
body.idle { cursor: none; }
#toolbar button {
  width: 6vh; height: 6vh;
  min-width: 40px; min-height: 40px;
  display: grid; place-items: center;
  border: 0;
  background: rgba(16, 22, 30, 0.5);
  backdrop-filter: blur(6px);
  color: #fff;
}
#toolbar button:hover { background: rgba(16, 22, 30, 0.8); }
#toolbar svg { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; }
#toolbar .text { font-size: max(15px, 2.3vh); font-weight: 600; }
.when-paused, .when-muted { display: none; }
body.paused .when-paused, body.muted .when-muted { display: block; }
body.paused .when-running, body.muted .when-sound { display: none; }
body.ready [data-action=pause], body.done [data-action=pause],
body.done [data-action=more], body.done [data-action=less] { display: none !important; }

/* ---------- Menu ---------- */
#setup {
  position: fixed; inset: 0;
  z-index: 20;
  overflow: auto;
  padding: 4vh 4vw;
  background: linear-gradient(90deg, rgba(12, 16, 22, 0.55), rgba(12, 16, 22, 0.15));
}
.panel {
  width: min(760px, 100%);
  background: var(--paper);
  color: var(--text);
  padding: 34px 40px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}
.panel header { border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 22px; }
.panel h1 { margin: 0; font-size: 44px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
.panel header p { margin: 10px 0 0; font-size: 18px; line-height: 1.4; color: var(--muted); max-width: 36em; }
.panel h2 {
  margin: 0 0 10px;
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted);
}

#lengths { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
#lengths button {
  padding: 10px 0 8px;
  border: 0;
  background: #e6e0d4;
  font-size: 24px; font-weight: 600; line-height: 1;
  font-variant-numeric: tabular-nums;
}
#lengths small { display: block; margin-top: 4px; font-size: 12px; font-weight: 500; color: var(--muted); }
#lengths button:hover { background: #dcd5c7; }
#lengths button[aria-pressed='true'] { background: var(--text); color: var(--paper); }
#lengths button[aria-pressed='true'] small { color: #b9b3a8; }
#custom { display: flex; align-items: center; gap: 14px; margin: 12px 0 26px; font-size: 16px; color: var(--muted); }
#custom label { display: flex; align-items: center; gap: 6px; }
#custom input {
  width: 64px;
  padding: 6px 8px;
  border: 0; border-bottom: 2px solid var(--line);
  background: #fbf9f5;
  color: var(--text);
  font-size: 18px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#custom input:focus { outline: none; border-bottom-color: var(--text); }

#themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.theme {
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  color: var(--text);
}
.theme img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #d9d3c7; transition: filter 0.2s; }
.theme b { display: block; margin-top: 9px; padding-top: 7px; border-top: 3px solid transparent; font-size: 16px; font-weight: 600; }
.theme span { display: block; margin-top: 2px; font-size: 13px; line-height: 1.35; color: var(--muted); }
.theme:not([aria-pressed='true']) img { filter: saturate(0.6) brightness(0.92); }
.theme:hover img { filter: none; }
.theme[aria-pressed='true'] b { border-top-color: var(--text); }

.check { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.check input { width: 18px; height: 18px; accent-color: var(--text); }
.buttons { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-top: 22px; }
.buttons .primary {
  border: 0;
  padding: 14px 34px;
  background: var(--text);
  color: var(--paper);
  font-size: 21px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.buttons .primary:hover { background: #33404f; }
.buttons .quiet {
  border: 0; padding: 4px 0;
  background: none;
  font-size: 16px; font-weight: 500;
  color: var(--muted);
  text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--line);
}
.buttons .quiet:hover { color: var(--text); text-decoration-color: var(--text); }
#offline-status { margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.help { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; font-size: 15px; color: var(--muted); }
.help summary { cursor: pointer; font-weight: 600; color: var(--text); }
.help ul { padding-left: 18px; line-height: 1.55; margin-bottom: 0; }

@media (max-width: 720px) {
  #lengths { grid-template-columns: repeat(5, 1fr); }
  #themes { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 24px 20px; }
}
