@font-face { font-family: 'Rye'; src: url('./fonts/rye-400n.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Staatliches'; src: url('./fonts/staatliches-400n.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('./fonts/spectral-400n.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('./fonts/spectral-500n.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('./fonts/spectral-600n.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('./fonts/spectral-400i.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --paper: #f1e7d2;
  --paper-hi: #f7efdd;
  --paper-lo: #e6d9bd;
  --ink: #2e2a24;
  --ink-soft: #5c554a;
  --ink-faint: #8a8172;
  --chalk: #f4ead2;
  --accent: #b5432c;
  --accent-deep: #8c2f1d;
  --accent-tint: rgba(181, 67, 44, 0.09);
  --rail-h: 30px;
  --display: 'Staatliches', 'Arial Narrow', sans-serif;
  --hand: 'Rye', Georgia, serif;
  --body: 'Spectral', Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 46% 38%, var(--paper-hi) 0%, var(--paper) 46%, var(--paper-lo) 100%);
  overflow: hidden;
  display: grid;
  grid-template-columns: 262px 1fr;
  height: 100dvh;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px dashed var(--accent); outline-offset: 2px; }

#grain, #vignette { position: fixed; inset: 0; pointer-events: none; }
#grain {
  z-index: 70; opacity: .38; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
}
#vignette {
  z-index: 69;
  background: radial-gradient(115% 90% at 50% 40%, transparent 52%, rgba(58, 44, 28, 0.20) 100%);
}

/* ---------- legend rail + masthead ---------- */

#legend {
  position: relative;
  z-index: 20;
  border-right: 1px solid rgba(46, 42, 36, 0.55);
  box-shadow: 6px 0 18px -12px rgba(46, 42, 36, 0.5);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(247, 239, 221, 0.6), rgba(247, 239, 221, 0) 140px);
}

#masthead { padding: 22px 20px 14px; border-bottom: 3px double rgba(46, 42, 36, 0.5); }
#masthead .kicker {
  font-family: var(--display); font-size: 10.5px; letter-spacing: 0.32em;
  text-transform: uppercase; color: var(--ink-soft);
}
#masthead h1 { display: flex; align-items: baseline; gap: 10px; margin-top: 8px; }
#masthead .mast-beef {
  font-family: var(--hand); font-weight: 400; font-size: 46px; line-height: 0.9;
  color: var(--ink); text-shadow: 2px 2px 0 rgba(181, 67, 44, 0.16);
}
#masthead .mast-sub {
  font-family: var(--display); font-size: 15px; letter-spacing: 0.30em;
  color: var(--accent); transform: translateY(-4px);
}
#masthead .mast-note {
  margin-top: 9px; font-style: italic; font-size: 12.5px; color: var(--ink-faint); line-height: 1.45;
}

#legend .legend-scroll { overflow-y: auto; flex: 1; padding: 6px 0 24px; scrollbar-width: thin; scrollbar-color: var(--ink-faint) transparent; }
.legend-group { padding: 0 12px; }
.legend-heading {
  font-family: var(--display); font-size: 11px; letter-spacing: 0.34em; text-transform: uppercase;
  color: var(--ink-faint); margin: 18px 8px 6px; display: flex; align-items: center; gap: 8px;
}
.legend-heading::after { content: ''; flex: 1; height: 1px; background: rgba(46, 42, 36, 0.25); }
.legend-group ul { list-style: none; }

.legend-item {
  width: 100%; display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px;
  padding: 8px 8px 8px 10px; text-align: left; position: relative;
  border-bottom: 1px dashed rgba(46, 42, 36, 0.16);
  transition: transform 0.16s ease, background 0.16s ease;
}
.legend-item::before {
  content: ''; position: absolute; left: 0; top: 15%; bottom: 15%; width: 3px;
  background: var(--accent); transform: scaleY(0); transform-origin: top; transition: transform 0.2s ease;
}
.legend-item:hover, .legend-item.is-hover { transform: translateX(3px); }
.legend-item:hover::before, .legend-item.is-hover::before { transform: scaleY(1); }
.legend-item.is-active { background: var(--accent-tint); }
.legend-item.is-active::before { transform: scaleY(1); }
.legend-no { font-family: var(--display); font-size: 11px; color: var(--ink-faint); letter-spacing: 0.08em; }
.legend-name {
  font-family: var(--display); font-size: 15.5px; letter-spacing: 0.12em; text-transform: uppercase;
  transition: color 0.16s ease;
}
.legend-item:hover .legend-name, .legend-item.is-hover .legend-name { color: var(--accent-deep); }
.legend-item.is-active .legend-name { color: var(--accent); }
.legend-meters { display: flex; flex-direction: column; gap: 2.5px; width: 24px; }
.legend-meters .mm { display: block; height: 3px; background: rgba(46, 42, 36, 0.14); position: relative; }
.legend-meters .mm b { position: absolute; inset: 0 auto 0 0; width: calc(var(--v) * 12.5%); background: var(--ink-soft); }
.legend-meters .mm:first-child b { background: var(--accent); }

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

#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#stage:focus-visible { outline: 2px dashed var(--accent); outline-offset: -4px; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#leaders { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: visible; }
#leaders .leader { stroke: rgba(58, 50, 40, 0.6); stroke-width: 1; stroke-dasharray: 3 3; }
#labels { position: absolute; inset: 0; pointer-events: none; z-index: 6; overflow: hidden; }

.cut-label {
  position: absolute; top: 0; left: 0; pointer-events: auto;
  font-family: var(--display); font-size: 15px; letter-spacing: 0.16em;
  color: var(--chalk); padding: 3px 7px; white-space: nowrap;
  text-shadow: 0 1px 3px rgba(20, 14, 8, 0.75), 0 0 12px rgba(20, 14, 8, 0.35);
  transition: opacity 0.35s ease;
  will-change: transform;
}
.cut-label span { display: inline-block; transition: transform 0.18s ease, color 0.18s ease; }
.cut-label.is-outside { color: var(--ink); text-shadow: none; font-size: 12.5px; }
.cut-label:hover span, .cut-label.is-hover span { transform: translateY(-4px); color: #ffd9a0; }
.cut-label.is-outside:hover span, .cut-label.is-outside.is-hover span { color: var(--accent); }
.cut-label.is-active span { color: #ffe9c9; border-bottom: 2px solid var(--accent); }
.cut-label.is-outside.is-active span { color: var(--accent-deep); }
.cut-label.is-dim { opacity: 0.2; }

/* hanging rail + tag */
#rail {
  position: absolute; top: 0; left: 0; right: 0; height: var(--rail-h); z-index: 12;
  border-bottom: 2px solid rgba(46, 42, 36, 0.65); pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(46, 42, 36, 0.4) 0 1px, transparent 1px 14px) bottom / 100% 8px no-repeat;
}
#tag {
  position: absolute; right: clamp(14px, 6vw, 84px); top: calc(var(--rail-h) - 2px);
  transform-origin: top center; animation: sway 5.2s ease-in-out infinite;
  filter: drop-shadow(1px 3px 2px rgba(46, 42, 36, 0.25));
  pointer-events: none;
}
#tag::before { content: ''; display: block; width: 1.5px; height: 20px; background: rgba(46, 42, 36, 0.7); margin: 0 auto; }
#tag .tag-body {
  display: flex; align-items: center; gap: 7px;
  background: var(--paper-hi); border: 1.5px solid var(--ink); padding: 5px 12px 5px 8px;
  transform: rotate(1.6deg);
}
#tag .tag-hole { width: 7px; height: 7px; border: 1.5px solid var(--accent); border-radius: 50%; }
#tagText {
  font-family: var(--display); font-size: 14px; letter-spacing: 0.22em; color: var(--ink);
  display: inline-block; transition: opacity 0.15s ease;
}
#tag.is-flip #tagText { animation: tagflip 0.45s ease; }
@keyframes sway { 0%, 100% { transform: rotate(-2.1deg); } 50% { transform: rotate(2.3deg); } }
@keyframes tagflip { 0% { transform: scaleY(0.1); opacity: 0.2; } 100% { transform: scaleY(1); opacity: 1; } }

/* reset + hint */
#resetBtn {
  position: absolute; top: calc(var(--rail-h) + 52px); right: 16px; z-index: 45;
  font-family: var(--display); font-size: 12.5px; letter-spacing: 0.24em;
  padding: 8px 14px; background: rgba(247, 239, 221, 0.85); border: 1.5px solid var(--ink);
  transition: all 0.22s cubic-bezier(0.22, 0.9, 0.28, 1); box-shadow: 2px 2px 0 rgba(46, 42, 36, 0.25);
}
#resetBtn:hover { border-color: var(--accent); color: var(--accent-deep); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 rgba(140, 47, 29, 0.3); }
body.is-scoped #resetBtn { right: calc(min(420px, 92vw) + 14px); background: var(--ink); color: var(--chalk); border-color: var(--ink); }
body.is-scoped #resetBtn:hover { background: var(--accent-deep); }

#hintbar {
  position: absolute; left: 16px; bottom: 14px; z-index: 15;
  font-family: var(--display); font-size: 11.5px; letter-spacing: 0.18em; color: var(--ink-soft);
  background: rgba(247, 239, 221, 0.8); border: 1px solid rgba(46, 42, 36, 0.4);
  padding: 7px 12px; transition: opacity 0.9s ease;
}
#hintbar b { color: var(--accent-deep); font-weight: 400; }
#hintbar.is-faded { opacity: 0; pointer-events: none; }

/* ---------- dossier ---------- */

#backdrop { display: none; position: fixed; inset: 0; background: rgba(40, 32, 22, 0.4); z-index: 30; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
#backdrop.is-open { opacity: 1; pointer-events: auto; }

#dossier {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(420px, 92vw); z-index: 40;
  background: linear-gradient(180deg, #f7efdd 0%, #f2e8d2 100%);
  border-left: 1px solid rgba(46, 42, 36, 0.6);
  box-shadow: -14px 0 34px -18px rgba(46, 42, 36, 0.55);
  transform: translateX(106%); transition: transform 0.45s cubic-bezier(0.22, 0.9, 0.28, 1);
  display: flex; flex-direction: column;
}
#dossier.is-open { transform: translateX(0); }
#dossier::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: var(--accent); }

.dossier-close {
  position: absolute; top: 12px; right: 12px; z-index: 2; width: 32px; height: 32px;
  border: 1.5px solid var(--ink); font-size: 14px; line-height: 1; background: var(--paper-hi);
  transition: all 0.15s ease;
}
.dossier-close:hover { background: var(--accent); border-color: var(--accent); color: var(--chalk); transform: rotate(90deg); }

.dossier-scroll { overflow-y: auto; flex: 1; padding: 26px 26px 30px; scrollbar-width: thin; scrollbar-color: var(--ink-faint) transparent; }

.dossier-head { position: relative; padding-right: 70px; border-bottom: 3px double rgba(46, 42, 36, 0.5); padding-bottom: 16px; }
.stamp {
  position: absolute; top: 2px; right: 0; width: 62px; height: 62px; border: 2.5px solid var(--accent);
  border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  transform: rotate(-9deg); opacity: 0.85; color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(181, 67, 44, 0.25);
  pointer-events: none;
}
.stamp span { font-family: var(--display); font-size: 9px; letter-spacing: 0.2em; }
.stamp b { font-family: var(--display); font-size: 21px; font-weight: 400; letter-spacing: 0.05em; }
.dossier-group { font-family: var(--display); font-size: 11px; letter-spacing: 0.34em; text-transform: uppercase; color: var(--accent-deep); }
.dossier-name { font-family: var(--display); font-weight: 400; font-size: clamp(34px, 4.4vw, 44px); letter-spacing: 0.06em; text-transform: uppercase; line-height: 1; margin-top: 6px; }
.dossier-aka { font-style: italic; font-size: 13.5px; color: var(--ink-soft); margin-top: 7px; }
.dossier-tagline { font-size: 15px; margin-top: 10px; line-height: 1.5; }

.meters { display: grid; gap: 8px; padding: 16px 0; border-bottom: 1px dashed rgba(46, 42, 36, 0.3); }
.meter { display: grid; grid-template-columns: 118px 1fr; align-items: center; gap: 10px; }
.meter-label { font-family: var(--display); font-size: 10.5px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-soft); }
.meter-segs { display: flex; gap: 4px; }
.meter-segs i { flex: 1; height: 9px; background: rgba(46, 42, 36, 0.13); }
.meter-segs i.on { background: var(--ink-soft); }
.meter:first-child .meter-segs i.on { background: var(--accent); }

.dossier-section { margin-top: 22px; }
.dossier-section h3 {
  font-family: var(--display); font-weight: 400; font-size: 12.5px; letter-spacing: 0.3em;
  text-transform: uppercase; color: var(--ink); display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.dossier-section h3::after { content: ''; width: 26px; height: 2px; background: var(--accent); }
.dossier-section p { font-size: 15.5px; line-height: 1.68; color: #3d382f; }

.dossier-logic {
  margin-top: 22px; padding: 12px 16px; border-left: 3px solid var(--accent);
  background: var(--accent-tint); font-style: italic; font-size: 16.5px; line-height: 1.5; color: var(--accent-deep);
}

.methods, .subs, .dishes { list-style: none; display: grid; gap: 12px; }
.methods li, .subs li, .dishes li { padding-left: 16px; position: relative; }
.methods li::before, .subs li::before, .dishes li::before {
  content: '◆'; position: absolute; left: 0; top: 1px; font-size: 8px; color: var(--accent);
}
.methods b, .subs b { font-family: var(--display); font-weight: 400; font-size: 14px; letter-spacing: 0.1em; text-transform: uppercase; display: block; }
.methods span, .subs span { display: block; font-size: 14px; line-height: 1.55; color: var(--ink-soft); margin-top: 2px; }
.dishes b { font-weight: 600; font-size: 15px; }
.dishes span { display: block; font-size: 13.5px; font-style: italic; color: var(--ink-soft); margin-top: 1px; }

.compare-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.compare-table th, .compare-table td { padding: 6px 8px; border-bottom: 1px dashed rgba(46, 42, 36, 0.25); text-align: left; vertical-align: top; }
.compare-table thead th { font-family: var(--display); font-weight: 400; letter-spacing: 0.14em; text-transform: uppercase; font-size: 12px; }
.compare-table tbody th { font-family: var(--display); font-weight: 400; letter-spacing: 0.14em; text-transform: uppercase; font-size: 10.5px; color: var(--ink-soft); }
.compare-logic td { font-style: italic; font-size: 12.5px; color: var(--ink-soft); }

.dossier-foot {
  margin-top: 26px; padding-top: 16px; border-top: 3px double rgba(46, 42, 36, 0.5);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.dossier-nav {
  font-family: var(--display); font-size: 11.5px; letter-spacing: 0.16em; text-transform: uppercase;
  border: 1.5px solid var(--ink); padding: 7px 10px; transition: all 0.15s ease; background: var(--paper-hi);
}
.dossier-nav:hover { border-color: var(--accent); color: var(--accent-deep); transform: translateY(-1px); }
.dossier-pin {
  font-family: var(--display); font-size: 11.5px; letter-spacing: 0.16em; text-transform: uppercase;
  border: 1.5px solid var(--accent); color: var(--accent-deep); padding: 7px 12px; transition: all 0.15s ease;
}
.dossier-pin:hover { background: var(--accent-tint); }
.dossier-pin.is-pinned { background: var(--accent); color: var(--chalk); }

/* ---------- title card ---------- */

#titlecard {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(100% 80% at 50% 40%, var(--paper-hi), var(--paper) 70%);
  transition: opacity 0.75s ease; text-align: center;
}
#titlecard.is-gone { opacity: 0; pointer-events: none; }
.card-inner { display: flex; flex-direction: column; align-items: center; padding: 24px; max-width: 620px; }
#cardCow { width: min(340px, 68vw); height: auto; margin-bottom: 10px; }
#cardCow path {
  fill: none; stroke: var(--ink); stroke-width: 0.055; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 2.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
#cardCow path:nth-child(2n) { animation-delay: 0.35s; }
#cardCow path:nth-child(3n) { animation-delay: 0.6s; }
#cardCow path:nth-child(4n) { animation-delay: 0.85s; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.card-beef { font-family: var(--hand); font-weight: 400; font-size: clamp(58px, 11vw, 92px); line-height: 0.95; text-shadow: 3px 3px 0 rgba(181, 67, 44, 0.18); }
.card-sub { font-family: var(--display); font-size: clamp(15px, 2.6vw, 20px); letter-spacing: 0.52em; color: var(--accent); margin-top: 10px; text-indent: 0.52em; }
.card-rule { width: 130px; height: 1px; background: var(--ink); margin: 22px auto; position: relative; }
.card-rule::after { content: '◆'; position: absolute; left: 50%; top: -7.5px; transform: translateX(-50%); font-size: 8px; color: var(--accent); background: var(--paper-hi); padding: 0 6px; }
.card-copy { font-style: italic; font-size: 15.5px; line-height: 1.6; color: var(--ink-soft); max-width: 44ch; }
#cardStatus {
  margin-top: 26px; font-family: var(--display); font-size: 12px; letter-spacing: 0.3em;
  color: var(--ink-faint); transition: color 0.3s ease;
}
#cardStatus.is-ready { color: var(--accent-deep); animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ---------- fallback ---------- */

#fallback { position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 18px 24px; }
#fallback[hidden] { display: none; }
.flat-notice {
  max-width: 52ch; text-align: center; font-size: 14.5px; line-height: 1.55; color: var(--ink-soft);
  border: 1.5px solid var(--accent); background: var(--accent-tint); padding: 12px 18px; margin-bottom: 18px;
}
.flat-notice b { color: var(--accent-deep); }
.flat-chart { width: min(880px, 94%); height: auto; }
.fc-decor { fill: rgba(46, 42, 36, 0.55); }
.fc-cut { fill: #332e27; stroke: var(--paper); stroke-width: 0.06; cursor: pointer; transition: fill 0.25s ease, opacity 0.25s ease; }
.fc-cut.is-hover { fill: #4a3a2c; }
.fc-cut.is-selected { fill: var(--accent); }
.fc-cut.is-dim { fill: #b8ad97; }
.fc-label { font-family: var(--display); font-size: 0.34px; letter-spacing: 0.05px; fill: var(--chalk); text-anchor: middle; pointer-events: none; }
.fc-label-out { fill: var(--ink); font-size: 0.3px; }
.fc-leader { stroke: rgba(58, 50, 40, 0.55); stroke-width: 0.025; stroke-dasharray: 0.09 0.09; }

/* ---------- responsive ---------- */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 1080px) {
  body { grid-template-columns: 224px 1fr; }
  #dossier { width: min(380px, 94vw); }
}

@media (max-width: 880px) {
  body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #backdrop { display: block; }
  #masthead {
    position: absolute; z-index: 14; top: calc(var(--rail-h) + 10px); left: 12px;
    padding: 8px 12px; border: 1px solid rgba(46, 42, 36, 0.4); background: rgba(247, 239, 221, 0.85);
    border-bottom-width: 1px;
  }
  #masthead .kicker, #masthead .mast-note { display: none; }
  #masthead h1 { margin-top: 0; }
  #masthead .mast-beef { font-size: 26px; }
  #masthead .mast-sub { font-size: 11px; }
  #legend {
    order: 2; border-right: 0; border-top: 1px solid rgba(46, 42, 36, 0.55);
    box-shadow: 0 -6px 18px -12px rgba(46, 42, 36, 0.5);
    width: 100%; min-width: 0;
  }
  #legend .legend-scroll { display: flex; overflow-x: auto; overflow-y: hidden; padding: 8px 10px; gap: 4px; }
  .legend-group { padding: 0; flex: 0 0 auto; display: flex; align-items: center; gap: 2px; }
  .legend-heading { margin: 0 8px 0 4px; }
  .legend-heading::after { display: none; }
  .legend-group ul { display: flex; }
  .legend-item { border-bottom: 0; border: 1px solid rgba(46, 42, 36, 0.3); padding: 6px 9px; grid-template-columns: auto auto; white-space: nowrap; }
  .legend-item::before { display: none; }
  .legend-meters { display: none; }
  #dossier {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 70dvh;
    transform: translateY(106%); border-left: 0; border-top: 1px solid rgba(46, 42, 36, 0.6);
    box-shadow: 0 -14px 34px -18px rgba(46, 42, 36, 0.55);
  }
  #dossier.is-open { transform: translateY(0); }
  #dossier::before { height: 3px; }
  .dossier-scroll { padding: 20px 18px 26px; }
  #resetBtn { top: 82px; right: 10px; left: auto; padding: 7px 10px; font-size: 11px; }
  body.is-scoped #resetBtn { right: 10px; }
  #hintbar { left: 10px; right: 10px; bottom: 10px; text-align: center; font-size: 10px; }
  .cut-label { font-size: 12px; }
  .cut-label.is-outside { font-size: 10.5px; }
  #tag { right: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  #tag { animation: none; }
  #cardCow path { animation-duration: 0.01s; }
  #cardStatus.is-ready { animation: none; }
}
