@font-face {
  font-family: 'Young Serif';
  src: url('fonts/young-serif-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* Registered so the whole palette glides when the mode changes. */
@property --hue {
  syntax: '<number>';
  inherits: true;
  initial-value: 192;
}

:root {
  --hue: 192;
  --breath: 10s;
  --deep: hsl(var(--hue) 52% 12%);
  --shallow: hsl(var(--hue) 46% 24%);
  --ink: hsl(var(--hue) 40% 93%);
  --ink-soft: hsl(var(--hue) 24% 72%);
  --glint: hsl(var(--hue) 78% 80%);
  --film: hsl(var(--hue) 60% 75% / 0.1);
  --edge: hsl(var(--hue) 60% 85% / 0.24);
  --serif: 'Young Serif', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
  transition: --hue 1.6s ease;
}

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(120% 80% at 50% 46%, var(--shallow), var(--deep) 70%);
  background-color: var(--deep);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#surface {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.stage {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  justify-items: center;
  height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.title {
  justify-self: start;
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 20px;
  letter-spacing: 0.01em;
}

.center {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 28px;
}

.charge {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  width: min(68vw, 300px, 44dvh);
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--edge);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, hsl(var(--hue) 60% 80% / 0.16), var(--film) 70%);
  color: var(--ink);
  font-family: var(--serif);
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: transform 0.2s ease, border-color 0.4s ease;
}

.charge:active {
  transform: scale(0.98);
}

.charge:focus-visible,
.mode:focus-visible {
  outline: 2px solid var(--glint);
  outline-offset: 6px;
}

.charge[aria-pressed='true'] {
  border-color: transparent;
  animation: breathe var(--breath) ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 40px hsl(var(--hue) 80% 70% / 0.12); }
  50% { box-shadow: 0 0 90px hsl(var(--hue) 80% 70% / 0.34); }
}

.ring {
  position: absolute;
  inset: -1px;
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  transform: rotate(-90deg);
  pointer-events: none;
}

.ring circle {
  fill: none;
  stroke-width: 1.2;
}

.ring-track {
  stroke: transparent;
}

.ring-fill {
  stroke: var(--glint);
  stroke-linecap: round;
  stroke-dasharray: 301.6;
  stroke-dashoffset: 301.6;
  opacity: 0;
  transition: stroke-dashoffset 0.3s linear, opacity 0.6s ease;
}

/* Hidden at rest: a zero-length dash still paints its round cap. */
.charge[aria-pressed='true'] .ring-fill {
  opacity: 1;
}

.freq {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: clamp(60px, 19vw, 96px);
  line-height: 1;
  font-variant-numeric: lining-nums;
}

.unit {
  font-size: 0.24em;
  color: var(--ink-soft);
}

.action {
  margin-top: 14px;
  font-size: 19px;
  color: var(--glint);
}

.status {
  max-width: 30ch;
  min-height: 3em;
  margin: 0;
  text-align: center;
  color: var(--ink-soft);
}

.modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(100%, 420px);
  margin-bottom: 14px;
}

.mode {
  display: grid;
  gap: 2px;
  padding: 12px 6px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  cursor: pointer;
  transition: background-color 0.4s ease, border-color 0.4s ease, color 0.4s ease;
}

.mode-name {
  font-family: var(--serif);
  font-size: 18px;
}

.mode-hz {
  font-size: 13px;
}

.mode[aria-pressed='true'] {
  border-color: var(--edge);
  background: var(--film);
  color: var(--ink);
}

.note {
  margin: 0;
  font-size: 12px;
  color: hsl(var(--hue) 20% 62%);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  :root,
  .mode,
  .ring-fill {
    transition: none;
  }

  .charge[aria-pressed='true'] {
    animation: none;
    box-shadow: 0 0 70px hsl(var(--hue) 80% 70% / 0.26);
  }
}
