/* SPDX-License-Identifier: MIT */
/* Squatch Tuner - ink on paper. Every colour comes from the Squatch Ink design tokens in tokens.css,
   which is a copy of the generated Squatch Ink stylesheet (squatch-ink.css) and is not edited
   here. To refresh it, copy the new one over it and keep its two header lines.
   Light is rice paper and sumi ink; dark is the default when the system is dark.
   Meanings: gold is "in tune", the seals and the needle; seal red is the limit only, here a hot
   input meter. */
:root {
  --paper: var(--sq-sys-color-surface-page);
  --paper-2: var(--sq-sys-color-surface-sunken);
  --ink: var(--sq-sys-color-text-primary);
  --ink-2: var(--sq-sys-color-text-secondary);
  --ink-3: var(--sq-sys-color-text-secondary);
  --tuned: var(--sq-sys-color-accent);
  --tuned-ink: var(--sq-sys-color-text-on-accent);
  --zone: color-mix(in srgb, var(--sq-sys-color-accent) 18%, transparent);
  --limit: var(--sq-sys-color-status-limit);
  --grain-blend: var(--sq-sys-ink-grain-blend);
  --grain-opacity: var(--sq-sys-ink-grain-opacity);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--paper); color: var(--ink);
  font: 16px/1.4 var(--sans);
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
/* Paper grain: a noise tile made once by tuner.js, laid over everything. */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 10;
  background-image: var(--grain, none); background-size: 256px 256px;
  mix-blend-mode: var(--grain-blend); opacity: var(--grain-opacity);
}
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---- header ---- */
.top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left));
}
.home {
  justify-self: start; color: var(--ink-2); text-decoration: none; font-size: 14px; letter-spacing: 0.02em;
  padding: 6px 0; border-bottom: 1px solid transparent;
}
.home.gone { visibility: hidden; }
.home:hover, .home:focus-visible { color: var(--ink); border-bottom-color: var(--ink-3); }
.brand { display: flex; flex-direction: column; align-items: center; text-align: center; }
.wordmark { font: italic 700 22px/1 var(--serif); letter-spacing: 0.01em; }
.swash { width: 150px; height: 9px; margin-top: 3px; fill: var(--tuned); opacity: 0.9; }
.sub { margin-top: 5px; font-size: 12px; color: var(--ink-2); letter-spacing: 0.08em; text-transform: uppercase; }
.theme {
  justify-self: end; display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid var(--ink-3); border-radius: 999px; color: var(--ink-2);
  font: 12px var(--sans); padding: 5px 11px 5px 7px; cursor: pointer;
}
.theme svg { width: 16px; height: 16px; fill: currentColor; }
.theme:hover, .theme:focus-visible { color: var(--ink); border-color: var(--ink-2); }

/* ---- stage ---- */
.stage {
  flex: 1; width: 100%; max-width: 1080px; margin: 0 auto;
  padding: 8px max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  display: grid; gap: 4px 40px;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  grid-template-areas: "note readout" "scale scale" "strobe strobe" "controls controls";
  align-items: center;
}
.note-block { grid-area: note; display: flex; flex-direction: column; align-items: center; }
.readout { grid-area: readout; display: flex; flex-direction: column; align-items: flex-start; }
.scale-block { grid-area: scale; }
.strobe-block { grid-area: strobe; }
.controls { grid-area: controls; }

.note {
  display: flex; align-items: flex-start; justify-content: center; min-height: 1em;
  font: 900 clamp(120px, 19vw, 220px)/0.92 var(--serif);
  filter: url(#ink-edge);
  transition: opacity 0.4s ease;
}
.note .acc { font-size: 0.42em; line-height: 1.1; margin-left: 0.02em; }
.note .oct { font-size: 0.3em; align-self: flex-end; margin: 0 0 0.12em 0.06em; color: var(--ink-2); }
.status { font-size: 14px; letter-spacing: 0.06em; color: var(--ink-2); min-height: 1.4em; font-variant-numeric: tabular-nums; }

.cents { font: 700 clamp(64px, 9vw, 104px)/1 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.cents .unit { font: italic 400 0.5em var(--serif); margin-left: 0.08em; color: var(--ink-2); }
.direction { font: italic 20px var(--serif); color: var(--ink-2); min-height: 1.5em; margin-top: 2px; }
.seals { display: flex; gap: 14px; margin-top: 12px; }
.seal { width: 74px; height: 74px; filter: url(#seal-edge); }
.seal .seal-body { fill: none; stroke: var(--ink-3); stroke-width: 2.5; }
.seal .seal-ring { fill: none; stroke: var(--ink-3); stroke-width: 1.2; stroke-dasharray: 3 4; }
.seal text { text-anchor: middle; fill: var(--ink-3); }
.seal .seal-num { font: 700 26px var(--serif); }
.seal .seal-cap { font: 11px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; }
.seal.on .seal-body { fill: var(--tuned); stroke: var(--tuned); }
.seal.on .seal-ring { stroke: var(--tuned-ink); stroke-dasharray: none; opacity: 0.8; }
.seal.on text { fill: var(--tuned-ink); }
.seal.on { animation: press 0.18s ease-out; }
@keyframes press { from { transform: scale(1.12) rotate(-3deg); } to { transform: none; } }

/* ---- scale ---- */
.scale { width: 100%; height: auto; display: block; overflow: visible; }
.scale .baseline, .scale .ticks { fill: var(--ink); }
.scale .ticks { opacity: 0.9; }
.scale .zone { fill: var(--zone); }
.scale .labels text { text-anchor: middle; fill: var(--ink-2); font: 15px var(--mono); }
.scale .labels .zero { font: 700 22px var(--serif); fill: var(--ink); }
.scale .end { fill: var(--ink-3); font: italic 15px var(--serif); }
.scale .end-r { text-anchor: end; }
.needle { fill: var(--ink); transition: opacity 0.4s ease; }
.stage[data-view="note"] .needle { fill: var(--ink); }
.stage.in-tune .needle { fill: var(--tuned); }

/* ---- strobe ---- */
.strobe-wrap { position: relative; }
#strobe { display: block; width: 100%; height: clamp(120px, 17vw, 168px); border-radius: 3px; }
.strobe-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font: italic 600 22px var(--serif); color: var(--ink); pointer-events: none;
  text-shadow: 0 0 12px var(--paper), 0 0 4px var(--paper);
  opacity: 0; transition: opacity 0.4s ease;
}
.stage:not([data-view="note"]) .strobe-msg { opacity: 1; }
.strobe-legend {
  display: flex; justify-content: space-between; margin: 6px 2px 0; font-size: 12px; color: var(--ink-2);
  letter-spacing: 0.04em;
}

/* ---- controls ---- */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 40px; margin-top: 14px; align-items: start; }
.ref label { font-size: 14px; color: var(--ink-2); }
.ref b { color: var(--ink); font: 700 17px var(--serif); margin-left: 4px; }
.ref-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.ref-row button {
  width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--ink-2); background: none;
  color: var(--ink); font: 700 20px/1 var(--sans); cursor: pointer; flex: none;
}
.ref-row button:hover, .ref-row button:focus-visible { border-color: var(--ink); background: var(--paper-2); }
input[type="range"] { flex: 1; min-width: 0; accent-color: var(--tuned); height: 28px; }
.meter-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); }
#level-num { font: 13px var(--mono); }
.meter { position: relative; height: 10px; margin-top: 10px; background: var(--paper-2); border-radius: 5px; overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ink-2); border-radius: 5px; transition: width 0.06s linear; }
.meter-fill.hot { background: var(--limit); }
.meter-mark { position: absolute; top: 0; bottom: 0; width: 1.5px; background: var(--ink-3); }
.meter-mark.m12 { left: 80%; }
.meter-mark.m6 { left: 90%; }
.detail { margin-top: 8px; font: 12px var(--mono); color: var(--ink-2); min-height: 1.4em; }

/* ---- footer ---- */
.foot {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom)); font: 11.5px var(--mono); color: var(--ink-2);
}

/* ---- states ---- */
.stage[data-view="offline"] .note, .stage[data-view="nosignal"] .note { opacity: 0.28; }
.stage[data-view="listening"] .note { opacity: 0.55; }
.stage:not([data-view="note"]) .cents, .stage:not([data-view="note"]) .needle { opacity: 0.3; }
.stage.fading .note, .stage.fading .cents { opacity: 0.55; }

/* ---- phone ---- */
@media (max-width: 720px) {
  .top { grid-template-columns: 1fr auto; padding-left: 16px; padding-right: 16px; }
  .brand { grid-column: 1 / -1; grid-row: 2; }
  .stage {
    grid-template-columns: 1fr; gap: 6px; padding-left: 16px; padding-right: 16px;
    grid-template-areas: "note" "readout" "scale" "strobe" "controls";
  }
  .note { font-size: min(40vw, 190px); }
  .readout { align-items: center; }
  .cents { font-size: min(17vw, 76px); }
  .seals { margin-top: 6px; }
  .seal { width: 60px; height: 60px; }
  #strobe { height: 132px; }
  .strobe-legend { font-size: 11px; }
  .controls { grid-template-columns: 1fr; gap: 16px; }
  .scale .labels text { font-size: 34px; }
  .scale .labels .zero { font-size: 40px; }
  .scale .labels .wide, .scale .end { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .seal.on { animation: none; }
}
