:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #080c17;
  color: #edf2ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 15%, rgba(79, 70, 229, .24), transparent 34rem),
    radial-gradient(circle at 90% 85%, rgba(14, 165, 233, .14), transparent 30rem),
    #080c17;
}

a { color: #a5b4fc; }
a:hover { color: #c7d2fe; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 68px;
  padding: 0 6vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(148, 163, 184, .12);
  background: rgba(8, 12, 23, .75);
  backdrop-filter: blur(16px);
}

.brand {
  color: #fff;
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: .02em;
}

.topbar-user { display: flex; align-items: center; gap: 1rem; color: #cbd5e1; }
.page { width: min(1100px, 88vw); margin: 0 auto; padding: 4rem 0; }
.page-wide { width: calc(100vw - 2rem); max-width: none; padding: 1rem 0; }
.auth-page { display: grid; place-items: center; }

.card {
  width: min(100%, 460px);
  padding: clamp(1.5rem, 5vw, 2.5rem);
  border: 1px solid rgba(148, 163, 184, .16);
  border-radius: 24px;
  background: rgba(15, 23, 42, .82);
  box-shadow: 0 32px 80px rgba(0, 0, 0, .35);
}

.card h1, .dashboard h1 { margin: 0 0 .5rem; font-size: clamp(2rem, 5vw, 3rem); }
.subtitle { margin: 0 0 2rem; color: #94a3b8; line-height: 1.6; }
.form { display: grid; gap: 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .75rem; margin-top: .5rem; }
.field { display: grid; gap: .5rem; }
.field span { font-size: .9rem; font-weight: 650; color: #cbd5e1; }

input {
  width: 100%;
  padding: .9rem 1rem;
  border: 1px solid #334155;
  border-radius: 12px;
  background: #0f172a;
  color: #f8fafc;
  font: inherit;
  outline: none;
}

textarea {
  width: 100%;
  padding: .9rem 1rem;
  border: 1px solid #334155;
  border-radius: 12px;
  background: #0f172a;
  color: #f8fafc;
  font: inherit;
  line-height: 1.55;
  resize: vertical;
  outline: none;
}

textarea:focus { border-color: #818cf8; box-shadow: 0 0 0 3px rgba(99, 102, 241, .18); }

input:focus { border-color: #818cf8; box-shadow: 0 0 0 3px rgba(99, 102, 241, .18); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  padding: .9rem 1.2rem;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
}

.button:hover { filter: brightness(1.08); color: #fff; }
.button.active { background: #166534; color: #dcfce7; }
.button-secondary { background: #1e293b; }
.button-link { padding: .65rem 1rem; font-size: .9rem; }
.auth-footer { margin: 1.5rem 0 0; color: #94a3b8; text-align: center; }

.alerts { display: grid; gap: .75rem; margin-bottom: 1.25rem; }
.alert { padding: .85rem 1rem; border-radius: 12px; line-height: 1.45; }
.alert-error { background: rgba(239, 68, 68, .14); color: #fecaca; border: 1px solid rgba(239, 68, 68, .24); }
.alert-success { background: rgba(34, 197, 94, .14); color: #bbf7d0; border: 1px solid rgba(34, 197, 94, .24); }

.dashboard { display: grid; gap: 2rem; }
.welcome { padding: 2rem; border-radius: 20px; background: rgba(15, 23, 42, .75); border: 1px solid rgba(148, 163, 184, .14); }
.empty-state { padding: 3rem 2rem; text-align: center; border: 1px dashed #334155; border-radius: 20px; color: #94a3b8; }
.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.story-card { padding: 1.5rem; border-radius: 18px; background: rgba(15, 23, 42, .75); border: 1px solid rgba(148, 163, 184, .14); }
.story-card-cover { width: calc(100% + 3rem); height: 170px; margin: -1.5rem -1.5rem 1.25rem; object-fit: cover; border-radius: 18px 18px 0 0; }
.story-card h2 { margin: 1rem 0 .4rem; }
.story-card p { margin: 0 0 1.4rem; color: #94a3b8; }
.story-card-meta { display: flex; justify-content: space-between; color: #64748b; font-size: .85rem; }
.status-badge { padding: .25rem .6rem; border-radius: 999px; background: rgba(99, 102, 241, .15); color: #c7d2fe; }
.story-card-actions { display: flex; gap: .65rem; }
.story-workspace { display: grid; gap: 1.5rem; }
.workspace-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; }
.workspace-heading h1 { margin: .5rem 0; font-size: clamp(2rem, 5vw, 3.25rem); }
.back-link { color: #94a3b8; text-decoration: none; }
.workspace-tabs { display: flex; gap: .4rem; padding: .35rem; width: fit-content; border-radius: 12px; background: #111827; }
.workspace-tabs a { padding: .65rem 1rem; border-radius: 9px; color: #94a3b8; text-decoration: none; font-weight: 650; }
.workspace-tabs a.active { color: #fff; background: #312e81; }
.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; }
.settings-panel { display: grid; align-content: start; gap: 1.25rem; padding: 1.5rem; border-radius: 20px; background: rgba(15, 23, 42, .75); border: 1px solid rgba(148, 163, 184, .14); }
.settings-panel h2 { margin: 0; }
.cover-preview { aspect-ratio: 3 / 2; overflow: hidden; border-radius: 14px; background: #0f172a; }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.cover-placeholder { height: 100%; display: grid; place-content: center; gap: .4rem; text-align: center; color: #64748b; }
.cover-placeholder span { color: #a5b4fc; font-size: 2rem; font-weight: 850; }
.file-field input { padding: .65rem; }
.file-field small, .field small { color: #64748b; }
.check-field { display: flex; align-items: center; gap: .65rem; color: #cbd5e1; }
.check-field input { width: auto; }
.project-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; margin-top: .5rem; }
.project-details div { display: grid; gap: .35rem; padding: 1rem; border-radius: 12px; background: #0f172a; overflow: hidden; }
.project-details span { color: #64748b; font-size: .8rem; }
.project-details code { overflow: hidden; text-overflow: ellipsis; color: #cbd5e1; }
.settings-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: .75rem; }
.editor-placeholder { min-height: 460px; display: grid; place-content: center; justify-items: center; padding: 3rem; text-align: center; border: 1px dashed #334155; border-radius: 24px; color: #94a3b8; }
.editor-placeholder h2 { margin: 1rem 0 .5rem; color: #e2e8f0; font-size: 1.8rem; }
.editor-placeholder p { max-width: 600px; line-height: 1.7; }
.editor-placeholder-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 18px; background: #312e81; color: #c7d2fe; font-size: 2rem; }
.button-compact { padding: .65rem .9rem; font-size: .88rem; }
.graph-editor { height: calc(100vh - 100px); min-height: 650px; display: grid; grid-template-rows: auto 1fr; overflow: hidden; border: 1px solid rgba(148, 163, 184, .16); border-radius: 20px; background: #0b1120; }
.graph-toolbar { min-height: 72px; padding: .75rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid #1e293b; background: #0f172a; }
.graph-title { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.graph-title > div { display: grid; min-width: 0; }
.graph-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.graph-title span { color: #64748b; font-size: .8rem; }
.graph-toolbar-actions { display: flex; align-items: center; gap: .6rem; }
.save-status { min-width: 105px; color: #94a3b8; font-size: .82rem; text-align: right; }
.save-status.saved { color: #86efac; }
.save-status.pending { color: #fde68a; }
.save-status.error { color: #fca5a5; }
.graph-layout { min-height: 0; display: grid; grid-template-columns: 220px minmax(0, 1fr) 390px; }
.graph-sidebar { min-width: 0; background: #0f172a; }
.scene-sidebar { padding: 1rem; border-right: 1px solid #1e293b; overflow-y: auto; }
.inspector { border-left: 1px solid #1e293b; overflow: hidden; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.sidebar-heading > span { min-width: 26px; padding: .2rem .45rem; border-radius: 999px; background: #1e293b; color: #94a3b8; font-size: .75rem; text-align: center; }
.scene-list { display: grid; gap: .45rem; margin-top: 1rem; }
.scene-list-item { display: grid; gap: .25rem; padding: .75rem; border: 1px solid transparent; border-radius: 10px; background: transparent; color: #cbd5e1; text-align: left; cursor: pointer; }
.scene-list-item span { color: #64748b; font-size: .75rem; }
.scene-list-item:hover { background: #111827; }
.scene-list-item.active { border-color: #4f46e5; background: rgba(49, 46, 129, .3); color: #fff; }
.sidebar-empty, .inspector-empty { padding: 1.25rem 0; color: #64748b; font-size: .9rem; line-height: 1.5; }
.inspector-empty { padding: 1.25rem; }
.graph-viewport { position: relative; overflow: auto; background-color: #080c17; background-image: radial-gradient(#26334d 1px, transparent 1px); background-size: 24px 24px; }
.graph-canvas { position: relative; width: 5000px; height: 5000px; }
.graph-edges, .graph-nodes { position: absolute; inset: 0; pointer-events: none; }
.graph-edge { fill: none; stroke: #6366f1; stroke-width: 2.2; opacity: .75; }
.graph-node { position: absolute; top: 0; left: 0; width: 260px; border: 1px solid #334155; border-radius: 14px; background: #111827; box-shadow: 0 12px 30px rgba(0, 0, 0, .28); overflow: hidden; pointer-events: auto; user-select: none; }
.graph-node.selected { border-color: #818cf8; box-shadow: 0 0 0 2px rgba(99, 102, 241, .22), 0 18px 40px rgba(0, 0, 0, .35); }
.graph-node.dragging { opacity: .88; cursor: grabbing; }
.graph-node-header { min-height: 48px; padding: .75rem; display: flex; justify-content: space-between; gap: .6rem; background: #172033; cursor: grab; touch-action: none; }
.graph-node-header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.graph-node-header > div { display: flex; gap: .25rem; }
.node-badge { padding: .18rem .4rem; border-radius: 999px; font-size: .64rem; text-transform: uppercase; }
.node-badge.start { background: rgba(34, 197, 94, .16); color: #86efac; }
.node-badge.ending { background: rgba(245, 158, 11, .16); color: #fcd34d; }
.graph-node-image { display: block; width: 100%; height: 112px; object-fit: cover; }
.graph-node-text { max-height: 67px; margin: 0; padding: .75rem; overflow: hidden; color: #94a3b8; font-size: .82rem; line-height: 1.4; }
.graph-node-choices { border-top: 1px solid #1e293b; }
.graph-node-choice { min-height: 36px; padding: .55rem .5rem .55rem .75rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; border-bottom: 1px solid rgba(30, 41, 59, .65); color: #cbd5e1; font-size: .76rem; }
.graph-node-choice span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.graph-node-choice i { flex: 0 0 auto; width: 11px; height: 11px; border: 2px solid #818cf8; border-radius: 50%; background: #111827; }
.graph-node-no-choices { padding: .65rem .75rem; color: #64748b; font-size: .75rem; }
.canvas-help { position: sticky; left: 1rem; bottom: 1rem; width: max-content; padding: .55rem .75rem; border-radius: 9px; background: rgba(15, 23, 42, .88); color: #64748b; font-size: .75rem; pointer-events: none; }
.inspector > .sidebar-heading { height: 56px; padding: 0 1rem; border-bottom: 1px solid #1e293b; }
.inspector-scroll { height: calc(100% - 56px); padding: 1rem; display: grid; align-content: start; gap: 1.1rem; overflow-y: auto; }
.icon-button { width: 30px; height: 30px; border: 0; border-radius: 8px; background: #1e293b; color: #cbd5e1; font-size: 1.15rem; cursor: pointer; }
.icon-button.danger:hover { background: rgba(239, 68, 68, .17); color: #fca5a5; }
.scene-flags { display: grid; gap: .6rem; }
.scene-image-editor { display: grid; gap: .65rem; padding-top: .25rem; }
.scene-image-preview { min-height: 110px; display: grid; place-items: center; position: relative; overflow: hidden; border-radius: 10px; background: #080c17; color: #64748b; font-size: .8rem; }
.scene-image-preview img { width: 100%; height: 150px; object-fit: cover; }
.scene-image-preview button { position: absolute; right: .5rem; bottom: .5rem; padding: .4rem .6rem; border: 0; border-radius: 7px; background: rgba(8, 12, 23, .86); color: #fca5a5; cursor: pointer; }
.file-button { width: fit-content; cursor: pointer; }
.file-button input { display: none; }
.answers-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding-top: .5rem; border-top: 1px solid #1e293b; }
.answers-heading > div { display: grid; gap: .2rem; }
.answers-heading small { color: #64748b; }
.choice-editor-list { display: grid; gap: .75rem; }
.choice-editor-card { display: grid; gap: .7rem; padding: .85rem; border: 1px solid #26334d; border-radius: 12px; background: #0b1120; }
.choice-editor-title, .condition-heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.condition-heading { color: #94a3b8; font-size: .78rem; }
.text-button { border: 0; background: transparent; color: #a5b4fc; cursor: pointer; }
.condition-list { display: grid; gap: .45rem; }
.condition-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px 30px; gap: .35rem; }
select { width: 100%; min-width: 0; padding: .65rem .7rem; border: 1px solid #334155; border-radius: 9px; background: #0f172a; color: #f8fafc; font: inherit; outline: none; }
.condition-row select { font-size: .72rem; }
.small-empty { padding: .7rem; border-radius: 9px; background: #0f172a; color: #64748b; font-size: .76rem; }
.graph-toast { position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 50; max-width: 420px; padding: .85rem 1rem; border: 1px solid #334155; border-radius: 11px; background: #111827; color: #e2e8f0; box-shadow: 0 18px 50px rgba(0, 0, 0, .35); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.graph-toast.visible { opacity: 1; transform: translateY(0); }
.graph-toast.error { border-color: rgba(239, 68, 68, .5); color: #fecaca; }
.graph-toast.success { border-color: rgba(34, 197, 94, .5); color: #bbf7d0; }

@media (max-width: 640px) {
  .topbar { padding: 0 1rem; }
  .topbar-user span { display: none; }
  .page { width: min(100% - 2rem, 1100px); padding: 2rem 0; }
  .workspace-heading { align-items: flex-start; flex-direction: column; }
  .settings-layout { grid-template-columns: 1fr; }
  .project-details { grid-template-columns: 1fr; }
  .settings-actions, .form-actions { flex-direction: column-reverse; }
  .page-wide { width: 100%; padding: 0; }
  .graph-editor { height: calc(100vh - 68px); min-height: 600px; border-radius: 0; border-inline: 0; }
  .graph-toolbar { align-items: flex-start; }
  .graph-title .back-link, .save-status { display: none; }
  .graph-toolbar-actions a.button-secondary { display: none; }
  .graph-layout { grid-template-columns: minmax(0, 1fr); }
  .scene-sidebar { display: none; }
  .inspector { position: absolute; right: 0; bottom: 0; z-index: 8; width: min(92vw, 390px); height: calc(100% - 72px); box-shadow: -16px 0 40px rgba(0, 0, 0, .35); }
}
