:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --line: #d9dee5;
  --line-strong: #b8c0ca;
  --ink: #171b22;
  --muted: #6f7885;
  --muted-2: #8e98a6;
  --cyan: #087f8c;
  --green: #15845b;
  --amber: #b36213;
  --red: #b84335;
  --blue: #3567b7;
  --violet: #7654a8;
  --shadow: 0 10px 32px rgba(26, 36, 48, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a, select, input[type="range"] { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(8, 127, 140, 0.23); outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template: 72px minmax(0, 1fr) / 248px minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 248px minmax(240px, 1fr) auto;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  color: inherit;
  text-decoration: none;
  border-right: 1px solid var(--line);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--ink);
  font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.brand-copy { display: flex; flex-direction: column; gap: 2px; }
.brand-copy strong { font-size: 16px; }
.brand-copy small { font: 500 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); text-transform: uppercase; }

.mode-control {
  justify-self: center;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 310px;
  padding: 3px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 6px;
}
.mode-button {
  border: 0;
  border-radius: 4px;
  padding: 8px 12px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.mode-button.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 5px rgba(20, 30, 40, 0.10); }

.topbar-actions { display: flex; align-items: center; gap: 10px; padding: 0 18px; }
.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 5px;
}
.icon-button:hover { border-color: var(--line-strong); background: var(--surface-2); }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.compact { width: 29px; height: 29px; border: 0; background: transparent; }
.icon-button.compact svg { width: 14px; height: 14px; }

.system-pill { display: flex; align-items: center; gap: 7px; min-width: 92px; color: var(--muted); font-size: 12px; }
.system-pill span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); box-shadow: 0 0 0 4px rgba(142, 152, 166, 0.12); }
.system-pill.is-ok span { background: var(--green); box-shadow: 0 0 0 4px rgba(21, 132, 91, 0.12); }
.system-pill.is-warn span { background: var(--amber); box-shadow: 0 0 0 4px rgba(179, 98, 19, 0.12); }
.system-pill b { font-weight: 600; }

.project-rail {
  position: sticky;
  top: 72px;
  align-self: start;
  height: calc(100vh - 72px);
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rail-heading, .artifacts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 17px 18px 12px;
  color: var(--muted);
  font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.project-list { overflow: auto; padding: 0 10px 14px; }
.project-item {
  width: 100%;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  text-align: left;
  padding: 12px 10px;
  cursor: pointer;
  color: var(--ink);
}
.project-item:hover { background: var(--surface-2); }
.project-item.is-active { border-left-color: var(--cyan); background: #edf7f7; }
.project-item strong { display: block; font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-item span { display: block; margin-top: 5px; color: var(--muted); font: 500 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }
.rail-meta { margin-top: auto; border-top: 1px solid var(--line); padding: 16px 18px; display: flex; justify-content: space-between; color: var(--muted); font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.rail-empty { padding: 14px 10px; color: var(--muted); font-size: 12px; }

.workspace { min-width: 0; padding-bottom: 80px; }
.input-band, .run-band, .preview-band, .artifacts-band, .auth-banner {
  width: min(1380px, calc(100% - 48px));
  margin-inline: auto;
}
.input-band { padding: 34px 0 26px; }
.idea-header, .run-header, .artifacts-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.idea-header label, .section-kicker, .project-code, .hash-field span, .field-control > span, .artifacts-header span {
  color: var(--muted);
  font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
}
.project-code { color: var(--cyan); }
#idea-input {
  width: 100%;
  resize: vertical;
  min-height: 126px;
  margin-top: 10px;
  padding: 18px 20px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 6px;
  color: var(--ink);
  font: 500 21px/1.45 Georgia, "Times New Roman", serif;
}
#idea-input::placeholder { color: #9aa3ad; }
.input-controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(230px, 0.7fr) auto;
  gap: 12px;
  margin-top: 12px;
  align-items: end;
}
.field-control { display: flex; flex-direction: column; gap: 7px; }
.field-control input[type="text"] {
  height: 43px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 5px;
  padding: 0 12px;
  color: var(--ink);
}
.distance-control > span { display: flex; justify-content: space-between; }
.distance-control output { color: var(--cyan); }
input[type="range"] { width: 100%; accent-color: var(--cyan); height: 43px; margin: 0; }

.primary-button, .secondary-button {
  min-height: 43px;
  border-radius: 5px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  cursor: pointer;
  font-weight: 700;
  border: 1px solid var(--ink);
  white-space: nowrap;
}
.primary-button { background: var(--ink); color: #fff; }
.primary-button:hover { background: #2a3039; }
.secondary-button { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.secondary-button:hover { background: var(--surface-2); }
.primary-button svg, .secondary-button svg { width: 16px; height: 16px; }
.primary-button:disabled, .secondary-button:disabled { opacity: 0.42; cursor: not-allowed; }

.auth-banner { margin-top: 4px; padding: 11px 14px; border: 1px solid #e5cba8; background: #fff8ee; display: flex; justify-content: space-between; font-size: 13px; }
.auth-banner a { color: var(--amber); font-weight: 700; }
.is-hidden { display: none !important; }

.run-band { border-top: 1px solid var(--line); padding: 26px 0 30px; }
.run-header h1 { margin: 7px 0 0; font: 600 24px/1.2 Georgia, "Times New Roman", serif; }
.run-identity { text-align: right; display: flex; flex-direction: column; gap: 6px; color: var(--muted); font: 600 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.run-identity code { color: var(--cyan); }

.stage-line {
  list-style: none;
  margin: 25px 0 9px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}
.stage-line li { position: relative; padding-top: 13px; color: var(--muted-2); min-width: 0; }
.stage-line li::before { content: ""; position: absolute; width: 8px; height: 8px; border: 2px solid var(--bg); background: var(--line-strong); border-radius: 50%; top: -5px; left: 0; }
.stage-line li span { display: block; font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.stage-line li b { display: block; margin-top: 4px; font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.stage-line li.is-done { color: var(--green); }
.stage-line li.is-active { color: var(--ink); }
.stage-line li.is-done::before { background: var(--green); }
.stage-line li.is-active::before { background: var(--cyan); box-shadow: 0 0 0 5px rgba(8, 127, 140, 0.12); }
.progress-track { height: 2px; background: var(--line); overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--green)); transition: width 300ms ease; }

.vector-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 22px; }
.vector-card {
  min-width: 0;
  min-height: 164px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--axis-color, var(--cyan));
  background: var(--surface);
  padding: 14px;
  border-radius: 5px;
  display: flex;
  flex-direction: column;
}
.vector-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.vector-card-head span { color: var(--muted); font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.vector-card-head b { font-size: 11px; text-transform: uppercase; }
.vector-card code, .vector-inspector code { display: block; margin-top: 10px; color: var(--axis-color, var(--cyan)); font: 600 9px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.vector-card p { margin: 10px 0 14px; font-size: 13px; line-height: 1.4; }
.vector-score { margin-top: auto; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; color: var(--muted); font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.vector-score i { display: block; height: 3px; background: var(--surface-2); overflow: hidden; }
.vector-score i::before { content: ""; display: block; width: var(--score, 0%); height: 100%; background: var(--axis-color, var(--cyan)); }
.vector-card.is-loading { border-top-color: var(--line-strong); }
.vector-card.is-loading p, .vector-card.is-loading code { color: transparent; background: linear-gradient(90deg, #edf0f3, #f8f9fa, #edf0f3); background-size: 200% 100%; animation: skeleton 1.5s infinite; border-radius: 3px; }
@keyframes skeleton { to { background-position: -200% 0; } }

.professional-stage {
  display: none;
  position: relative;
  margin-top: 22px;
  min-height: 580px;
  border-block: 1px solid var(--line);
  background: #f8fafb;
  overflow: hidden;
}
body[data-mode="professional"] .professional-stage { display: block; }
body[data-mode="professional"] .vector-grid { display: none; }
#vector-canvas { width: 100%; height: 580px; display: block; cursor: crosshair; }
.vector-inspector {
  position: absolute;
  right: 18px;
  top: 18px;
  width: min(320px, calc(100% - 36px));
  padding: 16px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  border-radius: 5px;
}
.inspector-head { display: flex; justify-content: space-between; color: var(--muted); font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.vector-inspector p { margin: 12px 0; font-size: 13px; line-height: 1.45; }
.vector-inspector select { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); padding: 7px 30px 7px 9px; font-size: 11px; }
.score-bars { margin-top: 14px; display: grid; gap: 7px; }
.score-row { display: grid; grid-template-columns: 70px 1fr 34px; align-items: center; gap: 7px; color: var(--muted); font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.score-row i { height: 3px; background: var(--surface-2); }
.score-row i b { display: block; width: var(--width); height: 100%; background: var(--cyan); }

.preview-band { border-top: 1px solid var(--line); padding-top: 26px; }
.tab-bar { display: flex; gap: 5px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab-button { border: 0; border-bottom: 2px solid transparent; background: transparent; padding: 10px 12px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab-button.is-active { color: var(--ink); border-bottom-color: var(--cyan); }
.preview-document { min-height: 250px; padding: 26px 0 30px; max-width: 980px; }
.preview-document h2 { margin: 0 0 16px; font: 600 25px/1.2 Georgia, "Times New Roman", serif; }
.preview-document h3 { margin: 24px 0 8px; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.preview-document p, .preview-document li { font: 400 16px/1.65 Georgia, "Times New Roman", serif; }
.preview-document pre { margin: 0; padding: 16px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 5px; white-space: pre-wrap; font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.ontology-entities { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ontology-entity { border-left: 3px solid var(--blue); padding: 9px 12px; background: var(--surface); }
.ontology-entity code { color: var(--blue); font-size: 9px; }
.ontology-entity b { display: block; margin-top: 4px; font-size: 13px; }
.ontology-entity p { margin: 5px 0 0; font: 400 12px/1.4 var(--font, inherit); color: var(--muted); }
.empty-state { color: var(--muted-2); }
.empty-state span { font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty-state p { font-size: 48px; margin: 18px 0; }

.approval-bar { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto auto; gap: 9px; align-items: center; padding: 15px 0; border-top: 1px solid var(--line); }
.hash-field { min-width: 0; }
.hash-field span { display: block; }
.hash-field code { display: block; margin-top: 5px; color: var(--muted); font: 500 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.artifacts-band { margin-top: 30px; border-top: 1px solid var(--line); }
.artifacts-header { padding-inline: 0; }
.artifact-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.artifact-card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.artifact-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--surface-2); }
.artifact-card figcaption { padding: 10px 12px; display: flex; justify-content: space-between; gap: 8px; font: 600 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.artifact-pending { aspect-ratio: 1; display: grid; place-items: center; background: repeating-linear-gradient(135deg, #f0f3f5, #f0f3f5 8px, #f8fafb 8px, #f8fafb 16px); color: var(--muted); font: 600 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 40; display: grid; gap: 8px; max-width: min(390px, calc(100vw - 36px)); }
.toast { padding: 12px 14px; border: 1px solid var(--line-strong); background: var(--surface); box-shadow: var(--shadow); border-radius: 5px; font-size: 13px; animation: toast-in 180ms ease-out; }
.toast.is-error { border-left: 4px solid var(--red); }
.toast.is-ok { border-left: 4px solid var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1060px) {
  .app-shell { grid-template-columns: 196px minmax(0, 1fr); }
  .topbar { grid-template-columns: 196px minmax(220px, 1fr) auto; }
  .brand { padding-inline: 14px; }
  .vector-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .approval-bar { grid-template-columns: 1fr auto auto; }
  .approval-bar .hash-field { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .topbar {
    min-height: 112px;
    grid-template: 62px 50px / minmax(0, 1fr) auto;
  }
  .brand { border-right: 0; padding: 0 12px; }
  .brand-mark { width: 34px; height: 34px; }
  .mode-control {
    position: static;
    grid-column: 1 / -1;
    grid-row: 2;
    align-self: start;
    justify-self: stretch;
    width: auto;
    margin: 0 12px 7px;
  }
  .topbar-actions { padding: 0 10px; }
  .system-pill { display: none; }
  .project-rail { display: none; }
  .input-band, .run-band, .preview-band, .artifacts-band, .auth-banner { width: calc(100% - 24px); }
  .input-band { padding-top: 22px; }
  #idea-input { min-height: 150px; font-size: 18px; }
  .input-controls { grid-template-columns: 1fr; }
  .primary-button, .secondary-button { min-height: 46px; }
  .stage-line li b { font-size: 8px; white-space: nowrap; }
  .stage-line li span { font-size: 8px; }
  .vector-grid { grid-template-columns: 1fr; }
  .vector-card { min-height: 142px; }
  .professional-stage, #vector-canvas { min-height: 620px; height: 620px; }
  .vector-inspector { top: auto; bottom: 12px; right: 12px; width: calc(100% - 24px); }
  .ontology-entities, .artifact-grid { grid-template-columns: 1fr; }
  .approval-bar { grid-template-columns: 1fr; }
  .approval-bar .hash-field { grid-column: auto; }
  .approval-bar button { width: 100%; }
  .workspace { padding-bottom: 94px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
