:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --border: #d6dce8;
  --accent: #1f4e79;
  --text: #102a43;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.toolbar .title {
  font-size: 18px;
  font-weight: 700;
}

.toolbar .version {
  margin-left: auto;
  margin-right: 16px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent);
  background: #f2f7ff;
  font-size: 13px;
  font-weight: 700;
}

.actions button {
  margin-left: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
}

.actions button#clearBtn {
  background: #6b7280;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr 260px;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 140px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
}

.subheading {
  margin-top: 14px;
  margin-bottom: 8px;
  font-size: 14px;
  color: #52606d;
}

.editor textarea {
  width: 100%;
  height: 260px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
}

.inspector textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.4;
  outline: none;
}

.console {
  margin: 0 12px 12px;
  height: 160px;
}

.trace {
  margin: 0 12px 12px;
  min-height: 120px;
}

.trace pre {
  margin-bottom: 10px;
}

.story-board {
  margin: 8px 0 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #eef4ff 100%);
}

#storyCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 75vh;
  border-radius: 10px;
  background: linear-gradient(180deg, #fefefe 0%, #e8f1ff 100%);
}

#storyCanvas[hidden] {
  display: none;
}

#storyVideo {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 75vh;
  border-radius: 10px;
  background: #000;
  object-fit: contain;
}

#storyVideo[hidden] {
  display: none;
}

.story-progress {
  position: relative;
  margin-top: 8px;
  height: 24px;
  border-radius: 8px;
  background: #e2e8f0;
  border: 1px solid var(--border);
  overflow: hidden;
}

.story-progress[hidden] {
  display: none;
}

.story-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #1f4e79, #3b82f6);
  transition: width 0.2s ease;
}

.story-progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #102a43;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.story-caption {
  margin-top: 8px;
  font-size: 13px;
  color: #52606d;
}

.source-view {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfe;
  min-height: 180px;
  max-height: 240px;
  overflow: auto;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre;
}

.source-view .line {
  display: block;
  padding: 0 6px;
  border-radius: 6px;
}

.source-view .line.active {
  background: #dbeafe;
  color: #102a43;
}

.step-status {
  margin-bottom: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  color: #334e68;
  font-size: 13px;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.tree .node {
  padding: 6px 0 6px 8px;
  border-left: 2px solid #cfd8e3;
  margin-left: 4px;
}

.tree .kind {
  font-weight: 700;
}

.tree .name {
  color: var(--accent);
}
