/* Classroom Stopwatch. The stage is a size container; .sw-main is one too,
   so the digits and the dial size themselves to whatever room the lap list
   leaves them. */

.sw {
  --sw-best: #1c9a56;
  --sw-worst: #e03131;
  --sw-hand: #e03131;
  position: absolute; inset: 0;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto;
  gap: 2.4cqmin;
  padding: 3cqmin 3cqmin calc(clamp(36px, 8.4cqmin, 84px) + 2 * clamp(8px, 2.6cqmin, 28px));
}

/* ---- the face ---- */
.sw-main { position: relative; container-type: size; min-height: 0; min-width: 0; display: grid; place-items: center; }
.sw-readout { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 1.5cqh; }
.sw-digits {
  font: 600 clamp(30px, min(40cqh, 20cqw), 640px)/1 var(--font-display);
  font-variant-numeric: tabular-nums; letter-spacing: -.025em; white-space: nowrap;
}
.sw-digits.is-long { font-size: clamp(26px, min(32cqh, 14.5cqw), 520px); }
.sw-cs { font-size: .56em; letter-spacing: -.01em; color: color-mix(in srgb, var(--stage-ink) 58%, transparent); }
.sw-sub {
  min-height: 1.25em; white-space: nowrap;
  font: 600 clamp(12px, min(7cqh, 4cqw), 46px)/1.2 var(--font-display); font-variant-numeric: tabular-nums;
  text-transform: uppercase; letter-spacing: .06em; color: color-mix(in srgb, var(--stage-ink) 55%, transparent);
}
.sw.is-running .sw-digits { color: var(--stage-ink); }
.sw.is-paused .sw-head { animation: t-flash 1.6s ease-in-out infinite; }

/* ---- the dial ---- */
.sw-dial {
  display: none; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(98cqh, 98cqw); height: min(98cqh, 98cqw); overflow: visible;
  filter: drop-shadow(0 .8cqmin 1.6cqmin rgba(16, 24, 40, .12));
}
.sw[data-style="dial"] .sw-dial { display: block; }
.sw[data-style="dial"] .sw-readout { transform: translateY(min(16cqh, 16cqw)); gap: .4cqmin; }
.sw[data-style="dial"] .sw-digits { font-size: clamp(16px, min(11cqh, 11cqw), 200px); }
.sw[data-style="dial"] .sw-digits.is-long { font-size: clamp(14px, min(8.5cqh, 8.5cqw), 160px); }
.sw[data-style="dial"] .sw-sub { font-size: clamp(10px, min(3.3cqh, 3.3cqw), 28px); }

.sw-bezel { fill: color-mix(in srgb, var(--stage-ink) 10%, var(--stage-bg)); }
.sw-face-bg { fill: var(--stage-bg); stroke: color-mix(in srgb, var(--stage-ink) 12%, transparent); stroke-width: .6; }
.sw-trail {
  fill: none; stroke: var(--cat); stroke-width: 5; opacity: .32;
  stroke-dasharray: 1000; stroke-dashoffset: 1000;
  transform: rotate(-90deg); transform-box: fill-box; transform-origin: center;
}
.sw-ticks line { stroke: color-mix(in srgb, var(--stage-ink) 38%, transparent); stroke-width: .7; stroke-linecap: round; }
.sw-ticks line.major { stroke: color-mix(in srgb, var(--stage-ink) 78%, transparent); stroke-width: 1.8; }
.sw-nums text { font: 600 8.6px var(--font-display); fill: color-mix(in srgb, var(--stage-ink) 80%, transparent); text-anchor: middle; }
.sw-sub-bg { fill: color-mix(in srgb, var(--stage-ink) 4%, var(--stage-bg)); stroke: color-mix(in srgb, var(--stage-ink) 18%, transparent); stroke-width: .5; }
.sw-subticks line { stroke: color-mix(in srgb, var(--stage-ink) 35%, transparent); stroke-width: .5; }
.sw-subticks line.major { stroke: color-mix(in srgb, var(--stage-ink) 70%, transparent); stroke-width: 1; }
.sw-subhand { stroke: var(--stage-ink); stroke-width: 1.4; stroke-linecap: round; }
.sw-sub-hub { fill: var(--stage-ink); }
.sw-hand line { stroke: var(--sw-hand); stroke-width: 1.5; stroke-linecap: round; }
.sw-hand circle { fill: var(--sw-hand); }
.sw-hand { filter: drop-shadow(.6px 1.2px 1px rgba(0, 0, 0, .25)); }
.sw-hub { fill: var(--stage-bg); }

/* ---- laps ---- */
.sw-laps {
  display: none; flex-direction: column; min-height: 0; max-height: 38cqh;
  border: 1px solid var(--line); border-radius: clamp(10px, 2cqmin, 20px); overflow: hidden;
  background: color-mix(in srgb, var(--stage-ink) 3%, var(--stage-bg));
  font-size: clamp(12px, 3cqmin, 30px);
}
.sw.has-laps .sw-laps { display: flex; }
.sw-laps.is-new { animation: sw-new .5s ease-out; }
@keyframes sw-new { 0% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--cat) 55%, transparent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.sw-laps-head {
  display: flex; align-items: center; gap: .55em; padding: .35em .45em .35em .9em;
  border-bottom: 1px solid var(--line); font-family: var(--font-display);
}
.sw-count {
  min-width: 1.7em; padding: .05em .5em; border-radius: 999px; text-align: center; font-weight: 650; font-size: .85em;
  background: color-mix(in srgb, var(--cat) 16%, var(--stage-bg)); font-variant-numeric: tabular-nums;
}
.sw-grow { flex: 1; }
.sw .sw-copy { min-height: clamp(34px, 6cqmin, 60px); padding: 0 clamp(8px, 1.6cqmin, 16px); box-shadow: none; }
.sw-laps-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.sw-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.sw-table th, .sw-table td { padding: .32em .9em; text-align: right; white-space: nowrap; }
.sw-table th:first-child { text-align: left; font-weight: 600; color: color-mix(in srgb, var(--stage-ink) 55%, transparent); }
.sw-table thead th {
  position: sticky; top: 0; z-index: 1; padding-block: .45em .35em;
  background: color-mix(in srgb, var(--stage-ink) 3%, var(--stage-bg));
  font-size: .72em; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: color-mix(in srgb, var(--stage-ink) 55%, transparent);
}
.sw-table tbody tr { border-top: 1px solid color-mix(in srgb, var(--stage-ink) 7%, transparent); }
.sw-table td { font-weight: 600; }
.sw-table td:last-child { font-weight: 500; color: color-mix(in srgb, var(--stage-ink) 65%, transparent); }
.sw-table tr.is-current td, .sw-table tr.is-current th { color: color-mix(in srgb, var(--stage-ink) 48%, transparent); font-weight: 500; }
.sw-table tr.is-best td:nth-child(2) { color: var(--sw-best); }
.sw-table tr.is-worst td:nth-child(2) { color: var(--sw-worst); }
.sw-tag {
  display: inline-block; margin-left: .55em; padding: .1em .55em; border-radius: 999px; vertical-align: .08em;
  font-size: .68em; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  background: color-mix(in srgb, currentColor 14%, transparent);
}
.sw-summary {
  display: flex; flex-wrap: wrap; justify-content: center; gap: .2em 1.1em; padding: .45em .9em;
  border-top: 1px solid var(--line); font-size: .82em; color: color-mix(in srgb, var(--stage-ink) 62%, transparent);
}
.sw-summary[hidden] { display: none; }
.sw-summary b { color: var(--stage-ink); font-variant-numeric: tabular-nums; }
.sw-summary .is-best b { color: var(--sw-best); }
.sw-summary .is-worst b { color: var(--sw-worst); }

:root[data-theme="dark"] .sw { --sw-best: #3ccf7d; --sw-worst: #ff6b6b; --sw-hand: #ff5c5c; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sw { --sw-best: #3ccf7d; --sw-worst: #ff6b6b; --sw-hand: #ff5c5c; }
}

/* Wide stage: laps in a column beside the face. */
@container (orientation: landscape) and (min-width: 620px) {
  .sw.has-laps { grid-template-columns: minmax(0, 1fr) clamp(230px, 36cqw, 640px); grid-template-rows: minmax(0, 1fr); }
  .sw.has-laps .sw-laps { max-height: none; }
}
/* Small widgets: the face only; the current lap still shows under the digits. */
@container (max-height: 340px) { .sw.has-laps .sw-laps { display: none; } }
@container (max-width: 400px) { .sw.has-laps .sw-laps { display: none; } }
@container (max-height: 260px) { .sw-sub { display: none; } }
