/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== NAV CENTER ===== */
.knav-center { flex: 1; text-align: center; }
.knav-feature {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: -0.01em;
}

/* ===== PHASES ===== */
.phase { display: none; flex: 1; }
.phase.active { display: flex; flex-direction: column; }

/* ===== INPUT PHASE ===== */
.input-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 20px 64px;
  gap: 32px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

.input-hero { text-align: center; }
.input-hero-glyph {
  font-size: 36px;
  color: var(--primary);
  filter: drop-shadow(0 0 16px var(--primary));
  margin-bottom: 12px;
}
.input-hero-title {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.04em;
  margin-bottom: 8px;
}
.input-hero-desc {
  font-size: 15px;
  color: var(--text-dim);
}

.input-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Source tabs */
.input-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  width: fit-content;
}
.input-tab {
  cursor: pointer;
  padding: 7px 16px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  transition: var(--t);
}
.input-tab:hover { color: var(--text); background: var(--surface3); }
.input-tab.active { background: var(--surface3); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.4); }

/* Tab content */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* URL row */
.url-row {
  display: flex;
  gap: 8px;
}
.url-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  transition: var(--t);
}
.url-input::placeholder { color: var(--muted); }
.url-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-dim); }
.url-fetch-btn {
  cursor: pointer;
  padding: 10px 16px;
  background: var(--surface3);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: var(--t);
}
.url-fetch-btn:hover { border-color: var(--primary-border); color: var(--primary); }

/* PDF drop zone */
.pdf-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  cursor: pointer;
  text-align: center;
  transition: var(--t);
  background: var(--surface2);
}
.pdf-zone:hover, .pdf-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-dim);
}
.pdf-zone-inner { pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pdf-zone-icon { font-size: 32px; }
.pdf-zone-text { font-size: 14px; font-weight: 600; color: var(--text-dim); }
.pdf-zone-hint { font-size: 11px; color: var(--muted); }

/* Paste textarea */
.paste-textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 12px 14px;
  resize: vertical;
  outline: none;
  transition: var(--t);
  line-height: 1.6;
  min-height: 160px;
}
.paste-textarea::placeholder { color: var(--muted); }
.paste-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-dim); }
.paste-hint { font-size: 11px; color: var(--muted); text-align: right; margin-top: 4px; }

/* Fetch / PDF status */
.fetch-status {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}
.fetch-status.hidden { display: none; }

/* Options grid */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.option-group { display: flex; flex-direction: column; gap: 10px; }
.option-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.radio-group { display: flex; flex-direction: column; gap: 6px; }
.radio-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  user-select: none;
  transition: color var(--t);
}
.radio-item:hover { color: var(--text); }
.radio-item input[type="radio"] { display: none; }
.radio-mark {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-glow);
  flex-shrink: 0;
  transition: var(--t);
  position: relative;
}
.radio-item input:checked + .radio-mark {
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}
.radio-item input:checked ~ span:not(.radio-mark) { color: var(--text); }

/* Topic hint */
.topic-hint-row { display: flex; flex-direction: column; gap: 6px; }
.topic-hint-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.topic-hint-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition: var(--t);
}
.topic-hint-input::placeholder { color: var(--muted); }
.topic-hint-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-dim); }

/* Build button */
.build-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 15px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--t);
  box-shadow: 0 0 40px rgba(108,99,255,0.3);
  letter-spacing: -0.01em;
}
.build-btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 0 60px rgba(108,99,255,0.45);
  transform: translateY(-1px);
}
.build-btn:active { transform: none; }
.build-btn-glyph { font-size: 18px; filter: brightness(1.5); }

.key-hint { text-align: center; font-size: 11px; color: var(--muted); }
.key-hint kbd {
  font-family: var(--font-mono);
  background: var(--surface2);
  border: 1px solid var(--border-glow);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
}

/* ===== PROCESSING PHASE ===== */
.processing-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 40px 24px;
}
.processing-glyph {
  font-size: 48px;
  color: var(--primary);
  filter: drop-shadow(0 0 20px var(--primary));
  animation: pulse-glyph 2s ease-in-out infinite;
}
@keyframes pulse-glyph {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 20px var(--primary)); }
  50% { opacity: 0.6; filter: drop-shadow(0 0 40px var(--primary)); }
}
.processing-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }

.processing-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 280px;
}
.process-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: var(--t);
}
.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-glow);
  flex-shrink: 0;
  transition: var(--t);
}
.step-label { font-size: 13px; color: var(--muted); }

.process-step.active {
  border-color: var(--primary-border);
  background: var(--primary-dim);
}
.process-step.active .step-dot {
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: pulse-dot 1s ease-in-out infinite;
}
.process-step.active .step-label { color: var(--text); }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 4px var(--primary); }
  50% { box-shadow: 0 0 14px var(--primary); }
}

.process-step.done .step-dot { background: var(--green); }
.process-step.done .step-label { color: var(--green); }
.process-step.done::after { content: '✓'; color: var(--green); font-size: 12px; margin-left: auto; }

.processing-hint { font-size: 11px; color: var(--muted); }

/* ===== GRAPH PHASE ===== */
#phaseGraph { display: none; flex-direction: column; }
#phaseGraph.active { display: flex; }

/* Graph top bar */
.graph-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  min-height: 52px;
}
.graph-back-btn {
  cursor: pointer;
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  transition: var(--t);
  white-space: nowrap;
  flex-shrink: 0;
}
.graph-back-btn:hover { border-color: var(--border-glow); color: var(--text); }

.graph-meta-wrap { flex: 1; min-width: 0; }
.graph-title { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.graph-desc { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.progress-wrap { display: flex; flex-direction: column; gap: 4px; min-width: 140px; flex-shrink: 0; }
.progress-track {
  height: 4px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--cyan));
  border-radius: 999px;
  width: 0%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-label { font-size: 10px; color: var(--muted); }

.graph-topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.graph-meta-tag {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 4px;
}
.graph-action-btn {
  cursor: pointer;
  padding: 5px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  transition: var(--t);
  white-space: nowrap;
}
.graph-action-btn:hover { border-color: var(--border-glow); color: var(--text); }

/* 3-column layout */
.graph-columns {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 300px;
  overflow: hidden;
  height: calc(100vh - var(--nav-height) - 52px);
}

/* Left column */
.col-left {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.col-left-head, .col-right-head {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, #0a1426, var(--surface));
}
.col-head-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.outline-count { font-size: 10px; color: var(--muted); }

.outline-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.outline-list::-webkit-scrollbar { width: 4px; }
.outline-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.outline-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: var(--t);
  border-left: 2px solid transparent;
}
.outline-item:hover { background: rgba(255,255,255,0.04); }
.outline-item.active { background: rgba(108,99,255,0.08); border-left-color: var(--primary); }
.outline-item.state-understood { opacity: 0.7; }
.outline-item.state-skipped { opacity: 0.35; }

.outline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.outline-label {
  font-size: 11px;
  color: var(--text-dim);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.outline-item.active .outline-label { color: var(--text); }
.outline-item.state-understood .outline-label::after { content: ' ✓'; color: var(--green); }
.outline-item.state-skipped .outline-label::after { content: ' ✗'; color: var(--muted); }
.outline-type { font-size: 9px; color: var(--muted); font-family: var(--font-mono); flex-shrink: 0; }

/* Legend */
.legend-section {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}
.legend-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.legend-list { display: flex; flex-direction: column; gap: 4px; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  color: var(--text-dim);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Center: canvas */
.col-center {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cy-canvas { flex: 1; }
.canvas-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
  background: rgba(6,9,15,0.7);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* Right: inspector */
.col-right {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.inspector {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.inspector::-webkit-scrollbar { width: 4px; }
.inspector::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.insp-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 20px;
  text-align: center;
}
.insp-empty-glyph { font-size: 36px; color: var(--border); }
.insp-empty-text { font-size: 14px; font-weight: 600; color: var(--text-dim); }
.insp-empty-hint { font-size: 11px; color: var(--muted); line-height: 1.5; max-width: 200px; }

/* Inspector: node selected */
.insp-head {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.insp-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}
.insp-type-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.insp-state-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(255,255,255,0.04);
}
.insp-state-badge.state-understood { border-color: rgba(52,211,153,0.4); color: var(--green); }
.insp-state-badge.state-skipped { border-color: rgba(248,113,113,0.3); color: var(--red); }
.insp-state-badge.state-reading { border-color: rgba(108,99,255,0.4); color: var(--primary); }
.insp-diff-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  font-family: var(--font-mono);
}
.insp-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}
.insp-text {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.65;
  white-space: pre-wrap;
}

/* Adapt section */
.insp-adapt {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.insp-adapt-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.adapt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.adapt-btn {
  cursor: pointer;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  transition: var(--t);
  text-align: left;
}
.adapt-btn:hover { border-color: var(--primary-border); color: var(--primary); background: var(--primary-dim); }
.adapt-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.adapt-got:hover { border-color: rgba(52,211,153,0.5); color: var(--green); background: rgba(52,211,153,0.06); }
.adapt-skip { grid-column: span 2; border-color: rgba(248,113,113,0.2); color: var(--muted); }
.adapt-skip:hover { border-color: rgba(248,113,113,0.5); color: var(--red); background: rgba(248,113,113,0.06); }

.adapt-status {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  line-height: 1.5;
  animation: pulse-text 1.5s ease-in-out infinite;
}
.adapt-status.hidden { display: none; }
@keyframes pulse-text { 0%,100%{opacity:1} 50%{opacity:0.5} }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .graph-columns {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
  }
  .col-left, .col-right {
    max-height: 40vh;
    overflow-y: auto;
  }
  .col-center { min-height: 60vw; }
  .options-grid { grid-template-columns: 1fr; }
  .input-card { padding: 18px; }
  .adapt-grid { grid-template-columns: 1fr; }
  .adapt-skip { grid-column: span 1; }
  .graph-topbar { flex-wrap: wrap; }
}
