@font-face {
  font-family: 'Instrument Serif';
  src: url('fonts/instrument-serif-italic.woff2') format('woff2');
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

/* Registered so the water colour can glide between moods. */
@property --water-hi { syntax: '<color>'; inherits: true; initial-value: #1D3B5C; }
@property --water-lo { syntax: '<color>'; inherits: true; initial-value: #081320; }

:root {
  --water-hi: #1D3B5C;
  --water-lo: #081320;
  --note-lo: hsl(344 92% 66%);
  --note-hi: hsl(46 92% 66%);
  --ink: #E4EEF0;
  --ink-soft: rgba(228, 238, 240, 0.66);
  --glass: rgba(228, 238, 240, 0.07);
  --glass-press: rgba(228, 238, 240, 0.15);
  --glass-edge: rgba(228, 238, 240, 0.16);
  --panel: #0B1726;
  --panel: color-mix(in srgb, var(--water-lo), #fff 4%);
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
  --gutter: 16px;
  color-scheme: dark;
  transition: --water-hi 0.8s ease, --water-lo 0.8s ease;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--water-lo);
}

body {
  color: var(--ink);
  font-family: var(--ui);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#water {
  position: fixed;
  inset: 0;
  background: radial-gradient(130% 95% at 50% 36%, var(--water-hi) 0%, var(--water-lo) 74%);
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#pool {
  touch-action: none;
  outline: none;
  cursor: crosshair;
}

#pool:focus-visible {
  box-shadow: inset 0 0 0 2px var(--ink-soft);
}

/* ---------- bars ---------- */

.bar {
  position: fixed;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  pointer-events: none;
}

.bar > * { pointer-events: auto; }

.top {
  top: 0;
  padding-top: max(14px, env(safe-area-inset-top));
}

.bottom {
  bottom: 0;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}

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

.wordmark {
  margin: 0;
  font: italic 400 30px/1 var(--serif);
  letter-spacing: -0.01em;
  color: var(--ink);
  opacity: 0.88;
  pointer-events: none;
}

/* ---------- buttons ---------- */

button {
  font: 500 15px/1 var(--ui);
  color: var(--ink);
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  border-radius: 999px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease;
}

button:hover { background: rgba(228, 238, 240, 0.11); }
button:active { background: var(--glass-press); }

button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--note-lo), var(--note-hi));
}

#sound {
  padding: 0;
  width: 44px;
}

.icon {
  width: 22px;
  height: 22px;
  fill: var(--ink);
}

.icon .wave {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.8;
  stroke-linecap: round;
}

#sound .icon.off,
#sound.off .icon.on { display: none; }
#sound.off .icon.off { display: block; }
#sound.off { color: var(--ink-soft); }

/* ---------- hint ---------- */

.hint {
  position: fixed;
  left: 50%;
  top: 63%;
  transform: translateX(-50%);
  margin: 0;
  width: min(84vw, 21em);
  text-align: center;
  font: italic 400 clamp(21px, 5.4vw, 27px)/1.28 var(--serif);
  color: var(--ink-soft);
  text-shadow: 0 0 14px var(--water-lo), 0 0 4px var(--water-lo);
  text-wrap: balance;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.7s ease;
}

.hint.show { opacity: 1; }

button[aria-pressed='true']:not(#sound),
button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--water-lo);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.quiet {
  background: none;
  border-color: transparent;
  color: var(--ink-soft);
  justify-self: start;
  padding: 0 4px;
}

button.quiet:hover { color: var(--ink); background: none; }

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

/* ---------- start button ---------- */

.start {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 15;
  min-height: 56px;
  padding: 0 26px 0 22px;
  gap: 12px;
  font: italic 400 24px/1 var(--serif);
  background: var(--panel);
  border-color: var(--glass-edge);
}

.start .icon { width: 24px; height: 24px; }

/* ---------- pebble menu ---------- */

.pop {
  position: fixed;
  z-index: 25;
  display: grid;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 12px 12px 6px;
  background: var(--panel);
  border: 1px solid var(--glass-edge);
  border-radius: 20px;
}

.pop-title {
  margin: 0 4px;
  font: italic 400 19px/1.1 var(--serif);
  color: var(--ink-soft);
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.seg button {
  min-height: 40px;
  padding: 0 13px;
  font-size: 14.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------- sheets ---------- */

.sheet {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 12px;
  max-height: min(78vh, 620px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px max(20px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: var(--panel);
  border-top: 1px solid var(--glass-edge);
  border-radius: 24px 24px 0 0;
  outline: none;
  -webkit-user-select: none;
  user-select: none;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.sheet h2 {
  margin: 0;
  font: italic 400 25px/1 var(--serif);
  letter-spacing: -0.01em;
}

.field {
  display: grid;
  gap: 0;
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
  color: var(--ink-soft);
}

.field-head output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.row.ends span {
  font-size: 13px;
  color: var(--ink-soft);
  min-width: 2.6em;
}

.row.ends span:last-child { text-align: right; }

.stepper output {
  min-width: 3ch;
  text-align: center;
  font: italic 400 26px/1 var(--serif);
}

.stepper button {
  width: 44px;
  padding: 0;
  font-size: 20px;
}

.note {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-soft);
}

#share-link {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  font: 14px/1 ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color: var(--ink);
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  border-radius: 12px;
  -webkit-user-select: text;
  user-select: text;
}

#share-link:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* Range sliders: a thin track with a round pebble of a thumb. */
input[type='range'] {
  flex: 1;
  min-width: 0;
  height: 40px;
  margin: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  touch-action: pan-y;
  cursor: pointer;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--glass-edge);
}

input[type='range']::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--glass-edge);
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--ink);
  border: 0;
}

input[type='range']::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--ink);
  border: 0;
}

input[type='range']:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 58px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 6px 4px 18px;
  border-radius: 999px;
  background: rgba(6, 14, 24, 0.86);
  border: 1px solid var(--glass-edge);
  font: 15px/1.2 var(--ui);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 30;
}

.toast:not(:has(.undo:not([hidden]))) { padding-right: 18px; }
.toast.show { opacity: 1; pointer-events: auto; }
.toast .undo { min-height: 36px; }

@media (min-width: 720px) {
  :root { --gutter: 24px; }
  .wordmark { font-size: 34px; }

  /* On wide screens the sheet floats above the controls instead. */
  .sheet {
    left: auto;
    right: max(24px, env(safe-area-inset-right));
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 58px);
    width: 380px;
    padding: 18px 20px 20px;
    border: 1px solid var(--glass-edge);
    border-radius: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root { transition: none; }
  .hint,
  .toast { transition: none; }
}
