:root {
  --md-sys-color-primary: #6750a4;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #e9ddff;
  --md-sys-color-on-primary-container: #21005d;

  --md-sys-color-secondary: #625b71;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #e8def8;
  --md-sys-color-on-secondary-container: #1e192b;

  --md-sys-color-tertiary: #7d5260;
  --md-sys-color-on-tertiary: #ffffff;

  --md-sys-color-error: #b3261e;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #f9dedc;

  --md-sys-color-background: #fdf8fd;
  --md-sys-color-on-background: #1d1b20;
  --md-sys-color-surface: #fdf8fd;
  --md-sys-color-surface-dim: #ddd8de;
  --md-sys-color-surface-bright: #fdf8fd;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f7f2fa;
  --md-sys-color-surface-container: #f3edf7;
  --md-sys-color-surface-container-high: #ece6f0;
  --md-sys-color-surface-container-highest: #e6e0e9;
  --md-sys-color-on-surface: #1d1b20;
  --md-sys-color-on-surface-variant: #49454f;

  --md-sys-color-outline: #79747e;
  --md-sys-color-outline-variant: #cac4d0;

  --md-sys-color-inverse-surface: #322f35;
  --md-sys-color-inverse-on-surface: #f5eff7;

  --md-sys-elevation-1: 0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
  --md-sys-elevation-2: 0 2px 6px rgba(0, 0, 0, 0.11), 0 1px 2px rgba(0, 0, 0, 0.06);

  --md-sys-shape-corner-xs: 8px;
  --md-sys-shape-corner-s: 12px;
  --md-sys-shape-corner-m: 16px;
  --md-sys-shape-corner-l: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  font-family: Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
}

.name-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(18, 18, 22, 0.58);
  backdrop-filter: blur(3px);
}

.name-overlay-card {
  width: min(440px, 94vw);
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-l);
  padding: 18px;
  box-shadow: var(--md-sys-elevation-2);
}

.name-overlay-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.name-overlay-form input {
  flex: 1;
}

.glow {
  display: none;
}

.app-shell {
  width: min(1420px, 96vw);
  margin: 16px auto 36px;
}

.hero {
  border-radius: var(--md-sys-shape-corner-l);
  padding: 20px 24px;
  background: linear-gradient(130deg, var(--md-sys-color-primary-container), var(--md-sys-color-surface-container-low));
  border: 1px solid var(--md-sys-color-outline-variant);
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0;
  color: var(--md-sys-color-primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 600;
}

h1,
h2,
h3,
h4,
summary {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-weight: 500;
}

h1 {
  margin-top: 8px;
  font-size: clamp(1.6rem, 2.6vw, 2.3rem);
  letter-spacing: 0;
}

h2 {
  font-size: 1.2rem;
}

h3 {
  font-size: 1rem;
  margin: 8px 0;
}

.subtitle,
.muted {
  color: var(--md-sys-color-on-surface-variant);
}

.subtitle {
  margin: 8px 0 0;
}

.panel {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-m);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--md-sys-elevation-1);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.controls {
  background: var(--md-sys-color-surface-container);
}

.control-row,
.story-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.layout-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.assistant-workspace {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(640px, 2fr);
  gap: 12px;
  margin-bottom: 12px;
  align-items: start;
}

.two-col {
  grid-template-columns: repeat(2, minmax(300px, 1fr));
}

.three-col {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.status-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
}

.status-chip.good {
  border-color: #9acb9e;
  background: #ddf5df;
  color: #205628;
}

.status-chip.warn {
  border-color: #d8bf8b;
  background: #fff3db;
  color: #74510a;
}

.agent-panel {
  padding: 0;
  overflow: hidden;
}

.agent-header {
  padding: 14px 16px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.agent-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chatgpt-shell .muted {
  padding: 0 16px;
  margin-bottom: 10px;
}

.starter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 8px;
  padding: 0 16px 12px;
}

.starter-card {
  display: grid;
  gap: 4px;
  text-align: left;
  border-radius: var(--md-sys-shape-corner-s);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  padding: 12px;
  box-shadow: none;
}

.starter-card .starter-title {
  font-weight: 500;
}

.starter-card .starter-subtitle {
  font-size: 0.85rem;
  color: var(--md-sys-color-on-surface-variant);
}

.starter-card:hover {
  background: var(--md-sys-color-surface-container-low);
  transform: none;
  filter: none;
}

.chat-thread-shell {
  border-top: 1px solid var(--md-sys-color-outline-variant);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
}

.chat-log {
  min-height: 220px;
  max-height: 430px;
  overflow: auto;
  padding: 16px;
  display: grid;
  gap: 8px;
}

.chat-bubble {
  max-width: min(100%, 920px);
  border-radius: 20px;
  padding: 12px 14px;
  line-height: 1.42;
  font-size: 0.95rem;
}

.chat-bubble.assistant {
  justify-self: start;
  background: var(--md-sys-color-surface-container);
}

.chat-bubble.user {
  justify-self: end;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.chat-bubble.thinking {
  color: var(--md-sys-color-on-surface-variant);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.45;
  }
}

.chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 16px 16px;
  background: var(--md-sys-color-surface-container-low);
}

.draft-review-panel {
  background: var(--md-sys-color-surface-container-low);
}

.draft-review-panel.collapsed .draft-grid,
.draft-review-panel.collapsed .draft-actions {
  display: none;
}

.draft-summary-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.draft-pill {
  font-size: 0.82rem;
  color: var(--md-sys-color-on-surface-variant);
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 999px;
  padding: 4px 10px;
}

.draft-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 12px;
}

.draft-people-list,
.draft-relationships-list {
  display: grid;
  gap: 4px;
  max-height: 320px;
  overflow: auto;
}

.draft-people-inline {
  font-size: 0.95rem;
  color: var(--md-sys-color-on-surface);
}

.draft-people-comma {
  color: var(--md-sys-color-on-surface-variant);
}

.draft-person-row,
.draft-rel-row {
  padding: 2px 0;
}

.draft-person-summary {
  min-height: 28px;
  display: flex;
  align-items: center;
}

.draft-person-name-link,
.draft-rel-text-link,
.profile-link {
  border: none;
  background: transparent;
  padding: 0;
  color: #1f5ea8;
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.95rem;
}

.draft-person-editor[hidden],
.draft-rel-editor[hidden] {
  display: none !important;
}

.draft-person-editor {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 6px;
  margin-top: 4px;
}

.draft-rel-display {
  display: flex;
  align-items: center;
}

.draft-rel-editor {
  margin-top: 4px;
  border: 1px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-s);
  padding: 8px;
  background: var(--md-sys-color-surface-container-lowest);
}

.draft-rel-include-label {
  font-size: 0.84rem;
  color: var(--md-sys-color-on-surface-variant);
}

.draft-rel-sentence {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.draft-sentence-word {
  color: var(--md-sys-color-on-surface-variant);
}

.draft-rel-controls {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}

.draft-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.draft-empty {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9rem;
}

.graph-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

#graphCanvas {
  width: 100%;
  height: auto;
  border-radius: var(--md-sys-shape-corner-s);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
}

.profile-panel .profile-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.profile-identity {
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 6px;
}

.profile-tools {
  margin-bottom: 12px;
}

.generation-lanes {
  position: relative;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-s);
  background: var(--md-sys-color-surface-container-lowest);
  padding: 8px;
}

.generation-members {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.org-chart-canvas {
  position: relative;
}

.org-chart-row {
  position: relative;
  z-index: 2;
  padding: 8px 0;
}

.org-chart-row + .org-chart-row {
  border-top: 1px dashed var(--md-sys-color-outline-variant);
}

.org-chart-row-label {
  font-size: 0.78rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 6px;
  text-align: center;
}

.org-chart-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.org-line.parent {
  stroke: #7f67be;
  stroke-width: 1.6;
  opacity: 0.55;
}

.org-line.partner {
  stroke: #86a0b8;
  stroke-width: 1.4;
  stroke-dasharray: 5 4;
  opacity: 0.6;
}

button.generation-member,
button.generation-member:hover {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 999px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  text-decoration: none;
  padding: 4px 8px;
  transform: none;
  filter: none;
}

form {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

label {
  font-size: 0.86rem;
  color: var(--md-sys-color-on-surface-variant);
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 12px;
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

textarea {
  min-height: 76px;
  resize: vertical;
}

button {
  border: none;
  border-radius: 999px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  padding: 9px 14px;
  font-weight: 500;
  cursor: pointer;
  transition: filter 120ms ease;
}

button:hover {
  filter: brightness(1.05);
}

.button-ghost {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.button-danger {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
}

.manual-tools summary {
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.data-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
  max-height: 280px;
  overflow: auto;
}

.data-list li {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.92rem;
}

.data-list.compact {
  max-height: 220px;
}

.inline-edit {
  display: flex;
  gap: 7px;
  align-items: center;
}

.inline-edit input {
  flex: 1;
  min-width: 120px;
}

.code-line {
  margin: 0;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}

.status {
  margin: 0;
  color: #1b6e2f;
  font-weight: 500;
}

.status.error {
  color: var(--md-sys-color-error);
}

@media (max-width: 1080px) {
  .two-col,
  .three-col,
  .draft-columns,
  .starter-grid,
  .draft-grid,
  .profile-panel .profile-layout,
  .assistant-workspace {
    grid-template-columns: 1fr;
  }

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

  .chat-input-row {
    grid-template-columns: 1fr;
  }
}
