/* Candlefish — Full-bleed zero-chrome stage and cross-device safe-area layout */

@font-face {
  font-family: "Geist";
  src: local("Geist Variable"), local("Geist"),
       url("https://fonts.candlefish.ai/geist/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Serif 4";
  src: local("Source Serif 4"), local("SourceSerif4-Regular"),
       url("https://fonts.candlefish.ai/source-serif-4/SourceSerif4-Variable.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Berkeley Mono";
  src: local("Berkeley Mono"), local("BerkeleyMono-Regular"),
       url("https://fonts.candlefish.ai/berkeley-mono/Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --cf-ground: #0B0B0C;
  --cf-surface: rgba(14, 16, 20, 0.88);
  --cf-surface-2: #16181D;
  --cf-ink: #FAFAFA;
  --cf-body: #D5D5D7;
  --cf-muted: #CFCFD4;
  --cf-faint: #A4A4AC;
  --cf-rule: rgba(255, 255, 255, 0.12);
  --cf-accent: #EC754A;
  --cf-accent-text: #F0A37F;
  --cf-horizon: #8FB0F5;
  --cf-focus: #F6B27E;
  --cf-shadow: 0 18px 48px rgba(0, 0, 0, 0.56);

  --cf-sans: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --cf-serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --cf-mono: "Berkeley Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --cf-ease: cubic-bezier(0.21, 0.47, 0.32, 0.98);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

:root[data-theme="light"] {
  color-scheme: light;
  --cf-ground: #FFFFFF;
  --cf-surface: rgba(255, 255, 255, 0.84);
  --cf-surface-2: #F6F9FC;
  --cf-ink: #0A2540;
  --cf-body: #1F3A5C;
  --cf-muted: #425466;
  --cf-faint: #697386;
  --cf-rule: rgba(10, 37, 64, 0.14);
  --cf-accent: #C4491E;
  --cf-accent-text: #85300F;
  --cf-horizon: #3A62C4;
  --cf-focus: #C4491E;
  --cf-shadow: 0 18px 44px rgba(10, 37, 64, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  height: 100svh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  background: var(--cf-ground);
  color: var(--cf-ink);
  font-family: var(--cf-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

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

/* Safe-area probe for canvas layout geometry */
.safe-probe {
  position: fixed;
  top: var(--safe-top);
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  left: var(--safe-left);
  pointer-events: none;
  visibility: hidden;
  z-index: -1;
}

/* Full-bleed optical instrument stage */
.stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--cf-ground);
  isolation: isolate;
}

#instrument-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* Smooth optical dissolve curtain between auto-rotating / arrow-switched scenes */
.stage-curtain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 3;
  background: var(--cf-ground);
  opacity: 0;
  transition: opacity 260ms var(--cf-ease);
}
.stage-curtain.is-fading {
  opacity: 0.92;
}

/* Subtle dark optical vignette */
.stage-vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 2;
  background: radial-gradient(ellipse at 50% 48%, transparent 56%, rgba(0, 0, 0, 0.42) 100%);
  transition: opacity 280ms var(--cf-ease);
}
:root[data-theme="light"] .stage-vignette {
  opacity: 0.14;
  background: radial-gradient(ellipse at 50% 48%, transparent 62%, rgba(10, 37, 64, 0.14) 100%);
}

/* Zero-chrome fading edge navigation arrows (invisible on load; wake gently on interaction) */
.edge-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 12;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--cf-ink);
  width: 52px;
  height: 76px;
  padding: 0;
  border-radius: 999px;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 420ms var(--cf-ease), transform 180ms var(--cf-ease), color 180ms ease;
}
.edge-arrow svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 1px 6px rgba(0, 0, 0, 0.55));
}
.edge-prev {
  left: max(8px, var(--safe-left));
}
.edge-next {
  right: max(8px, var(--safe-right));
}

body.controls-awake .edge-arrow,
.edge-arrow:focus-visible {
  opacity: 0.54;
  pointer-events: auto;
}
body.mobile-whisper:not(.controls-awake) .edge-arrow {
  opacity: 0.36;
  pointer-events: auto;
}
.edge-arrow:hover,
.edge-arrow:focus-visible {
  opacity: 0.96;
  color: var(--cf-accent);
}
.edge-arrow:active {
  transform: translateY(-50%) scale(0.92);
}
.edge-arrow:focus-visible {
  outline: 2px solid var(--cf-focus);
  outline-offset: 2px;
}

/* Gently permanent About door (bottom-left; calm atelier contrast, never vanishes) */
.about-trigger {
  position: fixed;
  left: max(16px, calc(var(--safe-left) + 10px));
  bottom: max(14px, calc(var(--safe-bottom) + 8px));
  z-index: 12;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(11, 11, 12, 0.36);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--cf-ink);
  min-height: 40px;
  padding: 0 13px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  font: 500 11px/1 var(--cf-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
  opacity: 0.68;
  pointer-events: auto;
  transition: opacity 280ms var(--cf-ease), color 180ms ease, border-color 180ms ease, background-color 180ms ease, transform 160ms var(--cf-ease);
}
:root[data-theme="light"] .about-trigger {
  border-color: rgba(10, 37, 64, 0.12);
  background: rgba(255, 255, 255, 0.66);
  text-shadow: none;
}

body.controls-awake .about-trigger {
  opacity: 0.84;
}
.about-trigger:hover,
.about-trigger:focus-visible {
  opacity: 1;
  color: var(--cf-accent);
  border-color: rgba(236, 117, 74, 0.34);
}
.about-trigger:active {
  transform: scale(0.95);
}
.about-trigger:focus-visible {
  outline: 2px solid var(--cf-focus);
  outline-offset: 2px;
}

/* Quiet permanent center-bottom instrument datum & ordinary HTML link to the Soundline field guide */
.slide-index {
  position: fixed;
  left: 50%;
  bottom: max(14px, calc(var(--safe-bottom) + 8px));
  transform: translateX(-50%);
  z-index: 12;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  max-width: calc(100vw - 172px - var(--safe-left) - var(--safe-right));
  white-space: nowrap;
  padding: 0 13px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(11, 11, 12, 0.36);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--cf-muted);
  font: 400 10.5px/1 var(--cf-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
  opacity: 0.78;
  transition: opacity 280ms var(--cf-ease), border-color 180ms ease;
}
.slide-index-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slide-index-sep {
  flex: none;
  white-space: pre;
}
:root[data-theme="light"] .slide-index {
  border-color: rgba(10, 37, 64, 0.12);
  background: rgba(255, 255, 255, 0.66);
  text-shadow: none;
}
body.controls-awake .slide-index,
body.mobile-whisper .slide-index {
  opacity: 0.92;
}
.slide-index:hover,
.slide-index:focus-within {
  opacity: 1;
  border-color: rgba(236, 117, 74, 0.34);
}
.slide-guide-link {
  flex: none;
  color: var(--cf-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(250, 250, 250, 0.42);
  padding: 8px 0;
  transition: color 180ms ease, text-decoration-color 180ms ease;
}
:root[data-theme="light"] .slide-guide-link {
  text-decoration-color: rgba(10, 37, 64, 0.42);
}
.slide-guide-link:hover {
  color: var(--cf-accent);
  text-decoration-color: var(--cf-accent);
}
.slide-guide-link:focus-visible {
  color: var(--cf-accent);
  text-decoration-color: var(--cf-accent);
  outline: 2px solid var(--cf-focus);
  outline-offset: 3px;
  border-radius: 3px;
}
@media (max-width: 780px) {
  .slide-index {
    font-size: 9.5px;
    letter-spacing: 0.08em;
    padding: 0 10px;
    max-width: calc(100vw - 168px - var(--safe-left) - var(--safe-right));
  }
  .slide-index .slide-index-name {
    display: none;
  }
}
@media (max-width: 520px) {
  .slide-index .slide-index-elev {
    display: none;
  }
}
@media (max-width: 390px) {
  .slide-index {
    left: calc(50% + 14px);
    font-size: 9.5px;
    letter-spacing: 0.04em;
    padding: 0 8px;
    max-width: calc(100vw - 156px - var(--safe-left) - var(--safe-right));
  }
}

/* Calm centered glass About sheet floating over the live blurred instrument */
.about-sheet {
  width: min(468px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
  max-height: min(88dvh, 580px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--cf-rule);
  border-radius: 16px;
  background: var(--cf-surface);
  color: var(--cf-ink);
  backdrop-filter: blur(24px) saturate(120%);
  -webkit-backdrop-filter: blur(24px) saturate(120%);
  box-shadow: var(--cf-shadow);
  overflow: auto;
  user-select: text;
  -webkit-user-select: text;
}
.about-sheet:modal {
  overscroll-behavior: contain;
}
.about-sheet:focus {
  outline: none;
}
.about-sheet::backdrop {
  background: rgba(5, 8, 14, 0.64);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  overscroll-behavior: contain;
}
:root[data-theme="light"] .about-sheet::backdrop {
  background: rgba(10, 37, 64, 0.24);
}
.about-inner {
  padding: 24px 26px 22px;
}
.about-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.about-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}
.about-mark {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  flex-shrink: 0;
}
.about-kicker {
  font: 500 10.5px/1 var(--cf-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cf-faint);
  white-space: nowrap;
}
@media (max-width: 420px) {
  .about-inner {
    padding: 20px 18px 18px;
  }
  .about-brand {
    gap: 8px;
  }
  .about-kicker {
    font-size: 9.5px;
    letter-spacing: 0.08em;
    white-space: normal;
    line-height: 1.3;
  }
}
.about-close {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--cf-muted);
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
}
.about-close svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  fill: none;
}
.about-close:hover {
  color: var(--cf-ink);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--cf-rule);
}
.about-close:focus-visible {
  outline: 2px solid var(--cf-focus);
  outline-offset: 2px;
}
.about-title {
  margin: 0 0 12px;
  font: 400 28px/1.15 var(--cf-serif);
  letter-spacing: -0.02em;
  color: var(--cf-ink);
}
.about-lead {
  margin: 0 0 12px;
  font: 400 15.5px/1.6 var(--cf-sans);
  color: var(--cf-ink);
}
.about-body {
  margin: 0 0 16px;
  font: 400 14.5px/1.62 var(--cf-sans);
  color: var(--cf-body);
}
.about-natural {
  margin: 0 0 20px;
  padding-top: 14px;
  border-top: 1px solid var(--cf-rule);
  font: 400 14.5px/1.6 var(--cf-serif);
  color: var(--cf-muted);
}
.about-natural em {
  font-style: italic;
  color: var(--cf-ink);
}
.about-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding-top: 16px;
  border-top: 1px solid var(--cf-rule);
}
.about-tag {
  font: 500 10.5px/1 var(--cf-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cf-accent-text);
}
.about-links {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
}
.about-sec {
  font: 400 11.5px/1 var(--cf-mono);
  color: var(--cf-faint);
  text-decoration: none;
  padding: 6px 0;
  border-bottom: 1px solid transparent;
  transition: color 180ms ease, border-color 180ms ease;
}
.about-sec:hover {
  color: var(--cf-ink);
  border-bottom-color: var(--cf-rule);
}
.about-sec:focus-visible {
  outline: 2px solid var(--cf-focus);
  outline-offset: 4px;
  border-radius: 3px;
}
.about-mail {
  font: 400 12.5px/1 var(--cf-mono);
  color: var(--cf-ink);
  text-decoration: none;
  padding: 6px 0;
  border-bottom: 1px solid transparent;
  transition: color 150ms ease, border-color 150ms ease;
}
.about-mail:hover,
.about-mail:focus-visible {
  color: var(--cf-accent);
  border-bottom-color: var(--cf-accent);
}
.about-mail:focus-visible {
  outline: 2px solid var(--cf-focus);
  outline-offset: 4px;
  border-radius: 3px;
}

/* Dignified fallback when JavaScript is disabled */
.noscript-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
  width: min(468px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
  max-height: calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  padding: 26px;
  border-radius: 16px;
  background: var(--cf-surface);
  border: 1px solid var(--cf-rule);
  color: var(--cf-ink);
  box-shadow: var(--cf-shadow);
  user-select: text;
  -webkit-user-select: text;
}
.noscript-card .about-mark {
  margin-bottom: 14px;
}
@media (max-width: 420px) {
  .noscript-card {
    padding: 20px 18px 18px;
  }
}

/* Gently permanent sound glyph (bottom-right; explicit opt-in on mobile, visibly lit while sound is live) */
.sound-glyph {
  position: fixed;
  right: max(14px, calc(var(--safe-right) + 8px));
  bottom: max(14px, calc(var(--safe-bottom) + 8px));
  z-index: 12;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(11, 11, 12, 0.36);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--cf-ink);
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0.68;
  pointer-events: auto;
  transition: opacity 280ms var(--cf-ease), color 180ms ease, border-color 180ms ease, background-color 180ms ease, transform 160ms var(--cf-ease);
}
:root[data-theme="light"] .sound-glyph {
  border-color: rgba(10, 37, 64, 0.12);
  background: rgba(255, 255, 255, 0.66);
}
.sound-glyph svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.sound-glyph .icon-muted {
  display: none;
}
.sound-glyph[aria-pressed="false"] .icon-on {
  display: none;
}
.sound-glyph[aria-pressed="false"] .icon-muted {
  display: block;
}

body.controls-awake .sound-glyph,
body.sound-awake .sound-glyph {
  opacity: 0.86;
}
body.audio-live .sound-glyph {
  opacity: 0.92;
  color: var(--cf-accent);
  border-color: rgba(236, 117, 74, 0.38);
}
.sound-glyph:hover,
.sound-glyph:focus-visible {
  opacity: 1;
  color: var(--cf-accent);
  border-color: rgba(236, 117, 74, 0.42);
}
.sound-glyph:active {
  transform: scale(0.92);
}
.sound-glyph:focus-visible {
  outline: 2px solid var(--cf-focus);
  outline-offset: 2px;
}

/* Optional keyboard-only live math probe overlay (P key, hidden by default) */
.probe-panel {
  position: fixed;
  top: max(16px, calc(var(--safe-top) + 8px));
  left: max(16px, calc(var(--safe-left) + 8px));
  z-index: 18;
  width: min(370px, calc(100vw - 32px));
  background: var(--cf-surface);
  border: 1px solid var(--cf-rule);
  border-radius: 12px;
  padding: 15px 17px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--cf-shadow);
  user-select: text;
  -webkit-user-select: text;
}
.probe-panel[hidden] {
  display: none;
}
.probe-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.probe-kicker {
  font: 500 10.5px/1 var(--cf-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cf-accent-text);
}
.probe-clue {
  font: 500 10.5px/1 var(--cf-mono);
  color: var(--cf-horizon);
}
.probe-eq {
  margin: 0 0 10px;
  font: 400 11.5px/1.55 var(--cf-mono);
  color: var(--cf-ink);
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--cf-surface-2);
  border: 1px solid var(--cf-rule);
  white-space: pre-wrap;
  word-break: break-word;
}
.probe-desc {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--cf-body);
}
.probe-live {
  margin: 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--cf-rule);
  font: 400 11px/1.6 var(--cf-mono);
  color: var(--cf-faint);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Foldable & dual-pane displays (iPhone Duo unfolded, Android foldables): dock About onto right segment clear of the hinge */
@media (horizontal-viewport-segments: 2) {
  .edge-prev {
    left: max(12px, var(--safe-left));
  }
  .edge-next {
    right: max(12px, var(--safe-right));
  }
  .about-sheet {
    position: fixed;
    margin: 0;
    top: 50%;
    transform: translateY(-50%);
    left: calc(env(viewport-segment-left 1 0) + max(18px, (env(viewport-segment-width 1 0) - min(432px, calc(env(viewport-segment-width 1 0) - 36px))) / 2));
    width: min(432px, calc(env(viewport-segment-width 1 0) - 36px));
  }
  .about-sheet::backdrop {
    background: rgba(5, 8, 14, 0.34);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
}

/* Compact short landscape (standard iPhone Landscape 852x330): fit About sheet cleanly with zero internal scroll */
@media (max-height: 440px) {
  .about-sheet {
    width: min(600px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
    max-height: calc(100dvh - 20px);
  }
  .noscript-card {
    width: min(600px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
    max-height: calc(100dvh - 20px);
    padding: 13px 22px 12px;
  }
  .noscript-card .about-mark {
    margin-bottom: 8px;
  }
  .about-inner {
    padding: 13px 22px 12px;
  }
  .about-top {
    margin-bottom: 6px;
  }
  .about-close {
    width: 34px;
    height: 34px;
  }
  .about-title {
    font-size: 20px;
    line-height: 1.1;
    margin-bottom: 6px;
  }
  .about-lead {
    font-size: 13.5px;
    line-height: 1.38;
    margin-bottom: 6px;
  }
  .about-body {
    font-size: 12.5px;
    line-height: 1.4;
    margin-bottom: 8px;
  }
  .about-natural {
    font-size: 12.5px;
    line-height: 1.4;
    padding-top: 8px;
    margin-bottom: 10px;
  }
  .about-foot {
    padding-top: 8px;
  }
}

/* Touch / mobile devices: pure native swipe (no mid-screen arrows bracketing CANDLEFISH or fighting Safari edge-back) */
@media (pointer: coarse) {
  .edge-arrow {
    display: none;
  }
  .about-trigger {
    min-height: 44px;
    padding: 0 14px;
  }
  .slide-index {
    min-height: 44px;
  }
  .sound-glyph {
    width: 44px;
    height: 44px;
  }
  .about-close {
    width: 44px;
    height: 44px;
  }
}
@media (pointer: coarse) and (max-height: 440px) {
  .about-close {
    width: 36px;
    height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage-curtain,
  .edge-arrow,
  .about-trigger,
  .slide-index,
  .slide-guide-link,
  .sound-glyph {
    transition-duration: 0.01ms !important;
  }
}
