:root{
  --bg:#05050b;
  --card1:#0b1022;
  --card2:#081022;
  --text:#eafff3;
  --muted:#a8b2d1;
  --line:rgba(255,255,255,0.09);

  --spud:#22ff88;
  --spud2:#9b5cff;
  --blue:#60a5fa;
  --danger:#ff4d6d;
  --warn:#ffd166;

  --shadow: 0 30px 140px rgba(0,0,0,0.62);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  color:var(--text);
  background: radial-gradient(1200px 800px at 20% 30%, rgba(34,255,136,0.10), transparent 60%),
              radial-gradient(1200px 800px at 80% 70%, rgba(155,92,255,0.10), transparent 60%),
              var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  overflow-x:hidden;
}

/* Background layers */
.bg-grid{
  position:fixed; inset:0; pointer-events:none; opacity:.35;
  background-image: linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 64px 64px;
  filter: drop-shadow(0 0 20px rgba(34,255,136,0.06));
}
.bg-scanlines{
  position:fixed; inset:0; pointer-events:none; opacity:.15;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.12) 0px, rgba(255,255,255,0) 2px, rgba(255,255,255,0) 10px);
  mix-blend-mode: overlay;
}
.bg-orbs{
  position:fixed; inset:-40px; pointer-events:none;
  background: radial-gradient(800px 600px at 25% 20%, rgba(34,255,136,0.14), transparent 60%),
              radial-gradient(900px 700px at 70% 80%, rgba(155,92,255,0.14), transparent 60%);
  filter: blur(10px);
  opacity: .8;
}

.top{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 18px;
  background: rgba(5,5,11,0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand{display:flex; align-items:center; gap:12px}
.dot{
  width:14px; height:14px; border-radius:999px;
  background: radial-gradient(circle at 30% 30%, #fff, rgba(255,255,255,0.1)),
              linear-gradient(90deg, var(--spud), var(--spud2));
  box-shadow: 0 0 22px rgba(34,255,136,0.25), 0 0 22px rgba(155,92,255,0.18);
}
.title{font-weight:900; letter-spacing:.3px}
.sub{color:var(--muted); font-size:12px}

.tabs{display:flex; gap:10px}
.tab{
  border:1px solid var(--line);
  color:var(--text);
  background: rgba(255,255,255,0.02);
  padding:8px 12px;
  border-radius:999px;
  cursor:pointer;
  font-weight:800;
}
.tab.active{
  border-color: rgba(34,255,136,0.55);
  box-shadow: 0 0 0 2px rgba(34,255,136,0.12), 0 0 24px rgba(34,255,136,0.14);
}

.wrap{max-width:1240px; margin:0 auto; padding:18px}

/* ✅ True tab separation */
.panel{display:none; margin-top:14px;}
.panel.active{display:block;}

.grid{display:grid; gap:18px}
.gen-grid{grid-template-columns: 1.2fr 0.9fr}
@media(max-width:1100px){
  .gen-grid{grid-template-columns:1fr}
}

.card{
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border:1px solid var(--line);
  border-radius:20px;
  padding:16px;
  box-shadow: var(--shadow);
}

.card-hero{padding:18px}
.hero{display:flex; align-items:flex-start; justify-content:space-between; gap:12px}
.hero h1{margin:0; font-size:24px}
.hero-sub{margin:6px 0 0; color:var(--muted)}
.hero-pill{
  font-size:12px;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid rgba(34,255,136,0.35);
  background: rgba(34,255,136,0.06);
}

.divider{height:1px; background: var(--line); margin:14px 0}
.divider.soft{opacity:.6}

label{display:block; color:var(--muted); font-size:12px; margin:10px 0 6px}
input, textarea, select{
  width:100%;
  padding:12px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.28);
  color:var(--text);
  outline:none;
}
textarea{resize:vertical}
.row{display:flex; gap:12px}
.row > div{flex:1}
.actions{display:flex; gap:10px}

.btn{
  border:1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color:var(--text);
  padding:10px 12px;
  border-radius:14px;
  cursor:pointer;
  font-weight:800;
}
.btn.primary{
  background: linear-gradient(90deg, rgba(34,255,136,0.18), rgba(155,92,255,0.12));
  border-color: rgba(34,255,136,0.45);
}
.btn.ghost{opacity:.9}
.btn.mini{padding:8px 10px; border-radius:12px; font-size:12px}
.btn:disabled{opacity:.5; cursor:not-allowed}

.hint{margin-top:12px; color:var(--muted); font-size:12px}

.now-card .now-top{
  display:flex; align-items:center; justify-content:space-between;
  gap:12px;
}
.now-title{font-weight:900}
.now-sub{color:var(--muted); font-size:12px; margin-top:2px}
.pill{
  padding:8px 10px;
  border-radius:999px;
  border:1px solid rgba(96,165,250,0.35);
  background: rgba(96,165,250,0.06);
  font-weight:900;
}
.pill.good{border-color: rgba(34,255,136,0.55); box-shadow: 0 0 26px rgba(34,255,136,0.12)}
.pill.bad{border-color: rgba(255,77,109,0.55); box-shadow: 0 0 26px rgba(255,77,109,0.10)}
.pill.run{border-color: rgba(155,92,255,0.55); box-shadow: 0 0 26px rgba(155,92,255,0.12)}

.row.mini{margin-top:12px}
.stat{
  flex:1;
  border:1px solid var(--line);
  border-radius:16px;
  padding:10px 12px;
  background: rgba(255,255,255,0.02);
}
.stat .k{color:var(--muted); font-size:11px}
.stat .v{font-weight:900; margin-top:2px}

.log{
  margin-top:10px;
  background: rgba(0,0,0,0.28);
  border:1px solid rgba(255,255,255,0.10);
  border-radius:16px;
  padding:12px;
  height:420px;
  overflow:auto;
  white-space:pre-wrap;
}

/* Moods */
.chip-row{
  display:grid;
  grid-template-columns: 1fr;
  gap:10px;
}
.chip-wrap{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
}
.chip{
  border:1px solid rgba(255,255,255,0.12);
  background: rgba(3,6,18,0.55);
  color:#eafff3;
  padding:7px 10px;
  border-radius:999px;
  font-size:12px;
  cursor:pointer;
  user-select:none;
  transition: transform .08s ease, border-color .2s ease, box-shadow .2s ease;
}
.chip:hover{transform: translateY(-1px)}
.chip.on{
  border-color: rgba(34,255,136,0.55);
  box-shadow: 0 0 0 2px rgba(34,255,136,0.12) inset, 0 0 26px rgba(34,255,136,0.12);
}
.chip.purple.on{
  border-color: rgba(155,92,255,0.60);
  box-shadow: 0 0 0 2px rgba(155,92,255,0.14) inset, 0 0 26px rgba(155,92,255,0.12);
}

/* Library grid + cards */
.library-grid{
  display:grid;
  grid-template-columns: repeat(5, minmax(0,1fr));
  gap:12px;
  margin-top:12px;
}
.lib-card{
  border:1px solid rgba(255,255,255,0.10);
  background: rgba(3,6,18,0.42);
  border-radius:16px;
  overflow:hidden;
  cursor:pointer;
  transition: transform .10s ease, border-color .2s ease, box-shadow .2s ease;
}
.lib-card:hover{
  transform: translateY(-2px);
  border-color: rgba(34,255,136,0.35);
  box-shadow: 0 18px 80px rgba(0,0,0,0.40);
}
.lib-thumb{width:100%; aspect-ratio:9/16; object-fit:cover; display:block}
.lib-meta{padding:10px}
.lib-title{font-weight:900; font-size:12px; line-height:1.2}
.lib-sub{margin-top:6px; font-size:11px; color:var(--muted)}
.badges{display:flex; flex-wrap:wrap; gap:6px; margin-top:8px}
.badge{
  font-size:10px;
  padding:5px 8px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,0.10);
  background: rgba(2,3,10,0.45);
}

/* Runs list */
.list{display:flex; flex-direction:column; gap:10px; margin-top:12px}
.run-card{
  border:1px solid rgba(255,255,255,0.10);
  background: rgba(3,6,18,0.40);
  border-radius:16px;
  padding:12px;
}
.run-top{display:flex; justify-content:space-between; gap:10px}
.run-id{font-weight:900}
.run-sub{margin-top:6px; font-size:12px; color:var(--muted)}

/* Toasts */
.toasts{
  position:fixed;
  right:16px;
  bottom:16px;
  display:flex;
  flex-direction:column;
  gap:10px;
  z-index:999;
}
.toast{
  width: 360px;
  border-radius:16px;
  padding:12px;
  border:1px solid rgba(255,255,255,0.12);
  background: rgba(2,3,10,0.80);
  box-shadow: 0 20px 80px rgba(0,0,0,0.55);
}
.toast .t{font-weight:900}
.toast .m{margin-top:6px; font-size:12px; color:var(--muted); white-space:pre-wrap}
.toast.good{border-color: rgba(34,255,136,0.35)}
.toast.bad{border-color: rgba(255,77,109,0.35)}

/* =========================================================
   LIBRARY: Single-scroll layout (NO double scrollbars)
========================================================= */
#tab-library{
  display:grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap:14px;
  align-items:start;
}
#tab-library > .row{ grid-column: 1 / -1; }

.library-preview{
  position: sticky;
  top: 86px;
  overflow: visible;
  max-height: none;
}

.player{
  width:100%;
  aspect-ratio: 9 / 16;
  height:auto;
  max-height: calc(100vh - 360px);
  object-fit: contain;
  border-radius:16px;
  border:1px solid rgba(255,255,255,0.10);
  background:#000;
  margin-top:12px;
}

.meta{
  height:auto;
  max-height:none;
  overflow:visible;
  background: rgba(2,3,10,0.55);
  border:1px solid rgba(255,255,255,0.10);
  border-radius:14px;
  padding:12px;
  white-space:pre-wrap;
  word-break:break-word;
  margin-top:12px;
}

/* TikTok panel (Library only) */
.tt-panel{
  margin-top:12px;
  border:1px solid rgba(255,255,255,0.10);
  background: rgba(3,6,18,0.35);
  border-radius:16px;
  padding:12px;
  box-shadow: 0 0 0 2px rgba(34,255,136,0.06) inset;
}
.tt-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.tt-title{
  font-weight:900;
  letter-spacing:.2px;
}
.tt-sub{
  margin-top:4px;
  color:var(--muted);
  font-size:12px;
}
.tt-actions{display:flex; gap:8px; align-items:center}
.tt-row{
  display:flex;
  gap:10px;
  margin-top:10px;
}
.tt-row input{
  flex:1;
}
.tt-hint{
  margin-top:10px;
  font-size:12px;
  color:var(--muted);
}

/* Responsive */
@media (max-width: 1400px){
  .library-grid{grid-template-columns: repeat(4, minmax(0,1fr));}
}
@media (max-width: 1100px){
  .gen-grid{grid-template-columns:1fr}
  .library-grid{grid-template-columns: repeat(2, minmax(0,1fr));}
  .log{height:260px}

  #tab-library{ grid-template-columns: 1fr; }
  .library-preview{ position: relative; top:auto; }
  .player{ max-height: 520px; }
  .tt-row{flex-direction:column;}
}
