/* ============================================================================
   PHC 2026 — shared "Reading Settings" panel chrome + scheme/typography layer.

   Link this AFTER each page's own stylesheet (and after phc-chrome.css). The
   engine lives in /phc2026/phc-reading.js.

   Sections:
     1. Toggle button (eye) + floating panel chrome — theme-reactive via
        html[data-theme="light"], mirroring phc-chrome.css.
     2. Immersive mode (html.phcr-immersive hides chrome).
     3. dim / sepia tints  — layered on the dark / light base (§ per-page below).
     4. Typography binding  — --phcr-* applied to PROSE selectors only (per page).
   ========================================================================== */

/* ── tokens: panel adopts a dark default, flips under [data-theme="light"] ── */
:root {
  --phcr-fg: rgba(255, 255, 255, 0.92);
  --phcr-fg-dim: rgba(255, 255, 255, 0.6);
  --phcr-fg-faint: rgba(255, 255, 255, 0.4);
  --phcr-surface: rgba(14, 18, 28, 0.96);
  --phcr-surface-2: rgba(255, 255, 255, 0.06);
  --phcr-surface-hover: rgba(255, 255, 255, 0.1);
  --phcr-border: rgba(255, 255, 255, 0.12);
  --phcr-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}
html[data-theme="light"] {
  --phcr-fg: #0d1b2a;
  --phcr-fg-dim: rgba(13, 27, 42, 0.66);
  --phcr-fg-faint: rgba(13, 27, 42, 0.46);
  --phcr-surface: rgba(255, 255, 255, 0.98);
  --phcr-surface-2: rgba(13, 27, 42, 0.05);
  --phcr-surface-hover: rgba(13, 27, 42, 0.09);
  --phcr-border: rgba(13, 27, 42, 0.14);
  --phcr-shadow: 0 18px 50px rgba(10, 22, 38, 0.18);
}

/* ── toggle button: shows/hides the open state (it reuses .phc-subhead-btn) ── */
.phcr-toggle.active {
  background: var(--phcr-surface-hover);
  border-color: var(--phcr-border);
}

/* ── floating panel ── */
.phcr-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  width: 268px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 88px);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 9000;
  padding: 12px 14px 14px;
  border-radius: 14px;
  border: 1px solid var(--phcr-border);
  background: var(--phcr-surface);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  box-shadow: var(--phcr-shadow);
  color: var(--phcr-fg);
  font-family: 'Alcyone', ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.phcr-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.phcr-panel-title {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--phcr-fg-faint);
  padding: 0 0 8px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--phcr-border);
}

.phcr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 8px;
  padding: 7px 0;
  min-width: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--phcr-border) 60%, transparent);
}
.phcr-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--phcr-fg-dim);
  flex-shrink: 0;
  user-select: none;
}
.phcr-options { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 1px; align-items: center; min-width: 0; }

.phcr-opt {
  padding: 4px 7px;
  border: none;
  background: none;
  color: var(--phcr-fg-dim);
  cursor: pointer;
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.74rem;
  line-height: 1.4;
  white-space: nowrap;
  position: relative;
  transition: color 0.15s ease, background 0.15s ease;
}
.phcr-opt:hover { color: var(--phcr-fg); background: var(--phcr-surface-2); }
.phcr-opt[aria-checked="true"] {
  color: var(--phcr-accent, var(--phcr-fg));
  background: color-mix(in srgb, var(--phcr-accent, #fff) 16%, transparent);
}
.phcr-opt-icon { display: inline-flex; align-items: center; justify-content: center; padding: 5px; }
.phcr-opt-size[data-size="0"] { font-size: 0.62rem; }
.phcr-opt-size[data-size="1"] { font-size: 0.7rem; }
.phcr-opt-size[data-size="2"] { font-size: 0.78rem; }
.phcr-opt-size[data-size="3"] { font-size: 0.86rem; }
.phcr-opt-size[data-size="4"] { font-size: 0.94rem; }

/* ── tooltips ── */
.phcr-opt[data-tooltip], .phcr-action[data-tooltip] { position: relative; }
.phcr-opt[data-tooltip]::before, .phcr-action[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.88);
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.62rem;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 9002;
}
.phcr-opt[data-tooltip]:hover::before, .phcr-action[data-tooltip]:hover::before { opacity: 1; }

/* ── font picker ── */
.phcr-font-current {
  border: none;
  background: none;
  color: var(--phcr-fg);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.74rem;
  padding: 4px 7px;
  border-radius: 5px;
  text-align: right;
  transition: color 0.15s ease, background 0.15s ease;
}
.phcr-font-current:hover { background: var(--phcr-surface-2); }
.phcr-font-list {
  display: none;
  flex-direction: column;
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0;
  margin: 0 -6px;
  border-bottom: 1px solid color-mix(in srgb, var(--phcr-border) 60%, transparent);
}
.phcr-font-list.open { display: flex; }
.phcr-font-list::-webkit-scrollbar { width: 4px; }
.phcr-font-list::-webkit-scrollbar-thumb { background: var(--phcr-surface-hover); border-radius: 2px; }
.phcr-font-group-label {
  font-size: 0.56rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--phcr-fg-faint);
  padding: 6px 12px 2px;
  user-select: none;
}
.phcr-font-opt {
  border: none;
  background: none;
  color: var(--phcr-fg-dim);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 5px 12px;
  text-align: left;
  border-radius: 5px;
  margin: 0 6px;
  position: relative;
  transition: color 0.15s ease, background 0.15s ease;
}
.phcr-font-opt:hover { color: var(--phcr-fg); background: var(--phcr-surface-2); }
.phcr-font-opt[aria-selected="true"] { color: var(--phcr-fg); }
.phcr-font-opt[aria-selected="true"]::before {
  content: '';
  position: absolute;
  left: 3px; top: 8px; bottom: 8px;
  width: 2px; border-radius: 1px;
  background: var(--phcr-accent, #23D18C);
}

/* ── actions ── */
.phcr-actions { display: flex; align-items: center; gap: 2px; padding-top: 8px; }
.phcr-action {
  border: none;
  background: none;
  color: var(--phcr-fg-dim);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.72rem;
  padding: 6px 9px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  position: relative;
  transition: color 0.15s ease, background 0.15s ease;
}
.phcr-action:hover { color: var(--phcr-fg); background: var(--phcr-surface-2); }
.phcr-action.active { color: var(--phcr-accent, #00E5FF); }
.phcr-action.copied { color: #23D18C; }
.phcr-divider { border: none; height: 1px; background: var(--phcr-border); margin: 4px 0 0; }
.phcr-kbd {
  font-size: 0.55rem;
  color: var(--phcr-fg-faint);
  margin-left: auto;
  padding-left: 8px;
  font-family: ui-monospace, monospace;
  letter-spacing: -0.02em;
}

/* hide the Width row where a reading-measure makes no sense (figure pages) */
html[data-phcr-no-width] .phcr-row-width { display: none; }

/* ============================================================================
   2. Immersive mode — hide the page chrome; show a floating exit button.
   Pages tag their header/footer with [data-phcr-chrome] (or rely on the
   defaults below) so immersive reading hides them.
   ========================================================================== */
html.phcr-immersive [data-phcr-chrome],
html.phcr-immersive .phc-subhead,
html.phcr-immersive .phc-header,
html.phcr-immersive .phc-footer {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 0.35s ease;
}

#phcr-exit {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  z-index: 9001;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  border: 1px solid var(--phcr-border);
  background: var(--phcr-surface);
  color: var(--phcr-fg-dim);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 0.35s ease, background 0.2s ease, color 0.2s ease;
}
#phcr-exit svg { width: 18px; height: 18px; }
html.phcr-immersive #phcr-exit { display: flex; opacity: 0.55; }
html.phcr-immersive #phcr-exit:hover { opacity: 1; }

/* ============================================================================
   3. dim / sepia tints (chrome + prose tokens only; figures keep native look)
      dim  = dark base, gently warmed + lifted off pure black
      sepia = light base, warm parchment
      Each page exposes different token names, so we override per token system.
   ========================================================================== */

/* — the reading panel + shared chrome follow the tint everywhere — */
html[data-reading-scheme="dim"] {
  --phcr-fg: #e7e2d8;
  --phcr-fg-dim: rgba(231, 226, 216, 0.6);
  --phcr-fg-faint: rgba(231, 226, 216, 0.4);
  --phcr-surface: rgba(26, 28, 33, 0.97);
  --phcr-surface-2: rgba(231, 226, 216, 0.07);
  --phcr-surface-hover: rgba(231, 226, 216, 0.12);
  --phcr-border: rgba(231, 226, 216, 0.14);
}
html[data-reading-scheme="sepia"] {
  --phcr-fg: #433422;
  --phcr-fg-dim: rgba(67, 52, 34, 0.66);
  --phcr-fg-faint: rgba(67, 52, 34, 0.46);
  --phcr-surface: rgba(250, 244, 232, 0.98);
  --phcr-surface-2: rgba(67, 52, 34, 0.05);
  --phcr-surface-hover: rgba(67, 52, 34, 0.1);
  --phcr-border: rgba(67, 52, 34, 0.16);
}
html[data-reading-scheme="dim"] .phc-subhead {
  --_fg: rgba(231, 226, 216, 0.9);
  --_btn-bg: rgba(231, 226, 216, 0.06);
  --_btn-bg-hover: rgba(231, 226, 216, 0.12);
  --_btn-border: rgba(231, 226, 216, 0.16);
}
html[data-reading-scheme="sepia"] .phc-subhead {
  --_fg: #433422;
  --_btn-bg: rgba(67, 52, 34, 0.05);
  --_btn-bg-hover: rgba(67, 52, 34, 0.1);
  --_btn-border: rgba(67, 52, 34, 0.18);
}

/* — phc2026 landing + figures hub/journey/acceleration (--phc-* tokens) — */
html[data-reading-scheme="dim"] {
  --phc-bg: #15161a; --phc-bg-2: #1b1d22;
  --phc-text: #e7e2d8;
  --phc-text-dim: rgba(231, 226, 216, 0.66);
  --phc-text-faint: rgba(231, 226, 216, 0.5);
  --phc-panel: #1a1c21; --phc-border: rgba(231, 226, 216, 0.12);
}
html[data-reading-scheme="sepia"] {
  --phc-bg: #f3ebdd; --phc-bg-2: #faf4e8;
  --phc-text: #433422;
  --phc-text-dim: rgba(67, 52, 34, 0.7);
  --phc-text-faint: rgba(67, 52, 34, 0.54);
  --phc-panel: #faf4e8; --phc-border: rgba(67, 52, 34, 0.16);
}

/* — bento (--bg-*, --ink-*) — */
html[data-reading-scheme="dim"] {
  --bg-0: #15161a; --bg-1: #1b1d22; --bg-2: #1f2127;
  --ink: #e7e2d8; --ink-dim: rgba(231, 226, 216, 0.66); --ink-faint: rgba(231, 226, 216, 0.42);
}
html[data-reading-scheme="sepia"] {
  --bg-0: #f3ebdd; --bg-1: #faf4e8; --bg-2: #f0e6d4;
  --ink: #433422; --ink-dim: rgba(67, 52, 34, 0.68); --ink-faint: rgba(67, 52, 34, 0.48);
}

/* — immersive (--ink, --panel-*) — KEEP --bg (the globe scene) untinted — */
html[data-reading-scheme="dim"] {
  --panel-bg: rgba(26, 28, 33, 0.66); --panel-border: rgba(231, 226, 216, 0.1); --hairline: rgba(231, 226, 216, 0.08);
}
html[data-reading-scheme="sepia"] {
  --panel-bg: rgba(250, 244, 232, 0.74); --panel-border: rgba(67, 52, 34, 0.12); --hairline: rgba(67, 52, 34, 0.08);
}

/* — organic (--o-* — warm by design; nudge toward dim/sepia) — */
html[data-reading-scheme="dim"] {
  --o-paper: #1a1712; --o-paper-deep: #110f0c;
  --o-ink: #efe6d4; --o-ink-soft: #c2b6a0; --o-ink-faint: #897e6c; --o-line: #3b352b;
}
html[data-reading-scheme="sepia"] {
  --o-paper: #f3ebdd; --o-paper-deep: #e7dcc8;
  --o-ink: #433422; --o-ink-soft: #6b5d49; --o-ink-faint: #97886f; --o-line: #d8ccb4;
}

/* ============================================================================
   4. Typography binding — PROSE ONLY.
      Each reading selector keeps its real base size, scaled by the multiplier,
      with font + line-height overridable. Figures / labels / layout untouched.
   ========================================================================== */

/* generic opt-in hook for any container a page marks explicitly */
[data-phcr-prose] { font-family: var(--phcr-font, inherit); }
[data-phcr-prose] p, [data-phcr-prose] li, [data-phcr-prose] blockquote {
  line-height: var(--phcr-height, 1.65);
}

/* — landing (phc2026) — */
html .phc-intro-body { max-width: var(--phcr-width, 68ch); }
html .phc-intro-body p {
  font-family: var(--phcr-font, inherit);
  font-size: calc(clamp(16px, 1.35vw, 18.5px) * var(--phcr-size-mult, 1));
  line-height: var(--phcr-height, 1.6);
}
html .phc-intro-head p {
  font-family: var(--phcr-font, inherit);
  font-size: calc(clamp(16px, 1.4vw, 18px) * var(--phcr-size-mult, 1));
  line-height: var(--phcr-height, 1.55);
}

/* — organic (the field-guide reading page) — */
html .o-prose {
  font-family: var(--phcr-font, inherit);
  font-size: calc(clamp(1.02rem, 1.7vw, 1.16rem) * var(--phcr-size-mult, 1));
  line-height: var(--phcr-height, 1.72);
}
html .o-spotlight-body {
  font-family: var(--phcr-font, inherit);
  font-size: calc(0.92rem * var(--phcr-size-mult, 1));
  line-height: var(--phcr-height, 1.62);
}
html .o-framework-variant, html .o-spec-story { max-width: var(--phcr-width, none); }

/* — figures / journey / acceleration (--phc-* prose) — */
html .fj-prose p {
  font-family: var(--phcr-font, inherit);
  font-size: calc(1.02rem * var(--phcr-size-mult, 1));
  line-height: var(--phcr-height, 1.72);
}
html .fj-prose .fj-lead {
  font-size: calc(1.12rem * var(--phcr-size-mult, 1));
  line-height: var(--phcr-height, 1.66);
}
html .fj-prose, html .fig-standfirst { max-width: var(--phcr-width, none); }
html .fj-prose { margin-left: auto; margin-right: auto; }

/* — immersive (narrative blurbs) — */
html .hero-sub {
  font-family: var(--phcr-font, inherit);
  font-size: calc(1.15rem * var(--phcr-size-mult, 1));
  line-height: var(--phcr-height, 1.6);
}
html .act-blurb {
  font-family: var(--phcr-font, inherit);
  font-size: calc(1.06rem * var(--phcr-size-mult, 1));
  line-height: var(--phcr-height, 1.62);
}

@media (prefers-reduced-motion: reduce) {
  .phcr-panel, #phcr-exit,
  html.phcr-immersive [data-phcr-chrome],
  html.phcr-immersive .phc-subhead,
  html.phcr-immersive .phc-header,
  html.phcr-immersive .phc-footer { transition: none; }
}
