/* PATH-FIT 1 — Interactive 3D Skeletal System
   Exequiel Fernando · Laguna University

   Aesthetic: early-terminal / CRT. Monospace throughout, phosphor accents on near-black.
   Green = bone, amber = joint, so the two selection kinds stay distinguishable without
   relying on colour alone (they also carry text labels).
   No web fonts, no remote assets: everything here must work offline. */

:root {
  --bg: #07080a;
  --bg-elev: #0c0e11;
  --panel: #0a0c0e;
  --line: #1b2024;
  --line-soft: #14181b;

  --text: #cfd4cc;          /* warm phosphor white */
  --text-dim: #8e968c;
  --text-faint: #5a625a;

  --bone: #6fcf97;          /* phosphor green — bones / primary */
  --bone-dim: #2f5c44;
  --joint: #e0a84a;         /* amber — joints */
  --joint-dim: #5c4620;
  --danger: #d2726b;

  --radius: 3px;            /* terminals don't do round corners */
  --ease: cubic-bezier(.22,.61,.36,1);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono", Menlo, Consolas,
          "DejaVu Sans Mono", "Liberation Mono", monospace;

  /* spacing scale — gaps must read as deliberate, not accidental */
  --gap-xs: 8px;
  --gap-sm: 14px;
  --gap-md: 22px;
  --gap-lg: 34px;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.7 var(--mono);
  letter-spacing: .01em;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

/* Very low-contrast scanlines + vignette. Static, no animation. */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 100;
  background:
    repeating-linear-gradient(to bottom, #ffffff06 0 1px, transparent 1px 3px),
    radial-gradient(130% 100% at 50% 45%, transparent 55%, #000000a8 100%);
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; letter-spacing: inherit; }
:focus-visible { outline: 1px solid var(--bone); outline-offset: 3px; }
[hidden] { display: none !important; }

.cursor {
  display: inline-block; width: .55em; height: 1em; margin-left: .35em;
  background: var(--bone); vertical-align: -.15em;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 0%, 50% { opacity: 1 } 50.01%, 100% { opacity: 0 } }

/* ---------- shared surfaces ---------- */
.stage {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 40;
}

.eyebrow {
  font-size: 10.5px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--bone); opacity: .8;
}

/* Buttons read as terminal commands: [ ACCEPT ] */
.btn {
  padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--text-dim);
  font-size: 12.5px; letter-spacing: .12em; text-transform: uppercase;
  transition: color .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.btn::before { content: "[ "; opacity: .45; }
.btn::after  { content: " ]"; opacity: .45; }
.btn:hover { color: var(--text); border-color: #2b3238; background: #101418; }
.btn-primary { color: var(--bone); border-color: var(--bone-dim); }
.btn-primary:hover { color: var(--bone); border-color: var(--bone); background: #0d1a13; }
.btn-ghost { border-color: transparent; }
.btn-ghost:hover { border-color: var(--line); }

/* ---------- usage notice ---------- */
.notice {
  width: min(600px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--gap-lg);
  position: relative;
}
/* corner ticks, like a framed terminal window */
.notice::before {
  content: ""; position: absolute; inset: 6px; pointer-events: none;
  border: 1px solid #ffffff08; border-radius: 2px;
}
.notice h1 {
  margin: var(--gap-sm) 0 var(--gap-md);
  font-size: 17px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
}
.notice p { margin: 0; color: var(--text-dim); font-size: 13.5px; }
.notice strong { color: var(--text); font-weight: 600; }
.notice-actions {
  display: flex; gap: var(--gap-xs); align-items: center;
  margin-top: var(--gap-lg); flex-wrap: wrap;
}
.notice-actions .spacer { flex: 1; }
.link-quiet {
  color: var(--text-faint); font-size: 11.5px;
  letter-spacing: .1em; text-transform: uppercase;
  border-bottom: 1px dotted #2e3630; padding-bottom: 2px;
}
.link-quiet:hover { color: var(--bone); border-bottom-color: var(--bone-dim); }

/* detailed notice sits ABOVE the first modal */
.detail-layer { z-index: 50; background: #04050699; backdrop-filter: blur(2px); }
.detail {
  width: min(660px, 100%); max-height: min(78vh, 720px);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.detail header {
  padding: var(--gap-md) var(--gap-lg) var(--gap-sm);
  border-bottom: 1px solid var(--line-soft);
}
.detail header h2 {
  margin: 0; font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--bone);
}
.detail .body { padding: var(--gap-md) var(--gap-lg); overflow-y: auto; }
.detail .body h3 {
  margin: var(--gap-md) 0 var(--gap-xs);
  font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--text-faint);
}
.detail .body h3::before { content: "> "; color: var(--bone-dim); }
.detail .body h3:first-child { margin-top: 0; }
.detail .body p { margin: 0 0 var(--gap-sm); color: var(--text-dim); font-size: 13px; }
.detail footer {
  padding: var(--gap-sm) var(--gap-lg) var(--gap-md);
  border-top: 1px solid var(--line-soft); text-align: right;
}

/* ---------- declined ---------- */
.declined { text-align: center; max-width: 420px; }
.declined h2 {
  font-size: 13px; letter-spacing: .2em; text-transform: uppercase;
  margin: 0 0 var(--gap-sm); color: var(--danger);
}
.declined p { color: var(--text-faint); font-size: 13px; margin: 0; }

/* ---------- loading ---------- */
.loading { width: min(440px, 100%); text-align: center; }
.loading .eyebrow { display: block; margin-bottom: var(--gap-md); }
.bar {
  height: 10px; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2px; background: #0a0d10;
}
.bar > span {
  display: block; height: 100%; width: 0%;
  background: repeating-linear-gradient(90deg, var(--bone) 0 3px, transparent 3px 5px);
  transition: width .25s var(--ease);
}
.loading-status {
  display: flex; justify-content: space-between; gap: var(--gap-sm);
  margin-top: var(--gap-sm); font-size: 11.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-faint);
}
.load-log {
  margin: 0 0 var(--gap-md); padding: 0;
  font: 11.5px/1.75 var(--mono); text-align: left;
  color: var(--text-faint); min-height: 5.25em; white-space: pre;
}
.load-log .ok   { color: var(--bone); }
.load-log .dots { color: #2a3230; }
.load-log .run  { color: var(--text-dim); }

.load-ready { margin-top: var(--gap-md); }

.loading-error { margin-top: var(--gap-md); color: var(--danger); font-size: 12.5px; }
.loading-error p { margin: 0 0 var(--gap-sm); }

/* ---------- main layout ---------- */
.app { position: fixed; inset: 0; display: grid; grid-template-columns: 65fr 35fr; }

#viewport {
  position: relative; min-width: 0; cursor: grab; overflow: hidden;
  background:
    linear-gradient(#ffffff03 1px, transparent 1px) 0 0 / 100% 42px,
    radial-gradient(90% 70% at 50% 45%, #0e1114 0%, var(--bg) 72%);
  touch-action: none;
}
/* Belt and braces: the canvas must never exceed its container regardless of DPR. */
#viewport canvas { display: block; width: 100% !important; height: 100% !important; }
#viewport.is-grabbing { cursor: grabbing; }
#viewport.is-over-structure { cursor: pointer; }
.viewport-placeholder {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: var(--gap-md); text-align: center;
}
/* ---------- filters ---------- */
.controls {
  position: absolute; z-index: 6; top: 16px; left: 18px;
  display: flex; flex-direction: column; gap: 7px;
  max-width: 340px;
}
.filter-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-search-row { position: relative; }

.filter-search {
  width: 190px; padding: 6px 9px;
  font: 11px/1.4 var(--mono); letter-spacing: .1em;
  color: var(--text); background: #0b0e10e6;
  border: 1px solid var(--line); border-radius: var(--radius);
  -webkit-appearance: none; appearance: none;
}
.filter-search::placeholder { color: var(--text-faint); text-transform: uppercase; letter-spacing: .12em; }
.filter-search:focus { outline: none; border-color: var(--bone-dim); }

.search-results {
  position: absolute; z-index: 8; top: calc(100% + 4px); left: 0;
  margin: 0; padding: 4px; list-style: none;
  width: 250px; max-height: 246px; overflow-y: auto;
  background: #0a0d0fF2; border: 1px solid var(--line); border-radius: var(--radius);
}
.search-results li { margin: 0; }
.search-results button {
  display: flex; width: 100%; gap: 8px; align-items: baseline;
  padding: 6px 8px; border-radius: 2px; text-align: left;
  font-size: 11px; letter-spacing: .08em; color: var(--text-dim);
}
.search-results button:hover,
.search-results button[aria-selected="true"] { background: #111a15; color: var(--bone); }
.search-results .r-meta {
  margin-left: auto; font-size: 9.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--text-faint);
}
.search-results .r-meta.is-joint { color: var(--joint); }
.search-empty { padding: 8px; font-size: 10.5px; letter-spacing: .1em; color: var(--text-faint); }
.filter-legend {
  font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--text-faint); width: 54px;
}
.filter-chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  padding: 4px 8px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #0b0e10cc; color: var(--text-faint);
  transition: color .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.chip:hover { color: var(--text-dim); border-color: #2b3238; }
.chip[aria-pressed="true"] { color: var(--bone); border-color: var(--bone-dim); background: #0d1a13; }
.filter-reset {
  font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-faint); border-bottom: 1px dotted #2e3630; padding-bottom: 1px;
}
.filter-reset:hover { color: var(--danger); }
.filter-hint {
  font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--text-faint);
}
.filter-hint.is-empty { color: var(--joint); }

/* hover identification — pointer devices only; mobile uses tap + panel */
.hover-label {
  position: absolute; z-index: 5; pointer-events: none;
  transform: translate(12px, -50%);
  padding: 5px 9px; border-radius: var(--radius);
  background: #0b0f0dee; border: 1px solid var(--bone-dim);
  color: var(--bone); font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  white-space: nowrap;
}

.identity {
  position: absolute; left: 20px; bottom: 16px; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: #39413a; user-select: none;
}
.identity-text { pointer-events: none; }
.identity-notice {
  font: inherit; color: #4d5a4f;
  border-bottom: 1px dotted #2b322c; padding-bottom: 1px;
}
.identity-notice:hover { color: var(--bone); border-bottom-color: var(--bone-dim); }

/* ---------- right panel: one centred block ---------- */
.panel {
  min-width: 0; background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; padding: var(--gap-lg) var(--gap-md);
}
.panel-center {
  width: 100%; max-width: 380px; max-height: 100%;
  display: flex; flex-direction: column; min-height: 0;
}
#panel-default { overflow-y: auto; min-height: 0; }
#panel-info { display: flex; flex-direction: column; min-height: 0; }

/* default facts view — centred on both axes */
#panel-default { text-align: center; }

.panel-kicker {
  font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--bone); opacity: .85; margin-bottom: var(--gap-md);
}
.fact-title {
  margin: 0 0 var(--gap-sm);
  font-size: 15px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
}
.fact-text { margin: 0; font-size: 13.5px; line-height: 1.85; color: var(--text-dim); }
.fact-text.is-instruction { color: var(--text); }
.source-note {
  margin-top: var(--gap-md); padding-top: var(--gap-sm);
  border-top: 1px solid var(--line-soft);
  font-size: 10.5px; letter-spacing: .06em; color: var(--text-faint);
}

/* navigation sits directly under the content */
.panel-foot { margin-top: var(--gap-lg); }
.fact-progress {
  height: 6px; border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 1px; margin-bottom: var(--gap-sm);
}
.fact-progress > span {
  display: block; height: 100%; width: 0%;
  background: repeating-linear-gradient(90deg, var(--bone-dim) 0 3px, transparent 3px 5px);
}
.fact-nav { display: flex; align-items: center; gap: var(--gap-xs); }
.fact-nav .count {
  flex: 1; text-align: left;
  font-size: 11px; letter-spacing: .14em; color: var(--text-faint);
}
.icon-btn {
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text-faint); font-size: 13px;
  transition: color .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.icon-btn:hover { color: var(--bone); border-color: var(--bone-dim); background: #0c1310; }

/* ---------- selected-structure panel ---------- */
#panel-info { text-align: left; }
/* Pinned header: stays put while the fields scroll underneath. */
.info-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--gap-sm);
  margin-bottom: var(--gap-md); padding-bottom: var(--gap-sm);
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel);
}
.info-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #232a26 transparent;
}
.info-body::-webkit-scrollbar { width: 4px; }
.info-body::-webkit-scrollbar-thumb { background: #232a26; border-radius: 99px; }
.info-head h2 {
  margin: 0; flex: 1;
  font-size: 15px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--gap-md); }
.tag {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  padding: 4px 8px; border-radius: var(--radius);
  background: #0d1210; border: 1px solid var(--bone-dim); color: var(--bone);
}
.tag.is-joint { color: var(--joint); border-color: var(--joint-dim); background: #14100a; }
.info-field { margin-bottom: var(--gap-md); }
.info-field h3 {
  margin: 0 0 6px; font-size: 10px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--text-faint);
}
.info-field h3::before { content: "> "; color: var(--bone-dim); }
.info-field p { margin: 0; color: var(--text-dim); font-size: 13px; line-height: 1.8; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  /* height:100% would make <body> the scroll container, leaving window.scrollY pinned at 0
     and breaking scrollIntoView. Let the document scroll instead. */
  html, body { height: auto; min-height: 100%; overflow: visible; }
  .app { position: static; display: block; min-height: 100svh; }

  /* Roughly 70/30 model-to-information. The model is the point of the page; the panel is
     compact and scrolls its own content rather than pushing the skeleton off screen. */
  #viewport { height: 70svh; min-height: 300px; }

  /* Controls move OUT of the viewport on mobile: overlaying them covered the skeleton. */
  .controls {
    position: static; max-width: none;
    padding: 8px 12px; gap: 5px;
    background: var(--bg-elev); border-top: 1px solid var(--line);
  }
  .filter-search { flex: 1 1 auto; min-width: 0; }
  .filter-row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .filter-row::-webkit-scrollbar { display: none; }
  .filter-chips { flex-wrap: nowrap; }   /* chips scroll sideways instead of stacking */
  .filter-search-row { overflow: visible; }
  .filter-search { width: 100%; }
  .search-results { width: 100%; }
  .filter-legend { width: auto; min-width: 42px; font-size: 9px; }
  .chip { padding: 5px 8px; flex: 0 0 auto; }

  .panel {
    border-left: 0; border-top: 1px solid var(--line);
    height: 30svh; min-height: 220px;
    align-items: stretch;                 /* content starts at the top, not floating mid-panel */
    padding: var(--gap-md);
  }
  .panel-center { max-width: none; }
  .panel-foot { margin-top: var(--gap-md); }

  /* Identity becomes a quiet line under everything instead of sitting on the skeleton. */
  .identity {
    position: static; flex-direction: column; align-items: center; gap: 6px;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line-soft); font-size: 9px; letter-spacing: .08em;
  }
  .identity-text { text-align: center; }

  .hover-label { display: none; }        /* no hover on touch; tap selects instead */
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .cursor { opacity: 1; animation: none; }
}
