@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Egyptian+Hieroglyphs&display=swap');

@font-face {
  font-family: 'CMU Serif';
  src: url('https://cdn.jsdelivr.net/gh/dreampulse/computer-modern-web-font@master/fonts/cmunrm.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'CMU Serif';
  src: url('https://cdn.jsdelivr.net/gh/dreampulse/computer-modern-web-font@master/fonts/cmunti.woff') format('woff');
  font-weight: normal;
  font-style: italic;
}

@font-face {
  font-family: 'CMU Serif';
  src: url('https://cdn.jsdelivr.net/gh/dreampulse/computer-modern-web-font@master/fonts/cmunbx.woff') format('woff');
  font-weight: bold;
  font-style: normal;
}

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

:root {
  --bg: #f4f1ec;
  --fg: #1a1a1a;
  --dim: #999;
  --accent: #1a1a1a;
  --border: #d4d0c8;
  --card: #fffef9;
  --shadow: rgba(0, 0, 0, 0.12);
  --shadow-lift: rgba(0, 0, 0, 0.2);
}

html, body {
  height: 100%;
  overflow: clip;
  background: var(--bg);
  color: var(--fg);
  font-family: "CMU Serif", "Times New Roman", Georgia, serif;
  font-size: 16px;
}

/* --- Header --- */

#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 250;
  background: linear-gradient(to bottom, #f0ede6, #e4e0d8);
  border-bottom: 1px solid #c8c4ba;
  border-top: 1px solid #faf8f4;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.header-brand {
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 0.02em;
  color: var(--fg);
}

.header-nav {
  display: flex;
  gap: 20px;
}

.header-nav a,
.header-nav button {
  background: none;
  border: none;
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  transition: color 0.2s ease;
}

.header-nav a:hover,
.header-nav button:hover {
  color: var(--fg);
}

.nav-btn-skeu {
  height: 24px;
  border-radius: 3px;
  background: transparent !important;
  border: 1px solid transparent !important;
  font-size: 13px !important;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px !important;
  text-decoration: none !important;
}

.nav-btn-skeu:hover {
  background: rgba(0, 0, 0, 0.06) !important;
  border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
  border-left: 1px solid rgba(0, 0, 0, 0.05) !important;
  border-right: 1px solid rgba(255, 255, 255, 0.3) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.4) !important;
}

.nav-btn-skeu:active {
  background: rgba(0, 0, 0, 0.1) !important;
  border-top: 1px solid rgba(0, 0, 0, 0.12) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.5) !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* --- Modals --- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(4px);
  transition: opacity 0.25s ease;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-body {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 4px 6px 24px var(--shadow);
  padding: 32px;
  max-width: 420px;
  width: 90vw;
  line-height: 1.6;
  font-size: 15px;
}

.modal-body h2 {
  font-size: 18px;
  font-weight: normal;
  margin-bottom: 12px;
}

.modal-body p {
  margin-bottom: 12px;
  color: var(--fg);
}

.modal-body a {
  color: var(--fg);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--dim);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--fg);
}

#api-key-status {
  font-size: 13px;
  margin-bottom: 10px;
  padding: 6px 10px;
  border-radius: 3px;
}

#api-key-status.active {
  background: color-mix(in srgb, #4a8 15%, var(--card));
  color: #3a7a5a;
}

#api-key-status.inactive {
  background: color-mix(in srgb, var(--border) 20%, var(--card));
  color: var(--dim);
}

#api-key-input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  outline: none;
  margin-bottom: 12px;
}

.scape-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, var(--card));
}

.scape-item:last-child {
  border-bottom: none;
}

.scape-item-name {
  flex: 1;
  font-size: 15px;
  cursor: pointer;
  color: var(--fg);
}

.scape-item-name:hover {
  text-decoration: underline;
}

.scape-item-meta {
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
}

.scape-item-active {
  font-size: 11px;
  color: #3a7a5a;
  font-style: italic;
}

.scape-item-delete {
  background: none;
  border: none;
  font-size: 14px;
  color: var(--dim);
  cursor: pointer;
  padding: 0 4px;
}

.scape-item-delete:hover {
  color: #a44;
}

#scapes-list:empty::after {
  content: 'No saved scapes yet.';
  color: var(--dim);
  font-style: italic;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  font: inherit;
  font-size: 13px;
  padding: 6px 16px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  transition: border-color 0.2s ease;
}

.modal-actions button:hover {
  border-color: var(--fg);
}

.modal-actions button.secondary {
  color: var(--dim);
}

/* --- The field: where concepts live --- */

#canvas {
  position: absolute;
  transform-origin: 0 0;
  will-change: transform;
  overflow: visible;
}

#edges {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 0;
}

.edge {
  stroke: var(--border);
  stroke-width: 1;
  opacity: 0;
  animation: fade-in 0.6s ease forwards;
}

/* valence only controls dash pattern — color comes from generation */
.edge.concrete { stroke-dasharray: none; }
.edge.abstract { stroke-dasharray: 4 4; }
.edge.resonant { stroke-dasharray: 1 6; stroke-linecap: round; }

#field {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  z-index: 1;
}

/* --- Nodes as cards --- */

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: grab;
  opacity: 0;
  transition: opacity 0.8s ease, box-shadow 0.2s ease;
  user-select: none;

  background: var(--node-bg, var(--card));
  border: 0.5px solid var(--node-accent, var(--border));
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 150px;
  color: var(--node-fg, var(--fg));

  box-shadow: 2px 3px 10px color-mix(in srgb, var(--node-accent, #000) 30%, transparent);
}

.node:hover {
  box-shadow: 3px 5px 16px color-mix(in srgb, var(--node-accent, #000) 45%, transparent);
  z-index: 10;
}

.node.dragging {
  cursor: grabbing;
  box-shadow: 6px 10px 28px color-mix(in srgb, var(--node-accent, #000) 50%, transparent);
  z-index: 100;
  transition: box-shadow 0.1s ease;
}

.node img {
  width: 100%;
  height: auto;
  display: block;
}

.node .label {
  text-align: center;
  white-space: normal;
  line-height: 1.35;
  font-size: 13px;
  color: var(--node-fg, var(--fg));
}

.node.visible {
  opacity: 1;
}

.node.expanded {
  opacity: 0.65;
}

.node.dimmed {
  opacity: 0.08 !important;
  transition: opacity 0.3s ease;
}

.edge.dimmed {
  opacity: 0.04 !important;
  transition: opacity 0.3s ease;
}

.node[data-valence="concrete"] .label { font-style: normal; }
.node[data-valence="abstract"] .label { font-style: italic; }
.node[data-valence="resonant"] .label { font-style: italic; opacity: 0.75; }

.expand-btn {
  background: linear-gradient(to bottom, #f8f6f2, #e8e4dc);
  border-top: 1px solid #faf8f4;
  border-left: 1px solid #eae7e0;
  border-right: 1px solid #ccc8be;
  border-bottom: 1px solid #b8b4aa;
  border-radius: 4px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.03em;
  cursor: pointer;
  color: var(--node-fg, var(--fg));
  padding: 3px 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  transition: all 0.15s ease;
}

.expand-btn:hover {
  background: linear-gradient(to bottom, #faf8f4, #eeebe4);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.expand-btn:active {
  background: linear-gradient(to bottom, #e2ded6, #eeebe4);
  border-top: 1px solid #b8b4aa;
  border-bottom: 1px solid #faf8f4;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* --- Loading skeleton --- */

.caustic-canvas {
  width: 128px;
  height: 96px;
  display: block;
}

.node.loading .img-slot {
  width: 128px;
  height: 96px;
  background: linear-gradient(
    110deg,
    var(--node-bg, var(--card)) 30%,
    color-mix(in srgb, var(--node-accent, var(--border)) 14%, var(--node-bg, var(--card))) 50%,
    var(--node-bg, var(--card)) 70%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.node.loading .label-slot {
  width: 80px;
  height: 14px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--node-accent, var(--border)) 8%, var(--node-bg, var(--card)));
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

@keyframes fade-in {
  to { opacity: 1; }
}

/* --- Input: bottom center, quiet --- */

#input-region {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 80vw);
  z-index: 200;
}

#prompt {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 2px 3px 8px var(--shadow);
  color: var(--fg);
  font: inherit;
  font-size: 17px;
  padding: 10px 14px;
  outline: none;
  text-align: center;
  caret-color: var(--fg);
}

#prompt::placeholder {
  color: var(--dim);
  font-style: italic;
}

/* --- Sidebar --- */

#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: min(38.2vw, 85vw);
  height: 100%;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px var(--shadow);
  z-index: 300;
  padding: 24px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.6;
  transform: translateX(0);
  transition: transform 0.35s ease;
}

#sidebar.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

#sidebar-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--dim);
  cursor: pointer;
  line-height: 1;
}

#sidebar-close:hover {
  color: var(--fg);
}

#sidebar-title {
  font-size: 22px;
  font-weight: normal;
  margin-bottom: 16px;
  padding-right: 24px;
}

.sidebar-caustic {
  width: 100%;
  height: 200px;
  display: block;
  margin-bottom: 16px;
}

#sidebar-img {
  width: 100%;
  height: auto;
  display: block;
  margin-bottom: 16px;
}

#sidebar-curatorial {
  font-style: italic;
  color: var(--fg);
  margin-bottom: 12px;
  min-height: 1.6em;
}

#sidebar-attribution {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 8px;
}

#sidebar hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

#sidebar-entry {
  color: var(--fg);
  min-height: 3em;
}

#sidebar-entry p {
  margin-bottom: 0.8em;
}

.detail-btn {
  display: block;
  margin-top: 16px;
  background: none;
  border: 1px solid var(--border);
  color: var(--dim);
  font: inherit;
  font-size: 13px;
  font-style: italic;
  padding: 6px 14px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.detail-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}

.detail-btn:disabled {
  cursor: default;
  opacity: 0.5;
}

.sidebar-loading {
  background: linear-gradient(
    110deg,
    var(--card) 30%,
    color-mix(in srgb, var(--border) 20%, var(--card)) 50%,
    var(--card) 70%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
  border-radius: 2px;
}

/* --- Hamburger (hidden on desktop) --- */

#hamburger {
  display: none;
  font-size: 18px !important;
  width: 32px;
  height: 28px;
  color: var(--fg) !important;
}

/* --- Mobile --- */

@media (max-width: 768px) {
  #hamburger {
    display: inline-flex;
  }

  .header-nav {
    display: none !important;
    position: absolute;
    top: 40px;
    right: 0;
    background: linear-gradient(to bottom, #f0ede6, #e4e0d8);
    border: 1px solid #c8c4ba;
    border-top: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    flex-direction: column;
    padding: 8px 0;
    min-width: 160px;
  }

  .header-nav.open {
    display: flex !important;
  }

  .header-nav .nav-btn-skeu {
    width: 100%;
    justify-content: flex-start;
    border-radius: 0 !important;
    height: 36px;
    padding: 0 16px !important;
    border: none !important;
  }

  .header-nav .nav-btn-skeu:hover {
    background: rgba(0, 0, 0, 0.06) !important;
    border: none !important;
  }

  #sidebar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 70vh;
    border-left: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px var(--shadow);
    border-radius: 12px 12px 0 0;
    transform: translateY(0);
    transition: transform 0.35s ease;
    padding-top: 20px;
  }

  #sidebar.hidden {
    transform: translateY(100%);
  }

  .sidebar-handle {
    display: block;
  }

  #sidebar-close {
    display: none;
  }

  #input-region {
    bottom: 20px;
  }
}

/* --- Tour --- */

#tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.55);
  transition: opacity 0.4s ease;
}

#tour-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#tour-spotlight {
  position: absolute;
  border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  background: transparent;
  transition: all 0.4s ease;
  pointer-events: none;
}

#tour-tooltip {
  position: absolute;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 4px 6px 20px rgba(0, 0, 0, 0.2);
  padding: 20px 24px;
  max-width: 340px;
  font-size: 15px;
  line-height: 1.6;
  transition: all 0.4s ease;
}

#tour-text {
  margin-bottom: 16px;
  color: var(--fg);
}

#tour-actions {
  display: flex;
  justify-content: space-between;
}

#tour-skip {
  background: none;
  border: none;
  font: inherit;
  font-size: 13px;
  color: var(--dim);
  cursor: pointer;
}

#tour-skip:hover {
  color: var(--fg);
}

#tour-next {
  background: linear-gradient(to bottom, #f8f6f2, #e8e4dc);
  border-top: 1px solid #faf8f4;
  border-left: 1px solid #eae7e0;
  border-right: 1px solid #ccc8be;
  border-bottom: 1px solid #b8b4aa;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  padding: 5px 16px;
  cursor: pointer;
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

#tour-next:hover {
  background: linear-gradient(to bottom, #faf8f4, #eeebe4);
}

#tour-next:active {
  background: linear-gradient(to bottom, #e2ded6, #eeebe4);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.sidebar-handle {
  display: none;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 12px;
}
