:root {
  --teal: #5ac0c8;
  --navy: #19194b;
  --button: #7b8292;
  font-family: "Trebuchet MS", sans-serif;
  background: var(--teal);
  color: #fff;
  font-synthesis: none;
}
* { box-sizing: border-box; letter-spacing: 0; }
body { margin: 0; min-width: 320px; }
button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid #fff3a2; outline-offset: 3px; }
button:enabled:hover { filter: brightness(1.04); }
button:enabled:active { filter: brightness(.92); }
button:disabled { cursor: default; }
.tool-button:disabled, .step-button:disabled { opacity: .48; }
.control-icon { display: block; width: 100%; height: 100%; background-image: url('../img/timer-controls.png'); background-repeat: no-repeat; background-size: 700% 100%; background-position: calc(var(--icon-frame) * 100% / 6) 0; }
.icon-minus { --icon-frame: 0; }
.icon-plus { --icon-frame: 1; }
.icon-reset { --icon-frame: 2; }
.icon-pause { --icon-frame: 3; }
.icon-play { --icon-frame: 4; }
.icon-expand { --icon-frame: 5; }
.icon-collapse { --icon-frame: 6; }
[hidden] { display: none !important; }
.app { position: relative; width: min(100%, calc(100svh * 16 / 9)); aspect-ratio: 16 / 9; margin: 0 auto; container-type: inline-size; }
.stage { position: absolute; top: 1.8%; left: 1.1%; right: 1.1%; bottom: 12.5%; overflow: hidden; isolation: isolate; border-radius: 7px; background: var(--navy); }
.clock-area { position: absolute; z-index: 2; top: 0; left: 0; width: 100%; height: 15.9%; text-align: center; }
.clock { position: absolute; bottom: 0; left: 0; width: 100%; display: flex; align-items: center; justify-content: center; height: 48%; isolation: isolate; background: #fff; color: #000; font: 48px/1 "Trebuchet MS", sans-serif; font-variant-numeric: tabular-nums; }
.clock::before { content: ""; position: absolute; inset: 0; z-index: -1; background: #c3c3c3; transform-origin: left center; transform: scaleX(var(--remaining, 1)); }
[data-state="running"] .clock::before { transition: transform .1s linear; }
.circus-scene { position: absolute; top: 15.9%; left: 0; width: 100%; height: 84.1%; display: block; }
.controlbar { position: absolute; left: 1.1%; right: 1.1%; top: 89.6%; height: 7.65%; }
.badge { position: absolute; left: 0; top: 0; width: 18%; height: 100%; display: block; }
.badge img { display: block; width: 100%; height: 100%; object-fit: contain; }
.badge:focus-visible { outline: 3px solid #fff3a2; outline-offset: 3px; }
.time-settings { position: absolute; left: 30.2%; width: 39.5%; height: 100%; }
.duration-fields { display: flex; gap: 2.6%; height: 100%; }
.duration-unit { width: 48.7%; height: 100%; }
.stepper { position: relative; isolation: isolate; display: flex; align-items: center; justify-content: space-between; height: 100%; border-radius: 6px; }
.stepper::before { content: ""; position: absolute; inset: 0 16%; z-index: -1; background: linear-gradient(#454851, #2f323b); border-radius: inherit; }
.stepper label { flex: 1; text-align: center; font-size: 24px; font-weight: bold; line-height: 1; }
.step-button, .tool-button { display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: transparent; color: #fff; height: 100%; aspect-ratio: 1; flex-shrink: 0; }
.step-button { width: 22%; }
.playback-controls { position: absolute; right: 0; top: 0; width: 18.6%; height: 100%; display: flex; justify-content: space-between; gap: 3%; }
.tool-button { width: 23%; }
.confetti { position: absolute; z-index: 4; top: 15.9%; bottom: 0; left: 0; right: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -30px; width: 7px; height: 12px; background: var(--particle-color); border-radius: 1px; animation: confetti-fall var(--fall-duration) var(--fall-delay) ease-in forwards; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
#finaleStars { opacity: 0; }
[data-state="finished"] #finaleStars { animation: finale-stars 1.8s ease-in-out infinite alternate; }
[data-state="finished"] #performerBody { animation: take-a-bow 2s .4s ease-in-out 2; transform-origin: 0 -121px; }
[data-state="finished"] .juggle-ball { transition: cx .35s ease-out, cy .35s ease-in; }
@keyframes confetti-fall { to { transform: translate(var(--drift), 720px) rotate(650deg); opacity: .2; } }
@keyframes finale-stars { from { opacity: .4; } to { opacity: 1; } }
@keyframes take-a-bow { 30%, 60% { transform: rotate(8deg); } }
@container (max-width: 1100px) {
  .clock { font-size: 42px; }
  .stepper label { font-size: 22px; }
}
@container (max-width: 850px) {
  .clock { font-size: 32px; }
  .stepper label { font-size: 17px; }
}
@container (max-width: 640px) {
  .clock { font-size: 25px; }
  .stepper label { font-size: 12px; }
  .stage, .stepper, .step-button, .tool-button { border-radius: 3px; }
}
@container (max-width: 420px) {
  .clock { font-size: 16px; }
  .stepper label { font-size: 8px; }
}
@media (max-width: 640px) {
  .app {
    width: 100%;
    min-height: 100svh;
    aspect-ratio: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    padding: 12px;
  }
  .stage {
    position: relative;
    inset: auto;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    min-height: 0;
    flex: none;
  }
  .controlbar {
    position: relative;
    inset: auto;
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "badge playback" "settings settings";
    gap: 10px;
    padding: 0;
  }
  .badge {
    position: relative;
    grid-area: badge;
    width: 100%;
    max-width: 140px;
    height: 40px;
  }
  .time-settings {
    position: relative;
    grid-area: settings;
    left: auto;
    width: 100%;
    height: 46px;
  }
  .duration-fields { gap: 10px; }
  .duration-unit { width: calc((100% - 10px) / 2); }
  .stepper { padding: 0 3px; }
  .stepper::before { inset: 0; }
  .stepper label { font-size: 14px; }
  .step-button {
    width: 40px;
    height: 46px;
    min-width: 40px;
    aspect-ratio: auto;
  }
  .step-button .control-icon { width: 40px; height: 46px; }
  .playback-controls {
    position: relative;
    grid-area: playback;
    top: auto;
    right: auto;
    width: auto;
    height: 40px;
    gap: 6px;
    justify-content: end;
  }
  .tool-button {
    width: 40px;
    height: 40px;
    aspect-ratio: auto;
  }
}
@media (max-width: 360px) {
  .stepper label { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confetti { display: none; }
  [data-state="finished"] #finaleStars { opacity: 1; }
}