:root {
  --grid-size: 44.8px;
  --dot-size: 1.4px;
  --grid-x: 0px;
  --grid-y: 0px;
  --grid-color: #d0d0d0;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --panel: #ffffff;
  --panel-border: #e2e2e2;
  --accent: #2f9e44;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: #ffffff;
}

button,
input,
textarea {
  font-family: inherit;
  color: inherit;
}

.topbar {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #efefef;
  background: #ffffff;
  position: relative;
  z-index: 5;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-weight: 600;
  font-size: 16px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.github-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--text);
  background: #f7f7f7;
  transition: background 0.2s ease, transform 0.2s ease;
}

.github-link:hover {
  background: #e7e7e7;
}

.github-link:active {
  transform: translateY(1px);
}

button {
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  background: #f0f0f0;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s ease, transform 0.2s ease;
}

button:hover:not(:disabled) {
  background: #e7e7e7;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.primary {
  background: #1f6feb;
  color: #ffffff;
}

.primary:hover:not(:disabled) {
  background: #1b5fc6;
}

.ghost {
  background: #f7f7f7;
}

.export {
  background: var(--accent);
  color: #ffffff;
  position: relative;
  padding-left: 34px;
}

.export::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 10px;
  height: 6px;
  border-left: 2px solid #ffffff;
  border-bottom: 2px solid #ffffff;
  transform: translateY(-60%) rotate(-45deg);
}

#viewport {
  position: relative;
  height: calc(100vh - 64px);
  overflow: hidden;
  background-color: #ffffff;
  background-image: radial-gradient(var(--grid-color) var(--dot-size), transparent var(--dot-size));
  background-size: var(--grid-size) var(--grid-size);
  background-position: var(--grid-x) var(--grid-y);
  cursor: grab;
}

#viewport.panning {
  cursor: grabbing;
}

#connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.connection {
  fill: none;
  stroke: #b5c2ce;
  stroke-width: 2;
  stroke-linecap: round;
}

#world {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  z-index: 2;
}

#nodes-layer {
  position: relative;
  width: 100%;
  height: 100%;
}

.node {
  position: absolute;
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.node--hidden {
  opacity: 0;
  transform: translateY(8px) scale(0.98);
}

.node--active {
  width: 420px;
  z-index: 10;
}

.node--complete .node-input {
  display: none;
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 8px 8px 4px;
  border-bottom: 1px solid #f0f0f0;
  background: #fafafa;
  border-radius: var(--radius) var(--radius) 0 0;
  gap: 4px;
}

.node-title {
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 13px;
  width: 100%;
  outline: none;
}

.node-actions {
  display: flex;
  gap: 6px;
}

.node-actions button {
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 8px;
}

.node-actions button.locked {
  background: #f4e5e5;
  color: #a33b3b;
}

.node-lock {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
}

.node-lock svg {
  width: 14px;
  height: 14px;
}

/* Collapse toggle button */
.node-collapse {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  flex-shrink: 0;
  visibility: hidden;
  color: var(--muted);
  transition: color 0.15s ease;
}

.node-collapse:hover {
  color: var(--fg);
}

.node-collapse svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}

.node--collapsed .node-collapse svg {
  transform: rotate(0deg);
}

.node:not(.node--collapsed) .node-collapse svg {
  transform: rotate(90deg);
}

/* Show collapse button when node has children */
.node--has-children .node-collapse {
  visibility: visible;
}

/* Hide nodes when ancestor is collapsed */
.node--ancestor-collapsed {
  display: none !important;
}

.node-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.node-status {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  border-radius: 999px;
  width: fit-content;
  background: #f0f0f0;
  color: var(--muted);
}

.status-draft {
  background: #f1f1f1;
}

.status-questioning {
  background: #fff5d6;
  color: #8a5a00;
}

.status-complete {
  background: #d8f5e4;
  color: #1e7a45;
}

.status-locked {
  background: #fbe7e7;
  color: #a13838;
}

.status-review {
  background: #e8f0fe;
  color: #1a56db;
}

.node-prompt-wrapper {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.node-prompt {
  flex: 1;
  font-size: 12px;
  line-height: 1.4;
  color: #1d1d1d;
  padding: 8px;
  border-radius: 10px;
  background: #f8f8f8;
  border: 1px solid #eeeeee;
  max-height: 110px;
  overflow: auto;
}

.node-prompt.empty {
  color: var(--muted);
  font-style: italic;
}

.lucky-button {
  flex-shrink: 0;
  font-size: 11px;
  padding: 6px 10px;
  white-space: nowrap;
  border-radius: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.lucky-button:hover {
  opacity: 0.9;
  transform: scale(1.02);
}

.node-chat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 140px;
  overflow: auto;
  padding-right: 4px;
}

.node-navigation {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.nav-button {
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 8px;
  width: 100%;
  text-align: center;
}

.nav-button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.node-status--toggle {
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.node-status--toggle:hover {
  transform: scale(1.05);
}

.node-status--toggle:active {
  transform: scale(0.98);
}

.chat-msg {
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 10px;
  background: #f6f6f6;
  line-height: 1.35;
}

.chat-msg.user {
  background: #e8f1ff;
  align-self: flex-end;
}

.chat-msg.assistant {
  background: #f5f5f5;
  align-self: flex-start;
}

.node-input {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.node-input textarea {
  resize: vertical;
  min-height: 54px;
  border-radius: 10px;
  border: 1px solid #e1e1e1;
  padding: 8px;
  font-size: 12px;
}

.node-input-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.keyboard-hint {
  font-size: 10px;
  color: var(--muted);
  margin-right: auto;
}

.node-loading {
  display: none;
  font-size: 12px;
  color: var(--muted);
}

.node--loading .node-loading {
  display: block;
}

.hint {
  position: absolute;
  bottom: 16px;
  left: 16px;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  border: 1px solid #f0f0f0;
  z-index: 3;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: 360px;
  background: #ffffff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-card h2 {
  margin: 0;
  font-size: 18px;
}

.modal-card p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.modal-card input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #dddddd;
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}
