/* ==========================================================================
   Layout: app shell, star rail, workspace, top bar, tabs
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  height: 100vh;
  width: 100vw;
  transition: grid-template-columns 0.36s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Desktop: hideable story rail — collapses to a slim reopen tab. */
.app.rail-collapsed {
  grid-template-columns: 0 1fr;
}
.app.rail-collapsed .rail {
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transform: translateX(-12px);
  transition: opacity 0.28s ease, transform 0.36s cubic-bezier(0.4, 0, 0.2, 1);
}
.app .rail {
  transition: opacity 0.28s ease, transform 0.36s cubic-bezier(0.4, 0, 0.2, 1);
}
.rail-reopen {
  position: absolute;
  top: 14px;
  left: 10px;
  z-index: 6;
  appearance: none;
  border: 1px solid var(--parchment-edge);
  background: var(--parchment-raised);
  color: var(--ink-soft);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: none;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-md, 0 8px 20px -12px rgba(0,0,0,.35));
  transition: color .2s, background .2s, border-color .2s, transform .2s;
}
.rail-reopen:hover {
  color: var(--ink);
  border-color: var(--gold);
  transform: translateY(-1px);
}
.rail-reopen .icon { width: 18px; height: 18px; }
.app.rail-collapsed .rail-reopen { display: grid; }

@media (prefers-reduced-motion: reduce) {
  .app { transition: none; }
  .app .rail { transition: none; }
}

/* ---- Left rail: the night sky of stories ---- */
.rail {
  position: relative;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 80% at 0% 0%, var(--night-raised), var(--night)) fixed;
  color: var(--night-text);
  box-shadow: var(--shadow-night);
  z-index: 3;
  overflow: hidden;
}
.rail::before {
  /* faint drifting starfield */
  content: "";
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1.2px 1.2px at 20% 15%, rgba(231,201,116,.7), transparent 60%),
    radial-gradient(1px 1px at 65% 25%, rgba(255,255,255,.5), transparent 60%),
    radial-gradient(1.4px 1.4px at 80% 55%, rgba(231,201,116,.6), transparent 60%),
    radial-gradient(1px 1px at 35% 70%, rgba(255,255,255,.45), transparent 60%),
    radial-gradient(1px 1px at 50% 90%, rgba(231,201,116,.5), transparent 60%),
    radial-gradient(1.2px 1.2px at 12% 88%, rgba(255,255,255,.4), transparent 60%);
  opacity: .8;
  pointer-events: none;
  animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .55; } to { opacity: .95; } }

.rail__brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 12px;
  position: relative;
}
.rail__brand > div:first-of-type { flex: 1; min-width: 0; }
.rail__brand img { width: 34px; height: 34px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.rail__title {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 600; letter-spacing: .02em;
  color: var(--night-text);
}
.rail__title b { color: var(--gold-bright); font-weight: 600; }
.rail__tagline {
  font-family: var(--font-ui); font-size: 11px; letter-spacing: .22em;
  text-transform: uppercase; color: var(--night-text-soft); opacity: .8;
}
.rail__collapse {
  appearance: none; border: none; background: transparent;
  color: var(--night-text-soft); width: 32px; height: 32px;
  border-radius: 8px; display: grid; place-items: center;
  cursor: pointer; flex: none;
  transition: color .2s, background .2s;
}
.rail__collapse:hover { color: var(--night-text); background: rgba(255,255,255,.08); }
.rail__collapse .icon { width: 18px; height: 18px; }

.rail__gallery {
  appearance: none; border: none;
  display: flex; align-items: center; gap: 8px;
  margin: 0 14px 10px; padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  color: var(--night-text-soft);
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 600;
  letter-spacing: .04em; cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}
.rail__gallery:hover {
  background: rgba(255,255,255,.09);
  color: var(--gold-bright);
  border-color: rgba(231, 201, 116, .28);
}
.rail__gallery .icon { width: 16px; height: 16px; }

.rail__more {
  appearance: none; border: none; background: transparent;
  width: 100%; margin-top: 6px; padding: 10px 12px;
  border-radius: 10px;
  color: var(--night-text-soft);
  font-family: var(--font-ui); font-size: 12px; font-weight: 600;
  letter-spacing: .04em; cursor: pointer; text-align: left;
  transition: background .2s, color .2s;
}
.rail__more:hover { background: rgba(255,255,255,.05); color: var(--gold-bright); }

.rail__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 18px 10px; position: relative;
}
.rail__head h2 {
  font-family: var(--font-ui); font-size: 11px; font-weight: 600;
  letter-spacing: .2em; text-transform: uppercase; color: var(--night-text-soft);
}

.rail__stories {
  flex: 1; overflow-y: auto; padding: 4px 12px 12px;
  position: relative;
}

.rail__foot {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--night-line);
  position: relative;
  display: flex; flex-direction: column; gap: 8px;
}

/* ---- Workspace ---- */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex; align-items: center; gap: 16px;
  padding: 0 22px;
  background: linear-gradient(180deg, var(--parchment-raised), var(--parchment));
  border-bottom: 1px solid var(--parchment-edge);
  box-shadow: var(--shadow-sm);
  z-index: 2;
}
.topbar__story { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.topbar__name {
  font-family: var(--font-display); font-size: 24px; font-weight: 600;
  color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 46vw; cursor: text;
}
.topbar__spacer { flex: 1; }

.tabs { display: flex; gap: 4px; align-items: center; }
.tab {
  appearance: none; border: none; background: transparent;
  font-family: var(--font-ui); font-size: 13px; font-weight: 600;
  color: var(--ink-soft); padding: 9px 14px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover { background: var(--parchment-sunk); color: var(--ink); }
.tab.is-active {
  background: var(--night);
  color: var(--gold-bright);
  box-shadow: var(--shadow-sm);
}
.tab .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; opacity: .8; }
.tab.is-hidden { display: none; }

.view {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.view > section {
  position: absolute; inset: 0;
  display: none;
  min-height: 0;
}
.view > section.is-active {
  display: flex;
  flex-direction: column;
}

/* Two-pane views (graph + side panel); solo = full-bleed graph */
.split {
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  width: 100%;
  flex: 1;
  min-height: 0;
  height: 100%;
  align-self: stretch;
}
.split--solo { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.split__main {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.split__panel {
  border-left: 1px solid var(--parchment-edge);
  background: linear-gradient(180deg, var(--parchment-raised), var(--parchment));
  display: flex; flex-direction: column; min-height: 0;
  box-shadow: -8px 0 24px rgba(51,40,26,.05);
}

@media (max-width: 1080px) {
  :root { --rail-w: 240px; --panel-w: 340px; }
  .topbar__name { max-width: 34vw; }
}
