:root {
  color-scheme: dark;
  --bg: #080a0f;
  --sidebar: rgba(7, 10, 16, 0.84);
  --panel: rgba(11, 15, 24, 0.78);
  --panel-strong: rgba(13, 19, 31, 0.9);
  --line: rgba(218, 226, 240, 0.16);
  --line-strong: rgba(218, 226, 240, 0.28);
  --text: #eef2f8;
  --muted: #a9b3c4;
  --soft: #748096;
  --accent: #d7b46a;
  --accent-soft: rgba(215, 180, 106, 0.16);
  --code: #cfe3ff;
  --sidebar-width: 286px;
  --sidebar-collapsed: 58px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(rgba(8, 10, 15, 0.42), rgba(8, 10, 15, 0.9)),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.035) 0,
      rgba(255, 255, 255, 0.035) 1px,
      transparent 1px,
      transparent 92px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.03) 0,
      rgba(255, 255, 255, 0.03) 1px,
      transparent 1px,
      transparent 92px
    ),
    #080a0f;
}

body::after {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(90deg, rgba(8, 10, 15, 0.62) 0%, rgba(8, 10, 15, 0.16) 48%, rgba(8, 10, 15, 0.68) 100%),
    linear-gradient(180deg, rgba(8, 10, 15, 0.02) 0%, rgba(8, 10, 15, 0.76) 100%);
}

#hero-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  outline: none;
  pointer-events: none;
}

.app-shell {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 180ms ease;
}

.app-shell.is-collapsed {
  grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr);
}

.sidebar {
  min-width: 0;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  backdrop-filter: blur(20px);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 62px;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--line);
}

.brand {
  overflow: hidden;
  padding: 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.08rem;
  white-space: nowrap;
  cursor: pointer;
}

.sidebar-toggle {
  display: grid;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(8, 10, 15, 0.6);
  font: inherit;
  cursor: pointer;
}

.sidebar-toggle:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.tree {
  padding: 18px 12px;
}

.tree summary {
  display: block;
  margin: 0;
  padding: 8px 10px;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  cursor: pointer;
  list-style: none;
}

.example-nav {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.example-button {
  min-height: 36px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.example-button:hover {
  color: var(--text);
  background: rgba(218, 226, 240, 0.07);
}

.example-button.is-active {
  color: var(--text);
  background: var(--accent-soft);
}

.app-shell.is-collapsed .brand,
.app-shell.is-collapsed .tree {
  display: none;
}

.app-shell.is-collapsed .sidebar-head {
  justify-content: center;
  padding: 0;
}

.stage {
  min-width: 0;
  min-height: 100vh;
  padding: 32px;
}

.blank-stage {
  min-height: calc(100vh - 64px);
}

.stage.is-home {
  padding: 0;
  cursor: grab;
  touch-action: none;
}

.stage.is-home .blank-stage {
  min-height: 100vh;
}

.stage.is-home.is-dragging {
  cursor: grabbing;
}

.viewer {
  display: grid;
  grid-template-columns: minmax(0, 0.96fr) minmax(420px, 1.04fr);
  min-height: calc(100vh - 64px);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(5, 8, 14, 0.72);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
}

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

.stage.is-viewing .blank-stage {
  display: none;
}

.code-panel,
.result-panel {
  min-width: 0;
  background: var(--panel);
}

.code-panel {
  border-right: 1px solid var(--line);
}

.panel-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 46px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel-strong);
  font-size: 0.88rem;
}

.path-label {
  overflow: hidden;
  color: var(--soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 54px;
  overflow-x: auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 8, 14, 0.86);
  scrollbar-width: thin;
}

.file-tab {
  flex: 0 0 96px;
  min-width: 0;
  height: 34px;
  overflow: hidden;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: rgba(8, 10, 15, 0.44);
  font: inherit;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.file-tab:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.file-tab.is-active {
  border-color: rgba(215, 180, 106, 0.58);
  color: var(--text);
  background: rgba(215, 180, 106, 0.24);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.file-tab.is-missing:not(.is-active) {
  color: var(--soft);
}

#open-link {
  color: var(--accent);
  text-decoration: none;
}

#open-link:hover {
  text-decoration: underline;
}

pre {
  height: calc(100% - 100px);
  min-height: calc(100vh - 164px);
  margin: 0;
  overflow: auto;
  padding: 22px;
}

code {
  color: var(--code);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.68;
  white-space: pre;
}

#result-frame {
  display: block;
  width: 100%;
  height: calc(100% - 46px);
  min-height: calc(100vh - 110px);
  border: 0;
  background: #ffffff;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-shell.is-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    min-height: auto;
  }

  .app-shell.is-collapsed .sidebar {
    height: 62px;
    overflow: hidden;
  }

  .app-shell.is-collapsed .brand {
    display: block;
  }

  .stage {
    min-height: calc(100vh - 62px);
    padding: 16px;
  }

  .stage.is-home {
    min-height: calc(100vh - 62px);
    padding: 0;
  }

  .viewer {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .code-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  pre,
  #result-frame {
    min-height: 440px;
  }

  pre {
    min-height: 380px;
  }
}

@media (max-width: 560px) {
  .panel-bar {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 10px 14px;
  }

  .file-tabs {
    min-height: 50px;
    padding: 8px 10px;
  }

  .file-tab {
    flex-basis: 84px;
    height: 30px;
    padding: 0 10px;
    font-size: 0.78rem;
  }

  pre {
    padding: 16px;
  }

  code {
    font-size: 0.84rem;
  }
}
