:root {
  --bg: #0b0d12;
  --bg-2: #0f1116;
  --sidebar: #0e1117;
  --panel: #14171f;
  --panel-2: #1a1e28;
  --elevated: #1e2330;
  --border: #262b37;
  --border-2: #313747;
  --text: #eef0f5;
  --muted: #97a0b0;
  --faint: #6a7384;
  --accent: #7c8cff;
  --accent-2: #b06cff;
  --accent-3: #4dd6c8;
  --danger: #ff6b81;
  --good: #57d99a;
  --shadow: 0 12px 40px -12px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1200px 700px at 80% -10%, #1a1330 0%, transparent 55%),
    radial-gradient(900px 600px at -10% 110%, #0d2a2a 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: grid;
  grid-template-columns: 96px 1fr;
  height: 100vh;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  background: rgba(14,17,23,.7);
  backdrop-filter: blur(18px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 16px;
  gap: 8px;
  -webkit-app-region: drag;
}
.logo {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 40px 0 22px;
}
.logo-dot {
  width: 30px; height: 30px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2) 55%, var(--accent-3));
  box-shadow: 0 0 22px -2px var(--accent);
}
.logo-text { font-size: 11px; line-height: 1.2; text-align: center; color: var(--muted); font-weight: 600; letter-spacing: .4px; }

.nav { display: flex; flex-direction: column; gap: 6px; width: 100%; padding: 0 12px; -webkit-app-region: no-drag; }
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: transparent; border: 1px solid transparent; color: var(--faint);
  border-radius: 12px; padding: 11px 4px; font-size: 10.5px; font-weight: 600;
  cursor: pointer; transition: all .16s ease; letter-spacing: .3px;
}
.nav-btn:hover { color: var(--text); background: var(--panel); }
.nav-btn.active { color: var(--text); background: var(--elevated); border-color: var(--border-2); box-shadow: inset 0 0 0 1px rgba(124,140,255,.18); }
.nav-btn svg { opacity: .9; }
.sidebar-foot { margin-top: auto; font-size: 9px; color: var(--faint); writing-mode: vertical-rl; transform: rotate(180deg); letter-spacing: .5px; opacity: .7; }

/* ---------------- Views ---------------- */
.view { display: none; height: 100vh; overflow: hidden; }
.view.active { display: block; }

.create-view {
  display: none;
  grid-template-columns: 372px 1fr;
  height: 100vh;
}
.create-view.active { display: grid; }

.panel-title { font-size: 15px; font-weight: 650; margin: 0 0 16px; letter-spacing: .2px; }

/* ---------------- Controls ---------------- */
.controls {
  position: relative;
  border-right: 1px solid var(--border);
  padding: 46px 22px 22px;
  display: flex; flex-direction: column; gap: 18px;
  overflow-y: auto;
  background: rgba(20,23,31,.45);
}
.drag-region { position: absolute; top: 0; left: 0; right: 0; height: 38px; -webkit-app-region: drag; }

.field { display: flex; flex-direction: column; gap: 9px; }
.field label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; font-weight: 600; }

.seg {
  display: flex; gap: 3px; padding: 3px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
}
.seg-btn {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 9px 6px; border-radius: 9px; font-size: 11.5px; font-weight: 600; cursor: pointer;
  transition: all .15s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 4px 14px -4px var(--accent); }

textarea {
  width: 100%; resize: vertical; min-height: 96px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 13px; font-size: 13px; font-family: inherit; line-height: 1.5;
  transition: border-color .15s ease;
}
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,140,255,.12); }
.hint { font-size: 11.5px; color: var(--faint); margin: 0; line-height: 1.45; }

.ref-count { color: var(--faint); font-size: 11px; font-weight: 600; margin-left: 4px; letter-spacing: 0; text-transform: none; }
.ref-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.ref-thumb {
  width: 78px; height: 78px; border-radius: 11px; overflow: hidden; position: relative;
  border: 1px solid var(--border-2); background: var(--panel-2); flex-shrink: 0;
}
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref-x {
  position: absolute; top: 3px; right: 3px; width: 19px; height: 19px; border-radius: 50%;
  background: rgba(8,10,14,.78); color: #fff; border: none; font-size: 10px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .14s ease;
}
.ref-thumb:hover .ref-x { opacity: 1; }
.ref-x:hover { background: var(--danger); }
.ref-add {
  width: 78px; height: 78px; border: 1.5px dashed var(--border-2); border-radius: 11px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; background: var(--panel-2); color: var(--faint); flex-shrink: 0;
  font-size: 11px; transition: all .15s ease;
}
.ref-add:hover { border-color: var(--accent); color: var(--text); background: #1c2230; }
.ref-add.drag { border-color: var(--accent); background: #20283a; color: var(--text); }

.ratios { display: flex; gap: 7px; flex-wrap: wrap; }
.ratio {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 11px; padding: 10px 11px; font-size: 11.5px; cursor: pointer; min-width: 54px;
  transition: all .15s ease;
}
.ratio:hover { color: var(--text); border-color: var(--border-2); }
.ratio.active { border-color: var(--accent); color: var(--text); background: #1b2233; box-shadow: inset 0 0 0 1px rgba(124,140,255,.2); }
.box { display: block; border: 1.5px solid currentColor; border-radius: 3px; }
.r-1-1 { width: 20px; height: 20px; }
.r-3-2 { width: 26px; height: 17px; }
.r-2-3 { width: 17px; height: 26px; }
.r-16-9 { width: 28px; height: 16px; }
.r-9-16 { width: 16px; height: 28px; }

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; padding: 13px; border-radius: 13px;
  font-size: 14px; font-weight: 650; cursor: pointer;
  transition: filter .15s ease, transform .05s ease; box-shadow: 0 8px 24px -8px var(--accent);
}
button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: translateY(1px); }
button.primary:disabled { opacity: .55; cursor: default; filter: none; box-shadow: none; }
.control-note { font-size: 11.5px; min-height: 14px; margin: 0; color: var(--faint); }
.control-note.error { color: var(--danger); }

button.ghost {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 7px 11px; font-size: 12px; cursor: pointer; transition: all .14s ease;
}
button.ghost:hover { border-color: var(--accent); background: var(--elevated); }
button.small { padding: 6px 10px; font-size: 11.5px; align-self: flex-start; }

/* ---------------- Workspace ---------------- */
.workspace { display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.job-tabs {
  display: flex; gap: 6px; padding: 44px 18px 0; overflow-x: auto;
  border-bottom: 1px solid var(--border); min-height: 56px; align-items: flex-end;
}
.job-tab {
  display: flex; align-items: center; gap: 8px; max-width: 220px;
  background: var(--panel); border: 1px solid var(--border); border-bottom: none;
  border-radius: 11px 11px 0 0; padding: 9px 11px; font-size: 12px; color: var(--muted);
  cursor: pointer; white-space: nowrap; transition: all .14s ease; position: relative; top: 1px;
}
.job-tab:hover { color: var(--text); }
.job-tab.active { background: var(--bg); color: var(--text); border-color: var(--border-2); }
.job-tab .label { overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.job-tab .st { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.st.running { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.st.done { background: var(--good); }
.st.error { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:.4} 50%{opacity:1} }
.job-tab .x { color: var(--faint); font-size: 14px; line-height: 1; padding: 0 2px; border-radius: 4px; }
.job-tab .x:hover { color: var(--text); background: var(--border-2); }
.job-tab.dragging { opacity: .45; }
.job-tab.drop-target { border-color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }

.stage {
  flex: 1; min-height: 0; padding: 22px; display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.stage-empty { text-align: center; color: var(--faint); display: flex; flex-direction: column; align-items: center; gap: 18px; }
.stage-empty p { font-size: 13px; line-height: 1.5; margin: 0; }
.ghost-ring { width: 64px; height: 64px; border-radius: 50%; border: 2px dashed var(--border-2); }

.job-panel { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 14px; }
.job-canvas {
  flex: 1; min-height: 0; border: 1px solid var(--border); border-radius: 16px;
  background:
    repeating-conic-gradient(#121620 0% 25%, #161b27 0% 50%) 50% / 26px 26px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative;
}
.job-canvas img { max-width: 100%; max-height: 100%; object-fit: contain; }
.result-heart {
  position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 20px; line-height: 1; z-index: 2;
  background: rgba(8,10,14,.55); color: #fff; backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s ease, background .14s ease, color .14s ease;
  box-shadow: 0 4px 14px -4px rgba(0,0,0,.5);
}
.result-heart:hover { transform: scale(1.12); background: rgba(8,10,14,.75); }
.result-heart.on { color: #ff5c7a; background: rgba(8,10,14,.7); }

/* progress ring */
.prog { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { transform: rotate(-90deg); }
.ring .track { stroke: var(--border-2); }
.ring .bar { stroke: url(#grad); stroke-linecap: round; transition: stroke-dashoffset .3s ease; }
.ring .pct {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.prog .stage-label { font-size: 12.5px; color: var(--muted); }

.job-error { color: var(--danger); font-size: 13px; max-width: 460px; text-align: center; line-height: 1.5; }

.job-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.job-meta { margin-left: auto; font-size: 11.5px; color: var(--faint); }

/* ---------------- Library ---------------- */
.library-view { padding: 46px 28px 24px; overflow-y: auto; }
.library-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 18px; }
.lib-count { font-size: 12px; color: var(--faint); }
.lib-filter { margin-left: auto; display: flex; gap: 4px; padding: 3px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; align-self: center; }
.lib-fil { background: transparent; border: none; color: var(--muted); padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all .14s ease; }
.lib-fil:hover { color: var(--text); }
.lib-fil.active { background: var(--elevated); color: var(--text); }
.lib-fil[data-filter="fav"].active { color: #ff7a93; }
.fil-count { opacity: .7; font-size: 11px; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.lib-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column; transition: transform .15s ease, border-color .15s ease;
}
.lib-card:hover { transform: translateY(-3px); border-color: var(--border-2); box-shadow: var(--shadow); }
.lib-thumb { aspect-ratio: 1/1; background: #0e121a; cursor: pointer; overflow: hidden; display: flex; align-items: center; justify-content: center; position: relative; }
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; }
.heart-btn {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 15px; line-height: 1;
  background: rgba(8,10,14,.55); color: #fff; backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .14s ease, transform .12s ease;
}
.lib-card:hover .heart-btn { opacity: 1; }
.heart-btn:hover { transform: scale(1.12); }
.heart-btn.on { opacity: 1; color: #ff5c7a; background: rgba(8,10,14,.7); }
.lb-heart.on { color: #ff5c7a; border-color: #ff5c7a; }
.lib-body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 9px; }
.lib-badges { display: flex; gap: 6px; }
.badge { font-size: 10px; font-weight: 650; padding: 3px 7px; border-radius: 999px; letter-spacing: .3px; text-transform: uppercase; }
.badge.mode { background: rgba(124,140,255,.16); color: #aeb6ff; }
.badge.aspect { background: var(--panel-2); color: var(--muted); }
.badge.num { background: rgba(77,214,200,.16); color: var(--accent-3); font-variant-numeric: tabular-nums; }
.badge.cat { background: rgba(176,108,255,.16); color: #c9a6ff; cursor: pointer; }
.badge.cat:hover { background: rgba(176,108,255,.28); }
.tag-hint { color: var(--faint); }
.tag-hint b { color: var(--accent-3); font-weight: 700; }

/* Library search + analyze status */
.lib-search {
  flex: 1; min-width: 180px; max-width: 460px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 11px; padding: 9px 13px; font-size: 13px; font-family: inherit;
  transition: border-color .15s ease;
}
.lib-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,140,255,.12); }
.lib-search::placeholder { color: var(--faint); }
.analyze-status {
  font-size: 11.5px; color: var(--accent-3); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.analyze-status::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-3); animation: pulse 1.1s ease-in-out infinite;
}

/* Tag chips on cards + lightbox */
.lib-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-chip {
  font-size: 10.5px; padding: 3px 8px; border-radius: 999px; cursor: pointer;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  transition: all .13s ease; white-space: nowrap;
}
.tag-chip:hover { color: var(--text); border-color: var(--accent); background: var(--elevated); }
.lib-analyzing { font-size: 11px; color: var(--faint); font-style: italic; }
.lb-tags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 720px; }
.lib-prompt { font-size: 12px; color: var(--muted); line-height: 1.4; max-height: 50px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.lib-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.lib-actions button { font-size: 11px; padding: 5px 8px; }
.lib-actions .del { margin-left: auto; color: var(--faint); }
.lib-actions .del:hover { color: var(--danger); border-color: var(--danger); }
.library-empty { color: var(--faint); font-size: 13px; padding: 40px 0; }

/* ---------------- Lightbox ---------------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(6,8,12,.86); backdrop-filter: blur(8px);
  z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 40px;
}
.lightbox img { max-width: 84vw; max-height: 74vh; border-radius: 12px; box-shadow: var(--shadow); object-fit: contain; }
.lb-close { position: absolute; top: 20px; right: 24px; background: var(--panel); border: 1px solid var(--border); color: var(--text); width: 38px; height: 38px; border-radius: 50%; font-size: 15px; cursor: pointer; }
.lb-close:hover { border-color: var(--accent); }
.lb-bar { display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 720px; }
.lb-prompt { font-size: 13px; color: var(--muted); text-align: center; line-height: 1.5; margin: 0; }
.lb-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------------- Settings ---------------- */
.settings-view { padding: 46px 28px 24px; overflow-y: auto; }
.settings-title { margin-bottom: 20px; }
.setting-card {
  max-width: 640px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px 18px; margin-bottom: 16px;
}
.setting-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.setting-name { font-size: 14px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.setting-desc { font-size: 12.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; max-width: 460px; }
.setting-note { font-size: 12px; color: var(--faint); margin: 12px 0 0; line-height: 1.5; }
.setting-tag {
  font-size: 10px; font-weight: 650; padding: 2px 7px; border-radius: 999px;
  background: rgba(124,140,255,.16); color: #aeb6ff; letter-spacing: .3px;
}
.backend-seg { margin-top: 14px; }
.backend-seg .seg-btn { padding: 10px 8px; font-size: 12px; }

/* toggle switch */
.switch {
  flex-shrink: 0; width: 46px; height: 27px; border-radius: 999px; border: none; cursor: pointer;
  background: var(--border-2); position: relative; transition: background .18s ease; padding: 0;
}
.switch.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.switch .knob {
  position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%;
  background: #fff; transition: transform .18s ease; box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.switch.on .knob { transform: translateX(19px); }

.hidden { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #3a4254; }

/* ===================== web edition: login + responsive ==================== */
.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.login-logo .logo-dot {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; letter-spacing: -.2px; }
.login-sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 11px;
  border: 1px solid var(--border-2);
  background: var(--bg-2);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .primary { width: 100%; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* The desktop build reserved space for the traffic-light window controls. */
.controls .panel-title { margin-top: 0; }

@media (max-width: 860px) {
  body { overflow: auto; }
  .app-shell { grid-template-columns: 1fr; height: auto; }
  .sidebar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    height: auto;
    padding: 10px 14px;
  }
  .sidebar .nav { flex-direction: row; gap: 6px; }
  .logo-text, .sidebar-foot { display: none; }
  .create-view { grid-template-columns: 1fr; }
  .controls { border-right: none; border-bottom: 1px solid var(--border); }
  .view { height: auto; }
}
