:root {
  --accent: #C1652E;
  --accent-soft: #fdf0e8;
  --accent-line: #f0d9c6;
  --ink: #2b2b2b;
  --muted: #8f8a86;
  --cream: #fdfbf9;
  --line: #ece7e2;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Inter, system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
}

.shell {
  display: flex;
  height: 100vh;
}

.chat-pane {
  width: 380px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fff;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #e0895a);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: #fff;
}

.chat-head-title { font-size: 14.5px; font-weight: 700; }
.chat-head-sub { font-size: 11.5px; color: var(--muted); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg-user {
  align-self: flex-end;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  max-width: 85%;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg-assistant {
  align-self: flex-start;
  max-width: 94%;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  margin: 4px 0;
}

.step.active { color: var(--accent); }

.secret-card, .egress-card {
  margin-top: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 14px;
  padding: 14px;
  font-size: 12.5px;
  line-height: 1.5;
}

.secret-card b, .egress-card b { display: block; margin-bottom: 6px; font-size: 13px; }

.secret-card .field-label {
  font-size: 11.5px;
  color: var(--muted);
  margin: 10px 0 4px;
}

.secret-card input {
  width: 100%;
  border: 1px solid var(--accent-line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  font-family: ui-monospace, monospace;
}

.card-btn {
  margin-top: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.card-btn:disabled { opacity: 0.6; cursor: default; }

.card-btn.ghost {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent-line);
}

.card-error { color: #b3261e; font-size: 11.5px; margin-top: 6px; }
.card-help { font-size: 11px; color: var(--muted); margin-top: 8px; }

.starters { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.starter-card {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--cream);
  text-align: left;
}

.starter-card:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.starter-card .icon { font-size: 16px; }
.starter-card .title { display: block; font-size: 12.5px; font-weight: 600; }
.starter-card .desc { font-size: 11px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px 10px; }

.chip {
  font-size: 11.5px;
  background: #f7f4f1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--ink);
  cursor: pointer;
}

.composer { border-top: 1px solid var(--line); padding: 14px; }

.composer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 9px 9px 9px 16px;
  background: #fff;
}

.composer-box input {
  border: none;
  background: transparent;
  flex: 1;
  font-size: 13.5px;
  outline: none;
}

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
  font-size: 15px;
}

.budget-progress { margin: 10px 4px 0; }
.budget-track { height: 5px; border-radius: 99px; background: #f0ece8; overflow: hidden; }
.budget-fill { display: block; height: 100%; background: var(--accent); }
.budget-label { font-size: 11px; color: var(--muted); margin: 6px 2px 0; }

.main-pane { flex: 1; display: flex; flex-direction: column; position: relative; min-width: 0; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 20px; }
.app-name { font-weight: 700; font-size: 14px; }

.status-pill {
  font-size: 11.5px;
  border-radius: 999px;
  padding: 3px 10px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-pill .dot { width: 6px; height: 6px; border-radius: 50%; display: block; }
.status-pill.idle { background: #eaf6ec; color: #2e7d32; }
.status-pill.idle .dot { background: #2e7d32; }
.status-pill.building { background: var(--accent-soft); color: #a6531f; }
.status-pill.building .dot { background: #a6531f; animation: pulse 1.1s infinite; }
.status-pill.crashed { background: #fdecec; color: #b3261e; }
.status-pill.crashed .dot { background: #b3261e; }
.status-pill.empty { background: #f3f1ef; color: var(--muted); }
.status-pill.empty .dot { display: none; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.topbar .spacer { flex: 1; }

.view-code-link {
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  background: none;
  border: none;
}

.canvas {
  flex: 1;
  margin: 0 20px 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.canvas iframe { width: 100%; height: 100%; border: none; }

.crash-banner {
  margin: 0 20px 14px;
  background: #fff8f6;
  border: 1px solid #f6d9d3;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.5;
  display: none;
}

.crash-banner.visible { display: block; }
.crash-banner b { display: block; margin-bottom: 4px; }

.code-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: 360px;
  height: 100%;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
  transform: translateX(100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
}

.code-drawer.open { transform: translateX(0); }

.code-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.code-drawer-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
}

.file-list { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }

.file-list button {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--cream);
  cursor: pointer;
}

.file-content {
  flex: 1;
  overflow: auto;
  padding: 14px 16px;
  white-space: pre-wrap;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

.mobile-tabbar { display: none; }

@media (max-width: 899px) {
  .shell { flex-direction: column; height: 100vh; }
  .chat-pane, .main-pane { width: 100%; flex: 1; }

  .shell:not([data-mobile-view="chat"]) .chat-pane { display: none; }
  .shell[data-mobile-view="chat"] .main-pane { display: none; }

  .code-drawer {
    position: static;
    width: 100%;
    height: 100%;
    border-left: none;
    box-shadow: none;
    transform: none;
    display: none;
  }

  .shell[data-mobile-view="code"] .code-drawer.open { display: flex; }
  .shell[data-mobile-view="code"] .canvas { display: none; }
  .shell[data-mobile-view="code"] .topbar,
  .shell[data-mobile-view="code"] .crash-banner { display: none; }

  .mobile-tabbar {
    display: flex;
    border-top: 1px solid var(--line);
    background: #fff;
  }

  .mobile-tabbar button {
    flex: 1;
    border: none;
    background: none;
    padding: 10px 0;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
  }

  .mobile-tabbar button.active { color: var(--accent); font-weight: 700; }
}
