:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #171a21;
  --muted: #5b6474;
  --border: #d5d9e2;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --accent-soft: #e4ecff;
  --ok: #15803d;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --warn-soft: #fff4d6;
  --warn-border: #e2b93b;
  --sidebar-w: 280px;
  --radius: 8px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #181c25;
    --surface-2: #222835;
    --text: #e8ebf1;
    --muted: #9aa4b6;
    --border: #323a4b;
    --accent: #7aa2ff;
    --accent-text: #0b1020;
    --accent-soft: #1d2a4d;
    --ok: #4ade80;
    --bad: #ff8a80;
    --bad-soft: #3a1a18;
    --warn-soft: #33290d;
    --warn-border: #8a6d12;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 0.25rem; overflow-wrap: anywhere; }
h2, h3 { font-size: 1rem; margin: 0; }
p { margin: 0.5rem 0; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 1.5rem 0 0.5rem;
  display: block;
}

/* ---- layout ---- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; padding: 1.5rem 2rem 4rem; max-width: 60rem; }
.solo { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.topbar { display: none; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; padding: 0.25rem 0.5rem; }
.sidebar .label { margin: 1.25rem 0.5rem 0.4rem; }
.project-list { list-style: none; margin: 0; padding: 0; }
.project-link {
  display: block;
  padding: 0.6rem 0.65rem;
  min-height: 44px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.project-link:hover { background: var(--surface-2); }
.project-link.active { border-color: var(--accent); background: var(--accent-soft); }
.project-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.project-status { display: block; font-size: 0.8rem; color: var(--muted); }
.project-list.built .project-link:not(.active) { opacity: 0.8; }
.sidebar .btn.block { margin-top: 1rem; }
.sidebar-foot {
  margin-top: auto;
  padding-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}
.sidebar-foot a, .linklike { min-height: 44px; display: inline-flex; align-items: center; padding: 0 0.5rem; }
.linklike { background: none; border: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 15; }

/* ---- controls ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { font-size: 0.875rem; padding: 0.35rem 0.75rem; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type="text"], input[type="password"] { min-height: 44px; }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.875rem; resize: vertical; }
label { display: block; margin-top: 0.75rem; }

.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-top: 0.75rem; }
.row form { margin: 0; }
.stack { margin-top: 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-top: 1rem;
}
.login { width: 100%; max-width: 22rem; }
.login .btn { width: 100%; margin-top: 1rem; }
.crumb { margin: 0 0 0.5rem; font-size: 0.9rem; }

.notice, .error, .banner {
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  margin: 0.75rem 0;
}
.notice, .banner { background: var(--warn-soft); border: 1px solid var(--warn-border); }
.error { background: var(--bad-soft); border: 1px solid var(--bad); color: var(--text); }
.notice ul, .error ul { margin: 0.25rem 0; padding-left: 1.2rem; }

/* ---- project screen ---- */
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 0.5rem; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; }

.prompt, .note {
  margin: 0;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: 0.875rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 22rem;
  overflow-y: auto;
}
pre.note { max-height: 12rem; background: var(--surface-2); }
span.note { padding: 0; border: 0; background: none; max-height: none; }
details { margin: 0.5rem 0; }
summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--accent); }
details .prompt { margin-top: 0.25rem; }

.copy-status { font-size: 0.875rem; color: var(--ok); font-weight: 600; }
.copy-status.bad { color: var(--bad); }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li label {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin: 0;
  padding: 0.6rem 0.25rem;
  min-height: 44px;
  cursor: pointer;
}
.checklist input[type="checkbox"] { width: 1.25rem; height: 1.25rem; margin-top: 0.15rem; flex: none; accent-color: var(--accent); }
.checklist input:checked + span { color: var(--muted); text-decoration: line-through; }
.checklist.plain li { padding: 0.2rem 0; color: var(--muted); }
.actions { margin-top: 1.25rem; }

.step-list { list-style: none; margin: 0; padding: 0; }
.step a {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.6rem 0.5rem;
  min-height: 44px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.step a:hover { background: var(--surface-2); }
.step .mark { width: 1.2rem; flex: none; text-align: center; }
.step-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.step-state { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.step.is-done a, .step.is-skipped a { color: var(--muted); }
.step.is-done .mark { color: var(--ok); }
.step.is-current a { font-weight: 700; border: 2px solid var(--accent); background: var(--accent-soft); }
.group-label {
  margin: 1rem 0 0.25rem;
  padding: 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}
.steps .row { margin-top: 1rem; }

.preview-steps { padding-left: 1.4rem; }
.preview-steps > li { margin: 0.75rem 0; }
.built-card h2 { color: var(--ok); font-size: 1.15rem; }
.history .card h3 { margin: 0.75rem 0 0.4rem; }
.history .card h3:first-child { margin-top: 0; }

/* ---- phones and narrow windows ---- */
@media (max-width: 799px) {
  .topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.25rem 0.5rem;
  }
  .menu-btn {
    width: 44px;
    height: 44px;
    border: 0;
    background: none;
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    border-radius: var(--radius);
  }
  .topbar-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .app { display: block; }
  .sidebar {
    position: fixed;
    z-index: 20;
    left: 0;
    top: 0;
    bottom: 0;
    height: auto;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    visibility: hidden;
  }
  .sidebar.open { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0, 0, 0, 0.35); }
  .main { padding: 1rem 1rem 4rem; }
  .actions .btn, .actions form { width: 100%; }
  .actions form .btn { width: 100%; }
  .prompt { max-height: 16rem; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
