/* 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: #16283a;
  --part: #3f7cc4;
  --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; }
button:disabled { cursor: default; opacity: 0.35; }
[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; }

/* ---------- Now: the part, the time left, what's next ---------- */
#now {
  position: fixed;
  left: 4.5vw; top: 5vh;
  z-index: 10;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 2.5vh rgba(255, 255, 255, 0.55);
}
#now-label {
  display: flex; align-items: center; gap: 1.2vh;
  margin: 0 0 0.6vh 0.4vh;
  font-size: 2.8vh; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
}
#now-chip { width: 2.2vh; height: 2.2vh; background: var(--part); box-shadow: 0 0 0 0.35vh rgba(255, 255, 255, 0.8); }
#part-name {
  margin: 0;
  font-size: 10vh; font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  max-width: 62vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#time {
  font-size: 19vh;
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.035em;
  white-space: nowrap;
  transform-origin: 0 60%;
}
#bar {
  position: relative;
  width: 44vh;
  height: 1.1vh;
  margin: 1.8vh 0 0 0.6vh;
  background: rgba(255, 255, 255, 0.6);
}
#bar-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--part); }
#next {
  margin: 1.8vh 0 0 0.6vh;
  font-size: 3.4vh;
  font-weight: 500;
}
body.paused #time, body.waiting #time { opacity: 0.45; }
body.paused #now-step { color: #b23a2a; }

/* Last ten seconds of a part: the time pulses each second */
body.soon #time { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }

/* The end of the lesson */
body.done #time, body.done #bar, body.done #next { display: none; }
body.done #part-name { font-size: 13vh; animation: arrive 0.9s cubic-bezier(.2, .7, .3, 1); }
@keyframes arrive { from { transform: translateY(3vh); opacity: 0; } to { transform: none; opacity: 1; } }
#end-buttons { display: none; gap: 1.2vh; margin: 2.6vh 0 0 0.6vh; }
body.done.settled #end-buttons { display: flex; animation: arrive 0.6s ease-out; }
#end-buttons button {
  border: 0;
  padding: 1.3vh 2.4vh;
  font-size: 2.4vh; font-weight: 600;
  background: rgba(16, 22, 30, 0.6);
  color: #fff;
  text-shadow: none;
}
#end-buttons button:first-child { background: var(--ink); }
#end-buttons button:hover { filter: brightness(1.15); }

/* ---------- The whole lesson, along the bottom ---------- */
#timeline {
  position: fixed;
  left: 3vw; right: 3vw; bottom: 3vh;
  z-index: 10;
  display: flex; gap: 0.6vh;
  margin: 0; padding: 0;
  list-style: none;
  color: var(--text);
}
#timeline li {
  position: relative;
  flex: 1 1 0;
  min-width: 10vw;
  overflow: hidden;
  padding: 1.3vh 1.4vh 1.2vh;
  background: rgba(247, 243, 234, 0.82);
  border-top: 0.8vh solid var(--part);
  backdrop-filter: blur(6px);
}
#timeline .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: color-mix(in srgb, var(--part) 22%, transparent);
}
#timeline b, #timeline span { position: relative; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#timeline b { font-size: 2.7vh; font-weight: 600; }
#timeline span { margin-top: 0.3vh; font-size: 1.9vh; color: var(--muted); font-variant-numeric: tabular-nums; }
#timeline.many li { min-width: 0; }
#timeline .current { background: #fff; box-shadow: 0 0 0 0.4vh var(--part); }
#timeline .current span { color: var(--text); font-weight: 600; }
#timeline .past { opacity: 0.55; background: rgba(230, 226, 216, 0.75); }
#timeline .past .fill { background: none; }
#timeline .past b::before { content: '✓ '; }
body.done #timeline .past { opacity: 0.8; }

/* ---------- "Time for Work" when a part starts ---------- */
#banner, #waiting {
  position: fixed;
  left: 50%; top: 44%;
  z-index: 15;
  transform: translate(-50%, -50%);
  min-width: 50vh;
  padding: 3vh 6vh 3.4vh;
  text-align: center;
  color: var(--text);
  background: #fff;
  border-top: 1.4vh solid var(--part);
  box-shadow: 0 2vh 6vh rgba(0, 0, 0, 0.3);
}
#banner p, #waiting p { margin: 0; font-size: 3vh; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
#banner b, #waiting b { display: block; margin: 0.6vh 0; font-size: 12vh; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; white-space: nowrap; }
#banner span { font-size: 4vh; font-weight: 500; color: var(--muted); }
#banner.show { animation: banner 5s ease-in-out forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.9); }
  8%, 85% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}
#go {
  margin-top: 1.6vh;
  border: 0;
  padding: 1.6vh 4vh;
  font-size: 3vh; font-weight: 600;
  background: var(--part);
  color: #fff;
}
#go:hover { filter: brightness(1.1); }

/* ---------- Toolbar: top right, out of the way ---------- */
#toolbar {
  position: fixed;
  right: 2vw; top: 2.4vh;
  z-index: 12;
  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.waiting .when-paused, body.muted .when-muted { display: block; }
body.paused .when-running, body.waiting .when-running, body.muted .when-sound { display: none; }
body.ready #toolbar [data-action]:not([data-action=menu]):not([data-action=sound]):not([data-action=fullscreen]),
body.done [data-action=pause], body.done [data-action=skip],
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: 24px 0 10px;
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted);
}
.panel header + h2 { margin-top: 0; }

/* The parts of the lesson */
#parts { margin: 0; padding: 0; list-style: none; counter-reset: part; }
#parts li { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
#parts li::before {
  counter-increment: part; content: counter(part);
  width: 20px; text-align: right;
  font-size: 14px; font-weight: 600; color: var(--muted);
}
#parts .swatch { width: 34px; height: 40px; border: 0; padding: 0; }
#parts input {
  height: 40px;
  padding: 6px 10px;
  border: 0; border-bottom: 2px solid var(--line);
  background: #fbf9f5;
  color: var(--text);
  font-size: 18px; font-weight: 600;
}
#parts input:focus { outline: none; border-bottom-color: var(--text); }
#parts .name { flex: 1; min-width: 0; }
#parts input[type=number] { width: 72px; font-variant-numeric: tabular-nums; text-align: right; }
#parts .unit { width: 34px; font-size: 15px; color: var(--muted); }
#parts li button:not(.swatch) {
  width: 36px; height: 40px;
  border: 0;
  background: #e6e0d4;
  font-size: 18px; font-weight: 600;
}
#parts li button:not(.swatch):not(:disabled):hover { background: #dcd5c7; }
#add-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 10px 0 0 26px; }
#add-row button {
  border: 0;
  padding: 7px 12px;
  background: #e6e0d4;
  font-size: 15px; font-weight: 500;
}
#add-row button:not(:disabled):hover { background: #dcd5c7; }
#add-row .add { background: var(--text); color: var(--paper); font-weight: 600; }
#add-row .add:not(:disabled):hover { background: #33404f; }
#quick { display: contents; }
.add-label { margin-left: 8px; font-size: 14px; color: var(--muted); }
#total { margin: 12px 0 0 26px; font-size: 16px; font-weight: 500; }

#plans { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
#plans button {
  border: 0;
  padding: 10px 12px;
  text-align: left;
  background: #e6e0d4;
}
#plans button:hover { background: #dcd5c7; }
#plans b { display: block; font-size: 16px; font-weight: 600; }
#plans span { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }

.check { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; font-size: 16px; line-height: 1.35; }
.check input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; 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;
}
.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) {
  #plans { grid-template-columns: 1fr; }
  .panel { padding: 24px 20px; }
  #parts li button:not(.swatch) { width: 30px; }
}
