/* Graph fullscreen layout */
body.graph-body {
  overflow: hidden;
  background: var(--bg);
}

.graph-shell {
  display: flex;
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Toolbar sidebar */
.graph-toolbar {
  width: 240px;
  min-width: 240px;
  height: calc(100vh - 48px);
  background: var(--bg-elevated);
  border-right: 2px solid var(--gold-dim);
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 4px 0 20px rgba(0,0,0,0.6);
  z-index: 100;
}

.graph-toolbar h2 {
  font-family: var(--font-title);
  font-size: 27px;
  color: var(--gold-bright);
  text-shadow: 0 0 8px var(--gold), 0 0 16px var(--glow-gold);
  border-bottom: 1px solid var(--gold-dim);
  padding-bottom: 8px;
  margin: 0;
  letter-spacing: 0.05em;
}

.graph-toolbar .meta {
  font-family: var(--font-accent);
  font-size: 18px;
  color: var(--ink-muted);
  font-style: italic;
}

.graph-toolbar input[type="text"],
.graph-toolbar input[type="search"] {
  font-size: 19px;
  padding: 6px 10px;
  background: rgba(0,0,0,0.5);
  border-color: var(--arcane);
}

.graph-toolbar select {
  font-family: var(--font-heading);
  font-size: 18px;
  letter-spacing: 0.05em;
  background: rgba(0,0,0,0.5);
  border-color: var(--arcane);
  color: var(--ink);
  padding: 6px 10px;
  width: 100%;
}

.graph-toolbar .btn {
  font-size: 12px;
  padding: 6px 10px;
  text-align: center;
}

/* Main canvas */
.graph-canvas {
  flex: 1;
  min-width: 0;
  height: calc(100vh - 48px);
  position: relative;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* CRT scanlines on graph */
.graph-canvas::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 3px,
    rgba(0,0,0,0.1) 3px,
    rgba(0,0,0,0.1) 4px
  );
  pointer-events: none;
  z-index: 1;
}

#graph {
  flex: 1;
  width: 100%;
  min-height: 0;
  background: radial-gradient(ellipse at center, #0f0820 0%, #07050d 70%);
}

/* Hover tooltip */
.node-tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--bg-elevated);
  border: 2px solid var(--gold);
  padding: 8px 10px;
  max-width: 240px;
  pointer-events: none;
  box-shadow: 0 0 16px var(--glow-gold), 0 4px 20px rgba(0,0,0,0.8);
  clip-path: polygon(
    0 6px, 6px 6px, 6px 0,
    calc(100% - 6px) 0, calc(100% - 6px) 6px, 100% 6px,
    100% calc(100% - 6px), calc(100% - 6px) calc(100% - 6px), calc(100% - 6px) 100%,
    6px 100%, 6px calc(100% - 6px), 0 calc(100% - 6px)
  );
}

.node-tooltip .tt-type {
  font-family: var(--font-psx);
  font-size: 10px;
  color: var(--arcane);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}

.node-tooltip .tt-img-full {
  display: block;
  max-width: 220px;
  max-height: 160px;
  width: auto;
  height: auto;
  border: 1px solid var(--gold-dim);
  object-fit: cover;
  cursor: zoom-in;
}

/* Entity side panel — fixed overlay, doesn't affect graph layout */
.entity-panel {
  position: fixed;
  top: 48px;
  right: 0;
  width: 380px;
  height: calc(100vh - 48px);
  background: var(--bg-elevated);
  border-left: 2px solid var(--gold-dim);
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0,0,0,0.6);
  z-index: 100;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.entity-panel[hidden] {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  display: block !important;
}

.entity-panel:not([hidden]) {
  transform: translateX(0);
  opacity: 1;
}

.entity-card {
  padding: 20px 18px;
  min-height: 100%;
  border: none;
  box-shadow: none;
}

.entity-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--gold-dim);
  padding-bottom: 12px;
}

.entity-card header h2 {
  font-family: var(--font-title);
  font-size: 33px;
  color: var(--gold-bright);
  text-shadow: 0 0 8px var(--gold), 0 0 16px var(--glow-gold);
  border: none;
  margin: 0;
  letter-spacing: 0.05em;
  flex: 1;
}

.entity-card .close-btn {
  font-family: var(--font-psx);
  font-size: 15px;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid var(--arcane);
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
  transition: all 0.15s;
}
.entity-card .close-btn:hover {
  color: var(--crimson);
  border-color: var(--crimson);
  box-shadow: 0 0 8px var(--glow-crimson);
}

/* Image grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.image-grid .img-wrap {
  position: relative;
  aspect-ratio: 4/3;
}
.image-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 2px solid var(--gold-dim);
  opacity: 0.85;
  transition: opacity 0.2s, border-color 0.2s;
}
.image-grid img:hover { opacity: 1; border-color: var(--gold); }
.image-grid .del-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--crimson);
  color: white;
  border: none;
  width: 18px;
  height: 18px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.image-grid .img-wrap:hover .del-btn { opacity: 1; }
.upload-btn {
  aspect-ratio: 4/3;
  border: 2px dashed var(--gold-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-psx);
  font-size: 24px;
  color: var(--gold-dim);
  cursor: pointer;
  transition: all 0.15s;
}
.upload-btn:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
  box-shadow: 0 0 8px var(--glow-gold);
}

/* Contenteditable fields */
.field { margin-bottom: 16px; }
.field label { margin-bottom: 4px; }
.contenteditable {
  min-height: 60px;
  font-family: var(--font-body);
  font-size: 24px;
  color: var(--ink);
  line-height: 1.6;
  padding: 8px 10px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--arcane);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  cursor: text;
}
.contenteditable:focus {
  border-color: var(--gold);
  box-shadow: 0 0 8px var(--glow-gold);
}

/* Tags */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.tag {
  font-family: var(--font-psx);
  font-size: 10px;
  color: var(--gold);
  background: rgba(193,154,59,0.1);
  border: 1px solid var(--gold-dim);
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.tag button {
  background: none;
  border: none;
  color: var(--crimson);
  cursor: pointer;
  font-size: 15px;
  padding: 0;
  line-height: 1;
}
.add-tag-input {
  font-family: var(--font-body);
  font-size: 19px;
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--gold-dim);
  color: var(--ink);
  width: 80px;
  outline: none;
  padding: 2px 4px;
}

/* Relations list */
.relations { margin-top: 20px; }
.relations h3 {
  font-family: var(--font-heading);
  font-size: 19px;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--gold-dim);
  padding-bottom: 6px;
  margin-bottom: 10px;
}
.rel-list { list-style: none; }
.rel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(193,154,59,0.15);
  font-family: var(--font-accent);
  font-size: 21px;
  color: var(--ink);
}
.rel-item .rel-dir { color: var(--gold); font-family: var(--font-psx); font-size: 12px; }
.rel-item .rel-name { color: var(--gold-bright); cursor: pointer; }
.rel-item .rel-name:hover { text-decoration: underline; }
.rel-item .rel-type { color: var(--arcane); font-size: 18px; font-style: italic; }
.rel-item .del-rel {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--crimson);
  cursor: pointer;
  font-size: 18px;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.rel-item .del-rel:hover { opacity: 1; }

.add-rel-btn {
  margin-top: 10px;
  font-size: 12px;
}

/* Relation modal */
.rel-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.rel-modal[hidden] { display: none; }
.rel-modal-content {
  background: var(--bg-elevated);
  border: 2px solid var(--gold);
  padding: 24px;
  width: 360px;
  box-shadow: 0 0 30px var(--glow-gold), 0 8px 40px rgba(0,0,0,0.9);
}
.rel-modal h3 {
  font-family: var(--font-title);
  font-size: 27px;
  color: var(--gold-bright);
  margin-bottom: 16px;
}
.rel-modal .field { margin-bottom: 12px; }
.rel-modal-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ── Mobile ── */
@media (max-width: 900px) {
  .graph-toolbar {
    position: fixed;
    top: 48px;
    left: 0;
    height: calc(100vh - 48px);
    width: 260px;
    min-width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 150;
  }
  .graph-toolbar.open {
    transform: translateX(0);
  }
  .graph-canvas {
    height: calc(100vh - 48px);
  }
  .entity-panel {
    width: 100%;
    max-width: 420px;
    height: calc(100vh - 48px);
  }
  .toolbar-toggle {
    display: flex !important;
  }
}

/* Toolbar toggle button (mobile only) */
.toolbar-toggle {
  display: none;
  position: fixed;
  top: 56px;
  left: 8px;
  z-index: 140;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 2px solid var(--gold-dim);
  color: var(--gold-bright);
  font-size: 20px;
  cursor: pointer;
}
