:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg-soft: #10131b;
  --surface: #171a22;
  --surface-2: #202532;
  --surface-3: #272d3c;
  --paper: #f1dfbd;
  --paper-ink: #251a0d;
  --text: #f4efe6;
  --muted: #aeb6c8;
  --muted-2: #798297;
  --border: #303849;
  --border-soft: rgba(244, 239, 230, 0.11);
  --accent: #d7a84f;
  --accent-dark: #8d6420;
  --accent-2: #8ab4f8;
  --success: #6fcf97;
  --warning: #f2c94c;
  --danger: #ff6b6b;
  --ai: #b084ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --font-ui: Inter, Manrope, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background:
    radial-gradient(circle at 18% -12%, rgba(215, 168, 79, 0.13), transparent 30%),
    radial-gradient(circle at 86% 6%, rgba(138, 180, 248, 0.08), transparent 26%),
    linear-gradient(135deg, #0b0d12 0%, #0f1117 48%, #090b10 100%);
  color: var(--text);
  font-family: var(--font-ui);
  margin: 0;
}

button,
input,
textarea,
select { font: inherit; }

button,
.ghost {
  align-items: center;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 40px;
  padding: 0.62rem 0.84rem;
  text-decoration: none;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

button {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--paper-ink);
}

button:hover,
.ghost:hover { transform: translateY(-1px); }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(138, 180, 248, 0.82);
  outline-offset: 2px;
}

input,
textarea,
select {
  background: #0f121a;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  min-height: 40px;
  padding: 0.7rem 0.78rem;
  width: 100%;
}

textarea {
  line-height: 1.52;
  min-height: 92px;
  resize: vertical;
}

label {
  color: var(--text);
  display: grid;
  font-size: 0.86rem;
  font-weight: 760;
  gap: 7px;
  line-height: 1.3;
}

label span {
  color: var(--muted-2);
  font-size: 0.78rem;
  font-weight: 650;
}

::placeholder { color: #747d91; opacity: 1; }

h1,
h2,
h3,
h4,
p { overflow-wrap: anywhere; }

h1,
h2,
h3,
h4 { margin: 0; }

h1 {
  font-size: clamp(1.8rem, 3.3vw, 3.4rem);
  letter-spacing: -0.055em;
  line-height: 0.98;
}

h2 {
  font-size: 1.32rem;
  letter-spacing: -0.035em;
  line-height: 1.08;
}

h3 {
  color: var(--text);
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.hidden { display: none !important; }

.hint {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
  margin: 10px 0 0;
}

.studio-body { min-height: 100vh; }

.studio-topbar {
  align-items: center;
  backdrop-filter: blur(18px);
  background: rgba(11, 13, 18, 0.86);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 66px;
  padding: 10px 18px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.studio-brand {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(145deg, var(--accent), #f4d58c);
  border-radius: 12px;
  color: var(--paper-ink);
  display: inline-flex;
  flex: none;
  font-size: 0.78rem;
  font-weight: 950;
  height: 38px;
  justify-content: center;
  letter-spacing: -0.06em;
  width: 38px;
}

.studio-brand strong,
.studio-brand small { display: block; }

.studio-brand strong {
  font-size: 1rem;
  letter-spacing: -0.03em;
}

.studio-brand small {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.studio-layout {
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr);
  min-height: calc(100vh - 66px);
}

.project-rail {
  align-self: start;
  border-right: 1px solid var(--border-soft);
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 66px);
  overflow: auto;
  padding: 16px;
  position: sticky;
  top: 66px;
}

.workspace {
  min-width: 0;
  padding: clamp(18px, 2.4vw, 30px);
}

.rail-card,
.panel {
  background: rgba(23, 26, 34, 0.92);
  border: 1px solid var(--border-soft);
  border-radius: 22px;
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.14);
}

.rail-card { padding: 15px; }
.panel { padding: clamp(16px, 1.8vw, 20px); }

.project-card-admin {
  background:
    linear-gradient(180deg, rgba(32, 37, 50, 0.88), rgba(23, 26, 34, 0.92));
  border-color: rgba(215, 168, 79, 0.22);
}

.rail-heading,
.panel-heading {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.badge {
  background: rgba(244, 239, 230, 0.06);
  border: 1px solid rgba(244, 239, 230, 0.12);
  border-radius: 999px;
  color: var(--muted);
  flex: none;
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  padding: 0.28rem 0.52rem;
  text-transform: uppercase;
}

.badge.ai {
  border-color: rgba(176, 132, 255, 0.45);
  color: var(--ai);
}

.project-list-admin,
.stack,
.form-stack,
.scene-list,
.line-list,
.choice-list,
.character-list {
  display: grid;
  gap: 10px;
}

.project-list-admin { margin-bottom: 12px; }

.small { font-size: 0.9rem; }

.form-stack { margin-top: 12px; }

.compact-form input { min-height: 38px; }

details {
  border-top: 1px solid rgba(244, 239, 230, 0.08);
  margin-top: 12px;
  padding-top: 12px;
}

summary {
  align-items: center;
  color: var(--text);
  cursor: pointer;
  display: flex;
  font-weight: 850;
  gap: 8px;
  justify-content: space-between;
  list-style: none;
  min-height: 34px;
}

summary::-webkit-details-marker { display: none; }

summary::after {
  color: var(--accent);
  content: "+";
  font-size: 1.05rem;
  font-weight: 900;
}

details[open] > summary::after { content: "-"; }

summary small {
  color: var(--muted-2);
  display: block;
  font-size: 0.76rem;
  font-weight: 650;
  margin-top: 2px;
}

.rail-nav {
  display: grid;
  gap: 6px;
}

.rail-nav a {
  align-items: center;
  background: rgba(244, 239, 230, 0.035);
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--muted);
  display: flex;
  font-size: 0.9rem;
  font-weight: 760;
  min-height: 38px;
  padding: 0 12px;
  text-decoration: none;
}

.rail-nav a:hover {
  border-color: rgba(215, 168, 79, 0.28);
  color: var(--text);
}

.ghost,
.secondary {
  background: rgba(244, 239, 230, 0.04);
  border: 1px solid var(--border-soft);
  color: var(--text);
}

.danger,
.ghost-danger {
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.42);
  color: #ffd5d5;
}

.empty-state {
  background:
    linear-gradient(145deg, rgba(32, 37, 50, 0.78), rgba(23, 26, 34, 0.72)),
    radial-gradient(circle at 8% 12%, rgba(215, 168, 79, 0.12), transparent 26%);
  border: 1px solid rgba(215, 168, 79, 0.2);
  border-radius: 30px;
  box-shadow: var(--shadow);
  color: var(--muted);
  line-height: 1.65;
  margin: min(9vh, 90px) auto;
  max-width: 930px;
  padding: clamp(24px, 5vw, 48px);
}

.empty-state h1 {
  color: var(--text);
  margin-bottom: 14px;
  max-width: 680px;
}

.empty-state > p:not(.eyebrow) {
  font-size: 1.04rem;
  margin: 0 0 26px;
  max-width: 720px;
}

.starter-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.starter-grid article {
  background: rgba(15, 18, 26, 0.62);
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  min-height: 160px;
  padding: 16px;
}

.starter-grid span {
  align-items: center;
  background: rgba(215, 168, 79, 0.15);
  border: 1px solid rgba(215, 168, 79, 0.35);
  border-radius: 999px;
  color: var(--accent);
  display: inline-flex;
  font-weight: 900;
  height: 30px;
  justify-content: center;
  margin-bottom: 12px;
  width: 30px;
}

.starter-grid strong { color: var(--text); display: block; }
.starter-grid p { color: var(--muted); font-size: 0.88rem; line-height: 1.5; margin: 8px 0 0; }

.project-workspace { display: grid; gap: 18px; }

.project-header {
  align-items: center;
  background: rgba(15, 17, 23, 0.78);
  border: 1px solid var(--border-soft);
  border-radius: 24px;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 16px;
  position: sticky;
  top: 78px;
  z-index: 10;
  backdrop-filter: blur(18px);
}

#projectTitle {
  font-size: clamp(1.6rem, 3vw, 2.7rem);
}

#projectMeta {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 8px 0 0;
}

.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: flex-end;
}

.editor-layout {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(260px, 0.82fr) minmax(440px, 1.55fr) minmax(300px, 0.95fr);
}

.scenes-panel,
.inspector {
  position: sticky;
  top: 172px;
}

.inspector {
  display: grid;
  gap: 18px;
}

.scene-editor {
  min-height: 58vh;
}

.scene-editor-heading { margin-bottom: 18px; }

.editor-block {
  border-top: 1px solid rgba(244, 239, 230, 0.08);
  display: grid;
  gap: 12px;
  padding-top: 18px;
}

.editor-block + .editor-block { margin-top: 20px; }

.editor-block h3 {
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.item,
.story-project,
.scene-node,
.line-row,
.choice-row,
.character-card {
  background: rgba(32, 37, 50, 0.78);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  color: var(--text);
  line-height: 1.38;
  padding: 12px;
}

.item strong,
.story-project strong,
.scene-node strong,
.line-row strong,
.choice-row strong,
.character-card strong { color: var(--text); }

.item small,
.meta-line,
.line-row small,
.choice-row small,
.character-card small {
  color: var(--muted);
  font-size: 0.8rem;
}

.story-project {
  align-items: flex-start;
  cursor: pointer;
  display: grid;
  gap: 5px;
  min-height: 74px;
  text-align: left;
  width: 100%;
}

.story-project:hover,
.story-project.active,
.scene-node.active {
  background: rgba(215, 168, 79, 0.12);
  border-color: rgba(215, 168, 79, 0.46);
}

.story-project span,
.scene-node span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.scene-node {
  border-left: 4px solid rgba(138, 180, 248, 0.42);
  display: grid;
  gap: 10px;
}

.scene-node.ending { border-left-color: rgba(111, 207, 151, 0.65); }
.scene-node.active { border-left-color: var(--accent); }

.node-body {
  display: grid;
  gap: 4px;
}

.node-actions,
.item-actions {
  display: grid;
  gap: 7px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.node-actions button,
.item-actions button {
  min-height: 34px;
  padding: 0.38rem 0.5rem;
}

.line-row,
.choice-row,
.character-card {
  display: grid;
  gap: 8px;
}

.line-row .line-text {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.58;
  white-space: pre-wrap;
}

.choice-row { border-left: 4px solid rgba(215, 168, 79, 0.48); }

.empty-inline {
  background: rgba(244, 239, 230, 0.035);
  border: 1px dashed var(--border-soft);
  border-radius: 16px;
  color: var(--muted);
  line-height: 1.5;
  padding: 13px;
}

.status-box {
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  line-height: 1.55;
  padding: 14px 16px;
  white-space: pre-wrap;
}

.status-box.ok {
  background: rgba(111, 207, 151, 0.1);
  border-color: rgba(111, 207, 151, 0.46);
  color: #baf3cf;
}

.status-box.error {
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.5);
  color: #ffd1d1;
}

.login-body {
  display: grid;
  min-height: 100vh;
  padding: 18px;
  place-items: center;
}

.login-card {
  background:
    linear-gradient(155deg, rgba(32, 37, 50, 0.96), rgba(23, 26, 34, 0.92));
  border: 1px solid rgba(215, 168, 79, 0.28);
  border-radius: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 15px;
  max-width: 440px;
  padding: clamp(24px, 6vw, 34px);
  width: min(92vw, 440px);
}

.login-card h1 { font-size: clamp(2rem, 8vw, 3.1rem); }

.login-lead {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.login-card button { width: 100%; }

.login-home {
  color: var(--muted);
  justify-self: center;
}

.error {
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.44);
  border-radius: 14px;
  color: #ffd1d1;
  margin: 0;
  padding: 10px 12px;
}

@media (max-width: 1400px) {
  .editor-layout {
    grid-template-columns: minmax(250px, 0.8fr) minmax(430px, 1.5fr);
  }

  .inspector {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    position: static;
  }

  .status-box { grid-column: 1 / -1; }
}

@media (max-width: 1060px) {
  .studio-layout { grid-template-columns: 1fr; }

  .project-rail {
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
    max-height: none;
    position: static;
  }

  .rail-nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }

  .editor-layout { grid-template-columns: 1fr; }

  .scenes-panel,
  .inspector,
  .project-header { position: static; }

  .inspector { grid-template-columns: 1fr; }

  .starter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .studio-topbar {
    align-items: stretch;
    flex-direction: column;
    position: static;
  }

  .topbar-actions { display: grid; grid-template-columns: 1fr 1fr; }

  .topbar-actions .ghost { width: 100%; }

  .project-rail,
  .workspace { padding: 12px; }

  .rail-nav { grid-template-columns: 1fr 1fr; }

  .project-header {
    align-items: stretch;
    flex-direction: column;
  }

  .project-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .project-actions > * { width: 100%; }

  .starter-grid { grid-template-columns: 1fr; }

  .panel,
  .rail-card,
  .empty-state,
  .project-header { border-radius: 18px; }

  button,
  .ghost,
  input,
  textarea,
  select { min-height: 44px; }
}

@media (max-width: 430px) {
  .topbar-actions,
  .project-actions,
  .rail-nav,
  .node-actions,
  .item-actions { grid-template-columns: 1fr; }

  h1 { font-size: 1.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
