:root {
  --mist: #d8dcdc;
  --ink: #14181b;
  --slate: #566064;
  --sand: #ece8de;
  --dim: #a9a69d;
  --serif: 'Gowun Batang', 'Iowan Old Style', Georgia, serif;
  --sans: 'Hanken Grotesk', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: #000; color: var(--ink); font-family: var(--sans); font-size: 17px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
:focus-visible { outline: 2px solid currentColor; outline-offset: 4px; }

/* Stage */
#stage { position: fixed; inset: 0; background: #000; color: var(--dim); font-size: 0.86rem; container-type: size; }
/* Reel view: an upright 9 by 16 frame in the middle of the window. The outline sits just outside it. */
#stage.reel { margin: 0 auto; width: min(100vw, calc(100vh * 9 / 16)); outline: 1px solid #2a2d2f; }
body:has(#stage.reel:not([hidden])) { background: #000; }
#stage[hidden] { display: none; }
#mount { position: absolute; inset: 0; display: grid; place-items: center; cursor: crosshair; touch-action: none; }
#mount canvas.square { width: min(84cqh, 92cqw); height: min(84cqh, 92cqw); display: block; }
#mount .error { max-width: 28rem; padding: 2rem; color: var(--sand); font-size: 1rem; }
.tools, .caption, .readout { position: absolute; margin: 0; z-index: 2; text-shadow: 0 0 12px #000, 0 0 3px #000; }
.tools { top: 1.1rem; right: 1.4rem; display: flex; gap: 1.4rem; }
.tools button { background: none; border: 0; padding: 0.1rem 0; font: inherit; color: var(--sand); cursor: pointer; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.25em; }
.caption { left: 1.4rem; bottom: 1.2rem; max-width: min(30rem, 60cqw); pointer-events: none; }
.caption h1 { font-family: var(--serif); font-weight: 400; font-size: 1.35rem; color: var(--sand); margin: 0 0 0.2rem; }
.caption p { margin: 0; }
.readout { right: 1.4rem; bottom: 1.2rem; max-width: 34cqw; text-align: right; font-variant-numeric: tabular-nums; pointer-events: none; }

/* With the controls hidden only the picture is left. The button to bring them back shows on hover. */
#stage.bare .caption, #stage.bare .readout, #stage.bare .tone, #stage.bare .tools button:not(.hide) { display: none; }
#stage.bare .hide { opacity: 0; }
#stage.bare .hide:hover, #stage.bare .hide:focus-visible { opacity: 1; }

@container (max-width: 800px) {
  .readout { bottom: auto; top: 3.2rem; left: 1.4rem; right: 1.4rem; max-width: none; text-align: left; }
  .caption { max-width: calc(100cqw - 2.8rem); }
}

/* Tone controls for the sand studies: what sets the tone, then one line per setting to step or swipe through. */
.tone { position: absolute; right: 1.4rem; top: 50%; transform: translateY(-50%); width: 14rem; z-index: 3; color: var(--sand); cursor: default; font-size: 0.95rem; }
.tone .row[hidden] { display: none; }
.tone button { background: none; border: 0; padding: 0.35rem 0; font: inherit; color: var(--sand); cursor: pointer; }
.tone .src { display: flex; gap: 1.1rem; margin-bottom: 1rem; }
.tone .src button { font-family: var(--serif); font-size: 1.15rem; opacity: 0.5; border-bottom: 1px solid transparent; }
.tone .src button:hover { opacity: 0.8; }
.tone .src button[aria-pressed="true"] { opacity: 1; border-bottom-color: currentColor; }
.tone .row { display: grid; grid-template-columns: 4.6rem 2rem 1fr 2rem; align-items: center; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.tone .row.wide { grid-template-columns: 2rem 1fr 2rem; }
.tone .row span, .tone .settle span { color: var(--dim); font-size: 0.86rem; }
.tone .row button { opacity: 0.55; font-size: 1.25rem; line-height: 1; padding: 0.45rem 0; }
.tone .row button:hover { opacity: 1; }
.tone .row output { text-align: center; white-space: nowrap; cursor: pointer; }
.tone .settle { display: grid; grid-template-columns: 4.6rem 1fr; align-items: center; margin-top: 0.7rem; }
.tone .settle input { width: 100%; min-width: 0; margin: 0; accent-color: var(--sand); cursor: ew-resize; }
.tone .say { color: var(--dim); font-size: 0.86rem; margin: 0.9rem 0 0; min-height: 3em; }

/* Reel view is for recording: no title, no hint, and the sand settles at the speed already set. */
#stage.reel .caption, #stage.reel .settle { display: none; }

/* Upright or narrow: the picture takes what room is left above the controls. */
@container (max-width: 800px) or (max-aspect-ratio: 13/10) {
  #mount:has(.tone) { display: flex; flex-direction: column; align-items: stretch; gap: 0.8rem; padding: 4.8rem 1.4rem 6.8rem; }
  #mount:has(.tone) canvas.square { flex: 1 1 0; min-height: 0; width: 100%; height: auto; object-fit: contain; }
  #stage.reel #mount:has(.tone) { padding-bottom: 1.4rem; }
  #stage.bare #mount:has(.tone) { padding: 0; }
  .tone { position: static; transform: none; width: auto; }
  /* Two settings to a line, so the picture keeps most of the frame. */
  .tone .src { margin-bottom: 0.5rem; }
  .tone .rows { display: grid; grid-template-columns: 1fr 1fr; column-gap: 1.4rem; }
  .tone .row { grid-template-columns: 3.8rem 1.4rem 1fr 1.4rem; }
  .tone .row.wide { grid-column: 1 / -1; grid-template-columns: 1.4rem 1fr 1.4rem; }
  .tone .row button { padding: 0.3rem 0; }
  .tone .say { min-height: 0; margin-top: 0.5rem; }
}
