:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #687076;
  --line: #d9dee3;
  --panel: #f7f8f5;
  --paper: #fffdf8;
  --accent: #2f6f63;
  --accent-dark: #214f47;
  --warm: #b85b38;
  --blue: #2f5f85;
  --gold: #8d6b1f;
  --shadow: 0 12px 30px rgba(31, 35, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #ecefe9;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  border-radius: 6px;
}

button:hover {
  border-color: #9ca8a3;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: wait;
  opacity: 0.58;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(236, 239, 233, 0.94);
}

.login-gate[hidden] {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid #cfd8d3;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.login-card .brand-mark {
  width: 48px;
  height: 48px;
}

.login-copy,
.login-message {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  color: #42474c;
  font-size: 13px;
  font-weight: 600;
}

.login-form input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 8px;
  align-items: end;
}

.login-form button {
  min-height: 38px;
  padding: 0 12px;
}

.auth-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid #dfe5e0;
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.auth-strip button {
  min-height: 28px;
  padding: 0 8px;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #fbfaf4;
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
}

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

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

.nav-item {
  height: 38px;
  text-align: left;
  padding: 0 12px;
  background: transparent;
}

.nav-item.active {
  background: #e7eee9;
  border-color: #b6c9c1;
  color: var(--accent-dark);
  font-weight: 600;
}

.compact-panel {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: grid;
  gap: 12px;
}

.panel-row,
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #42474c;
  font-size: 14px;
}

.panel-title {
  color: #42474c;
  font-size: 14px;
  font-weight: 600;
}

.book-library,
.progress-summary {
  display: grid;
  gap: 8px;
}

.book-item {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid #e2e4df;
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
}

.book-item.active {
  border-color: #b6c9c1;
  background: #eef5f1;
}

.book-title {
  font-weight: 600;
  color: var(--accent-dark);
}

.book-title-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent-dark);
  text-align: left;
  font-weight: 600;
}

.book-path {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-actions {
  display: grid;
  gap: 6px;
}

.book-artifact-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-top: 5px;
}

.book-artifact-button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.progress-card {
  display: grid;
  gap: 8px;
}

.progress-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.progress-stat {
  border: 1px solid #e2e4df;
  border-radius: 6px;
  background: #fff;
  padding: 8px;
}

.progress-stat strong {
  display: block;
  color: var(--accent-dark);
  font-size: 16px;
}

.progress-stat span {
  color: var(--muted);
  font-size: 12px;
}

.panel-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.side-artifacts {
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow: auto;
}

.chapter-group {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid #e2e4df;
  border-radius: 6px;
  background: #fff;
}

.chapter-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
}

.chapter-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.chapter-badge {
  border-radius: 4px;
  background: #edf0ec;
  color: #55605b;
  padding: 2px 5px;
  font-size: 11px;
}

.chapter-badge.done {
  background: #e0eee8;
  color: var(--accent-dark);
}

.chapter-files {
  display: grid;
  gap: 4px;
}

.side-artifact {
  min-height: 32px;
  padding: 7px 9px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.wide-button {
  min-height: 34px;
  width: 100%;
}

.panel-row input {
  width: 74px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: #f7f8f5;
  border-bottom: 1px solid var(--line);
}

.topbar h2 {
  font-size: 25px;
  margin-top: 4px;
}

.editor-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.actions button,
.command-zone button,
#clearLogBtn {
  min-height: 36px;
  padding: 0 12px;
}

.next-step-panel {
  margin: 16px 24px 0;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid #bfd0c8;
  border-radius: 8px;
  background: #eef6f2;
}

.next-step-panel h3 {
  margin-top: 4px;
  font-size: 19px;
}

.next-step-panel p:last-child {
  margin-top: 5px;
  color: #46524d;
  font-size: 14px;
  line-height: 1.45;
}

.next-step-panel button {
  min-width: 118px;
}

.command-zone {
  display: grid;
  gap: 12px;
  padding: 12px 24px 0;
}

.section-heading h3 {
  margin-top: 3px;
  font-size: 17px;
}

.request-card {
  display: grid;
  gap: 7px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.request-card label {
  color: #42474c;
  font-size: 13px;
  font-weight: 600;
}

.request-card input {
  height: 38px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
}

.range-console {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #cfd8d3;
  border-radius: 8px;
  background: #fbfcf9;
}

.range-console h3 {
  margin-top: 3px;
  font-size: 17px;
}

.range-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(100px, 150px)) auto;
  gap: 10px;
  align-items: end;
}

.range-grid label {
  display: grid;
  gap: 6px;
  color: #42474c;
  font-size: 13px;
  font-weight: 600;
}

.range-grid input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
}

.range-preview {
  padding: 10px 12px;
  border: 1px solid #e1e6e2;
  border-radius: 6px;
  background: #ffffff;
  color: #46524d;
  font-size: 13px;
  line-height: 1.5;
}

.command-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.command-card {
  display: grid;
  align-content: space-between;
  gap: 14px;
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.command-card.featured {
  border-color: #aac2b8;
  background: #f4faf7;
}

.command-card h3 {
  margin-top: 6px;
  font-size: 16px;
}

.command-card p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.command-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 22px;
  border-radius: 5px;
  background: #edf0ec;
  color: #4d5652;
  font-size: 12px;
  font-weight: 700;
}

.command-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.command-zone button.primary,
.next-step-panel button.primary,
.confirm-card button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(32, 33, 36, 0.36);
}

.confirm-dialog[hidden] {
  display: none;
}

.confirm-card {
  width: min(560px, 100%);
  display: grid;
  gap: 14px;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid #c8d3cf;
  background: #fffdf8;
  box-shadow: var(--shadow);
}

.confirm-card h3 {
  font-size: 20px;
}

.confirm-body {
  display: grid;
  gap: 8px;
  color: #42474c;
  font-size: 14px;
}

.confirm-body div,
.confirm-warning {
  padding: 9px 10px;
  border-radius: 6px;
  background: #f3f5f0;
}

.confirm-warning {
  color: #6b4f17;
  background: #fff6dc;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.run-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  border-bottom: 1px solid #c9d7d1;
  background: #eaf3ef;
  color: var(--accent-dark);
  font-size: 14px;
}

.run-status-copy {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 7px;
}

.run-status[hidden] {
  display: none;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: #d1ded8;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #b8cbc3;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.content-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px 24px 24px;
}

.editor-pane,
.output-pane {
  min-height: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.editor-pane {
  overflow: hidden;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 520px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 22px;
  background: transparent;
  color: #24272a;
  line-height: 1.7;
  font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
  font-size: 15px;
}

.workspace-meta {
  display: grid;
  gap: 8px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 9px;
  border: 1px solid #e2e4df;
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
}

.meta-row span:first-child {
  color: var(--muted);
}

.meta-row strong {
  color: var(--ink);
}

.output-pane {
  padding: 16px;
  display: grid;
  grid-template-rows: auto minmax(210px, 1fr) auto;
  gap: 12px;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.output-header h3,
.file-list h3 {
  font-size: 15px;
}

pre {
  margin: 0;
  min-height: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #f5f5f0;
  font-size: 13px;
  line-height: 1.5;
}

.file-list {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  gap: 10px;
}

.chapter-workbench {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #d7dfda;
  border-radius: 8px;
  background: #fbfcf9;
}

.chapter-workbench h3 {
  margin-top: 3px;
  font-size: 16px;
}

.chapter-workbench-status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chapter-status-chip {
  padding: 4px 7px;
  border-radius: 5px;
  background: #edf0ec;
  color: #59625e;
  font-size: 12px;
}

.chapter-status-chip.done {
  background: #e0eee8;
  color: var(--accent-dark);
  font-weight: 600;
}

.chapter-workbench-files,
.chapter-workbench-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chapter-workbench-files button,
.chapter-workbench-actions button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

.chapter-workbench-actions button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#artifactList {
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
}

.artifact {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #e2e4df;
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
}

.artifact span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .command-strip,
  .command-cards,
  .range-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .next-step-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .output-pane {
    min-height: 420px;
  }
}
