:root {
  color-scheme: light;
  --bg-main: #f4ecd8;
  --bg-panel: #fff8e8;
  --bg-panel-soft: #fbf2df;
  --bg-sidebar: #e9ddc3;
  --bg-hover: #eadbbf;
  --bg-active: #e1cfaa;
  --bg-input: #f8efd9;
  --editor-canvas: #f7f0e2;
  --editor-paper: #fffaf0;
  --ink: #3f3426;
  --ink-soft: #756450;
  --ink-muted: #a18f7a;
  --line: #d7c7a7;
  --line-strong: #c8b48c;
  --accent: #b85f31;
  --accent-soft: rgba(184, 95, 49, 0.14);
  --accent-ink: #9c4d28;
  --teal: #3f6f70;
  --teal-soft: rgba(63, 111, 112, 0.13);
  --green: #687935;
  --warning: #aa6700;
  --danger: #a34d3f;
  --shadow: 0 10px 24px rgba(72, 55, 35, 0.07);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 320px;
  background: var(--bg-main);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 13px;
}

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

button {
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--ink);
  min-height: 28px;
  border-radius: 7px;
  cursor: pointer;
}

button:hover {
  border-color: var(--line-strong);
  background: var(--bg-hover);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-input);
  color: var(--ink);
  padding: 6px 8px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  min-height: 64px;
  resize: vertical;
  line-height: 1.5;
}

label {
  display: block;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  margin: 8px 0 4px;
}

.hidden {
  display: none !important;
}

.muted-row,
.editor-status,
.current-meta,
.evidence-item span,
.suggestion-item span,
.context-item span,
.report-row span {
  color: var(--ink-soft);
  font-size: 11.5px;
  line-height: 1.45;
}

.muted-row {
  padding: 4px 2px;
}

/* --- Shell + topbar --- */

.app-shell {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr);
}

@supports (height: 100dvh) {
  .app-shell {
    height: 100dvh;
  }
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr auto;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
  padding: 0 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.brand:hover {
  background: transparent;
  border-color: transparent;
}

.mark {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  background: var(--bg-input);
  font-size: 12px;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.brand-copy {
  min-width: 0;
  display: grid;
}

.brand-name {
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.14em;
  line-height: 1.1;
  text-transform: uppercase;
}

.brand-caption {
  margin-top: 2px;
  color: var(--ink-soft);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.mode-switch {
  flex: 0 0 auto;
  width: 232px;
  height: 28px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-input);
  padding: 2px;
}

.mode-pill {
  height: 22px;
  min-height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 800;
}

.mode-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.top-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.lang-switch {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-input);
  padding: 2px;
}

.lang-pill {
  height: 22px;
  min-height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  padding: 0 10px;
  font-size: 10.5px;
  font-weight: 800;
}

.lang-pill:hover {
  background: var(--bg-hover);
  border-color: transparent;
}

.lang-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.import-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.file-pick {
  display: none;
}

.ghost-button {
  min-height: 26px;
  padding: 0 9px;
  font-size: 10.5px;
  font-weight: 800;
  background: transparent;
}

.user-avatar {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 11px;
  font-weight: 900;
}

.icon-button {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-input);
  color: var(--ink-soft);
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.icon-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* --- Workspace grid --- */

.workspace {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 54px minmax(220px, 262px) minmax(0, 1fr) minmax(280px, var(--agent-width, 320px));
}

/* Agent mode flips the primary pane: the Agent panel becomes the wide center
   column and the editor/studio shrinks to a secondary right drawer. */
.mode-agent .workspace {
  grid-template-columns: 54px minmax(190px, 225px) minmax(0, 1fr) minmax(300px, var(--studio-width, 440px));
}

.mode-agent .rail {
  order: 1;
}

.mode-agent .tool-panel {
  order: 2;
}

.mode-agent .agent-panel {
  order: 3;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.mode-agent .editor {
  order: 4;
}

.mode-agent.studio-collapsed .editor {
  display: none;
}

.mode-onboarding .workspace {
  grid-template-columns: minmax(360px, 0.92fr) minmax(360px, 1.08fr);
}

.mode-onboarding .rail,
.mode-onboarding .tool-panel,
.mode-onboarding .editor-toolbar,
.mode-onboarding .studio-resize-handle,
.mode-onboarding .agent-resize-handle {
  display: none;
}

.mode-onboarding .editor {
  min-height: 0;
}

.mode-onboarding .agent-panel {
  display: flex;
  border-left: 1px solid var(--line);
}

.mode-onboarding.onboarding-device-mobile .workspace {
  grid-template-columns: minmax(360px, 1fr) minmax(390px, 430px);
}

.mode-onboarding.onboarding-device-mobile .agent-panel {
  width: min(100%, 390px);
  justify-self: center;
  border: 1px solid var(--line);
  box-shadow: 0 18px 48px rgba(60, 45, 28, 0.14);
}

.app-shell.resizing-agent,
.app-shell.resizing-agent * {
  user-select: none;
  cursor: col-resize;
}

/* --- Rail --- */

.rail {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border-right: 1px solid var(--line);
  background: var(--bg-sidebar);
  padding: 10px 5px;
}

.rail-button {
  width: 44px;
  height: 46px;
  min-height: 46px;
  display: grid;
  grid-template-rows: auto auto;
  gap: 2px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  padding: 5px 2px;
}

.rail-button:hover {
  background: var(--bg-hover);
  border-color: transparent;
}

.rail-icon {
  font-size: 14px;
  line-height: 1;
}

.rail-label {
  max-width: 40px;
  overflow: hidden;
  font-size: 9.5px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.rail-settings {
  margin-top: auto;
}

/* --- Left panel (file workspace / tools) --- */

.tool-panel {
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--bg-sidebar);
  padding: 8px;
}

.left-pane {
  display: block;
}

.file-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}

.file-toolbar-title {
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.file-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-mini-button {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 900;
  padding: 0;
  min-height: 0;
}

.icon-mini-button:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.icon-mini-button.accent {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.file-search {
  height: 28px;
  font-size: 12px;
}

.tree-newfile-row {
  display: flex;
  gap: 5px;
  margin-bottom: 8px;
}

.tree-newfile-row input {
  flex: 1;
  min-width: 0;
  height: 26px;
  font-size: 11px;
}

/* Agent Sessions pane (left sidebar, Agent mode) */
.sessions-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}

.sessions-head-copy {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.sessions-head-copy strong {
  font-size: 12px;
  font-weight: 900;
}

.sessions-project {
  color: var(--ink-muted);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-list {
  display: grid;
  gap: 6px;
}

.session-card {
  width: 100%;
  display: grid;
  gap: 3px;
  text-align: left;
  border: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: 8px;
  background: var(--bg-panel);
  padding: 7px 9px;
  min-height: 0;
}

.session-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.session-card.active {
  border-color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

.session-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.session-card-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
}

.session-badge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 6px;
  font-size: 9px;
  font-weight: 900;
  color: var(--ink-muted);
}

.session-summary {
  color: var(--ink-soft);
  font-size: 10.5px;
  line-height: 1.45;
}

.session-meta {
  color: var(--ink-muted);
  font-size: 9.5px;
  font-weight: 700;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  padding: 9px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.14em;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.counter {
  color: var(--accent-ink);
}

.suggestions,
.report,
.evidence-list,
.context-preview {
  display: grid;
  gap: 5px;
}

/* Compact project switcher above the tree */
.project-switch {
  padding: 0 1px;
  margin-bottom: 8px;
}

.project-switch-label {
  display: block;
  margin: 0 0 5px 2px;
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.project-switch select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 8px;
}

/* --- Flat file tree (neuro-book style): compact single-line rows --- */

.tree-panel {
  min-height: 0;
}

.tree-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 7px 5px;
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.tree {
  display: grid;
  gap: 1px;
}

.tree-item,
.tree-dir {
  width: 100%;
  display: grid;
  grid-template-columns: 11px 17px minmax(0, 1fr) auto 8px;
  gap: 5px;
  align-items: center;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  padding: 3px 7px;
  padding-left: calc(5px + var(--tree-depth, 0) * 14px);
  min-height: 26px;
}

.tree-item:hover,
.tree-dir:hover {
  background: var(--bg-hover);
}

.tree-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tree-arrow {
  color: var(--ink-muted);
  font-size: 9px;
  text-align: center;
}

.tree-icon {
  color: var(--ink-soft);
  font-size: 12px;
  text-align: center;
  opacity: 0.85;
}

.tree-name {
  min-width: 0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-dir .tree-name {
  font-weight: 800;
}

.tree-kind {
  color: var(--ink-muted);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tree-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--ink-muted);
  justify-self: center;
}

.tone-manifest {
  background: var(--ink-muted);
}
.tone-canon {
  background: var(--teal);
}
.tone-plot {
  background: var(--accent);
}
.tone-scene {
  background: #7c6bb0;
}
.tone-genui {
  background: #2f7994;
}
.tone-reference {
  background: var(--warning);
}
.tone-migration {
  background: var(--green);
}

.view-hint {
  margin: 0 0 8px;
  color: var(--ink-muted);
  font-size: 10.5px;
  line-height: 1.5;
}

/* --- Editor column --- */

.editor {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--editor-canvas);
}

.editor-toolbar {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel-soft);
  padding: 5px 10px;
}

.tab-stack {
  min-width: 0;
}

.active-tab {
  max-width: min(48vw, 640px);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-status {
  font-size: 10.5px;
}

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

.editor-scroll {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.badge-row,
.reference-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge,
.ref-chip {
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--ink-soft);
  padding: 2px 7px;
  font-size: 10.5px;
  font-weight: 700;
}

/* --- Studio dashboard --- */

.dashboard {
  width: min(100%, 980px);
  margin: 16px auto;
  padding: 0 18px 22px;
  display: grid;
  gap: 16px;
  align-content: start;
}

.onboarding-pane {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.onboarding-card {
  width: min(100%, 720px);
  display: grid;
  gap: 18px;
  border: 1px solid rgba(195, 90, 48, 0.34);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(255, 253, 247, 0.96), rgba(246, 223, 183, 0.86)),
    radial-gradient(circle at 92% 12%, rgba(63, 111, 112, 0.15), transparent 34%);
  box-shadow: 0 22px 58px rgba(60, 45, 28, 0.14);
  padding: 24px;
}

.onboarding-copy {
  display: grid;
  gap: 8px;
}

.onboarding-copy > span {
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.onboarding-copy h1 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 32px;
  font-style: italic;
  line-height: 1.08;
}

.onboarding-copy p {
  margin: 0;
  max-width: 58ch;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.55;
}

.onboarding-control {
  display: grid;
  gap: 10px;
}

.onboarding-control label {
  margin: 0;
}

.onboarding-device-switch {
  width: fit-content;
  max-width: 100%;
  min-height: 30px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-input);
  padding: 2px;
}

.onboarding-device-switch button {
  min-height: 24px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  padding: 0 12px;
  font-size: 11px;
  font-weight: 900;
}

.onboarding-device-switch button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.onboarding-primary {
  min-height: 46px;
  border-color: var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: #fffaf0;
  box-shadow: 0 12px 28px rgba(195, 90, 48, 0.24);
  font-size: 13px;
  font-weight: 900;
}

.onboarding-primary:hover:not(:disabled) {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
}

.onboarding-primary:disabled {
  cursor: not-allowed;
  opacity: 0.66;
}

.onboarding-status {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 253, 247, 0.72);
  color: var(--ink-soft);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.45;
}

.onboarding-status.running {
  border-color: rgba(63, 111, 112, 0.34);
  color: var(--teal);
}

.onboarding-current {
  display: grid;
  gap: 4px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.onboarding-current span {
  color: var(--ink-muted);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.onboarding-current strong {
  color: var(--ink);
  font-size: 16px;
}

.onboarding-current em,
.onboarding-current.empty {
  color: var(--ink-soft);
  font-size: 12px;
  font-style: normal;
}

.dash-hero {
  display: grid;
  gap: 8px;
}

.dash-hero h1 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-style: italic;
  line-height: 1.2;
}

.dash-hero p {
  margin: 0;
  max-width: 640px;
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.55;
}

.dash-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.dash-stats div {
  min-width: 84px;
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  padding: 8px 10px;
}

.dash-stats strong {
  color: var(--teal);
  font-size: 17px;
  line-height: 1;
}

.dash-stats span {
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 700;
}

.enrich-spotlight {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  border: 1px solid rgba(195, 90, 48, 0.34);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255, 253, 247, 0.96), rgba(246, 223, 183, 0.86)),
    radial-gradient(circle at 90% 16%, rgba(195, 90, 48, 0.14), transparent 32%);
  box-shadow: 0 18px 44px rgba(60, 45, 28, 0.12);
  padding: 16px 18px;
}

.enrich-spotlight-copy {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.enrich-spotlight-copy > span {
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.enrich-spotlight-copy h2 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 25px;
  font-style: italic;
  line-height: 1.15;
}

.enrich-spotlight-copy p {
  margin: 0;
  max-width: 68ch;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.55;
}

.enrich-spotlight-copy em {
  color: var(--teal);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.enrich-spotlight-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.spotlight-primary,
.spotlight-secondary {
  min-height: 38px;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 12px;
  font-weight: 900;
}

.spotlight-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fffaf0;
  box-shadow: 0 10px 24px rgba(195, 90, 48, 0.24);
}

.spotlight-primary:hover {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
}

.spotlight-secondary {
  border-color: var(--line);
  background: rgba(255, 253, 247, 0.76);
  color: var(--ink-soft);
}

.dash-group {
  display: grid;
  gap: 9px;
}

.dash-group h2 {
  margin: 0;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.dash-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 9px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 7px;
  max-height: 280px;
  overflow: auto;
  padding-right: 2px;
}

.character-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  padding: 8px;
  text-align: left;
}

.character-card:hover {
  border-color: var(--accent);
  background: #fffdf5;
}

.character-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.character-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 11px;
  font-weight: 900;
}

.character-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.character-copy strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-copy em,
.character-state {
  color: var(--ink-muted);
  font-size: 10px;
  font-style: normal;
  font-weight: 700;
}

.character-state {
  color: var(--accent-ink);
  white-space: nowrap;
}

.dash-card {
  display: grid;
  gap: 4px;
  align-content: start;
  text-align: left;
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--editor-paper);
  box-shadow: var(--shadow);
  padding: 11px;
}

.dash-card:hover {
  border-color: var(--accent);
  background: #fffdf5;
}

.dash-card strong {
  color: var(--ink);
  font-size: 12.5px;
  line-height: 1.3;
}

.dash-card span {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
}

.dash-cta {
  margin-top: 2px;
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 800;
  font-style: normal;
  letter-spacing: 0.05em;
}

/* --- Markdown file editor --- */

.file-editor {
  min-height: 0;
  height: calc(100% - 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  width: min(100%, 920px);
  margin: 12px auto;
  padding: 0 16px 16px;
}

.file-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--ink);
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 700;
}

.meta-chip em {
  color: var(--ink-muted);
  font-size: 9.5px;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.meta-chip.muted {
  color: var(--ink-muted);
}

.file-body {
  height: 100%;
  min-height: 0;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--editor-paper);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  color: var(--ink);
  font-family: "SFMono-Regular", ui-monospace, Consolas, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.65;
}

.file-body:read-only {
  color: var(--ink-soft);
  background: var(--bg-panel-soft);
}

.genui-preview {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

/* --- Agent panel: head / body / composer (Cursor-like 3 sections) --- */

.agent-panel {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: #f3e7cf;
}

.app-shell:not(.mode-agent).agent-collapsed .agent-panel {
  display: none;
}

.app-shell.mode-onboarding.agent-collapsed .agent-panel {
  display: flex;
}

.agent-resize-handle,
.studio-resize-handle {
  display: none;
  position: absolute;
  top: 0;
  left: -3px;
  z-index: 30;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.agent-resize-handle::before,
.studio-resize-handle::before {
  content: "";
  position: absolute;
  top: 0;
  left: 3px;
  width: 2px;
  height: 100%;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.agent-resize-handle:hover::before,
.studio-resize-handle:hover::before,
.app-shell.resizing-agent .agent-resize-handle::before,
.app-shell.resizing-agent .studio-resize-handle::before {
  opacity: 1;
}

.app-shell.mode-ide:not(.agent-collapsed) .agent-resize-handle {
  display: block;
}

.app-shell.mode-agent:not(.studio-collapsed) .studio-resize-handle {
  display: block;
}

.agent-head {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel-soft);
  padding: 7px 10px;
}

.avatar-preview {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--teal-soft);
  background-position: center;
  background-size: cover;
  display: grid;
  place-items: center;
  color: var(--teal);
  font-size: 10px;
  font-weight: 900;
}

.agent-head-copy {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
  overflow: hidden;
}

.current-title {
  flex: 0 1 auto;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-style: italic;
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current-meta {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 10.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Cursor-style composer pills: mode / profile / model dropdowns */
.composer-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.composer-pill {
  flex: 0 1 auto;
  min-width: 0;
  width: auto;
  max-width: 132px;
  min-height: 22px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 800;
  color: var(--ink-soft);
  text-overflow: ellipsis;
}

.composer-pill:focus-visible {
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* Director action cards inside assistant bubbles */
.agent-action-list {
  display: grid;
  gap: 5px;
  margin-top: 4px;
}

.agent-action-card {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-panel);
  padding: 6px 8px;
}

.agent-action-card.applied {
  border-color: rgba(104, 121, 53, 0.42);
  background: rgba(104, 121, 53, 0.08);
}

.agent-action-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.agent-action-head strong {
  color: var(--ink);
  font-size: 11px;
  line-height: 1.3;
}

.agent-action-card > span {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.agent-apply-btn {
  flex: 0 0 auto;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* Parallel sub-agent run chips (leader dispatch trace) */
.agent-runs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 2px 0;
}

.agent-run-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1;
  padding: 4px 8px;
  white-space: nowrap;
}

.agent-run-chip.blocked {
  border-color: rgba(176, 82, 54, 0.5);
  color: rgba(176, 82, 54, 0.9);
}

.agent-mode-badge {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  font-size: 9px;
  font-weight: 600;
  color: var(--ink-soft);
  vertical-align: 1px;
}

/* Plan mode card: dispatch steps + run button */
.plan-card {
  border-color: rgba(104, 121, 53, 0.35);
}

.plan-steps {
  margin: 2px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.plan-steps li {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.4;
}

.plan-steps li strong {
  color: var(--ink);
  font-weight: 600;
}

.plan-step-tool {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  margin: 0 4px;
  font-size: 10px;
}

.plan-step-note {
  display: block;
  font-size: 10px;
  color: var(--ink-faint);
}

.plan-execute-btn {
  flex: 0 0 auto;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.agent-applied-link {
  width: fit-content;
  max-width: 100%;
  min-height: 0;
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 0;
  font-size: 10.5px;
  font-weight: 800;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-applied-link:hover {
  background: transparent;
  border-color: transparent;
  text-decoration: underline;
}

/* Middle: message stream (flex-1). Context strip collapses like Cursor's
   "current file" pill; nothing lives below the composer. */
.agent-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 10px;
}

.context-strip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-panel-soft);
  overflow: hidden;
}

.context-strip > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  padding: 6px 9px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.context-strip > summary::-webkit-details-marker {
  display: none;
}

.context-strip > summary::before {
  content: "▸";
  color: var(--ink-muted);
  margin-right: 4px;
}

.context-strip[open] > summary::before {
  content: "▾";
}

.context-strip-hint {
  flex: 1;
  min-width: 0;
  text-align: right;
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-strip-body {
  display: grid;
  gap: 6px;
  padding: 0 9px 9px;
}

.context-strip-body .panel-subtitle {
  margin: 2px 0 0;
}

.agent-context-body {
  display: grid;
  gap: 5px;
}

.agent-context-card {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-input);
  padding: 7px 8px;
}

.agent-context-kind {
  color: var(--accent-ink);
  font-size: 9.5px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.agent-context-card strong {
  color: var(--ink);
  font-size: 12px;
  line-height: 1.25;
}

.agent-context-card span {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
}

.chat-log {
  flex: 0 0 auto;
  display: grid;
  gap: 6px;
  min-width: 0;
  min-height: 90px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fffdf7;
  padding: 6px;
}

.chat-message {
  display: grid;
  gap: 3px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
}

.chat-message.user {
  margin-left: 16px;
  background: var(--teal-soft);
}

.chat-message.assistant {
  margin-right: 16px;
  background: var(--bg-input);
}

.chat-message strong {
  color: var(--ink);
  font-size: 10.5px;
}

.chat-message span {
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.genui-inline-widget {
  position: relative;
  z-index: 0;
  contain: layout paint;
  isolation: isolate;
  margin-top: 7px;
  border: 1px solid rgba(60, 45, 28, 0.22);
  border-radius: 9px;
  background: #13110f;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.genui-inline-frame {
  display: block;
  width: 100%;
  height: clamp(220px, 35vh, 300px);
  border: 0;
  background: #13110f;
}

.test-report {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: grid;
  gap: 5px;
}

.check-row {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-input);
  padding: 6px 8px;
}

.check-row.pass {
  border-color: rgba(104, 121, 53, 0.42);
  background: rgba(104, 121, 53, 0.12);
}

.check-row.review {
  border-color: rgba(170, 103, 0, 0.36);
  background: rgba(170, 103, 0, 0.1);
}

.check-row strong {
  color: var(--ink);
  font-size: 11px;
}

.check-row span {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.4;
}

/* Bottom: composer pinned last, nothing after it. */
.composer {
  flex: 0 0 auto;
  display: grid;
  gap: 6px;
  border-top: 1px solid var(--line);
  background: var(--bg-panel-soft);
  padding: 8px 10px;
}

.playtest-status {
  color: var(--teal);
  font-size: 10.5px;
  line-height: 1.35;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-input {
  min-height: 44px;
  max-height: 120px;
  margin: 0;
  font-size: 12px;
}

/* Status text on the left, quick-action chips on the right */
.composer-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

.composer-status-row .playtest-status {
  flex: 1 1 auto;
  min-width: 0;
}

/* Bottom row: pills grow/shrink on the left, send button pinned right */
.composer-bar {
  display: flex;
  align-items: center;
  gap: 5px;
}

.composer-bar .composer-pills {
  flex: 1 1 auto;
}

.composer-bar .send-button {
  flex: 0 0 auto;
  margin-left: auto;
}

.quick-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
}

.chip-button {
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 800;
}

.chip-button:hover {
  border-color: var(--accent);
  background: #fffdf5;
  color: var(--ink);
}

.mini-button {
  min-height: 22px;
  padding: 0 9px;
  font-size: 10px;
  font-weight: 900;
}

.send-button {
  min-height: 22px;
  padding: 0 12px;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 10.5px;
  font-weight: 900;
}

.send-button:hover {
  background: var(--accent);
  color: #fff8e8;
}

.wide-button {
  width: 100%;
  min-height: 26px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 800;
}

/* --- Suggestions (shared: dashboard + agent strip) --- */

.suggestion-actions {
  display: grid;
  gap: 5px;
}

.suggestion-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-input);
  padding: 6px 8px;
}

.suggestion-action:hover {
  border-color: var(--accent);
  background: #fffdf5;
}

.suggestion-action span {
  color: var(--ink);
  font-size: 11.5px;
  line-height: 1.4;
}

.suggestion-action em {
  color: var(--accent-ink);
  font-size: 10.5px;
  font-weight: 800;
  font-style: normal;
  white-space: nowrap;
}

/* --- Tool groups (left tools pane) --- */

.tool-group {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  overflow: hidden;
}

.tool-group > summary {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tool-group > summary::-webkit-details-marker {
  display: none;
}

.tool-group > summary::before {
  content: "▸";
  color: var(--ink-muted);
}

.tool-group[open] > summary::before {
  content: "▾";
}

.tool-name {
  flex: 1;
}

.tool-count {
  color: var(--accent-ink);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0;
}

.tool-group-body {
  display: grid;
  gap: 7px;
  padding: 0 10px 10px;
}

.tool-group-body .panel-subtitle,
.tool-group-body .view-hint {
  margin: 0;
}

.tool-group-body label {
  margin: 4px 0 0;
}

.panel-subtitle {
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 12px 0 6px;
}

/* --- Shared cards (pipeline, evidence, context, ai) --- */

.pipeline {
  display: grid;
  gap: 6px;
}

.pipeline-stage {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-input);
  padding: 7px 8px;
}

.pipeline-stage.ready {
  border-color: rgba(104, 121, 53, 0.42);
  background: rgba(104, 121, 53, 0.1);
}

.pipeline-index {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 900;
}

.pipeline-stage.ready .pipeline-index {
  border-color: var(--green);
  color: var(--green);
}

.pipeline-body {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.pipeline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pipeline-head strong {
  color: var(--ink);
  font-size: 11.5px;
}

.pipeline-status {
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pipeline-stage.ready .pipeline-status {
  color: var(--green);
}

.pipeline-body span {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.4;
}

.evidence-item,
.suggestion-item,
.context-item,
.report-row,
.warning-row {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-input);
  padding: 6px 8px;
}

.evidence-item strong,
.suggestion-item strong,
.context-item strong,
.report-row strong {
  color: var(--ink);
  font-size: 11.5px;
  line-height: 1.25;
}

.suggestion-type {
  color: var(--accent-ink);
  font-size: 9.5px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.context-layer {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-input);
  overflow: hidden;
}

.context-layer summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 850;
  padding: 6px 8px;
}

.context-layer summary span {
  color: var(--teal);
}

.context-item {
  margin: 0 6px 6px;
  background: var(--bg-panel);
}

.context-item code {
  color: var(--teal);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10.5px;
  overflow-wrap: anywhere;
}

.warning-row {
  border-color: rgba(170, 103, 0, 0.36);
  background: rgba(170, 103, 0, 0.1);
  color: var(--warning);
  font-size: 11.5px;
}

.ai-result,
.preview {
  margin-top: 3px;
  min-height: 44px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf7;
  color: #4f5f63;
  padding: 8px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
}

/* --- Settings dialog --- */

.settings-dialog {
  width: min(94vw, 880px);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--bg-panel);
  color: var(--ink);
  padding: 0;
  box-shadow: 0 24px 60px rgba(72, 55, 35, 0.25);
}

.settings-dialog::backdrop {
  background: rgba(63, 52, 38, 0.35);
}

/* Diff confirmation dialog (Cursor-style apply review) */
.diff-dialog {
  width: min(94vw, 860px);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--bg-panel);
  color: var(--ink);
  padding: 0;
  box-shadow: 0 24px 60px rgba(72, 55, 35, 0.25);
}

.diff-dialog::backdrop {
  background: rgba(63, 52, 38, 0.35);
}

.diff-dialog-inner {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: min(80vh, 620px);
}

.diff-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.diff-head-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.diff-head-main > strong {
  font-size: 13px;
}

.diff-file-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11.5px;
}

.diff-path {
  font-family: var(--mono, ui-monospace, monospace);
  color: var(--ink-soft);
  word-break: break-all;
}

.diff-type-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg-panel-soft);
}

.diff-stats {
  font-weight: 700;
  font-size: 11.5px;
}

.diff-stat-add {
  color: #3e7d4c;
}

.diff-stat-del {
  color: #b05236;
}

.diff-body {
  overflow: auto;
  background: var(--bg-input);
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 11.5px;
  line-height: 1.55;
  padding: 6px 0;
}

.diff-line {
  display: grid;
  grid-template-columns: 42px 42px 18px minmax(0, 1fr);
  align-items: baseline;
}

.diff-gutter {
  text-align: right;
  padding-right: 8px;
  color: var(--ink-faint, #9a8d7a);
  font-size: 10.5px;
  user-select: none;
}

.diff-sign {
  text-align: center;
  user-select: none;
  color: var(--ink-soft);
}

.diff-text {
  white-space: pre-wrap;
  word-break: break-word;
  padding-right: 12px;
}

.diff-line.add {
  background: rgba(90, 141, 96, 0.16);
}

.diff-line.add .diff-sign {
  color: #3e7d4c;
  font-weight: 700;
}

.diff-line.del {
  background: rgba(176, 82, 54, 0.14);
}

.diff-line.del .diff-sign {
  color: #b05236;
  font-weight: 700;
}

.diff-line.del .diff-text {
  text-decoration: line-through;
  text-decoration-color: rgba(176, 82, 54, 0.45);
}

.diff-line.gap {
  color: var(--ink-soft);
  background: var(--bg-panel-soft);
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
  margin: 4px 0;
  font-size: 10.5px;
}

.diff-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}

.diff-foot button {
  white-space: nowrap;
}

.diff-foot .wide-button {
  flex: 0 0 auto;
  width: auto;
  padding: 8px 22px;
}

.diff-foot .settings-status {
  margin-right: auto;
}

.settings-form {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  margin: 0;
  height: min(82vh, 640px);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel-soft);
  padding: 10px 14px;
}

.settings-head strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  font-style: italic;
}

.settings-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-right: 1px solid var(--line);
  background: var(--bg-sidebar);
  padding: 10px 8px;
  overflow: auto;
}

.settings-nav-item {
  min-height: 28px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 800;
}

.settings-nav-item:hover {
  background: var(--bg-hover);
  border-color: transparent;
}

.settings-nav-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.settings-content {
  min-height: 0;
  overflow: auto;
  padding: 12px 16px 16px;
}

.settings-pane .panel-subtitle {
  margin: 0 0 4px;
}

.settings-pane .panel-subtitle + .view-hint {
  margin-bottom: 10px;
}

.settings-provider-grid {
  display: grid;
  grid-template-columns: minmax(160px, 200px) minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.settings-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 10px 0 6px;
}

.settings-provider-list {
  display: grid;
  gap: 5px;
  align-content: start;
}

.settings-provider-item {
  display: grid;
  gap: 2px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-input);
  padding: 6px 8px;
  min-height: 0;
}

.settings-provider-item strong {
  color: var(--ink);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-provider-item span {
  color: var(--ink-soft);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-provider-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.settings-provider-form {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-panel-soft);
  padding: 10px 12px 12px;
}

.settings-field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

/* Profile editor: tool whitelist checkboxes + system prompt textarea */
.profile-tool-checks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-input);
  padding: 8px 10px;
}

.tool-check {
  font-size: 11px;
}

#profileFieldPrompt {
  min-height: 76px;
  resize: vertical;
  font-size: 11.5px;
  line-height: 1.5;
}

/* Role-specific prompt layering fields (style/persona presets, preferences) */
.profile-prompt-config {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-input);
  padding: 8px 10px 10px;
  margin: 6px 0 2px;
}

.prompt-config-field > label {
  display: block;
  margin-bottom: 3px;
}

.prompt-config-field textarea {
  resize: vertical;
  font-size: 11.5px;
  line-height: 1.5;
}

.prompt-config-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.prompt-config-radios .settings-check {
  margin: 0;
  font-size: 11.5px;
}

.prompt-config-radios input[type='radio'] {
  width: auto;
}

/* Presets library pane */
.preset-kind-tabs {
  display: flex;
  gap: 6px;
  margin: 10px 0;
}

.preset-kind-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--ink-soft);
  font-size: 12px;
  padding: 5px 12px;
  cursor: pointer;
}

.preset-kind-tab.active {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--bg-panel-soft);
}

.preset-source-badge {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  margin-left: 6px;
  color: var(--ink-soft);
  vertical-align: 1px;
}

.preset-source-badge.user {
  border-color: rgba(90, 141, 96, 0.55);
  color: var(--ok, #5a8d60);
}

#presetFieldBody {
  min-height: 220px;
  resize: vertical;
  font-size: 11.5px;
  line-height: 1.55;
}

#presetForm .settings-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

#presetForm .settings-actions .settings-status {
  margin-right: auto;
}

.settings-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin: 8px 0 0;
}

.settings-check input[type='checkbox'] {
  width: auto;
}

button.danger {
  border-color: rgba(163, 77, 63, 0.5);
  color: var(--danger);
}

button.danger:hover {
  border-color: var(--danger);
  background: rgba(163, 77, 63, 0.1);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.settings-test-result,
.settings-key-status,
.settings-status {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.4;
}

.settings-key-status {
  margin-top: 4px;
}

.settings-lang {
  width: fit-content;
}

.settings-foot {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}

.settings-foot .wide-button {
  width: auto;
  padding: 0 16px;
}

/* --- Chinese typography tweaks --- */

:root[lang^="zh"] .panel-title,
:root[lang^="zh"] .file-toolbar-title,
:root[lang^="zh"] .panel-subtitle,
:root[lang^="zh"] .pipeline-status,
:root[lang^="zh"] .dash-group h2,
:root[lang^="zh"] .tool-group > summary,
:root[lang^="zh"] .context-strip > summary,
:root[lang^="zh"] .agent-context-kind,
:root[lang^="zh"] .meta-chip em,
:root[lang^="zh"] .suggestion-type {
  letter-spacing: 0.02em;
  text-transform: none;
}

:root[lang^="zh"] .brand-name {
  letter-spacing: 0.08em;
}

/* --- Responsive --- */

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 50px minmax(200px, 235px) minmax(340px, 1fr) var(--agent-width, 300px);
  }

  .mode-agent .workspace {
    grid-template-columns: 50px minmax(200px, 235px) minmax(340px, 1fr) minmax(280px, 320px);
  }
}

@media (max-width: 1024px) {
  .top-center {
    justify-content: flex-start;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-rows: auto 1fr;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 8px 10px;
  }

  .top-center {
    grid-column: 1 / -1;
    order: 3;
    justify-content: center;
  }

  .import-controls {
    display: none;
  }

  .workspace,
  .mode-agent .workspace {
    grid-template-columns: 1fr;
  }

  .app-shell.chat-playtest .workspace {
    display: block;
    min-height: 0;
    overflow: hidden;
  }

  .app-shell.chat-playtest .rail,
  .app-shell.chat-playtest .tool-panel,
  .app-shell.chat-playtest .editor {
    display: none;
  }

  .app-shell.chat-playtest .agent-panel {
    height: 100%;
    min-height: 0;
    border-top: 0;
  }

  .app-shell.chat-playtest #playtestReport {
    display: none;
  }

  .app-shell.mode-onboarding.chat-playtest .workspace {
    display: grid;
    grid-template-rows: auto minmax(520px, 1fr);
    min-height: 0;
    overflow: auto;
  }

  .app-shell.mode-onboarding.chat-playtest .editor {
    display: grid;
    min-height: auto;
  }

  .mode-onboarding .workspace {
    grid-template-columns: 1fr;
  }

  .mode-onboarding.onboarding-device-mobile .workspace {
    grid-template-columns: 1fr;
  }

  .mode-onboarding.onboarding-device-mobile .agent-panel {
    width: 100%;
    justify-self: stretch;
    box-shadow: none;
  }

  .mode-onboarding .onboarding-pane {
    min-height: auto;
    padding: 14px;
  }

  .mode-onboarding .agent-panel {
    min-height: 520px;
  }

  .rail {
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rail-settings {
    margin-top: 0;
    margin-left: auto;
  }

  .tool-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 40vh;
  }

  .editor {
    min-height: 60vh;
  }

  .agent-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .enrich-spotlight {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .enrich-spotlight-actions {
    justify-content: flex-start;
  }

  .spotlight-primary,
  .spotlight-secondary {
    flex: 1 1 150px;
  }

  .agent-head {
    grid-template-columns: 36px minmax(0, 1fr) auto;
    padding: 10px 12px;
  }

  .avatar-preview {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 12px;
  }

  .agent-head-copy {
    display: grid;
    gap: 2px;
  }

  .current-title {
    font-size: 17px;
  }

  .current-meta {
    font-size: 12px;
  }

  .agent-body {
    padding: 8px;
    gap: 8px;
  }

  .chat-log {
    gap: 8px;
    border-radius: 10px;
    padding: 7px;
  }

  .chat-message {
    gap: 5px;
    padding: 8px 9px;
  }

  .chat-message.user,
  .chat-message.assistant {
    margin-left: 0;
    margin-right: 0;
  }

  .chat-message span,
  .check-row span {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .test-report {
    gap: 6px;
  }

  .test-report .badge-row {
    gap: 4px;
  }

  .test-report .badge {
    max-width: 100%;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .check-row {
    background: rgba(255, 253, 247, 0.92);
    padding: 7px 9px;
  }

  .genui-inline-frame {
    height: min(260px, 42vh);
  }

  .app-shell.mode-ide:not(.agent-collapsed) .agent-resize-handle,
  .app-shell.mode-agent:not(.studio-collapsed) .studio-resize-handle {
    display: none;
  }

  .mode-agent .workspace,
  .mode-agent.studio-collapsed .workspace {
    grid-template-columns: 1fr;
  }

  .mode-agent .rail,
  .mode-agent .tool-panel,
  .mode-agent .agent-panel,
  .mode-agent .editor {
    order: 0;
  }

  .file-editor {
    margin: 10px auto;
  }
}
