:root {
  --bg: #090b0d;
  --bg-2: #0d1114;
  --panel: #12171b;
  --panel-2: #161d22;
  --line: #273139;
  --line-soft: #1d252b;
  --text: #edf4f2;
  --muted: #91a0a6;
  --faint: #5f6d73;
  --cyan: #22d3ee;
  --green: #a3e635;
  --amber: #f59e0b;
  --red: #fb7185;
  --blue: #38bdf8;
  --rail-start: #0b0f12;
  --rail-end: #080a0c;
  --control: #0b0f12;
  --surface-strong: #101418;
  --button: #11181d;
  --button-alt: #10202a;
  --button-border: #1f4654;
  --on-accent: #051012;
  --meter-dark: #1f3540;
  --log-text: #b9c7cc;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.38);
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(34, 211, 238, 0.08), transparent 360px),
    radial-gradient(circle at 100% 0%, rgba(163, 230, 53, 0.08), transparent 320px),
    var(--bg);
  font-family: Inter, ui-sans-serif, "Segoe UI", Aptos, Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }
h1, h2, p { margin: 0; }

body.auth-required .app-shell {
  display: none;
}

body.auth-required.authenticated .app-shell {
  display: grid;
}

body.auth-required.authenticated .auth-gate {
  display: none;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(1020px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
  align-items: stretch;
}

.auth-copy,
.auth-card,
.tutorial-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(18, 23, 27, 0.92), rgba(16, 20, 24, 0.96));
  box-shadow: var(--shadow);
}

.auth-copy {
  min-height: 520px;
  display: grid;
  align-content: end;
  gap: 16px;
  padding: clamp(24px, 6vw, 58px);
  background:
    linear-gradient(135deg, rgba(34, 211, 238, 0.16), transparent 42%),
    linear-gradient(315deg, rgba(163, 230, 53, 0.12), transparent 46%),
    var(--panel);
}

.auth-mark {
  width: 58px;
  height: 58px;
  font-size: 1.35rem;
}

.auth-copy h1 {
  max-width: 720px;
  font-size: clamp(2.4rem, 7vw, 5.7rem);
  line-height: 0.94;
}

.auth-lede {
  max-width: 620px;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.55;
}

.auth-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-steps span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.78rem;
  font-weight: 800;
}

.auth-card {
  display: grid;
  align-content: center;
  gap: 14px;
  padding: 24px;
}

.auth-card h2 {
  font-size: 1.35rem;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.45;
}

.auth-card small {
  line-height: 1.4;
}

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

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: linear-gradient(180deg, var(--rail-start), var(--rail-end));
  border-right: 1px solid var(--line-soft);
}

.brand, .status-card, .provider-tile {
  display: flex;
  gap: 11px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--cyan), var(--green));
  font-weight: 900;
  letter-spacing: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.brand strong, .status-card strong, .provider-tile strong { display: block; }
.brand small, .status-card small, small { color: var(--muted); }

.nav {
  display: grid;
  gap: 7px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
}

.nav-item span {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--cyan);
  background: rgba(34, 211, 238, 0.1);
  font-weight: 900;
}

.nav-item.active, .nav-item:hover {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}

.status-stack {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.status-card, .provider-tile {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
}

.dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 18px currentColor;
}

.dot.good { color: var(--green); background: var(--green); }
.dot.warn { color: var(--amber); background: var(--amber); }

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(18, 23, 27, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.app-notice {
  margin: -6px 0 18px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(34, 211, 238, 0.08);
  color: var(--text);
}

.app-notice.error {
  border-color: rgba(251, 113, 133, 0.6);
  background: rgba(251, 113, 133, 0.1);
}

.app-notice.warn {
  border-color: rgba(245, 158, 11, 0.6);
  background: rgba(245, 158, 11, 0.1);
}

.app-notice.success {
  border-color: rgba(163, 230, 53, 0.55);
  background: rgba(163, 230, 53, 0.1);
}

h1 {
  font-size: 1.9rem;
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: 0;
}

h2 {
  font-size: 0.98rem;
  line-height: 1.2;
  font-weight: 750;
  letter-spacing: 0;
}

.subhead {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.88rem;
}

.eyebrow {
  color: var(--cyan);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-actions, .button-row, .filters, .prompt-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.top-actions {
  justify-content: flex-end;
  max-width: 660px;
}

.tutorial-dialog {
  width: min(820px, calc(100vw - 32px));
  color: var(--text);
  padding: 0;
}

.tutorial-dialog::backdrop {
  background: rgba(0, 0, 0, 0.64);
  backdrop-filter: blur(8px);
}

.tutorial-head,
.tutorial-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.tutorial-actions {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.tutorial-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 16px;
}

.tutorial-grid article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.025);
  padding: 12px;
}

.tutorial-grid strong {
  display: block;
  margin-bottom: 6px;
}

.tutorial-grid p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.view { display: none; }
.view.active { display: block; }

.dense-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }

.panel {
  background: linear-gradient(180deg, var(--panel), var(--surface-strong));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 12px;
}
.panel-head.compact { align-items: center; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.74rem;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 8px;
  border: 1px solid rgba(34, 211, 238, 0.45);
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.08);
  color: var(--text);
  font-size: 0.74rem;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.form-grid.single { grid-template-columns: 1fr; }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  color: var(--text);
  background: var(--control);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--cyan);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  background: var(--control);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.toggle.inline { display: flex; }
.toggle input { width: auto; }

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text);
  background: var(--button);
  font-weight: 800;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  filter: grayscale(0.8);
}

.primary {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--cyan), var(--green));
  border-color: transparent;
}
.secondary {
  color: var(--text);
  background: var(--button-alt);
  border-color: var(--button-border);
}
.ghost {
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}
.full { width: 100%; justify-content: center; }
button:hover:not(:disabled) { border-color: var(--cyan); }

.google-button-host {
  min-height: 40px;
  overflow: hidden;
  border-radius: var(--radius);
}

.split-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.preset-list, .model-list, .chain-list, .provider-list, .history-list, .run-log, .asset-list {
  display: grid;
  gap: 8px;
}

.usage-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.usage-panel > div,
.usage-panel > article {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.025);
  padding: 10px;
}

.usage-panel > article {
  grid-column: span 2;
}

.usage-panel strong,
.usage-panel small {
  display: block;
  overflow-wrap: anywhere;
}

.preset, .model, .chain-step, .history-item, .log-item, .provider-list div, .theme-card, .trait-control, .stem, .asset-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.025);
  padding: 10px;
}

.preset {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  cursor: pointer;
}

.preset.active {
  border-color: var(--cyan);
  box-shadow: inset 3px 0 0 var(--cyan);
}

.provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
}

.provider-tile {
  min-width: 0;
}

.provider-tile small {
  display: block;
  overflow-wrap: anywhere;
}

.provider-tile.ready { border-color: rgba(163, 230, 53, 0.45); }
.provider-tile.missing { border-color: rgba(245, 158, 11, 0.45); }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 10px;
  overflow-x: auto;
}

.theme-card {
  display: grid;
  gap: 8px;
  min-height: 210px;
}

.theme-card.selected {
  border-color: var(--green);
  box-shadow: inset 0 3px 0 var(--green);
}
.theme-card p { color: var(--muted); font-size: 0.84rem; line-height: 1.35; }

.theme-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.selected-mark {
  border: 1px solid rgba(163, 230, 53, 0.55);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--green);
  font-size: 0.68rem;
  font-weight: 800;
}

.trait-matrix {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.trait-control header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.78rem;
}

.tab.active {
  background: var(--cyan);
  color: var(--on-accent);
  border-color: var(--cyan);
}

.report {
  min-height: 28px;
  color: var(--red);
  font-size: 0.82rem;
  margin-top: 8px;
}

.stem-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stem {
  min-height: 150px;
  display: grid;
  align-content: space-between;
}

.stem-meter {
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(34, 211, 238, 0.18), rgba(163, 230, 53, 0.14)),
    repeating-linear-gradient(90deg, var(--meter-dark) 0 8px, var(--control) 8px 15px);
}

.asset-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 11px;
}

.asset-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 50%;
}

#assetPlayer[controls] {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(420px, calc(100vw - 36px));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.run-log {
  max-height: 240px;
  overflow: auto;
  color: var(--log-text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.8rem;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  gap: 12px;
  align-items: center;
}

.history-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

@media (max-width: 1180px) {
  .app-shell, body.auth-required.authenticated .app-shell { grid-template-columns: 1fr; }
  .auth-panel { grid-template-columns: 1fr; }
  .auth-copy { min-height: 420px; }
  .rail {
    position: static;
    height: auto;
  }
  .nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .dense-grid, .easy-grid, .advanced-grid, .finishing-grid { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .theme-grid, .stem-grid, .trait-matrix, .split-controls, .provider-grid { grid-template-columns: 1fr; }
  .usage-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { align-items: start; flex-direction: column; }
}

@media (max-width: 680px) {
  .workspace, .rail { padding: 14px; }
  .auth-gate { padding: 14px; }
  .auth-copy, .auth-card { padding: 18px; }
  .nav { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .history-item, .asset-row, .usage-panel { grid-template-columns: 1fr; }
  .tutorial-grid { grid-template-columns: 1fr; }
  .tutorial-head, .tutorial-actions { align-items: stretch; flex-direction: column; }
  .usage-panel > article { grid-column: auto; }
}
