/* MOIRÉ — an instrument, not a page. One screen, no scroll narrative.
   Every colour comes from the active palette through custom properties set by app.mjs;
   the values below are the darkroom defaults so the first frame is never wrong. */

:root {
  --surface: #0A0C0B;
  --dock: #101413;
  --chip: #161B19;
  --hair: #232B28;
  --text: #E8F2ED;
  --dim: #6B7A74;
  --signal: #F0A23B;
  --bar-h: 46px;
  --radius: 12px;
  --ease: cubic-bezier(.22, .61, .36, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Class rules below set display, which would otherwise out-specify the UA's
   [hidden] rule and leave hidden elements covering the stage. */
[hidden] { display: none !important; }

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

body {
  font-family: system-ui, "Segoe UI", "Noto Sans TC", "PingFang TC", "Hiragino Sans TC", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }

.app {
  display: grid;
  grid-template-rows: var(--bar-h) minmax(0, 1fr) auto;
  height: 100dvh;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- top bar ---- */

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--hair);
}
.back {
  color: var(--dim);
  text-decoration: none;
  font-size: 12.5px;
  letter-spacing: .04em;
  white-space: nowrap;
  transition: color .16s var(--ease);
}
.back:hover { color: var(--text); }
.wordmark {
  font-size: 17px;
  font-weight: 620;
  letter-spacing: .2em;
  margin-inline: auto;
  padding-left: .2em;
}
.wordmark i { color: var(--signal); font-style: normal; }
.bar-right { display: flex; align-items: center; gap: 14px; }
.palettes { display: flex; gap: 6px; }
.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--hair);
  background: linear-gradient(135deg, var(--a) 0 50%, var(--b) 50% 100%);
  transition: transform .16s var(--ease), box-shadow .16s var(--ease);
}
.swatch:hover { transform: scale(1.12); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--signal); }
.ghost {
  color: var(--dim);
  font-size: 13px;
  letter-spacing: .06em;
  padding: 6px 12px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  transition: color .16s var(--ease), border-color .16s var(--ease);
}
.ghost:hover { color: var(--text); border-color: var(--dim); }
.ghost.strong { color: var(--signal); border-color: var(--signal); }

/* ---- stage ---- */

.stage { position: relative; min-height: 0; }
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
.stage canvas.is-dragging { cursor: grabbing; }

.overlay { position: absolute; inset: 0; pointer-events: none; }
.tag {
  position: absolute;
  font-size: 11px;
  letter-spacing: .14em;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(3px);
  padding: 5px 10px;
  border-radius: 999px;
}
.tag.tl { top: 14px; left: 16px; }
.tag.tr { top: 14px; right: 16px; color: var(--signal); }
.tag.bl { bottom: 14px; left: 16px; color: var(--dim); }

.view-toggle {
  position: absolute;
  right: 16px;
  bottom: 14px;
  min-width: 62px;
  padding: 8px 14px;
  font-size: 12.5px;
  letter-spacing: .12em;
  color: var(--signal);
  border: 1px solid var(--signal);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 76%, transparent);
}

.reveal {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px solid var(--signal);
}
.reveal.at-edge .reveal-grip { translate: -100% -50%; }
.reveal-grip {
  position: absolute;
  top: 50%;
  left: 0;
  translate: -50% -50%;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--signal);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--signal);
  font-size: 12px;
  letter-spacing: -.08em;
  touch-action: none;
}
.stage-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  margin: 0;
  color: var(--dim);
}

/* ---- dock ---- */

.dock {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 22px;
  padding: 12px 16px 14px;
  background: var(--dock);
  border-top: 1px solid var(--hair);
}

.samples { display: flex; gap: 8px; }
.sample {
  display: grid;
  grid-template-rows: auto auto;
  justify-items: center;
  gap: 6px;
  width: 66px;
  padding: 9px 4px 8px;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  background: var(--chip);
  color: var(--dim);
  transition: color .16s var(--ease), border-color .16s var(--ease);
}
.sample:hover { color: var(--text); border-color: var(--dim); }
.sample[aria-pressed="true"] { color: var(--text); border-color: var(--signal); }
.sample-name { font-size: 12px; line-height: 1.25; text-align: center; }
.sample-name em {
  display: block;
  font-style: normal;
  font-size: 8.5px;
  letter-spacing: .14em;
  color: var(--dim);
}
.sample-mark {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  color: currentColor;
  opacity: .95;
}
.mark-lines { background: repeating-linear-gradient(90deg, currentColor 0 1.5px, transparent 1.5px 6px); }
.mark-grid {
  background:
    repeating-linear-gradient(90deg, currentColor 0 1.5px, transparent 1.5px 7px),
    repeating-linear-gradient(0deg, currentColor 0 1.5px, transparent 1.5px 7px);
}
.mark-rings { background: repeating-radial-gradient(circle at 50% 50%, currentColor 0 1.5px, transparent 1.5px 6px); }
.mark-hex {
  background:
    repeating-linear-gradient(60deg, currentColor 0 1.4px, transparent 1.4px 8px),
    repeating-linear-gradient(-60deg, currentColor 0 1.4px, transparent 1.4px 8px),
    repeating-linear-gradient(0deg, currentColor 0 1.4px, transparent 1.4px 8px);
}
.mark-sheets { position: relative; background: none; }
.mark-sheets::before, .mark-sheets::after {
  content: "";
  position: absolute;
  width: 17px;
  height: 17px;
  border: 1.4px solid currentColor;
  background: repeating-linear-gradient(90deg, currentColor 0 1px, transparent 1px 5px);
}
.mark-sheets::before { left: 0; top: 0; opacity: .5; }
.mark-sheets::after { right: 0; bottom: 0; }

.sample.lift { margin-left: 10px; position: relative; }
.sample.lift::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 12%;
  bottom: 12%;
  border-left: 1px solid var(--hair);
}
.sample.lift[aria-pressed="true"] { background: color-mix(in srgb, var(--signal) 14%, var(--chip)); }

.meter { display: flex; align-items: center; gap: 24px; min-width: 0; }
.amp { display: flex; align-items: baseline; gap: 10px; }
.amp b {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(38px, 4.4vw, 62px);
  font-weight: 600;
  line-height: .86;
  letter-spacing: -.03em;
  color: var(--signal);
}
.amp b[data-reason="single"], .amp b[data-reason="local"], .amp b[data-reason="anisotropic"] { color: var(--dim); }
.amp-label {
  font-size: 10px;
  letter-spacing: .18em;
  color: var(--dim);
  white-space: nowrap;
  align-self: flex-end;
  padding-bottom: .15em;
}

.dial { flex: 1; min-width: 0; max-width: 460px; }
.track { position: relative; height: 40px; cursor: ew-resize; touch-action: none; }
.track.is-disabled { opacity: .34; cursor: not-allowed; }
.track svg { display: block; width: 100%; height: 40px; overflow: visible; }
.scale {
  display: flex;
  padding-top: 1px;
  justify-content: space-between;
  font-size: 10.5px;
  letter-spacing: .08em;
  color: var(--dim);
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.tools { display: flex; gap: 8px; }
.tool {
  display: grid;
  justify-items: center;
  gap: 5px;
  min-width: 58px;
  padding: 9px 8px 8px;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  background: var(--chip);
  color: var(--dim);
  transition: color .16s var(--ease), border-color .16s var(--ease);
}
.tool:hover { color: var(--text); border-color: var(--dim); }
.tool[aria-pressed="true"], .tool[aria-expanded="true"] { color: var(--signal); border-color: var(--signal); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.tool em { font-style: normal; font-size: 10.5px; letter-spacing: .06em; }
.tool:disabled { opacity: .4; cursor: not-allowed; }

/* ---- drawer ---- */

.drawer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 62dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--dock);
  border-top: 1px solid var(--hair);
  box-shadow: 0 -24px 48px -28px #000;
  z-index: 3;
}
.drawer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px 24px;
}
.field { min-width: 0; }
.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 12.5px;
  color: var(--dim);
  margin-bottom: 4px;
}
.field-head output { color: var(--text); font-family: ui-monospace, Menlo, Consolas, monospace; }
.field input[type="range"] { width: 100%; accent-color: var(--signal); }
.exact {
  margin-top: 6px;
  width: 100%;
  padding: 6px 9px;
  background: var(--chip);
  border: 1px solid var(--hair);
  border-radius: 8px;
}
.field-toggles { display: grid; align-content: start; gap: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { accent-color: var(--signal); width: 16px; height: 16px; }

.drawer-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--hair);
}
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset {
  display: grid;
  gap: 2px;
  max-width: 230px;
  text-align: left;
  padding: 9px 13px;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  background: var(--chip);
  transition: border-color .16s var(--ease);
}
.preset:hover { border-color: var(--signal); }
.preset strong { font-size: 13px; font-weight: 600; }
.preset small { font-size: 11px; color: var(--dim); line-height: 1.45; }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.status {
  grid-column: 1 / -1;
  order: -1;
  margin: 0 2px 2px;
  min-height: 1.35em;
  font-size: 12px;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- about ---- */

.about {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(8px);
}
.about-inner { max-width: 62ch; margin: 0 auto; padding: 68px 24px 100px; }
.about-close {
  position: fixed;
  top: 14px;
  right: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--hair);
  color: var(--dim);
  background: var(--chip);
}
.about h1 { font-size: clamp(24px, 3.4vw, 34px); line-height: 1.32; margin: 0 0 20px; font-weight: 600; }
.about h2 { font-size: 15px; letter-spacing: .06em; margin: 34px 0 10px; color: var(--signal); font-weight: 600; }
.about p { margin: 0 0 12px; color: color-mix(in srgb, var(--text) 84%, var(--dim)); }
.about em { font-style: italic; color: var(--text); }
.about strong { color: var(--text); }
.about code {
  display: block;
  margin: 14px 0;
  padding: 12px 14px;
  background: var(--chip);
  border: 1px solid var(--hair);
  border-radius: 10px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  overflow-x: auto;
}
.about ul { margin: 0; padding-left: 1.1em; }
.about li { margin-bottom: 8px; font-size: 13.5px; }
.about a { color: var(--signal); }
.boundary {
  border-left: 2px solid var(--signal);
  padding-left: 14px;
  font-size: 13.5px;
}
.colophon { margin-top: 40px; font-size: 12px; letter-spacing: .1em; color: var(--dim); }
.noscript { padding: 24px; color: var(--dim); }

/* ---- narrow ---- */

@media (max-width: 900px) {
  .dock { grid-template-columns: 1fr; gap: 12px; padding: 10px 12px 12px; }
  .samples { overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .samples::-webkit-scrollbar { display: none; }
  .sample { width: 62px; flex: 0 0 auto; }
  .meter { gap: 16px; }
  .dial { max-width: none; }
  .tools { justify-content: space-between; }
  .tool { flex: 1; }
  .wordmark { letter-spacing: .14em; font-size: 15px; }
  .back span { display: none; }
}

@media (max-width: 560px) {
  :root { --bar-h: 42px; }
  .amp b { font-size: clamp(34px, 12vw, 48px); }
  .amp-label { max-width: none; }
  .tag { font-size: 10px; padding: 4px 8px; }
  .tag.bl { display: none; }
  .drawer-grid { grid-template-columns: 1fr; }
  .preset { max-width: none; }
  .drawer-actions { width: 100%; }
  .drawer-actions .ghost { flex: 1; text-align: center; }
}

/* Short landscape phones: the stage must keep the majority of the screen. */
@media (max-height: 560px) and (orientation: landscape) {
  .sample-name em { display: none; }
  .sample { width: 54px; padding: 7px 4px 6px; }
  .tool em { display: none; }
  .tool { min-width: 46px; }
  .dock { padding: 8px 12px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
