/* intima — a semantic poetry field */

:root {
  --bg: #07080c;
  --ink: #e8e4da;
  --ink-dim: rgba(232, 228, 218, 0.55);
  --ink-faint: rgba(232, 228, 218, 0.32);
  --accent: #d8b26a;
  --accent-soft: rgba(216, 178, 106, 0.35);
  --line: rgba(255, 255, 255, 0.09);
  --panel-bg: rgba(10, 12, 18, 0.86);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
}

/* ---------------- field layers (DOM node rendering) ---------------- */

#field {
  position: fixed;
  inset: 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
#field.dragging { cursor: grabbing; }

#edge-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

#node-layer {
  position: absolute;
  inset: 0;
  /* no overflow clip and no layer transform: nodes are individually
     projected in 3D — #field clips at the viewport */
  pointer-events: none;
  z-index: 2;
}

#label-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 5;
}

/* one node: 40px world hit area, 30px image, centered on its world point */
.fnode {
  position: absolute;
  left: 0;
  top: 0;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  pointer-events: auto;
  cursor: pointer;
  will-change: transform, opacity;
  contain: layout style;
}
.fnode-img {
  position: absolute;
  inset: 5px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--tint, rgba(255, 255, 255, 0.15));
  transition: transform 160ms cubic-bezier(0.4, 0.0, 0.2, 1);
  pointer-events: none;
}
.fnode.hovered .fnode-img { transform: scale(1.24); }

.fnode-arc {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: conic-gradient(from -90deg, rgba(216, 178, 106, 0.85) calc(var(--u, 0) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(closest-side, transparent calc(100% - 3px), #000 calc(100% - 2.4px));
  mask: radial-gradient(closest-side, transparent calc(100% - 3px), #000 calc(100% - 2.4px));
  pointer-events: none;
}
.fnode.no-arc .fnode-arc { display: none; }

/* state classes */
.fnode.active .fnode-img {
  border-color: var(--accent);
  border-width: 2px;
}
.fnode.active::before {
  content: '';
  position: absolute;
  inset: -26px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(216, 178, 106, 0.30) 0%, rgba(216, 178, 106, 0.10) 45%, transparent 70%);
  animation: fnode-pulse 2.1s ease-in-out infinite;
}
@keyframes fnode-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}
.fnode.locked .fnode-img {
  border-color: rgba(127, 212, 255, 0.9);
  border-width: 2px;
  box-shadow: 0 0 12px rgba(127, 212, 255, 0.35);
}
.fnode.anchor .fnode-img {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.16);
}

/* pooled labels (UI overlay layer) */
.flabel {
  position: absolute;
  left: 0;
  top: 0;
  font: italic 11px Georgia, 'Times New Roman', serif;
  color: rgba(232, 228, 218, 0.82);
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 6px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, 0);
  will-change: transform;
  display: none;
}
.flabel.active-label { color: #f2ead8; font-size: 12px; }

/* hover metadata card (two lines) */
.fmeta {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  background: rgba(5, 6, 10, 0.82);
  border-radius: 6px;
  padding: 4px 9px;
  text-align: center;
  white-space: nowrap;
  will-change: transform;
  display: none;
}
.fmeta .fmeta-title {
  display: block;
  font: italic 12px Georgia, 'Times New Roman', serif;
  color: #f2ead8;
}
.fmeta .fmeta-axes {
  display: block;
  font: 9px ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  color: rgba(216, 178, 106, 0.9);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------------- topbar ---------------- */

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  z-index: 20;
  pointer-events: none;
  background: linear-gradient(rgba(5, 6, 10, 0.85), rgba(5, 6, 10, 0));
}
#topbar > * { pointer-events: auto; }

.brand {
  font-family: var(--serif);
  font-style: italic;
  font-size: 21px;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-shadow: 0 0 24px rgba(216, 178, 106, 0.25);
}

.mode-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.7);
  backdrop-filter: blur(8px);
  overflow: hidden;
}
.mode-btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 7px 16px;
  color: var(--ink-dim);
  transition: color 0.25s, background 0.25s;
}
.mode-btn.active {
  color: #14100a;
  background: var(--accent);
}
.mode-btn:not(.active):hover { color: var(--ink); }

.topbar-actions { display: flex; gap: 8px; }

.ghost-btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.7);
  backdrop-filter: blur(8px);
  color: var(--ink-dim);
  transition: color 0.25s, border-color 0.25s;
}
.ghost-btn:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.25); }
.ghost-btn.engaged { color: var(--accent); border-color: var(--accent-soft); }
#filter-count { margin-left: 6px; color: var(--accent); }

/* ---------------- hud ---------------- */

#hud {
  position: fixed;
  left: 20px;
  bottom: 16px;
  z-index: 15;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  display: flex;
  gap: 8px;
  pointer-events: none;
}
#hud-mode { color: var(--ink-dim); }
.hud-sep { opacity: 0.5; }

#hud-rot { color: var(--accent); }

/* ---------------- axis filters ---------------- */

#filters {
  position: fixed;
  top: 64px;
  left: 20px;
  bottom: 52px;
  width: 288px;
  z-index: 18;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(14px);
  padding: 20px;
  overflow-y: auto;
  transform: translateX(-120%);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s;
  visibility: hidden;
}
#filters.open { transform: translateX(0); opacity: 1; visibility: visible; }

#filters h2 {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 8px;
}
.filters-hint {
  font-size: 12.5px;
  font-style: italic;
  color: var(--ink-faint);
  line-height: 1.5;
  margin-bottom: 18px;
}

.axis-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.axis-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 0.2s;
}
.axis-label:hover { color: var(--accent); }
.axis-marker {
  position: absolute;
  bottom: 2px;
  width: 7px;
  height: 7px;
  margin-left: -3.5px;
  background: var(--accent);
  transform: rotate(45deg);
  box-shadow: 0 0 8px rgba(216, 178, 106, 0.55);
  pointer-events: none;
}
.axis-label.positive { text-align: right; }
.axis-row input[type="range"] {
  grid-column: 1 / 4;
  grid-row: 2;
  width: 100%;
  appearance: none;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(216,178,106,0.25), rgba(255,255,255,0.18), rgba(216,178,106,0.25));
  outline: none;
  margin-top: 4px;
}
.axis-row input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  cursor: grab;
}
.axis-row input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  cursor: grab;
}

#clear-filters { margin-top: 8px; width: 100%; border-radius: 10px; }

/* ---------------- poem panel ---------------- */

#panel {
  position: fixed;
  top: 64px;
  right: 20px;
  bottom: 52px;
  width: min(400px, calc(100vw - 40px));
  z-index: 19;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(14px);
  padding: 28px 26px;
  overflow-y: auto;
  transform: translateX(115%);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s;
  visibility: hidden;
}
#panel.open { transform: translateX(0); opacity: 1; visibility: visible; }

.panel-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 13px;
  transition: color 0.2s, border-color 0.2s;
}
.panel-close:hover { color: var(--ink); border-color: var(--accent-soft); }

#panel-vizhash {
  width: 84px; height: 84px;
  border-radius: 50%;
  border: 1px solid var(--accent-soft);
  box-shadow: 0 0 34px rgba(216, 178, 106, 0.18);
  margin-bottom: 16px;
}

.panel-coll {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

#panel-title {
  font-size: 26px;
  font-weight: 400;
  font-style: italic;
  line-height: 1.2;
  margin-bottom: 16px;
}

#panel-body {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.8;
  white-space: pre-wrap;
  color: var(--ink);
  margin-bottom: 26px;
}

details#panel-neighbors-wrap {
  margin-bottom: 22px;
  border-top: 1px solid var(--line);
}
summary.panel-neighbors-h {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  padding: 16px 2px 12px;
  transition: color 0.2s;
}
summary.panel-neighbors-h::-webkit-details-marker { display: none; }
summary.panel-neighbors-h:hover { color: var(--accent); }
summary.panel-neighbors-h::after {
  content: '+';
  font-size: 13px;
  color: var(--accent);
  line-height: 1;
}
details#panel-neighbors-wrap[open] summary.panel-neighbors-h::after { content: '\2212'; }
details#panel-neighbors-wrap[open] summary.panel-neighbors-h { color: var(--ink); }
#panel-neighbors { margin-top: 4px; }

.panel-compare {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(127, 212, 255, 0.28);
  background: rgba(127, 212, 255, 0.06);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 22px;
}
.panel-compare.hidden { display: none; }
.panel-compare img { width: 26px; height: 26px; border-radius: 50%; }
.compare-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.compare-title { font-style: italic; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compare-meta { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.06em; color: var(--ink-faint); text-transform: uppercase; }
.compare-close { flex: none; width: 22px; height: 22px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink-dim); font-size: 10px; }
.compare-close:hover { color: var(--ink); border-color: rgba(127, 212, 255, 0.5); }

#panel-neighbors { list-style: none; }
.neighbor {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  grid-template-areas: "img title bar" "img coll bar";
  column-gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 8px 6px;
  border-radius: 10px;
  transition: background 0.2s;
}
.neighbor:hover { background: rgba(255, 255, 255, 0.05); }
.neighbor img {
  grid-area: img;
  width: 30px; height: 30px;
  border-radius: 50%;
}
.neighbor-title { grid-area: title; font-style: italic; font-size: 14px; }
.neighbor-coll { grid-area: coll; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em; color: var(--ink-faint); text-transform: uppercase; }
.neighbor-bar { grid-area: bar; width: 46px; height: 2px; background: rgba(255, 255, 255, 0.08); border-radius: 2px; overflow: hidden; }
.neighbor-bar i { display: block; height: 100%; background: var(--accent); opacity: 0.8; }

/* ---------------- entry overlay ---------------- */

#entry-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(5, 6, 10, 0.66);
  backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}
#entry-overlay.visible { opacity: 1; pointer-events: auto; }

.entry-inner {
  max-width: 640px;
  width: calc(100% - 48px);
  text-align: center;
  padding: 24px 0;
}

.entry-title {
  font-size: clamp(44px, 8vw, 68px);
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0.03em;
  text-shadow: 0 0 60px rgba(216, 178, 106, 0.4);
  margin-bottom: 14px;
}
.entry-sub {
  font-size: 15px;
  font-style: italic;
  color: var(--ink-dim);
  line-height: 1.7;
  margin-bottom: 34px;
}

.entry-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-bottom: 22px;
}
.entry-row h2 {
  width: 100%;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 2px;
}

.entry-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(12, 14, 20, 0.55);
  transition: border-color 0.25s, transform 0.25s, background 0.25s;
}
.entry-card:hover {
  border-color: var(--accent-soft);
  background: rgba(20, 22, 30, 0.6);
  transform: translateY(-2px);
}
.entry-poem img { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); }
.entry-poem-title { font-style: italic; font-size: 15px; }
.entry-poem-coll { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.entry-action span:nth-child(2) { font-style: italic; font-size: 16px; }
.entry-action-sub { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; color: var(--ink-faint); }
.entry-action-glyph { font-size: 30px; color: var(--accent); line-height: 1; }
#entry-random-thumb { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); }

.entry-foot {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
}

/* ---------------- boot ---------------- */

#boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--bg);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
}
.boot-error { color: #c9837a; }

/* ---------------- scrollbars ---------------- */

#panel::-webkit-scrollbar, #filters::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb, #filters::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* ---------------- small screens ---------------- */

@media (max-width: 720px) {
  .brand { display: none; }
  #topbar { justify-content: center; flex-wrap: wrap; }
  #filters {
    left: 12px; right: 12px;
    width: auto;
    top: auto;
    bottom: 12px;
    max-height: 46vh;
  }
  #panel {
    top: auto;
    left: 12px; right: 12px;
    bottom: 12px;
    width: auto;
    max-height: 62vh;
  }
  #hud { display: none; }
}
