:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --ink: #16150f;
  --muted: #6f6b60;
  --line: #e4e0d6;
  --accent: #16150f;
  --accent-ink: #f7f6f2;
  --danger: #b3261e;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 24px;
  background: rgba(247, 246, 242, 0.86);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.brand .dot {
  color: #c2410c;
}

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

.pill {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  white-space: nowrap;
}

.pill.zero {
  color: #9a3412;
  border-color: #fed7aa;
  background: #fff7ed;
}

.ghost {
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

.ghost:hover {
  color: var(--ink);
  background: var(--surface);
}

main {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

.empty {
  max-width: 720px;
  margin: 14vh auto 0;
  text-align: center;
}

h1 {
  margin: 0 0 14px;
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.sub {
  margin: 0 auto 28px;
  max-width: 540px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.scope-line {
  margin: 16px 0 0;
  color: #a8a294;
  font-size: 12px;
  letter-spacing: 0.01em;
}

.github-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 220px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.github-btn:hover {
  opacity: 0.9;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  color: #9a3412;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.auth-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
}

.guest-only #auth-row {
  display: none;
}

.auth-note {
  color: #a8a294;
  font-size: 12px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  box-shadow:
    0 1px 2px rgba(20, 18, 12, 0.04),
    0 8px 30px rgba(20, 18, 12, 0.04);
}

.composer:focus-within {
  border-color: #c9c3b4;
  box-shadow: 0 0 0 4px rgba(22, 21, 15, 0.06);
}

textarea {
  flex: 1;
  min-height: 40px;
  max-height: 180px;
  padding: 10px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
}

textarea::placeholder {
  color: #a8a294;
}

.send {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 18px;
  cursor: pointer;
}

.send:disabled {
  opacity: 0.4;
  cursor: default;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 18px;
}

.chips button {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
}

.chips button:hover {
  color: var(--ink);
  background: var(--surface);
}

.workspace {
  max-width: 900px;
  margin: 24px auto 0;
}

.repo-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin: 0 auto 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.repo-button:hover {
  border-color: #c9c3b4;
}

.repo-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.repo-mark {
  color: #c2410c;
  font-size: 11px;
}

.repo-chevron {
  color: #a8a294;
  font-size: 10px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 21, 15, 0.45);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(70vh, 640px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(20, 18, 12, 0.24);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.repo-search {
  width: calc(100% - 36px);
  margin: 0 18px 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfaf7;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.repo-search:focus {
  outline: none;
  border-color: #c9c3b4;
  background: var(--surface);
}

.repo-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px 8px;
  overflow: auto;
}

.repo-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.repo-item:hover {
  background: #fbfaf7;
}

.repo-item.selected {
  border-color: #f0c9a8;
  background: #fff7ed;
}

.repo-item-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.repo-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.repo-private {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
}

.repo-desc {
  overflow: hidden;
  color: #a8a294;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repo-empty {
  padding: 22px 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px 14px;
  border-top: 1px solid var(--line);
}

.modal-hint {
  color: #a8a294;
  font-size: 11px;
}

.msg-agent {
  align-self: flex-start;
  max-width: 85%;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.msg-agent p {
  margin: 0 0 8px;
  white-space: pre-wrap;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-chip {
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
}

.ask-card {
  padding: 14px 16px;
  border: 1px solid #f0c9a8;
  border-radius: 14px;
  background: #fffaf3;
}

.ask {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 24px;
  background: rgba(247, 246, 242, 0.94);
  backdrop-filter: blur(4px);
}

/*
 * When a question and an ad are live at the same time, split the stage: the
 * ad keeps playing (and stays visible) on the left, the question sits on the
 * right. Never cover the ad with the dialog.
 */
.stage.split .ad {
  right: 46%;
}

.stage.split .ask {
  left: 54%;
  padding: 14px;
  background: var(--bg);
  backdrop-filter: none;
}

.stage.split .ask-dialog {
  max-width: 100%;
  box-shadow: none;
}

@media (max-width: 760px) {
  .stage.split .ad {
    right: 0;
    bottom: 54%;
  }

  .stage.split .ask {
    top: 46%;
    left: 0;
    padding: 10px;
  }
}

.ask-dialog {
  width: 100%;
  max-width: 560px;
  padding: 18px 20px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  outline: none;
  box-shadow:
    0 1px 2px rgba(20, 18, 12, 0.05),
    0 18px 50px rgba(20, 18, 12, 0.14);
}

.ask-kicker {
  margin-bottom: 6px;
  color: #9a3412;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.ask-title-text {
  margin-bottom: 14px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.ask-field-title {
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.ask-option-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}

.ask-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.ask-option:hover {
  border-color: #c9c3b4;
  background: #fbfaf7;
}

.ask-option.selected {
  border-color: #9a3412;
  background: #fff7ed;
}

.ask-num {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.ask-option.selected .ask-num {
  border-color: #9a3412;
  color: #9a3412;
}

.ask-custom {
  width: 100%;
  margin: 4px 0 2px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfaf7;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.ask-custom:focus {
  outline: none;
  border-color: #c9c3b4;
  background: var(--surface);
}

.ask-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: #a8a294;
  font-size: 10px;
}

.ask-hints {
  letter-spacing: 0.02em;
}

.ask-submit {
  width: auto;
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.ask-resources {
  margin: 0 0 10px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  word-break: break-all;
}

.ask-reject {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.ask-reject textarea {
  width: 100%;
  min-height: 64px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfaf7;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  resize: vertical;
}

.ask-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ask-title {
  margin-bottom: 6px;
  color: #9a3412;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.ask-text {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.ask-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ask-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.ask-field input[type="text"],
.ask-field input[type="number"],
.ask-field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.ask-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.ask-field small {
  color: #a8a294;
}

.ask-submit {
  align-self: flex-start;
  width: auto;
  height: 34px;
  padding: 0 14px;
  font-size: 12px;
}

.ask-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ask-resources {
  margin: -4px 0 10px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  word-break: break-all;
}

.ghost.danger {
  color: #b3261e;
  border-color: #f3c6c2;
}

.diff {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 16px 18px;
}

.diff-summary {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.diff-file {
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.diff-file summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: #fbfaf7;
  cursor: pointer;
  font-size: 12px;
}

.fname {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.stat {
  color: var(--muted);
}

.patch {
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  background: #fff;
  color: #3f3a30;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.pr-link a {
  color: #9a3412;
  font-size: 12px;
  text-decoration: none;
}

.pr-link a:hover {
  text-decoration: underline;
}

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 8px;
}

.file-name {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.stage-actions {
  display: flex;
  gap: 6px;
}

.stage-actions .ghost {
  padding: 4px 10px;
  font-size: 11px;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 30vh;
  margin-bottom: 16px;
  padding-right: 4px;
  overflow-y: auto;
}

.thread-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-user {
  position: relative;
  align-self: flex-end;
  max-width: 80%;
  max-height: 64px;
  padding: 10px 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  cursor: pointer;
}

.msg-user.expanded {
  max-height: none;
}

.msg-user:not(.expanded)::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 20px;
  background: linear-gradient(to bottom, transparent, var(--surface));
  content: "";
  pointer-events: none;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c2410c;
  animation: pulse 1.2s ease-in-out infinite;
}

.status.error {
  color: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

.stage {
  position: relative;
  width: 100%;
  min-height: 360px;
  max-height: 62vh;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stage.previewing {
  min-height: 570px;
  max-height: 80vh;
}

.preview {
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4f2ec;
}

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf7;
  color: var(--muted);
  font-size: 11px;
}

.preview-tag {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.preview iframe {
  display: block;
  width: calc(100% - 20px);
  height: 420px;
  margin: 10px auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(40, 35, 25, 0.08);
}

.diff-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.ad {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #0a0a0a;
  color: #fff;
}

.ad-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}

.ad-badge {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 1px 6px;
}

.ad-video-wrap {
  position: relative;
  flex: 1;
  overflow: hidden;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ad-bottom {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 18px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0));
}

.ad-bottom p {
  margin: 0 0 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
}

.bar {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
}

#ad-bar {
  width: 0;
  height: 100%;
  background: #fff;
  transition: width 0.2s linear;
}

.ad-times {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
}

.ad-note {
  padding: 10px 16px;
  font-size: 10px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.35);
}

.building {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line);
  border-top-color: #c2410c;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.composer-slot {
  margin-top: 16px;
}

.gate-hint {
  margin: 0 0 8px;
  color: #9a3412;
  font-size: 12px;
  text-align: center;
}

.footer {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px 28px;
  font-size: 11px;
  color: #a8a294;
}

@media (max-width: 640px) {
  .empty {
    margin-top: 8vh;
  }

  .stage {
    min-height: 420px;
    max-height: 70vh;
  }

  .stage.previewing {
    min-height: 520px;
    max-height: 85vh;
  }

  .preview iframe {
    height: 320px;
  }

  .topbar,
  main,
  .footer {
    padding-right: 16px;
    padding-left: 16px;
  }
}
