:root {
  color-scheme: dark;
  --bg: #12122a;
  --bg-glow: #2a2160;
  --surface: #23234a;
  --border: rgb(255 255 255 / 0.14);
  --text: #f4f4fb;
  --muted: #a6a6c8;
  --accent: #9b5de5;
  --accent-dark: #4a2391;
  --record: #ff5a5f;
  --gold: #ffc23d;
  --on-gold: #1d1606;
  /* Replaced at runtime with the measured bar height (see app.js). */
  --orb-size: min(52vw, 30vh, 240px);
  --bar-height: calc(89px + env(safe-area-inset-bottom, 0px));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --gutter-left: max(16px, env(safe-area-inset-left, 0px));
  --gutter-right: max(16px, env(safe-area-inset-right, 0px));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

html {
  background-color: var(--bg);
  /* iOS Safari enlarges text in landscape unless told not to. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Keeps pinch zoom but drops double-tap zoom, so fast taps never zoom the page. */
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
  /* Not "fixed": iOS ignores it and it forces repaints while scrolling. */
  background: radial-gradient(circle at 20% -10%, var(--bg-glow), var(--bg) 55%) no-repeat;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 1.4rem;
}

h2 {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

button,
select {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: inherit;
  /* 16px or more stops iOS Safari from zooming in on focus. */
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}

button {
  transition: transform 0.1s;
}

button:active:not(:disabled) {
  transform: scale(0.96);
}

@media (hover: hover) {
  button:hover:not(:disabled),
  select:hover:not(:disabled) {
    border-color: rgb(255 255 255 / 0.35);
  }
}

button:focus-visible,
select:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

button:disabled,
button[aria-disabled="true"],
select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Classes below set "display", which would otherwise beat the hidden attribute. */
[hidden] {
  display: none !important;
}

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

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) var(--gutter-right) 4px var(--gutter-left);
}

.toggles {
  display: flex;
  gap: 8px;
}

.toggles button {
  padding-inline: 0.85rem;
  white-space: nowrap;
}

/* Layout */

.app {
  display: grid;
  gap: 28px;
  max-width: 560px;
  margin: 0 auto;
  /* Leave room for the fixed action bar on phones, with a clear gap under the last option. */
  padding: 8px var(--gutter-right) calc(var(--bar-height) + 40px) var(--gutter-left);
}

.step {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Stage: the orb, the instruction and the buttons */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.orb {
  /* Set while recording (see app.js): 0 for silence, 1 for a loud voice. */
  --level: 0;
  display: grid;
  place-items: center;
  width: var(--orb-size);
  aspect-ratio: 1;
  margin: 12px 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #cfa8ff, var(--accent) 42%, var(--accent-dark));
  box-shadow:
    inset -12px -16px 30px rgb(0 0 0 / 0.35),
    0 24px 48px rgb(0 0 0 / 0.45);
  transform: scale(calc(1 + var(--level) * 0.18));
  transition: transform 0.08s;
}

.orb-icon {
  font-size: calc(var(--orb-size) * 0.4);
  line-height: 1;
}

.orb.recording {
  background: radial-gradient(circle at 32% 28%, #ffb0b3, var(--record) 42%, #b3262b);
}

.orb.playing {
  animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.06);
  }
}

.headline {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-wrap: balance;
}

.status {
  margin: 0;
  min-height: 1.4em;
  color: var(--muted);
  text-align: center;
}

/* On phones the main buttons sit in a bar pinned to the bottom, within thumb reach. */
.actions {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  gap: 8px;
  padding: 12px var(--gutter-right) calc(12px + var(--safe-bottom)) var(--gutter-left);
  border-top: 1px solid var(--border);
  background: rgb(18 18 42 / 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.actions .primary {
  flex: 1;
  min-height: 64px;
  border: none;
  background: var(--gold);
  color: var(--on-gold);
  font-size: 1.35rem;
  font-weight: 800;
}

.actions .secondary {
  min-height: 64px;
}

@media (hover: hover) {
  .actions .primary:hover:not(:disabled) {
    background: #ffd36f;
  }
}

.status.problem {
  color: var(--gold);
}

/* The button of the sound that is playing now. */
button.sounding {
  border-color: var(--gold);
  color: var(--gold);
}

.actions .primary.sounding {
  color: var(--on-gold);
}

/* Secondary buttons: smaller than the main ones, and away from the thumb bar. */
.tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.tools button {
  padding-inline: 0.9rem;
  font-size: 0.95rem;
}

.count {
  margin-left: 8px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: normal;
}

/* Options */

/* A list of label | control rows. The divider spans the full width, the rows at most 420px. */
.options {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px 14px;
  padding: 20px max(0px, calc((100% - 420px) / 2)) 0;
  border-top: 1px solid var(--border);
}

/* Each label spans both columns and puts its text and control in the columns of .options.
   justify-items pushes the label text to the right, next to its control. */
.field {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: center;
  justify-items: end;
  color: var(--muted);
}

.field select {
  width: 100%;
  color: var(--text);
}

.options #reset {
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: 4px;
}

.check {
  min-height: 44px;
  cursor: pointer;
}

.check input {
  justify-self: start;
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--gold);
  cursor: pointer;
}

/* Wide screens: the buttons go back into the page, under the stage. */

@media (min-width: 900px) {
  .app {
    padding: 16px var(--gutter-right) calc(32px + var(--safe-bottom)) var(--gutter-left);
  }

  .actions {
    position: static;
    width: 100%;
    max-width: 400px;
    padding: 0;
    border: none;
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  button,
  .orb {
    transition: none;
  }

  .orb.playing {
    animation: none;
  }
}

.app-description {
  margin: 0;
  color: var(--muted);
}
