:root {
  color-scheme: dark;
  --bg: #07111f;
  --panel: rgba(12, 28, 47, 0.72);
  --panel-solid: #0d2035;
  --line: rgba(180, 221, 255, 0.13);
  --text: #eef6ff;
  --muted: #91a9be;
  --accent: #63e6d1;
  --accent-strong: #44cbb8;
  --accent-2: #9b8cff;
  --danger: #ff9d9d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
html { background: var(--bg); }
body { min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--text); overflow-x: hidden; }
/* Author CSS can otherwise override the browser's default hidden rule. */
*[hidden] { display: none !important; }
/* Keep the unauthenticated shell login-only even during the session check. */
body.pre-auth #app-view,
body.pre-auth .app-view,
body.authenticated #login-view,
body.authenticated .login-view { display: none !important; }
body.pre-auth #login-view { display: grid !important; }
body.authenticated #app-view { display: grid !important; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.ambient { position: fixed; z-index: -1; width: 42vw; height: 42vw; border-radius: 50%; filter: blur(90px); opacity: .21; pointer-events: none; }
.ambient-one { top: -12vw; left: -12vw; background: #3f8cff; }
.ambient-two { right: -14vw; bottom: -16vw; background: #7e62ff; }
.shell { width: min(1440px, 100%); min-height: 100vh; min-height: 100dvh; margin: 0 auto; padding: 24px; }
.glass-card { background: linear-gradient(135deg, rgba(20, 47, 75, .76), rgba(7, 20, 36, .72)); border: 1px solid var(--line); box-shadow: 0 24px 80px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.05); backdrop-filter: blur(22px); }
.login-view { min-height: calc(100vh - 48px); min-height: calc(100dvh - 48px); display: grid; place-items: center; padding: 24px 0; }
.login-card { width: min(470px, 100%); border-radius: 28px; padding: 42px; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; color: #06121d; background: linear-gradient(135deg, var(--accent), #b3fff1); font-weight: 900; font-size: 22px; box-shadow: 0 10px 28px rgba(99,230,209,.25); }
.brand-mark.small { width: 36px; height: 36px; border-radius: 11px; font-size: 17px; }
.eyebrow, .section-label { margin: 0 0 8px; letter-spacing: .14em; font-size: 10px; font-weight: 800; color: var(--accent); }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 370px; margin-bottom: 14px; font-size: clamp(31px, 4vw, 48px); line-height: 1.04; letter-spacing: -.04em; }
h2 { margin: 0; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.035em; }
h3 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); line-height: 1.65; }
.stack-form { display: grid; gap: 10px; margin-top: 30px; }
.stack-form label { color: #c4d6e6; font-size: 13px; }
input, textarea { width: 100%; color: var(--text); background: rgba(3, 12, 23, .58); border: 1px solid var(--line); border-radius: 14px; outline: none; transition: border .2s, box-shadow .2s; }
input { padding: 14px 16px; }
input:focus, textarea:focus { border-color: rgba(99,230,209,.75); box-shadow: 0 0 0 4px rgba(99,230,209,.1); }
.primary-button, .ghost-button, .text-button, .send-button { border: 0; transition: transform .18s, background .18s, opacity .18s; }
.primary-button { display: inline-flex; justify-content: center; align-items: center; gap: 12px; padding: 14px 18px; border-radius: 14px; color: #04111d; background: var(--accent); font-weight: 800; }
.primary-button:hover { transform: translateY(-1px); background: #89f4e4; }
.primary-button:disabled, .send-button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.ghost-button { display: inline-flex; align-items: center; gap: 8px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; color: #cfe3f2; background: rgba(255,255,255,.04); }
.ghost-button:hover { background: rgba(255,255,255,.08); }
.text-button { padding: 0; color: var(--muted); background: transparent; font-size: 12px; }
.text-button:hover { color: var(--text); }
.form-error { min-height: 18px; margin: 2px 0 0; color: var(--danger); font-size: 12px; }
.app-view { display: grid; grid-template-columns: 260px minmax(0, 1fr); align-items: start; gap: 24px; min-height: calc(100vh - 48px); min-height: calc(100dvh - 48px); }
.sidebar { position: sticky; top: 24px; display: flex; flex-direction: column; max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); min-height: calc(100vh - 48px); min-height: calc(100dvh - 48px); overflow-y: auto; padding: 18px; border-radius: 24px; scrollbar-width: thin; }
.sidebar-top { display: grid; gap: 22px; }
.brand-row { display: flex; align-items: center; gap: 11px; }
.brand-row strong { font-size: 17px; }
.side-section { margin-top: 38px; }
.section-label { color: #6e8ba5; }
.agent-pill { display: flex; align-items: center; gap: 10px; padding: 12px 10px; margin: 6px -2px; border-radius: 13px; }
.agent-pill.active { background: rgba(99,230,209,.08); }
.agent-pill strong, .agent-pill small, .privacy-note strong, .privacy-note small { display: block; }
.agent-pill strong { font-size: 13px; }
.agent-pill small, .privacy-note small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.muted-agent { opacity: .52; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(99,230,209,.1); }
.sidebar-footer { display: grid; gap: 18px; margin-top: auto; padding-top: 22px; border-top: 1px solid var(--line); }
.privacy-note { display: flex; gap: 10px; align-items: flex-start; color: var(--accent); }
.privacy-note > span { font-size: 12px; }
.privacy-note strong { color: #cfe3f2; font-size: 12px; }
.workspace { display: flex; flex-direction: column; width: min(890px, 100%); min-width: 0; min-height: calc(100vh - 48px); min-height: calc(100dvh - 48px); margin: 0 auto; padding: 22px 0 28px; }
.workspace-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 10px 6px 22px; }
.header-status { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.progress-wrap { padding: 14px 16px; border-radius: 16px; }
.progress-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.progress-track { height: 5px; margin-top: 10px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.08); }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .35s ease; }
.chat-scroll { display: flex; flex: 1 1 auto; flex-direction: column; gap: 18px; min-height: 220px; max-height: none; overflow-y: auto; overscroll-behavior: contain; padding: 28px 7px 14px; scrollbar-width: thin; scrollbar-gutter: stable; }
.message-row { display: flex; gap: 11px; align-items: flex-start; }
.message-row.user { justify-content: flex-end; }
.message-avatar { flex: 0 0 auto; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; color: #06121d; background: var(--accent); font-size: 12px; font-weight: 900; }
.message-row.user .message-avatar { order: 2; color: #e8e8ff; background: rgba(155,140,255,.9); }
.message-bubble { max-width: min(78%, 650px); padding: 14px 16px; border: 1px solid var(--line); border-radius: 17px 17px 17px 4px; color: #dbeaf7; background: rgba(14, 34, 55, .62); white-space: pre-wrap; line-height: 1.58; font-size: 14px; }
.message-row.user .message-bubble { order: 1; border-radius: 17px 17px 4px 17px; color: #f4f1ff; background: rgba(87, 74, 167, .56); }
.message-meta { margin-top: 6px; color: #69839a; font-size: 10px; }
.composer-wrap { margin-top: auto; padding-top: 14px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; min-height: 0; margin: 0 4px 10px; }
.suggestion { padding: 8px 11px; border: 1px solid rgba(99,230,209,.2); border-radius: 99px; color: #aeece1; background: rgba(99,230,209,.06); font-size: 12px; }
.suggestion:hover { background: rgba(99,230,209,.13); }
.composer { display: flex; align-items: flex-end; gap: 12px; padding: 10px 10px 10px 16px; border-radius: 18px; }
.composer textarea { min-height: 38px; max-height: 150px; padding: 9px 0; border: 0; resize: none; background: transparent; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.send-button { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 12px; color: #06121d; background: var(--accent); font-size: 22px; font-weight: 800; }
.send-button:hover { background: #89f4e4; }
.composer-hint { margin: 7px 5px 0; color: #69839a; font-size: 10px; }
.brief-panel { margin-top: 18px; padding: 20px; border-radius: 20px; }
.brief-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ready-badge { padding: 7px 9px; border: 1px solid rgba(99,230,209,.25); border-radius: 99px; color: #aeece1; background: rgba(99,230,209,.08); font-size: 10px; white-space: nowrap; }
.brief-content { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.brief-item { padding: 12px; border: 1px solid var(--line); border-radius: 13px; background: rgba(4, 14, 25, .3); }
.brief-item strong { display: block; margin-bottom: 5px; color: var(--accent); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.brief-item span { color: #dbeaf7; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.plan-panel { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.plan-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.plan-heading h4 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.plan-intro { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.plan-content { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.plan-card { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(4, 14, 25, .3); }
.plan-card h5 { margin: 0 0 10px; color: var(--accent); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.plan-card p { margin: 0 0 9px; color: #dbeaf7; font-size: 13px; line-height: 1.48; white-space: pre-wrap; }
.plan-card p:last-child { margin-bottom: 0; }
.plan-card strong { color: #a7bdd0; font-size: 11px; }
.plan-list { margin: 6px 0 0; padding-left: 17px; color: #c4d6e6; font-size: 12px; line-height: 1.5; }
.plan-list li + li { margin-top: 4px; }
.plan-open-questions { margin-top: 12px; padding: 13px 14px; border: 1px solid rgba(155,140,255,.25); border-radius: 13px; color: #d9d2ff; background: rgba(155,140,255,.08); font-size: 12px; line-height: 1.5; }
.plan-open-questions strong { display: block; margin-bottom: 6px; color: #c9c0ff; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.plan-open-questions ul { margin: 0; padding-left: 17px; }
.plan-open-questions li + li { margin-top: 4px; }
.implementation-panel { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.implementation-files { margin-top: 14px; padding: 13px 14px; border: 1px solid rgba(99,230,209,.18); border-radius: 13px; background: rgba(99,230,209,.04); }
.implementation-files-heading { margin: 0 0 9px; color: #aeece1; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.implementation-file-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.implementation-file-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; color: #c4d6e6; font-size: 12px; line-height: 1.45; }
.implementation-file-list code { padding: 3px 6px; border-radius: 6px; color: #d9d2ff; background: rgba(155,140,255,.12); font-size: 11px; }
.implementation-file-list span { color: var(--muted); }
.runner-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.preview-button { margin-top: 16px; }
.preview-dialog:not([open]) { display: none; }
.runner-result { margin-top: 16px; padding: 13px; border: 1px solid rgba(99,230,209,.2); border-radius: 13px; color: #cfe3f2; background: rgba(99,230,209,.05); white-space: pre-wrap; font-size: 12px; line-height: 1.55; }
.runner-result.error { border-color: rgba(255,157,157,.3); color: var(--danger); background: rgba(255,157,157,.05); }
.loading { opacity: .62; }
.preview-dialog { width: min(1180px, calc(100vw - 32px)); height: min(88dvh, 860px); max-width: none; max-height: calc(100dvh - 32px); padding: 0; border: 1px solid rgba(180,221,255,.2); border-radius: 24px; color: var(--text); background: #091827; box-shadow: 0 30px 100px rgba(0,0,0,.45); }
.preview-dialog::backdrop { background: rgba(2, 8, 17, .78); backdrop-filter: blur(8px); }
.preview-shell { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0; }
.preview-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.preview-header h2 { font-size: 21px; }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 11px; color: #cfe3f2; background: rgba(255,255,255,.05); font-size: 24px; line-height: 1; }
.icon-button:hover { background: rgba(255,255,255,.1); }
.preview-frame-wrap { flex: 1 1 auto; min-height: 0; padding: 14px; background: #06111f; }
.preview-frame { display: block; width: 100%; height: 100%; min-height: 260px; border: 0; border-radius: 14px; background: #f7f8fa; }
.preview-footer { padding: 10px 20px 13px; color: #7892a8; font-size: 11px; line-height: 1.45; }

@media (max-width: 840px) {
  .shell { padding: 12px; }
  .login-view { min-height: calc(100vh - 24px); min-height: calc(100dvh - 24px); padding: 12px 0; }
  .app-view { display: block; min-height: calc(100vh - 24px); min-height: calc(100dvh - 24px); }
  .sidebar { position: static; max-height: none; min-height: auto; margin-bottom: 12px; padding: 13px; overflow: visible; }
  .sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .side-section { display: none; }
  .sidebar-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 13px; padding-top: 13px; }
  .workspace { min-height: auto; padding-top: 4px; }
  .workspace-header { padding-top: 6px; }
  .chat-scroll { min-height: clamp(280px, 48vh, 520px); }
  .brief-content { grid-template-columns: 1fr; }
  .plan-content { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
  .login-card { padding: 28px 22px; border-radius: 22px; }
  .stack-form input { font-size: 16px; }
  .workspace-header { align-items: flex-start; flex-direction: column; }
  .message-bubble { max-width: 88%; }
  .runner-actions .primary-button, .runner-actions .ghost-button { width: 100%; }
  .preview-dialog { width: calc(100vw - 18px); height: calc(100dvh - 18px); max-height: calc(100dvh - 18px); border-radius: 18px; }
  .preview-header { padding: 15px 15px 12px; }
  .preview-frame-wrap { padding: 9px; }
  .preview-footer { padding: 8px 15px 11px; }
}
