/* The Butcher's Chart — warm paper, charcoal ink, chalk seams, one red accent. */

@font-face {
  font-family: 'Permanent Marker';
  src: url('../fonts/PermanentMarker-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'EB Garamond';
  src: url('../fonts/EBGaramond-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'EB Garamond';
  src: url('../fonts/EBGaramond-400i.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'EB Garamond';
  src: url('../fonts/EBGaramond-600.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}

:root {
  --paper: #efe6d3;
  --paper-deep: #e6dac1;
  --ink: #2b241d;
  --ink-soft: #4a4036;
  --chalk: #f0e6cf;
  --accent: #b5432e;
  --accent-bright: #d35b41;
  --panel: rgba(246, 240, 226, 0.92);
  --line: rgba(43, 36, 29, 0.28);
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --hand: 'Permanent Marker', 'Segoe Print', cursive;
  --px: 0px;
  --py: 0px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
}

/* ---------------------------------------------------------- paper atmosphere */
.paper-grain {
  position: fixed; inset: -40px; z-index: 3; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.25 0 0 0 0 0.2 0 0 0 0 0.14 0 0 0 0.5 0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.16;
  mix-blend-mode: multiply;
  transform: translate(calc(var(--px) * -1), calc(var(--py) * -1));
  transition: transform 0.4s ease-out;
}
.paper-vignette {
  position: fixed; inset: 0; z-index: 3; pointer-events: none;
  background:
    radial-gradient(ellipse 120% 90% at 50% 42%, transparent 55%, rgba(58, 44, 28, 0.20) 100%),
    linear-gradient(to bottom, rgba(58, 44, 28, 0.06), transparent 12%, transparent 88%, rgba(58, 44, 28, 0.10));
}
.measure-rail {
  position: fixed; left: 0; right: 0; bottom: 0; height: 26px; z-index: 4;
  pointer-events: none;
  background:
    repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px 10px),
    repeating-linear-gradient(to right, rgba(43,36,29,0.5) 0 1px, transparent 1px 50px);
  background-size: 100% 8px, 100% 15px;
  background-position: bottom left, bottom left;
  background-repeat: no-repeat;
  border-top: 1px solid rgba(43, 36, 29, 0.18);
  opacity: 0.7;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 1px 8px 0;
}
.measure-rail span {
  font-family: var(--serif); font-size: 9px; letter-spacing: 0.06em;
  color: rgba(43, 36, 29, 0.55);
}

/* ------------------------------------------------------------------- viewport */
#scene {
  position: fixed; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  cursor: grab;
  touch-action: none;
}
#scene:active { cursor: grabbing; }
#scene:focus-visible { outline: 3px dashed var(--accent); outline-offset: -6px; }
body.is-transitioning #scene { cursor: wait; }

/* --------------------------------------------------------------------- chrome */
#chrome {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 22px 0;
  pointer-events: none;
}
#chrome .brand h1 {
  font-family: var(--hand);
  font-weight: 400;
  font-size: clamp(22px, 3vw, 34px);
  color: var(--ink);
  letter-spacing: 0.01em;
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}
#chrome .brand p {
  font-style: italic;
  font-size: clamp(12px, 1.4vw, 15px);
  color: var(--ink-soft);
  margin-top: 2px;
}
.chrome-actions { display: flex; gap: 8px; pointer-events: auto; }
.chrome-actions button {
  font-family: var(--serif); font-size: 14px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid rgba(43, 36, 29, 0.35);
  border-radius: 3px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: 1px 2px 0 rgba(43, 36, 29, 0.18);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.chrome-actions button:hover { background: #fbf6e9; transform: translateY(-1px); box-shadow: 1px 3px 0 rgba(43,36,29,0.22); }
.chrome-actions button:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(43,36,29,0.2); }

/* --------------------------------------------------------------------- legend */
#legend {
  position: fixed; z-index: 10; left: 22px; top: 108px;
  width: 208px; max-height: calc(100vh - 160px);
  overflow-y: auto;
  pointer-events: auto;
  scrollbar-width: thin;
}
.legend-group { margin-bottom: 14px; }
.legend-group h3 {
  font-family: var(--serif); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.18em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
  padding-bottom: 3px; margin-bottom: 5px;
}
.legend-subhead {
  font-style: italic; font-size: 13px; color: var(--ink-soft);
  margin: 6px 0 2px 8px;
}
.legend-nest { margin-left: 12px; }
#legend button {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  font-family: var(--serif); font-size: 16px; text-align: left;
  background: transparent; color: var(--ink);
  border: none; border-radius: 3px;
  padding: 4px 8px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}
#legend button .swatch {
  width: 9px; height: 9px; border-radius: 50%;
  background: transparent; border: 1.5px solid rgba(43,36,29,0.5);
  flex: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
#legend button:hover, #legend button.sync-hover {
  background: rgba(43, 36, 29, 0.07);
  transform: translateX(2px);
}
#legend button:hover .swatch, #legend button.sync-hover .swatch { border-color: var(--ink); }
#legend button.active { background: rgba(181, 67, 46, 0.10); }
#legend button.active .swatch { background: var(--accent); border-color: var(--accent); transform: scale(1.25); }
#legend button:focus-visible, #legend button:focus {
  outline: 2px dashed var(--accent); outline-offset: 1px;
  background: rgba(181, 67, 46, 0.08);
}

/* -------------------------------------------------------------------- dossier */
#dossier {
  position: fixed; z-index: 11;
  top: 108px; right: 22px; bottom: 34px;
  width: min(400px, calc(100vw - 44px));
  pointer-events: none;
}
#dossier-scroll {
  height: 100%; overflow-y: auto;
  background: var(--panel);
  border: 1px solid rgba(43, 36, 29, 0.32);
  border-radius: 4px;
  box-shadow: 3px 6px 0 rgba(43, 36, 29, 0.14), 0 18px 50px rgba(43, 36, 29, 0.18);
  padding: 26px 28px 34px;
  opacity: 0;
  transform: translateX(48px) rotate(0.4deg);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.22, 0.9, 0.3, 1);
  pointer-events: none;
  scrollbar-width: thin;
}
#dossier.open #dossier-scroll {
  opacity: 1; transform: translateX(0) rotate(0deg);
  pointer-events: auto;
}
#dossier-close {
  position: sticky; top: 0; float: right;
  width: 34px; height: 34px;
  font-family: var(--serif); font-size: 22px; line-height: 1;
  background: transparent; color: var(--ink-soft);
  border: 1px solid rgba(43, 36, 29, 0.3); border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
}
#dossier-close:hover { background: var(--accent); color: var(--paper); border-color: var(--accent); transform: rotate(90deg); }
.dossier-kicker {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.2em;
  color: var(--accent);
  margin-bottom: 4px;
}
#dossier-content h2 {
  font-family: var(--hand); font-weight: 400;
  font-size: clamp(30px, 4vw, 40px);
  color: var(--ink);
  line-height: 1.05;
  margin-bottom: 6px;
}
#dossier-content h2:focus-visible { outline: 2px dashed var(--accent); outline-offset: 4px; }
.dossier-tagline {
  font-style: italic; font-size: 16.5px; color: var(--ink-soft);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 12px; margin-bottom: 14px;
}
#dossier-content section { margin-bottom: 16px; }
#dossier-content h3 {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.16em;
  color: var(--ink);
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
}
#dossier-content h3::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(to right, var(--line), transparent);
}
#dossier-content p { font-size: 15.5px; }
#dossier-content ul { list-style: none; }
#dossier-content li {
  font-size: 15px; padding-left: 16px; position: relative;
  margin-bottom: 7px;
}
#dossier-content li::before {
  content: ''; position: absolute; left: 0; top: 9px;
  width: 7px; height: 2px; background: var(--accent);
}
#dossier-content li strong { color: var(--ink); }
.methods li::before { height: 7px; width: 7px; top: 7px; border-radius: 50%; background: transparent; border: 1.5px solid var(--accent); }

/* -------------------------------------------------------------------- loading */
#loading {
  position: fixed; inset: 0; z-index: 40;
  background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.6s ease, visibility 0.6s;
}
#loading.hidden { opacity: 0; visibility: hidden; }
.loading-inner { text-align: center; width: min(320px, 80vw); }
.loading-title {
  font-family: var(--hand); font-size: 34px; color: var(--ink);
  margin-bottom: 22px;
}
.loading-track {
  height: 3px; background: rgba(43, 36, 29, 0.18);
  border-radius: 2px; overflow: hidden;
}
#loading-bar {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width 0.35s ease;
}
#loading-note {
  margin-top: 12px; font-style: italic; font-size: 14px; color: var(--ink-soft);
}

/* ----------------------------------------------------------------- title card */
#titlecard {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
  background: rgba(239, 230, 211, 0.88);
  backdrop-filter: blur(3px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s;
}
#titlecard.visible { opacity: 1; visibility: visible; }
.tc-rule {
  width: min(340px, 60vw); height: 12px;
  border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink);
  margin: 18px 0;
}
.tc-kicker {
  font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 14px;
}
#titlecard h2 {
  font-family: var(--hand); font-weight: 400;
  font-size: clamp(44px, 9vw, 92px);
  line-height: 0.95; color: var(--ink);
}
.tc-body {
  max-width: 520px; font-size: clamp(15px, 2vw, 18px);
  color: var(--ink); margin: 6px 0 14px;
}
.tc-hint {
  font-style: italic; font-size: 14px; color: var(--ink-soft);
  margin-bottom: 22px;
}
#titlecard-btn {
  font-family: var(--hand); font-size: 19px;
  background: var(--accent); color: var(--paper);
  border: none; border-radius: 3px;
  padding: 13px 34px;
  cursor: pointer;
  box-shadow: 2px 4px 0 rgba(43, 36, 29, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
#titlecard-btn:hover { background: var(--accent-bright); transform: translateY(-2px); box-shadow: 2px 6px 0 rgba(43,36,29,0.3); }
#titlecard-btn:active { transform: translateY(1px); box-shadow: 1px 2px 0 rgba(43,36,29,0.35); }
#titlecard-btn:focus-visible { outline: 3px dashed var(--ink); outline-offset: 3px; }

/* ------------------------------------------------------------------- fallback */
#fallback {
  position: fixed; inset: 0; z-index: 35;
  background: var(--paper);
  display: none;
  overflow-y: auto;
}
#fallback.visible { display: block; }
.fb-inner { max-width: 720px; margin: 0 auto; padding: 60px 24px 80px; }
.fb-inner h2 { font-family: var(--hand); font-weight: 400; font-size: 34px; margin-bottom: 12px; }
.fb-inner > p { margin-bottom: 22px; }
#fallback-list details {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}
#fallback-list summary {
  cursor: pointer; font-weight: 600; font-size: 19px;
}
#fallback-list summary span { font-weight: 400; font-style: italic; font-size: 15px; color: var(--ink-soft); }
.fb-body { padding: 8px 0 12px 12px; font-size: 15.5px; }
.fb-body p { margin-bottom: 8px; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 880px) {
  #chrome { padding: 12px 14px 0; }
  #chrome .brand p { display: none; }
  .chrome-actions button { font-size: 12.5px; padding: 6px 10px; }

  #legend {
    left: 0; right: 0; top: auto; bottom: 26px;
    width: 100%; max-height: none;
    padding: 4px 10px;
    background: linear-gradient(to top, rgba(239,230,211,0.96) 70%, transparent);
  }
  #legend-list { display: flex; gap: 18px; overflow-x: auto; padding-bottom: 4px; }
  .legend-group { flex: none; margin-bottom: 0; }
  .legend-group h3 { font-size: 10px; }
  .legend-nest { margin-left: 0; display: flex; }
  .legend-group { display: flex; flex-direction: column; }
  .legend-group > button, .legend-nest > button { white-space: nowrap; font-size: 14px; padding: 3px 6px; }
  body.has-selection #legend { display: none; }

  #dossier {
    top: auto; left: 10px; right: 10px; bottom: 0;
    width: auto; max-height: 62vh;
  }
  #dossier-scroll {
    border-radius: 10px 10px 0 0;
    transform: translateY(105%);
    padding: 20px 22px 40px;
  }
  #dossier.open #dossier-scroll { transform: translateY(0); }
  .measure-rail { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .paper-grain { transition: none; }
  #dossier-scroll { transition-duration: 0.15s; }
}
