:root {
  --bg: #f5f0eb;
  --bg-2: #efe6da;
  --paper: rgba(255, 250, 244, 0.88);
  --paper-solid: #fffaf4;
  --ink: #171827;
  --muted: #6c6878;
  --accent: #c97b4b;
  --accent-soft: #ead1c0;
  --indigo: #2d3561;
  --navy: #1a2144;
  --line: rgba(45, 53, 97, 0.18);
  --line-strong: rgba(45, 53, 97, 0.34);
  --shadow: 0 22px 70px rgba(45, 53, 97, 0.16);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 8%, rgba(201, 123, 75, 0.22), transparent 34rem),
    radial-gradient(circle at 70% 88%, rgba(45, 53, 97, 0.10), transparent 38rem),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--ink);
  font-family: var(--serif);
}

button { font: inherit; }

.spatial-app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#scene:active { cursor: grabbing; }

.site-header {
  position: absolute;
  z-index: 10;
  top: 24px;
  left: 28px;
  display: flex;
  align-items: flex-start;
  gap: 18px;
  max-width: min(590px, calc(100vw - 390px));
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 250, 244, 0.66);
  box-shadow: 0 14px 44px rgba(45, 53, 97, 0.10);
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.site-header h1,
.tree-panel h2,
.content-panel h2 {
  margin: 0;
  color: var(--indigo);
  line-height: 1.05;
  letter-spacing: -0.025em;
}

.site-header h1 { font-size: clamp(1.55rem, 3vw, 2.35rem); }

.site-header p:last-child {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.86rem;
}

.back-button,
.icon-button {
  border: 1px solid var(--line-strong);
  background: rgba(255, 250, 244, 0.82);
  color: var(--indigo);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.back-button {
  flex: 0 0 auto;
  padding: 0.6rem 0.85rem;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.82rem;
}

.back-button:not(:disabled):hover,
.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: var(--paper-solid);
}

.back-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hint-card {
  position: absolute;
  z-index: 9;
  left: 28px;
  bottom: 28px;
  width: min(420px, calc(100vw - 390px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 244, 0.60);
  box-shadow: 0 12px 36px rgba(45, 53, 97, 0.10);
  backdrop-filter: blur(16px);
}

.hint-card strong {
  display: block;
  color: var(--indigo);
  font-size: 1rem;
}

.hint-card span {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.tree-panel {
  position: absolute;
  z-index: 12;
  top: 22px;
  right: 22px;
  bottom: 22px;
  width: min(350px, 34vw);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 250, 244, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tree-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.tree-panel h2 { font-size: 1.25rem; }

.node-count {
  flex: 0 0 auto;
  margin-top: 0.2rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.node-tree {
  flex: 1;
  overflow: auto;
  padding: 10px 10px 18px;
  font-family: var(--mono);
}

.tree-children {
  margin-left: 13px;
  padding-left: 12px;
  border-left: 1px solid rgba(45, 53, 97, 0.14);
}

.tree-node {
  width: 100%;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 3px 0;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(245, 240, 235, 0.50);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font-size: 0.76rem;
}

.tree-node:hover {
  border-color: rgba(201, 123, 75, 0.45);
  background: rgba(255, 250, 244, 0.92);
}

.tree-node.is-active,
.tree-node.is-current {
  border-color: rgba(201, 123, 75, 0.68);
  background: rgba(236, 209, 189, 0.56);
  color: var(--indigo);
  font-weight: 700;
}

.tree-node.is-visible:not(.is-active):not(.is-current) {
  border-color: rgba(45, 53, 97, 0.20);
  background: rgba(255, 250, 244, 0.76);
}

.tree-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-meta {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 400;
}

.cube-icon {
  position: relative;
  width: 13px;
  height: 13px;
  transform: rotateX(58deg) rotateZ(45deg);
  transform-style: preserve-3d;
  background: var(--indigo);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}

.cube-icon::before {
  content: "";
  position: absolute;
  inset: -5px 0 5px 0;
  background: var(--accent);
  transform: translateY(-4px) skewX(-45deg) scaleY(0.55);
  transform-origin: bottom;
}

.cube-icon.file {
  width: 10px;
  height: 10px;
  opacity: 0.86;
}

.connection-lines {
  position: absolute;
  z-index: 5;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.connection-lines line {
  stroke: rgba(93, 93, 108, 0.42);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.connection-lines circle {
  fill: rgba(201, 123, 75, 0.72);
}

.content-panel {
  position: absolute;
  z-index: 30;
  top: 50%;
  left: calc(50% - 90px);
  transform: translate(-50%, -50%);
  width: min(820px, calc(100vw - 430px));
  max-height: min(82vh, 900px);
  border: 1px solid rgba(45, 53, 97, 0.22);
  border-radius: 22px;
  background: rgba(255, 250, 244, 0.93);
  box-shadow: 0 30px 100px rgba(26, 33, 68, 0.26);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.content-panel[hidden] { display: none; }

.content-panel__bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.78);
}

.content-panel h2 { font-size: clamp(1.25rem, 2vw, 1.75rem); }

.content-path {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.icon-button {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
}

.markdown-body {
  max-height: calc(82vh - 112px);
  overflow: auto;
  padding: 18px 28px 32px;
  line-height: 1.58;
  font-size: 1rem;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: var(--indigo);
  line-height: 1.18;
}

.markdown-body h1 { font-size: 2rem; }
.markdown-body h2 { margin-top: 2rem; font-size: 1.45rem; }
.markdown-body h3 { margin-top: 1.45rem; font-size: 1.16rem; }
.markdown-body p { margin: 0.85rem 0; }
.markdown-body a { color: var(--accent); text-underline-offset: 0.16em; }

.markdown-body blockquote {
  margin: 1rem 0;
  padding: 0.15rem 1rem;
  border-left: 4px solid var(--accent);
  background: rgba(236, 209, 189, 0.35);
  color: #302d44;
}

.markdown-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: rgba(45, 53, 97, 0.08);
  border-radius: 0.28rem;
  padding: 0.1rem 0.25rem;
}

.markdown-body pre {
  overflow: auto;
  padding: 1rem;
  border-radius: 0.8rem;
  background: #1a1a2e;
  color: #fffaf4;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.92rem;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
  vertical-align: top;
}

.markdown-body th { background: rgba(236, 209, 189, 0.35); }

.loading {
  position: absolute;
  z-index: 40;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.86);
  box-shadow: var(--shadow);
  color: var(--indigo);
  font-family: var(--mono);
}

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

@media (max-width: 940px) {
  .site-header,
  .hint-card {
    max-width: calc(100vw - 32px);
    left: 16px;
  }

  .site-header { top: 14px; }
  .hint-card { bottom: 14px; width: calc(100vw - 32px); }

  .tree-panel {
    top: auto;
    left: 16px;
    right: 16px;
    bottom: 82px;
    width: auto;
    height: 35vh;
  }

  .content-panel {
    left: 50%;
    width: calc(100vw - 32px);
    max-height: 78vh;
  }
}
