:root {
  --bg: #e3e0d8;
  --soft: #efece6;
  --ink: #2a2824;
  --muted: #6a645c;
  --faint: #8a837a;
  --line: #ddd6cc;
  --link: #0e7c74;
  --accent: #0e7c74;
  --danger: #a33b32;
  --sans: Manrope, "Segoe UI", sans-serif;
  --serif: Manrope, "Segoe UI", sans-serif;
  --radius: 8px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--sans);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { min-height: 100dvh; }
.atmosphere { display: none; }

.micro {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.muted, .hint { color: var(--muted); }
.hint { margin: 0; font-size: 14px; line-height: 1.5; }

.btn, .icon-btn, .chip {
  border-radius: 6px;
  border: 1px solid transparent;
  min-height: 36px;
  padding: 8px 14px;
  background: transparent;
}
.btn-primary { background: var(--accent); color: #fff; font-weight: 700; }
.btn-primary:hover { background: #0b6861; }
.chip.is-on { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn-ghost { border-color: var(--line); background: #fff; }
.btn-ghost:hover { background: var(--soft); }
.btn-text { color: var(--link); padding-inline: 0; background: none; }
.btn-danger { color: var(--danger); background: none; }
.icon-btn {
  width: 36px;
  padding: 0;
  border-color: var(--line);
  background: #fff;
}
.chip {
  min-height: 32px;
  padding: 4px 10px;
  border-color: var(--line);
  color: var(--muted);
  font-size: 13px;
  background: #fff;
}
.chip.is-on { color: #fff; background: var(--accent); border-color: var(--accent); }
.field, .genre-select, textarea.field, select.field {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px 12px;
  outline: none;
}
textarea.field, .plot-input, .plot-text { min-height: 140px; resize: vertical; line-height: 1.55; }
.plot-input { min-height: 160px; }
select,
select.field,
.genre-select {
  appearance: none;
  -webkit-appearance: none;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='M3 5.2 L7 9.2 L11 5.2' fill='none' stroke='%230e7c74' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  border: 1px solid #c9d7d4;
  border-radius: 10px;
  color: var(--ink);
  padding-right: 36px;
  box-shadow: none;
}
select:focus,
.genre-select:focus { border-color: var(--accent); outline: none; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }

.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  gap: 20px;
}
.auth-brand { text-align: center; max-width: 420px; }
.auth-brand h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 12px 0 8px;
  line-height: 1.15;
}
.auth-brand p { margin: 0; color: var(--muted); }
.brand-points { display: none; }
.mark { width: 40px; height: 40px; }
.auth-card { width: min(400px, 100%); padding: 24px; }
.auth-switch { display: flex; gap: 8px; margin-bottom: 8px; }
.auth-card h2 { font-size: 22px; font-weight: 700; margin: 8px 0 16px; }
.auth-card label, .editor label, .stack label { display: grid; margin-bottom: 12px; }
.pass-row { display: flex; gap: 8px; }
.pass-row .field { flex: 1; }
.form-error { min-height: 1.2em; color: var(--danger); font-size: 14px; margin: 0 0 8px; }
.auth-card .btn-primary, .plot-box .btn-primary { width: 100%; }

.app-shell { min-height: 100dvh; }
.topnav {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: #fffcf8;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.tabs-nav { display: flex; gap: 4px; background: var(--soft); padding: 4px; border-radius: 12px; }
.topnav .side-link { width: auto; padding: 8px 14px; border-radius: 8px; font-weight: 700; }
.topnav .side-user { width: auto; margin-left: auto; margin-top: 0; }
.topnav .side-brand { margin: 0; }
.app-shell .dash-main { max-width: 920px; margin: 0 auto; }
.settings-grid { display: grid; gap: 14px; max-width: 520px; }
.settings-card { padding: 18px; }
.settings-card h2 { margin: 0 0 6px; font-size: 20px; font-weight: 800; }
.app-shell h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.04em; margin: 0 0 16px; }
.sidebar {
  width: 220px;
  flex: none;
  padding: calc(20px + env(safe-area-inset-top)) 16px 20px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.side-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.side-link, .side-user {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
}
.side-link.is-on, .side-link:hover, .side-user:hover { background: var(--soft); }
.side-user { margin-top: auto; }
.side-user span { display: grid; min-width: 0; }
.side-user strong { font-size: 14px; }
.side-user em { font-style: normal; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.dash-main {
  flex: 1;
  min-width: 0;
  max-width: 820px;
  padding: calc(36px + env(safe-area-inset-top)) 40px 48px;
}
.dash-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 8px; }
.dash-head h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.03em; margin: 0; }
.dash-head .lede { margin: 8px 0 0; color: var(--muted); max-width: 460px; }
.dash-tools { display: flex; gap: 8px; align-items: center; }
.dash-tools .field { width: 200px; }
.quiet-stats { margin: 0 0 20px; color: var(--faint); font-size: 14px; }
.install-hint {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 14px;
}
.project-grid { display: grid; }
.project-card {
  padding: 18px 0;
  text-align: left;
  width: 100%;
  display: grid;
  gap: 6px;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.project-card h3 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.project-card:hover h3 { color: var(--link); }
.project-card p { margin: 0; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-top, .card-actions, .row-actions, .ai-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.genre-chip { color: var(--faint); font-size: 13px; background: none; padding: 0; }
.empty-state { padding: 28px 0; color: var(--muted); }
.empty-state h2, .empty-state h3 { color: var(--ink); font-weight: 700; margin: 0 0 8px; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--soft);
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  flex: none;
}
.avatar-lg { width: 96px; height: 96px; font-size: 32px; }
.avatar-btn { border: none; background: none; padding: 0; border-radius: 50%; }
.profile-card { max-width: 440px; padding: 28px; display: grid; justify-items: start; gap: 12px; }
.profile-quiet { display: flex; gap: 16px; margin-top: 8px; }

.workspace { height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.title-input {
  width: min(460px, 40vw);
  border: none;
  background: transparent;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
  padding: 4px 0;
}
.genre-select { width: auto; max-width: 160px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.logline {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.logline span { color: var(--faint); font-size: 13px; }
.logline input { border: none; background: transparent; padding: 4px 0; }
.chain-banner {
  margin: 12px 16px 0;
  padding: 4px 0 4px 12px;
  border-left: 3px solid var(--ink);
}
.chain-banner p { margin: 4px 0 0; font-size: 16px; line-height: 1.5; }
.branch-advice,
.logic-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  background: none;
  border: none;
  box-shadow: none;
}
.branch-advice { margin: 8px 16px 0; padding-left: 15px; }
.branch-advice p { margin: 0; color: var(--muted); }
.logic-note { margin-top: 6px; }
.emphasis { display: flex; flex-wrap: wrap; gap: 6px; }
.workspace-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 340px;
  gap: 12px;
  padding: 12px;
}
.canvas-wrap { position: relative; min-width: 0; min-height: 0; height: 100%; background: var(--soft); }
.canvas-toolbar {
  position: absolute;
  z-index: 2;
  left: 12px;
  top: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}
.canvas-toolbar .btn { background: #fff; }
.canvas-toolbar [data-action="zoom-out"] { margin-left: 0; }
.add-menu { position: relative; }
.add-menu summary { list-style: none; }
.add-menu summary::-webkit-details-marker { display: none; }
.add-list {
  position: absolute;
  top: 40px;
  left: 0;
  z-index: 3;
  min-width: 180px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
}
.add-list button {
  border: none;
  background: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: 4px;
}
.add-list button:hover { background: var(--soft); }
.graph-host { position: absolute; inset: 0; }
.legend {
  position: absolute;
  z-index: 2;
  left: 16px;
  bottom: 12px;
  display: flex;
  gap: 12px;
  color: var(--faint);
  font-size: 12px;
  pointer-events: none;
}
.legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--swatch, #ccc);
}
.legend i[data-type="exposition"] { --swatch: #7dbe98; }
.legend i[data-type="hook"] { --swatch: #e39a62; }
.legend i[data-type="rise"] { --swatch: #6aaed4; }
.legend i[data-type="turn"] { --swatch: #b48ad4; }
.legend i[data-type="climax"] { --swatch: #e07a72; }
.legend i[data-type="end"] { --swatch: #6aaa96; }
.viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background-color: #eceae4;
  background-image:
    linear-gradient(to right, rgba(90, 78, 62, 0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(90, 78, 62, 0.18) 1px, transparent 1px);
  background-size: 32px 32px;
}
.viewport.is-grabbing { cursor: grabbing; }
.world { position: relative; transform-origin: 0 0; }
svg.edges { position: absolute; overflow: visible; pointer-events: none; }
path.edge { fill: none; stroke: #c5c8cc; stroke-width: 1.5; pointer-events: stroke; }
path.edge.is-selected { stroke: var(--ink); }
path.edge-temp { stroke-dasharray: 4 4; pointer-events: none; }
path.edge-branch { stroke-dasharray: 4 4; }
.viewport .empty-state {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  width: min(360px, 80%);
  text-align: center;
  pointer-events: none;
}
article.node {
  position: absolute;
  width: 220px;
  padding: 12px 14px 14px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid rgba(42, 40, 36, 0.06);
  box-shadow: 0 10px 24px rgba(60, 50, 40, 0.1);
  cursor: grab;
  user-select: none;
}
.node[data-type="exposition"] { background: #e7f6ee; }
.node[data-type="hook"] { background: #fff0e0; }
.node[data-type="intrigue"] { background: #eceeff; }
.node[data-type="rise"] { background: #e5f4fb; }
.node[data-type="turn"] { background: #f6eaf8; }
.node[data-type="climax"] { background: #ffe8e5; }
.node[data-type="fall"] { background: #f7f0e8; }
.node[data-type="end"] { background: #e5f5f0; }
.node[data-type="character"] { background: #fff6dc; }
.node[data-type="conflict"] { background: #ffe8dc; }
.node[data-type="place"] { background: #eaf3e4; }
.node[data-type="motif"] { background: #f3eaf6; }
.node.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(14, 124, 116, 0.35); }
.node-head { display: flex; justify-content: space-between; align-items: center; }
.node-type { font-size: 12px; color: var(--muted); }
.node-index { color: var(--faint); font-size: 12px; }
.node-title { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; margin: 8px 0 6px; line-height: 1.2; }
.node-body, .node-why {
  margin: 0;
  color: #3d4248;
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.node-why { margin-top: 8px; color: var(--muted); }
.node-offer {
  margin: 8px 0 0;
  color: #3d7ea6;
  font-size: 12px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.node.is-fork { box-shadow: inset 3px 0 0 #1a1a1a; }
.node.is-selected.is-fork { box-shadow: inset 3px 0 0 #1a1a1a; }
.port {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid #8b9198;
  background: #fff;
  top: 50%;
  margin-top: -5px;
  padding: 0;
  z-index: 2;
}
.port::after { content: ""; position: absolute; inset: -10px; }
.port-out { right: -6px; }
.port-in { left: -6px; }
.inspector {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  border-radius: 16px;
  background: #fffcf8;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.block-menu {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: #fffcf8;
  border: 1px solid var(--line);
}
.menu-notes, .menu-blocks {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.menu-blocks { overflow: auto; gap: 8px; }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu-suggest { width: 100%; margin-top: 4px; }
.block-menu .tabs { padding: 0 0 8px; }
.block-menu .tab-panel { flex: 1; min-height: 0; overflow: auto; padding: 8px 0 0; }
.inspector .plot-text { min-height: 88px; }
.menu-type {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(42, 40, 36, 0.08);
  text-align: left;
  padding: 8px 12px;
  font-weight: 700;
  background: #fff;
  box-shadow: inset 4px 0 0 var(--swatch, var(--accent));
}
.menu-type[data-type="exposition"] { --swatch: #7dbe98; background: #e7f6ee; }
.menu-type[data-type="hook"] { --swatch: #e39a62; background: #fff0e0; }
.menu-type[data-type="intrigue"] { --swatch: #7d8ad4; background: #eceeff; }
.menu-type[data-type="rise"] { --swatch: #6aaed4; background: #e5f4fb; }
.menu-type[data-type="turn"] { --swatch: #b48ad4; background: #f6eaf8; }
.menu-type[data-type="climax"] { --swatch: #e07a72; background: #ffe8e5; }
.menu-type[data-type="end"] { --swatch: #6aaa96; background: #e5f5f0; }
.menu-type[data-type="character"] { --swatch: #d4b45a; background: #fff6dc; }
.menu-type[data-type="conflict"] { --swatch: #e08a62; background: #ffe8dc; }
.menu-type[data-type="place"] { --swatch: #7aaa62; background: #eaf3e4; }
.menu-type[data-type="motif"] { --swatch: #b48ad4; background: #f3eaf6; }
.menu-type[data-type="fall"] { --swatch: #c4a882; background: #f7f0e8; }
.block-menu .tabs { padding: 0 0 8px; }
.block-menu .tab-panel { flex: 1; min-height: 140px; padding: 8px 0 12px; }
.block-menu > .btn, .block-menu .menu-suggest { margin-top: 8px; }
.plot-box .logline {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 0;
  border: none;
  background: transparent;
}
.plot-box .logline input {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
}
.inspector .chain-banner,
.inspector .branch-advice { margin: 0 12px 8px; }
.plot-box { padding: 16px; display: grid; gap: 8px; }
.tabs { display: flex; gap: 4px; padding: 0 12px 8px; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1;
  background: none;
  border: none;
  min-height: 36px;
  color: var(--faint);
  border-radius: 6px;
}
.tabs button.is-active { color: var(--ink); background: var(--soft); font-weight: 600; }
.tab-panel { padding: 16px; overflow: auto; flex: 1; }
.editor, .stack { display: grid; gap: 8px; }
.type-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.why-block { margin-bottom: 14px; }
.offer-card {
  margin: 0 0 16px;
  padding-top: 12px;
  background: none;
  border: none;
  border-top: 1px solid var(--line);
  box-shadow: none;
}
.offer-card h3 { margin: 0 0 6px; font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.offer-card p { margin: 0 0 8px; }
.offer-card .row-actions { margin-top: 4px; }
.why-block p { margin: 8px 0; }
.why-quote { margin: 0; padding-left: 12px; border-left: 2px solid var(--ink); color: var(--ink); }
.feed { list-style: none; margin: 0; padding: 0; }
.feed-item { padding: 12px 0; border-top: 1px solid var(--line); }
.feed-kicker { font-size: 12px; color: var(--link); }
.feed-item h3, .ai-card h3 { margin: 4px 0; font-size: 18px; }
.feed-item p, .ai-body, .ai-why { margin: 0; color: var(--muted); }
.ai-card { padding: 14px 0; border-bottom: 1px solid var(--line); background: none; border-radius: 0; box-shadow: none; }
.ai-kicker { font-size: 12px; color: var(--link); }
.composer { display: grid; gap: 8px; margin-top: 12px; }
.composer textarea { min-height: 90px; }
.tension-chart { width: 100%; height: 72px; margin: 8px 0 16px; }
.history-list, .link-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.history-item, .link-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.history-meta { color: var(--muted); font-size: 12px; display: block; }

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(26, 26, 26, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal { width: min(520px, 100%); max-height: min(86dvh, 760px); overflow: auto; padding: 24px; }
.modal h2 { font-size: 26px; font-weight: 700; margin: 0 0 12px; }
.modal-body { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts {
  position: fixed;
  z-index: 50;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
}
.context-menu {
  position: fixed;
  z-index: 80;
  min-width: 210px;
  padding: 6px;
  background: #fffcf8;
  border: 1px solid #ddd6cc;
  border-radius: 12px;
  box-shadow: 0 16px 36px rgba(60, 50, 40, 0.16);
}
.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 9px 10px;
  font-weight: 700;
  color: var(--ink);
}
.context-menu button:hover { background: #e7f5f3; }
.context-menu button.is-danger { color: var(--danger); }
.context-menu button.is-danger:hover { background: #fff1ee; }
.toast {
  background: var(--ink);
  color: #fff;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
}

@media (max-width: 960px) {
  .dash { flex-direction: column; }
  .topnav { flex-wrap: wrap; }
  .tabs-nav { order: 3; width: 100%; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
  .side-user { margin-top: 0; }
  .dash-main { padding: 20px 16px 32px; max-width: none; }
  .dash-head, .dash-tools, .install-hint { flex-direction: column; align-items: stretch; }
  .dash-tools .field { width: 100%; }
  .workspace-body { grid-template-columns: 1fr; grid-template-rows: minmax(320px, 52dvh) auto auto; }
  .canvas-wrap { min-height: 280px; height: 46dvh; order: -1; }
  .block-menu { grid-template-rows: auto auto; overflow: auto; }
  .title-input { width: 100%; font-size: 22px; }
  .topbar { flex-wrap: wrap; }
  .logline { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
