:root {
  --bg: #0b0f1a;
  --card-bg: rgba(18, 24, 38, 0.5);
  --card-border: rgba(96, 165, 250, 0.25);
  --card-border-hover: rgba(96, 165, 250, 0.7);
  --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --accent: #60a5fa;
  --accent-dim: #1e3a5f;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --link: #7dd3fc;
  --hud-bg: rgba(11, 15, 26, 0.7);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app, #scene-container { position: relative; width: 100%; height: 100%; }

#scene-container > * { position: absolute; inset: 0; }

#scene-container canvas { z-index: 1; }

#scene-container .css3d-container { z-index: 2; }

#scene-container .css3d-container:empty { display: none; }

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  top: 12px;
  left: 52px;
  right: 12px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  font-size: 13px;
  transition: left 0.25s ease;
}

.tree-panel:not(.collapsed) ~ #hud { left: 272px; }

#hud-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
}

#status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--hud-bg);
  border: 1px solid rgba(148, 163, 184, 0.2);
  backdrop-filter: blur(4px);
  color: var(--text-dim);
}

#status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
}

#status.connected .dot { background: #34d399; }
#status.disconnected .dot { background: #f87171; }
#status.connected #status-text { color: var(--text); }

#hint {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 6px 10px 6px 12px;
  border-radius: 999px;
  background: var(--hud-bg);
  border: 1px solid rgba(148, 163, 184, 0.2);
  backdrop-filter: blur(4px);
  color: var(--text-dim);
  pointer-events: auto;
}

#hint.hidden { display: none; }

#hint kbd {
  font-family: inherit;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 4px;
  padding: 0 4px;
}

.hint-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 15px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.2s ease;
}

.hint-close:hover { color: var(--text); }

.hud-button {
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(96, 165, 250, 0.5);
  background: rgba(96, 165, 250, 0.12);
  color: var(--link);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.2s ease;
}

.hud-button:hover { background: rgba(96, 165, 250, 0.25); }

/* ---------- Start overlay ---------- */

#start-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(11, 15, 26, 0.55), var(--bg));
}

#start-overlay.hidden { display: none; }

.start-panel {
  max-width: 440px;
  padding: 40px 48px;
  border-radius: 16px;
  background: var(--card-bg);
  border: 1px solid rgba(96, 165, 250, 0.2);
  box-shadow: var(--card-shadow);
  text-align: center;
}

.start-panel h1 {
  margin: 0 0 8px;
  font-size: 32px;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.start-panel .subtitle {
  margin: 0 0 28px;
  color: var(--text-dim);
  font-size: 14px;
}

.start-panel .primary {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  color: #08111f;
  background: linear-gradient(135deg, #7dd3fc, #60a5fa);
  cursor: pointer;
  transition: filter 0.2s ease, transform 0.1s ease;
}

.start-panel .primary:hover { filter: brightness(1.08); }
.start-panel .primary:active { transform: scale(0.98); }

.start-panel .hint-text {
  margin: 22px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
}

.start-panel .hint-text code {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.95em;
}

/* ---------- File tree panel ---------- */

.tree-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  background: rgba(11, 15, 26, 0.92);
  border-right: 1px solid rgba(96, 165, 250, 0.2);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  transition: width 0.25s ease;
  width: 260px;
}

.tree-panel.collapsed { width: 40px; }

.tree-toggle {
  flex: 0 0 auto;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  width: 40px;
  height: 40px;
  font-size: 17px;
  cursor: pointer;
  transition: color 0.2s ease;
}

.tree-toggle:hover { color: var(--accent); }

.tree-panel.collapsed .tree-toggle { width: 40px; }

.tree-content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0 16px;
  font-size: 13px;
  line-height: 1.5;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
}

.tree-panel.collapsed .tree-content { display: none; }

.tree, .tree-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-folder-label {
  display: block;
  padding: 3px 10px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.tree-folder-label::before {
  content: "▸ ";
  font-size: 10px;
  color: rgba(148, 163, 184, 0.5);
}

.tree-folder.expanded > .tree-folder-label::before { content: "▾ "; }

.tree-folder-label:hover { color: var(--text); background: rgba(96, 165, 250, 0.08); }

.tree-children.collapsed { display: none; }

.tree-children .tree-folder-label { padding-left: 26px; }
.tree-children .tree-children .tree-folder-label { padding-left: 42px; }
.tree-children .tree-children .tree-children .tree-folder-label { padding-left: 58px; }

.tree-file {
  padding: 3px 10px 3px 26px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12.5px;
  transition: color 0.15s ease, background 0.15s ease;
}

.tree-file:hover { color: var(--text); background: rgba(96, 165, 250, 0.08); }

.tree-file.active {
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
  font-weight: 600;
}

.tree-file.linked {
  color: #ff44cc;
}

.tree-children .tree-file { padding-left: 42px; }
.tree-children .tree-children .tree-file { padding-left: 58px; }
.tree-children .tree-children .tree-children .tree-file { padding-left: 74px; }

/* ---------- Reader panel ---------- */

.reader {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 92vw);
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: rgba(11, 15, 26, 0.92);
  border-left: 1px solid rgba(96, 165, 250, 0.25);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.reader.hidden { display: none; }

.reader.expanded { width: 50vw; }

.reader-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  background: linear-gradient(180deg, rgba(96, 165, 250, 0.1), transparent);
}

.reader-heading {
  flex: 1 1 auto;
  min-width: 0;
}

.reader-heading #reader-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.3;
}

.reader-heading #reader-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.reader-btn {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(148, 163, 184, 0.1);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.reader-btn:hover { background: rgba(96, 165, 250, 0.25); border-color: var(--accent); }

#reader-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 20px 32px;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text);
}

#reader-body > :first-child { margin-top: 0; }

#reader-body h1, #reader-body h2, #reader-body h3,
#reader-body h4, #reader-body h5, #reader-body h6 {
  margin: 1.1em 0 0.4em;
  color: var(--text);
}

#reader-body h1 { font-size: 1.5em; }
#reader-body h2 { font-size: 1.25em; }
#reader-body h3 { font-size: 1.1em; }

#reader-body p { margin: 0.55em 0; }
#reader-body ul, #reader-body ol { margin: 0.55em 0; padding-left: 1.4em; }
#reader-body pre {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-size: 0.92em;
}
#reader-body code {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
#reader-body pre code { background: transparent; padding: 0; }

#reader-body a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px dotted rgba(125, 211, 252, 0.5);
  cursor: pointer;
}
#reader-body a:hover { border-bottom-style: solid; }

#reader-body blockquote {
  margin: 0.55em 0;
  padding-left: 0.9em;
  border-left: 3px solid var(--accent-dim);
  color: var(--text-dim);
}

#reader-body img { max-width: 100%; border-radius: 8px; }
#reader-body table { border-collapse: collapse; margin: 0.6em 0; }
#reader-body th, #reader-body td {
  border: 1px solid rgba(148, 163, 184, 0.25);
  padding: 5px 10px;
}

#reader-body hr { border: none; border-top: 1px solid rgba(148, 163, 184, 0.2); margin: 1.2em 0; }

#reader-body input[type="checkbox"] { margin-right: 6px; }

/* ---------- Tooltip ---------- */

.loading-dialog {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 26, 0.45);
  backdrop-filter: blur(2px);
}

.loading-dialog.hidden { display: none; }

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 36px;
  border-radius: 14px;
  background: rgba(11, 15, 26, 0.94);
  border: 1px solid rgba(96, 165, 250, 0.25);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
  min-width: 300px;
}

#loading-text {
  font-size: 13.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.loading-bar {
  width: 280px;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  overflow: hidden;
}

.loading-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #60a5fa, #34d399);
  transition: width 0.15s ease;
}

.loading-warn {
  font-size: 12px;
  color: #f59e0b;
  max-width: 280px;
  line-height: 1.5;
}

.loading-warn.hidden { display: none; }

#loading-close.hidden { display: none; }

#loading-close {
  align-self: flex-end;
}

.tooltip {
  position: fixed;
  z-index: 20;
  max-width: 320px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(11, 15, 26, 0.95);
  border: 1px solid rgba(96, 165, 250, 0.3);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
}

.tooltip.hidden { display: none; }

.tooltip .t-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
}

.tooltip .t-path {
  color: var(--text-dim);
  word-break: break-all;
}

.tooltip .t-meta {
  color: rgba(148, 163, 184, 0.75);
  font-size: 11px;
}

.tooltip .t-files {
  margin-top: 5px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  max-height: 140px;
  overflow: hidden;
}

/* ---------- Cards ---------- */

.card {
  position: absolute;
  top: 0;
  left: 0;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  cursor: pointer;
  transition: opacity 0.5s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  user-select: none;
}

.card:hover {
  border-color: var(--card-border-hover);
  box-shadow: 0 0 0 1px var(--card-border-hover), 0 8px 32px rgba(0, 0, 0, 0.6);
}

.card.selected {
  border-color: #34d399;
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.55), 0 0 32px rgba(52, 211, 153, 0.35),
    0 12px 48px rgba(0, 0, 0, 0.7);
}

.card.linked {
  border-color: rgba(52, 211, 153, 0.45);
}

.card.preview {
  border-color: var(--link);
  box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.4), 0 0 24px rgba(125, 211, 252, 0.3);
}

.card.hover-linked {
  border-color: rgba(255, 68, 204, 0.55);
}

.card-filename {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  white-space: normal;
  word-break: break-word;
  max-width: 100%;
  line-height: 1.3;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85), 0 0 2px rgba(0, 0, 0, 0.9);
  letter-spacing: 0.2px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
