@font-face {
  font-family: "Hanken Grotesk";
  src: url("../fonts/hanken-grotesk.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ground: #1136c4;
  --ground-deep: #0d2a9f;
  --paper: #f6f8ff;
  --mist: #dbe4ff;
  --cyan: #6aebf8;
  --signal: #ff7a3d;
  --ink: #0a1a5c;
  --ink-line: #2a3a80;
  --tint: #e9eeff;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  display: grid;
  place-items: center;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  font-family: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  font-weight: 500;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
h1, p { margin: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-home {
  position: fixed;
  right: 16px;
  bottom: 12px;
  color: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  text-underline-offset: 3px;
}
.framed .app-home { display: none; }

/* Drum machine */
.page-drum { --focus: var(--cyan); background: var(--ink); color: var(--paper); }
.page-drum ::selection { background: var(--cyan); color: var(--ink); }
.page-drum :focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }

#drum-machine {
  --pad: min(29vh, 17vw);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: min(5vw, 7vh);
  padding: 2vh 3vw;
}

.pads {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, var(--pad));
  grid-auto-rows: var(--pad);
  gap: calc(var(--pad) * 0.08);
}

.drum-pad {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 22%;
  background: var(--ground);
  color: var(--paper);
  font-size: calc(var(--pad) * 0.34);
  font-weight: 800;
  line-height: 1;
  transition: background-color 280ms ease, color 280ms ease, transform 180ms var(--ease-out);
}
.drum-pad:active,
.drum-pad.is-hit { transition: none; background: var(--signal); color: var(--ink); transform: scale(0.95); }

.deck {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: min(2.4vh, 16px);
  width: min(34vw, 62vh);
}

.readout {
  display: grid;
  place-items: center;
  width: min(30vw, 50vh);
  aspect-ratio: 1;
  padding: 24px;
  border-radius: 50%;
  outline: 3px solid var(--cyan);
  outline-offset: 7px;
  background: var(--ground-deep);
  text-align: center;
  transition: background-color 280ms ease;
}
.readout.is-hit { transition: none; background: var(--ground); }
#display {
  font-size: clamp(1.125rem, min(4.6vh, 3vw), 2.25rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.volume { display: grid; gap: 4px; width: 100%; font-size: 0.9375rem; font-weight: 600; }
.volume input { width: 100%; margin: 0; accent-color: var(--signal); }
.hint { color: var(--mist); font-size: 0.9375rem; text-align: center; }

@media (hover: hover) and (pointer: fine) {
  .drum-pad:hover { background: #2448d8; }
}

@media (max-aspect-ratio: 1/1) {
  #drum-machine { --pad: min(27vw, 19vh); flex-direction: column-reverse; gap: 2.4vh; }
  .deck { width: min(84vw, 340px); }
  .readout { width: 100%; aspect-ratio: auto; min-height: 12vh; padding: 16px; border-radius: 28px; outline-offset: 4px; }
  #display { font-size: clamp(1.25rem, 6vw, 2rem); }
  .hint { display: none; }
}

/* Calculator */
.page-calculator { background: var(--cyan); color: var(--ink); }
.page-calculator :focus-visible { outline: 3px solid var(--ground); outline-offset: 2px; }

.calculator {
  --key: min(13vh, 8vw);
  display: flex;
  align-items: stretch;
  gap: 0.9rem;
  padding: 0.9rem;
  border-radius: 28px;
  background: var(--paper);
}

.screen {
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: min(36vw, 60vh);
  min-width: 0;
  padding: 1rem 1.2rem;
  border-radius: 16px;
  background: var(--ink);
  color: var(--paper);
  text-align: right;
}
.formula {
  min-height: 1.4em;
  overflow-wrap: anywhere;
  color: var(--cyan);
  font-size: clamp(0.9375rem, 2.4vh, 1.125rem);
  font-variant-numeric: tabular-nums;
}
#display {
  overflow: hidden;
  font-size: clamp(2.25rem, 9vh, 4rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  letter-spacing: -0.03em;
  white-space: nowrap;
}
#display.is-long { font-size: clamp(1.5rem, 5vh, 2.25rem); letter-spacing: -0.02em; }
#display.is-message { font-size: clamp(1.25rem, 4vh, 1.75rem); letter-spacing: 0; white-space: normal; }

.keys {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, calc(var(--key) * 1.3));
  grid-auto-rows: var(--key);
  gap: 0.45rem;
}
.keys button {
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--tint);
  font-size: calc(var(--key) * 0.4);
  font-weight: 700;
  line-height: 1;
  transition: background-color 160ms ease, transform 160ms var(--ease-out);
}
.keys button:active,
.keys button.is-pressed { transform: scale(0.96); }
.keys .wide { grid-column: span 2; }
.keys .operator { background: var(--ground); color: var(--paper); }
.keys .quiet { background: var(--mist); }
.keys #equals { background: var(--signal); }

@media (hover: hover) and (pointer: fine) {
  .keys button:hover { background: #dce4ff; }
  .keys .operator:hover { background: var(--ground-deep); }
  .keys .quiet:hover { background: #cbd7fb; }
  .keys #equals:hover { background: #ff9462; }
}

@media (max-aspect-ratio: 1/1) {
  .calculator { --key: min(12.6vh, 18vw); flex-direction: column; gap: 0.6rem; padding: 0.7rem; }
  .screen { width: 100%; min-height: 15vh; padding: 0.7rem 1rem; }
  .keys { grid-template-columns: repeat(4, minmax(0, 1fr)); width: min(86vw, 380px); }
}

/* 25 + 5 clock */
.page-clock { background: var(--paper); color: var(--ink); }
.page-clock :focus-visible { outline: 3px solid var(--ground); outline-offset: 2px; }

.clock {
  --dial: min(78vh, 44vw);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: min(6vw, 8vh);
  padding: 2vh 3vw;
}

.dial {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: var(--dial);
  aspect-ratio: 1;
  text-align: center;
}
.dial svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.dial circle { fill: none; stroke-width: 6; }
.dial .track { stroke: var(--tint); }
.dial .progress {
  stroke: var(--ground);
  stroke-dasharray: 1;
  stroke-linecap: round;
  transition: stroke 240ms ease, stroke-dashoffset 1000ms linear;
}
.is-break .dial .progress { stroke: var(--signal); }
.is-reset .dial .progress { transition: stroke 240ms ease; }
.is-ending #time-left { color: #c8281c; }

.dial-text { position: relative; }
#timer-label { font-size: calc(var(--dial) * 0.075); font-weight: 700; }
#time-left {
  color: var(--ground);
  font-size: calc(var(--dial) * 0.215);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.03em;
}

.settings { flex: none; display: grid; gap: min(3vh, 22px); width: min(34vw, 340px); }
.lengths { display: grid; gap: min(2.2vh, 16px); }
.length { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.5rem 1rem; }
.length > span { font-size: 1.0625rem; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 0.5rem; }
.stepper output,
.stepper span {
  min-width: 2.2ch;
  font-size: 1.625rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.stepper button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--tint);
  transition: background-color 160ms ease, transform 160ms var(--ease-out);
}
.stepper button:active { transform: scale(0.95); }
.stepper svg { width: 16px; height: 16px; fill: currentColor; }

.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.controls button {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 52px;
  padding: 0 1.2rem;
  border-radius: 999px;
  font-weight: 700;
  transition: background-color 160ms ease, transform 160ms var(--ease-out);
}
.controls button:active { transform: scale(0.97); }
.controls svg { width: 14px; height: 14px; fill: currentColor; }
#start_stop { border: 1.5px solid var(--ground); background: var(--ground); color: var(--paper); }
#reset { border: 1.5px solid var(--ink); background: transparent; }
.is-running .icon-play,
.clock:not(.is-running) .icon-pause { display: none; }

@media (hover: hover) and (pointer: fine) {
  .stepper button:not(:disabled):hover { background: #dce4ff; }
  #start_stop:hover { background: var(--ground-deep); }
  #reset:hover { background: var(--tint); }
}

.stepper button:disabled { color: #5a6898; cursor: default; }

@media (max-aspect-ratio: 1/1) {
  .clock { --dial: min(66vw, 48vh); flex-direction: column; gap: 2.6vh; }
  .settings { width: min(84vw, 340px); }
}

@media (prefers-reduced-motion: reduce) {
  .drum-pad:active,
  .drum-pad.is-hit,
  .keys button:active,
  .keys button.is-pressed { transform: none; }
  .dial .progress { transition: stroke 240ms ease; }
}
