:root {
  --bg0: #141311;
  --bg1: #1c1b18;
  --bg2: #26241f;
  --line: #3a3730;
  --text: #f3f0ea;
  --muted: #9a958c;
  --accent: #2f9e8f;
  --accent2: #217a6f;
  --accent-soft: rgba(47, 158, 143, 0.14);
  --ok: #3cb371;
  --warn: #c4a35a;
  --err: #c45c5c;
  --display: "Syne", "Segoe UI", sans-serif;
  --font: "Figtree", "Segoe UI", sans-serif;
  --mono: "Cascadia Mono", "Consolas", monospace;
  --rail: 13.5rem;
  --ease: 180ms ease;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 520px at 0% 0%, #1f2a26 0%, transparent 55%),
    radial-gradient(700px 480px at 100% 10%, #2a2418 0%, transparent 50%),
    var(--bg0);
  color: var(--text);
  font-family: var(--font);
}
body { min-height: 100vh; }

button, .btn {
  font: inherit;
  cursor: pointer;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  transition: background var(--ease), border-color var(--ease), color var(--ease), transform var(--ease);
}
button:hover:not(:disabled), .btn:hover { border-color: #524e45; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary, .btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { filter: brightness(1.05); }
button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
button.ghost:hover { color: var(--text); background: var(--bg2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.studio {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.35rem 1rem 1.1rem;
  border-right: 1px solid rgba(58, 55, 48, 0.85);
  background: rgba(20, 19, 17, 0.55);
  backdrop-filter: blur(8px);
}
.rail-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.15rem 0.35rem;
}
.rail-mark {
  width: 2rem;
  height: 2rem;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 800;
  background: linear-gradient(145deg, var(--accent), #1a5c54);
  color: #fff;
  font-size: 0.95rem;
}
.rail-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}
.rail-nav button, .rail-foot > button {
  text-align: left;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  border-radius: 9px;
  padding: 0.6rem 0.75rem;
  font-weight: 500;
}
.rail-nav button:hover, .rail-foot > button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.rail-nav button.active {
  color: var(--text);
  background: var(--accent-soft);
  border-color: transparent;
  box-shadow: inset 3px 0 0 var(--accent);
}
.rail-foot {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}
.lang {
  display: flex;
  gap: 0.3rem;
}
.lang button {
  flex: 1;
  padding: 0.35rem;
  font-size: 0.78rem;
  background: var(--bg1);
  color: var(--muted);
}
.lang button.active {
  color: var(--text);
  border-color: var(--accent);
}
.rail-status {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
  word-break: break-word;
  min-height: 1em;
}

.stage {
  padding: 2rem 2.25rem 3rem;
  min-width: 0;
}

.view { display: none; animation: fadeIn 280ms ease; }
.view.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .view { animation: none; }
  button, .btn, .action-tile { transition: none; }
}

.home-view {
  display: none;
  min-height: calc(100vh - 4rem);
  flex-direction: column;
  justify-content: center;
  gap: 1.75rem;
}
.home-view.active { display: flex; }

.home-hero { max-width: 28rem; }
.home-brand {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.4rem, 5vw, 3.4rem);
  letter-spacing: -0.035em;
  line-height: 1.02;
  margin: 0 0 0.65rem;
}
.lead {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 22rem;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 16rem));
  gap: 0.85rem;
}
.action-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  text-align: left;
  padding: 1.25rem 1.2rem;
  min-height: 7.2rem;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.action-tile:hover {
  border-color: #5a554c;
  transform: translateY(-1px);
}
.action-tile.primary {
  background: linear-gradient(160deg, rgba(47, 158, 143, 0.28), rgba(28, 27, 24, 0.9) 55%);
  border-color: rgba(47, 158, 143, 0.45);
}
.action-tile.primary:hover { filter: none; border-color: var(--accent); }
.action-label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.action-hint { color: var(--muted); font-size: 0.9rem; }

.view-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.view-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}

label {
  display: block;
  margin: 0.95rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}
input[type=text], select {
  width: 100%;
  background: var(--bg1);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 0.65rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.88rem;
}
.row { display: flex; gap: 0.5rem; align-items: center; }
.row input { flex: 1; min-width: 0; }
.actions-row { margin-top: 1.15rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.45rem 0 0; }
.meta { color: var(--muted); font-size: 0.85rem; min-height: 1.2rem; }

.panel {
  margin-top: 1rem;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  white-space: pre-wrap;
}
.mono { font-family: var(--mono); font-size: 0.85rem; }
.log {
  margin-top: 0.8rem;
  background: #0e0d0b;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
  max-height: 280px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: #c9c3b6;
}
.log-wrap { margin-top: 1rem; color: var(--muted); }
.log-wrap summary { cursor: pointer; margin-bottom: 0.35rem; }

.recent {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-width: 34rem;
}
.recent[hidden] { display: none !important; }
.recent-title {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  margin: 0.4rem 0 0.1rem;
}
.recent-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem 0.75rem;
  align-items: center;
  padding: 0.65rem 0.8rem;
  background: rgba(28, 27, 24, 0.7);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.9rem;
}
.recent-item .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-item .path {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-list {
  margin-top: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.history-row {
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem 0.95rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.35rem 0.85rem;
  align-items: start;
}
.history-row .when { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.history-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}
.history-badge.success { background: rgba(60, 179, 113, 0.18); color: var(--ok); }
.history-badge.partial { background: rgba(196, 163, 90, 0.18); color: var(--warn); }
.history-badge.failed { background: rgba(196, 92, 92, 0.18); color: var(--err); }
.history-paths {
  grid-column: 1 / -1;
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-all;
}
.history-paths .arrow { color: var(--muted); margin: 0 0.35rem; }
.history-paths .out { color: var(--muted); font-family: var(--mono); font-size: 0.8rem; }
.history-actions { grid-column: 1 / -1; }
.history-empty, .history-err { color: var(--muted); padding: 1rem 0.2rem; }
.history-err { color: var(--err); }

.progress {
  margin-top: 0.55rem;
  height: 10px;
  background: var(--bg2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
#progBar, #analyzeProgBar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent2), var(--ok));
  transition: width 0.25s ease;
}
.progress-panel {
  margin-top: 1.2rem;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.05rem 1.05rem;
}
.progress-panel.hidden, .hidden { display: none !important; }
.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.progress-head-right { display: flex; align-items: center; gap: 0.65rem; }
.pct { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.checklist {
  list-style: none;
  margin: 0.9rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
}
.checklist li {
  display: grid;
  grid-template-columns: 1.25rem 1fr auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.4rem 0.45rem;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 0.9rem;
}
.checklist li .mark {
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
}
.checklist li.active {
  color: var(--text);
  background: var(--accent-soft);
  border-color: rgba(47, 158, 143, 0.35);
}
.checklist li.active .mark {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 158, 143, 0.15);
  animation: pulse 1.2s ease-in-out infinite;
}
.checklist li.done { color: var(--ok); }
.checklist li.done .mark {
  border-color: var(--ok);
  background: var(--ok);
  color: #0a140f;
}
.checklist li.fail { color: var(--err); }
.checklist li.fail .mark { border-color: var(--err); background: var(--err); color: #fff; }
.checklist li .step-pct { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }
.live { margin-top: 0.75rem; min-height: 1.2rem; color: var(--muted); }

.btn-cancel {
  border-color: rgba(196, 92, 92, 0.5) !important;
  color: #e0a0a0 !important;
  background: transparent !important;
}
.btn-cancel:not(:disabled):hover {
  background: rgba(196, 92, 92, 0.14) !important;
  color: #fff !important;
}

.warn-box {
  margin-top: 0.6rem;
  padding: 0.65rem 0.8rem;
  border-radius: 9px;
  border: 1px solid rgba(196, 163, 90, 0.45);
  background: rgba(196, 163, 90, 0.1);
  color: #e6d3a0;
  white-space: pre-wrap;
  font-size: 0.9rem;
}

.ok { color: var(--ok); }
.err { color: var(--err); }
.warn { color: var(--warn); }

.agent-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(12, 11, 10, 0.92);
}
.agent-gate.hidden { display: none !important; }
.agent-gate-card {
  max-width: 380px;
  width: 100%;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.5rem 1.35rem;
}
.gate-brand {
  font-family: var(--display);
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 0.35rem;
}
.agent-gate-card h1 {
  font-family: var(--display);
  font-size: 1.55rem;
  margin: 0 0 0.55rem;
  letter-spacing: -0.02em;
}
.agent-gate-card p { color: var(--muted); line-height: 1.5; margin: 0; }
.agent-gate-card .cta { display: flex; gap: 0.55rem; flex-wrap: wrap; margin: 1.15rem 0 0; }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.8; }
}

@media (max-width: 860px) {
  .studio {
    grid-template-columns: 1fr;
  }
  .rail {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0.85rem;
  }
  .rail-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .rail-foot {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .rail-status { flex: 1 1 100%; }
  .stage { padding: 1.25rem 1.1rem 2.5rem; }
  .action-grid { grid-template-columns: 1fr; }
  .home-view.active { justify-content: flex-start; padding-top: 0.5rem; }
}
