:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #69716d;
  --paper: #f4f3ed;
  --panel: #fbfaf5;
  --line: #d8d8cf;
  --accent: #e4572e;
  --accent-dark: #bd3e1d;
  --green: #2c7657;
  --shadow: 0 22px 70px rgba(29, 37, 33, 0.12);
  font-family: "Manrope", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, textarea, input { font: inherit; }
button { color: inherit; }

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  opacity: 0.42;
  background-image: linear-gradient(rgba(23, 33, 29, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(23, 33, 29, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
}

.topbar { height: 66px; display: flex; align-items: center; justify-content: space-between; padding: 0 30px; border-bottom: 1px solid var(--line); background: rgba(244, 243, 237, 0.88); backdrop-filter: blur(16px); }
.brand { display: inline-flex; gap: 11px; align-items: center; color: var(--ink); font-size: 14px; font-weight: 700; text-decoration: none; }
.brand-mark { display: grid; grid-template-columns: repeat(3, 6px); align-items: end; gap: 2px; width: 22px; height: 22px; padding: 3px; border: 1px solid var(--ink); }
.brand-mark i { display: block; height: 7px; background: var(--ink); }
.brand-mark i:nth-child(2) { height: 14px; background: var(--accent); }
.brand-mark i:nth-child(3) { height: 10px; }
.account { display: flex; align-items: center; gap: 12px; color: var(--muted); font: 500 10px "DM Mono", monospace; }
.account span { max-width: min(40vw, 280px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account button, .auth-state button { min-height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: var(--panel); cursor: pointer; font-size: 10px; font-weight: 700; }
.account button:hover, .auth-state button:hover { border-color: #a9aba4; background: #fff; }

.workspace { display: grid; grid-template-columns: minmax(340px, 430px) minmax(0, 1fr); min-height: calc(100vh - 66px); }
.auth-state { display: flex; min-height: calc(100vh - 66px); padding: 40px; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.auth-state .agent-orbit { margin-bottom: 30px; }
.auth-state h1 { margin-bottom: 12px; }
.auth-state > p:not(.eyebrow) { max-width: 440px; margin: 0 0 24px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.brief-panel { display: flex; flex-direction: column; padding: 50px 38px 28px; border-right: 1px solid var(--line); background: rgba(251, 250, 245, 0.72); }
.panel-heading { margin-bottom: 34px; }
.eyebrow { margin: 0 0 10px; color: var(--accent-dark); font: 500 10px "DM Mono", monospace; text-transform: uppercase; }
h1, h2, h3, p { letter-spacing: 0; }
h1 { max-width: 360px; margin: 0 0 13px; font-size: clamp(30px, 3vw, 44px); line-height: 1.02; }
.panel-heading > p:last-child { max-width: 350px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
form > label, legend, .research-row label { display: block; margin: 0 0 9px; font-size: 12px; font-weight: 700; }
.prompt-wrap { position: relative; }
textarea { display: block; width: 100%; min-height: 164px; resize: vertical; padding: 16px 16px 34px; color: var(--ink); border: 1px solid #c8c9bf; border-radius: 4px; outline: 0; background: #fff; font-size: 13px; line-height: 1.6; transition: border-color 160ms, box-shadow 160ms; }
textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(44, 118, 87, 0.12); }
textarea::placeholder { color: #989e99; }
#character-count { position: absolute; right: 12px; bottom: 10px; color: #929791; font: 400 9px "DM Mono", monospace; }
fieldset { padding: 0; margin: 24px 0; border: 0; }
.segments { display: grid; grid-template-columns: repeat(5, 1fr); padding: 3px; border: 1px solid var(--line); border-radius: 4px; background: #e9e8e1; }
.segments input { position: absolute; opacity: 0; pointer-events: none; }
.segments label { min-width: 0; padding: 8px 3px; overflow: hidden; border: 1px solid transparent; border-radius: 3px; color: var(--muted); font-size: 10px; text-align: center; text-overflow: ellipsis; cursor: pointer; }
.segments input:focus-visible + label { outline: 2px solid var(--green); outline-offset: 2px; }
.segments input:checked + label { color: var(--ink); border-color: #cfcec6; background: #fff; box-shadow: 0 2px 6px rgba(23, 33, 29, 0.08); font-weight: 700; }
.research-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 0; border-top: 1px solid var(--line); }
.research-row label { margin-bottom: 3px; }
.research-row p { margin: 0; color: var(--muted); font-size: 10px; }
.switch { position: relative; flex: 0 0 40px; height: 22px; margin: 0 !important; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 20px; background: #b8bcb8; cursor: pointer; transition: background 160ms; }
.switch span::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; content: ""; border-radius: 50%; background: #fff; transition: transform 160ms; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--green); outline-offset: 2px; }
.generate-button { display: flex; width: 100%; min-height: 48px; align-items: center; justify-content: center; gap: 10px; margin-top: 9px; border: 0; border-radius: 4px; color: #fff; background: var(--ink); cursor: pointer; font-size: 12px; font-weight: 700; transition: transform 160ms, background 160ms; }
.generate-button:hover { background: #29362f; transform: translateY(-1px); }
.generate-button:disabled { cursor: wait; opacity: 0.62; transform: none; }
.generate-button svg, .export-button svg { width: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.skill-flow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; padding: 28px 0 0; margin: auto 0 0; list-style: none; }
.skill-flow li { position: relative; padding-top: 13px; color: #8b908c; border-top: 1px solid var(--line); font: 400 8px "DM Mono", monospace; text-align: center; text-transform: uppercase; }
.skill-flow li::before { position: absolute; top: -3px; left: calc(50% - 3px); width: 5px; height: 5px; content: ""; border: 1px solid var(--panel); border-radius: 50%; background: #afb2ae; }
.skill-flow li span { display: block; margin-bottom: 3px; color: #b4b7b3; font-size: 7px; }

.output-panel { position: relative; min-width: 0; padding: 24px 30px 30px; overflow: hidden; }
.output-toolbar { display: flex; min-height: 48px; align-items: flex-start; justify-content: space-between; gap: 20px; }
.output-toolbar .eyebrow { margin-bottom: 4px; }
h2 { margin: 0; font-size: 17px; }
.toolbar-actions { display: flex; gap: 7px; }
.icon-button, .export-button, .error-state button { display: inline-flex; min-height: 34px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); cursor: pointer; }
.icon-button { width: 36px; padding: 0; }
.icon-button svg { width: 15px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.export-button { gap: 7px; padding: 0 12px; font-size: 10px; font-weight: 700; }
.icon-button:hover, .export-button:hover { border-color: #a9aba4; background: #fff; }
.empty-state, .working-state, .error-state { position: absolute; inset: 72px 30px 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
[hidden] { display: none !important; }
.empty-canvas { position: relative; width: min(50%, 300px); aspect-ratio: 4 / 3; margin-bottom: 34px; border: 1px solid #cfd0c8; background: rgba(251, 250, 245, 0.5); box-shadow: var(--shadow); transform: rotate(-1deg); }
.empty-canvas::before { position: absolute; inset: 13%; content: ""; border: 1px dashed #c3c5bd; }
.empty-canvas span { position: absolute; display: block; background: #adb1ac; }
.empty-canvas span:nth-child(1) { top: 27%; left: 22%; width: 43%; height: 5px; background: var(--ink); }
.empty-canvas span:nth-child(2) { top: 37%; left: 22%; width: 56%; height: 2px; }
.empty-canvas span:nth-child(3) { right: 22%; bottom: 24%; left: 22%; height: 30%; background: #e2e1d9; }
.empty-canvas span:nth-child(4) { right: -11px; bottom: -12px; width: 38%; height: 45%; border: 1px solid var(--accent); background: rgba(228, 87, 46, 0.1); }
.empty-state h3 { margin: 0 0 8px; font-size: 17px; }
.empty-state p { max-width: 330px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.agent-orbit { display: grid; width: 76px; height: 76px; place-items: center; margin-bottom: 26px; border: 1px solid var(--line); border-radius: 50%; animation: spin 1.6s linear infinite; }
.agent-orbit::before { position: absolute; width: 7px; height: 7px; content: ""; border-radius: 50%; background: var(--accent); transform: translateY(-38px); }
.agent-orbit span { width: 25px; height: 25px; background: var(--ink); clip-path: polygon(50% 0, 61% 36%, 100% 50%, 61% 64%, 50% 100%, 39% 64%, 0 50%, 39% 36%); }
.working-state p { min-height: 18px; margin: 0 0 14px; font: 500 11px "DM Mono", monospace; }
.progress-track { width: min(340px, 70%); height: 5px; overflow: hidden; border-radius: 999px; background: #d8d9d2; }
.progress-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width 240ms ease; }
.working-status { display: flex; width: min(340px, 70%); justify-content: space-between; gap: 16px; margin-top: 10px; color: var(--muted); font: 400 9px "DM Mono", monospace; text-align: left; }
.working-status strong { color: var(--ink); font-weight: 600; }
.result-state { height: calc(100vh - 162px); min-height: 560px; margin-top: 16px; overflow: hidden; border: 1px solid #c8c9c0; border-radius: 4px; background: #fff; box-shadow: var(--shadow); animation: reveal 420ms ease-out both; }
#preview { display: block; width: 100%; height: calc(100% - 86px); border: 0; background: #fff; }
.result-meta { display: grid; grid-template-columns: minmax(160px, .35fr) 1fr; gap: 25px; min-height: 86px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel); }
.result-meta span { display: block; margin-bottom: 4px; color: var(--muted); font: 400 8px "DM Mono", monospace; text-transform: uppercase; }
.result-meta strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.result-meta p { display: -webkit-box; margin: 0; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.5; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.error-state { margin: auto; }
.error-state strong { margin-bottom: 9px; font-size: 16px; }
.error-state p { max-width: 430px; margin: 0 0 18px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.error-state button { padding: 0 15px; font-size: 11px; font-weight: 700; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes progress { from { transform: translateX(-105%); } to { transform: translateX(255%); } }
@keyframes reveal { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; } }
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .brief-panel { min-height: calc(100vh - 66px); border-right: 0; border-bottom: 1px solid var(--line); }
  .output-panel { min-height: 760px; }
  .result-state { height: 650px; }
}
@media (max-width: 540px) {
  .topbar { padding: 0 18px; }
  .brief-panel { padding: 38px 20px 24px; }
  .segments { grid-template-columns: repeat(3, 1fr); }
  .segments label:nth-of-type(n+4) { margin-top: 3px; }
  .output-panel { min-height: 690px; padding: 20px 14px; }
  .empty-state, .working-state, .error-state { right: 14px; left: 14px; }
  .result-state { height: 580px; }
  .result-meta { grid-template-columns: 1fr; gap: 6px; }
  .result-meta p { display: none; }
  .export-button { width: 36px; padding: 0; font-size: 0; }
}