:root{
  --app-bg:#0e0f13;
  --app-bg-2:#15171e;
  --line:#262a35;
  --text:#e8eaf0;
  --muted:#8c93a6;
  --accent:#7c5cff;
  --accent-2:#4ad9c0;
  --radius:10px;
  --size:96px;
  --gap:6px;
  --labelw:96px;
  --tile-radius:4px;
  --board-bg:#15161c;
  --board-fg:#ffffff;
  --title-size:22px;
  --label-size:20px;
  --cap-size:10px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  background:
    radial-gradient(1200px 600px at 15% -10%, #1d1b3a 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #103033 0%, transparent 55%),
    var(--app-bg);
  color:var(--text);
  font:14px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,Roboto,Helvetica,Arial,sans-serif;
  -webkit-font-smoothing:antialiased;
  display:flex;flex-direction:column;
}
button,input,select{font:inherit;color:inherit}

/* ---------- top bar ---------- */
.topbar{
  display:flex;align-items:center;justify-content:space-between;gap:16px;
  padding:10px 16px;border-bottom:1px solid var(--line);
  background:rgba(14,15,19,.72);backdrop-filter:blur(12px);
  position:sticky;top:0;z-index:40;
}
.topbar-left{display:flex;align-items:center;gap:14px;flex-wrap:wrap;min-width:0}
.brand{font-weight:700;letter-spacing:.2px;font-size:16px;display:flex;align-items:center;gap:8px;white-space:nowrap}
.listbar{display:flex;align-items:center;gap:6px;min-width:0;flex:1 1 auto}
#listPicker{
  /* the floor matters on a phone: without it the flex row squeezes the name to "F…" */
  flex:1 1 auto;min-width:132px;max-width:220px;
  padding:7px 10px;border-radius:8px;cursor:pointer;
  border:1px solid var(--line);background:var(--app-bg-2);color:var(--text);
}
#listPicker:hover{border-color:#3a4153}
#listPicker:focus{outline:none;border-color:var(--accent)}
.logo{color:var(--accent);transform:translateY(-1px)}
.brand-sub{font-weight:400;color:var(--muted);font-size:12px;letter-spacing:.3px}
.topbar-actions{display:flex;gap:8px;flex-wrap:wrap}

.btn{
  border:1px solid var(--line);background:var(--app-bg-2);color:var(--text);
  padding:7px 12px;border-radius:8px;cursor:pointer;transition:.14s;white-space:nowrap;
}
.btn:hover{border-color:#3a4153;background:#1c1f28;transform:translateY(-1px)}
.btn:active{transform:translateY(0)}
.btn-primary{background:linear-gradient(180deg,#8a6cff,#6b47f5);border-color:#7250ff;color:#fff;font-weight:600}
.btn-primary:hover{background:linear-gradient(180deg,#9b80ff,#7a56ff);border-color:#8f73ff}
.btn-wide{display:block;text-align:center;width:100%}
.btn-icon{padding:7px 10px}
.only-narrow{display:none}

/* ---------- layout ---------- */
.layout{flex:1;display:grid;grid-template-columns:minmax(0,1fr) 330px;min-height:0}
.workspace{min-width:0;display:flex;flex-direction:column;padding:20px 20px 0;gap:14px;overflow:auto}
.board-scroll{min-width:0}

/* ---------- board ---------- */
.board{
  background:var(--board-bg);color:var(--board-fg);
  border-radius:14px;padding:16px 44px 16px 16px;
  box-shadow:0 20px 60px rgba(0,0,0,.45),0 0 0 1px rgba(255,255,255,.06);
  max-width:1060px;
}
.board-title{
  font-size:var(--title-size);font-weight:700;letter-spacing:.2px;padding:2px 6px 10px;outline:none;min-height:1em;
}
.board-title:empty::before{content:attr(data-ph);color:currentColor;opacity:.35}
.board-foot{font-size:12px;opacity:.55;padding:8px 6px 0;outline:none;min-height:1em}
.board-foot:empty::before{content:attr(data-ph);opacity:.5}
.rows{display:flex;flex-direction:column;gap:3px}

.tier-row{display:flex;align-items:stretch;position:relative;min-height:calc(var(--size) + var(--gap)*2)}
.tier-label{
  width:var(--labelw);flex:0 0 var(--labelw);
  display:flex;align-items:center;justify-content:center;text-align:center;
  border-radius:3px 0 0 3px;padding:6px;
}
.tier-label-text{
  color:#101114;font-weight:800;font-size:var(--label-size);line-height:1.15;outline:none;
  /* Full width, not shrink-to-fit. Hugging the text gave the box zero slack, and
     the PNG exporter ellipsises anything measuring wider than its box — so a
     label that fit exactly came out as "Brilli…" the moment canvas measured the
     font a hair differently from layout. Centring comes from .tier-label. */
  word-break:break-word;width:100%;display:block;
}
.tier-items{
  flex:1;min-width:0;display:flex;flex-wrap:wrap;align-content:flex-start;align-items:flex-start;
  gap:var(--gap);padding:var(--gap);background:color-mix(in srgb, var(--board-fg) 7%, transparent);border-radius:0 3px 3px 0;
}
.tier-items.drop-hot{background:rgba(124,92,255,.18);box-shadow:inset 0 0 0 1px rgba(124,92,255,.45)}

.tier-actions{
  position:absolute;left:100%;top:0;height:100%;width:40px;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
  opacity:0;transition:.15s;
}
.tier-row:hover .tier-actions,.tier-actions:focus-within{opacity:1}
.tier-actions button{
  width:22px;height:18px;line-height:1;padding:0;border-radius:4px;cursor:pointer;
  border:1px solid var(--line);background:var(--app-bg-2);color:var(--muted);font-size:11px;
}
.tier-actions button:hover{color:var(--text);border-color:#454c61}
.tier-actions input[type=color]{width:22px;height:18px;padding:0;border:1px solid var(--line);border-radius:4px;background:none;cursor:pointer}
input[type=color]::-webkit-color-swatch-wrapper{padding:2px}
input[type=color]::-webkit-color-swatch{border:none;border-radius:2px}

/* ---------- tiles ---------- */
.tile{
  width:var(--size);position:relative;touch-action:none;cursor:grab;user-select:none;-webkit-user-select:none;
}
.tile:active{cursor:grabbing}
.art{
  width:var(--size);height:var(--size);border-radius:var(--tile-radius);overflow:hidden;position:relative;
  background:#2b2f3c;display:block;
}
.art img{width:100%;height:100%;object-fit:cover;display:block;pointer-events:none;position:relative;z-index:1}
.art-fallback{
  position:absolute;inset:0;display:flex;align-items:center;justify-content:center;
  font-weight:700;font-size:calc(var(--size)/4);color:rgba(255,255,255,.75);text-align:center;padding:4px;
  line-height:1.1;overflow:hidden;
}
.tile-num{
  position:absolute;left:0;top:0;min-width:18px;height:18px;padding:0 4px;
  display:flex;align-items:center;justify-content:center;
  background:rgba(0,0,0,.66);color:#fff;font-size:11px;font-weight:700;
  border-radius:var(--tile-radius) 0 6px 0;z-index:2;
}
.cap{width:var(--size);padding-top:3px;overflow:hidden}
/* Both wrap as far as they need. Capping the title at one line cut "FULL COLOR
   ECLIPSE" in half; capping it at two still cut "Sgt. Pepper's Lonely Hearts Club
   Band", and the artist stayed on one line so "Godspeed You! Black Emperor" lost
   its tail. A long title makes for a taller tile, which beats an unreadable one.
   Whatever the board shows, the PNG shows — drawText wraps to the measured box. */
.cap-t{font-size:var(--cap-size);font-weight:600;line-height:1.25;text-align:center;overflow-wrap:anywhere}
.cap-a{font-size:calc(var(--cap-size) - 1px);line-height:1.25;opacity:.62;text-align:center;overflow-wrap:anywhere}

/* Visible by default: a touch screen has no hover to reveal it with, so hiding
   it until :hover put it out of reach there entirely. Where a pointer really can
   hover, keep it tucked away until the cover is pointed at. */
.tile-x{
  position:absolute;right:-6px;top:-6px;width:19px;height:19px;border-radius:50%;
  border:1px solid rgba(0,0,0,.35);background:#e04f5f;color:#fff;font-size:12px;line-height:1;
  cursor:pointer;display:flex;padding:0;align-items:center;justify-content:center;z-index:3;
}
@media (hover:hover){
  .tile-x{display:none}
  .tile:hover .tile-x{display:flex}
}
@media (hover:none){                    /* finger-sized, and clear of the artwork */
  .tile-x{width:26px;height:26px;right:-9px;top:-9px;font-size:16px}
}

.placeholder{
  height:var(--size);border-radius:var(--tile-radius);
  border:2px dashed rgba(124,92,255,.85);background:rgba(124,92,255,.14);
}
.ghost{
  position:fixed;z-index:999;pointer-events:none;opacity:.92;
  transform:scale(1.06) rotate(-2deg);filter:drop-shadow(0 12px 22px rgba(0,0,0,.55));
}
.ghost .tile-x{display:none}

/* ---------- bench ---------- */
.bench-wrap{max-width:1060px;padding-bottom:22px}
.bench-head{display:flex;align-items:baseline;gap:10px;margin-bottom:6px}
.bench-title{font-weight:600;font-size:13px;letter-spacing:.4px;text-transform:uppercase;color:var(--muted)}
.hint{color:var(--muted);font-size:12px}
.bench{
  display:flex;flex-wrap:wrap;gap:var(--gap);padding:12px;min-height:calc(var(--size) + 24px);
  border:1px dashed var(--line);border-radius:12px;background:rgba(255,255,255,.025);align-content:flex-start;
}
.bench.drop-hot{border-color:var(--accent);background:rgba(124,92,255,.12)}

/* ---------- sidebar ---------- */
.sidebar{
  border-left:1px solid var(--line);background:rgba(16,17,23,.6);
  padding:16px;overflow:auto;display:flex;flex-direction:column;gap:14px;
}
/* The sidebar is a flex column: without this, panels shrink under their own
   content and `overflow:hidden` crops the last controls off. Let them keep
   their height and scroll the sidebar instead. */
.panel{border:1px solid var(--line);border-radius:12px;background:var(--app-bg-2);overflow:hidden;flex:0 0 auto}
.panel-head{
  padding:10px 12px;font-size:12px;font-weight:700;letter-spacing:.6px;text-transform:uppercase;
  color:var(--muted);border-bottom:1px solid var(--line);
}
.search{display:flex;gap:8px;padding:12px}
.search input{
  flex:1;min-width:0;padding:8px 10px;border-radius:8px;border:1px solid var(--line);background:#0f1118;outline:none;
}
.search input:focus{border-color:var(--accent)}
.results{max-height:46vh;overflow:auto;padding:0 12px 12px;display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.results .pad{grid-column:1/-1;margin:0;font-size:12px}
.muted{color:var(--muted)}
.res{cursor:grab;touch-action:none;user-select:none;-webkit-user-select:none}
.res .art{width:100%;height:auto;aspect-ratio:1/1;border-radius:6px}
.res-t{font-size:10px;line-height:1.25;margin-top:3px;max-height:24px;overflow:hidden}
.res-a{font-size:9px;color:var(--muted);overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.upload-row{padding:0 12px 12px}

.opts{padding:12px;display:flex;flex-direction:column;gap:11px}
.opt{display:flex;align-items:center;gap:10px;font-size:12px;color:var(--muted)}
.opt:not(.opt-check)>span{width:88px;flex:0 0 88px}   /* label column — sliders and swatches only */
.opt input[type=range]{flex:1;min-width:0;accent-color:var(--accent)}
.opt output{width:34px;text-align:right;font-variant-numeric:tabular-nums}
.opt input[type=color]{width:44px;height:24px;padding:0;border:1px solid var(--line);border-radius:6px;background:none;cursor:pointer}
.opt-check{cursor:pointer}
.opt-check input{accent-color:var(--accent);width:15px;height:15px;flex:0 0 auto;margin:0}
.opt-check span{color:var(--text)}
.swatches{display:flex;flex-wrap:wrap;gap:6px;flex:1}
.sw{flex:1 1 0;min-width:20px;height:22px;border-radius:6px;border:1px solid var(--line);cursor:pointer;padding:0}
.sw:hover{outline:2px solid var(--accent);outline-offset:1px}
.tips{margin:0;padding:12px 12px 12px 26px;color:var(--muted);font-size:12px;display:flex;flex-direction:column;gap:6px}

.toast{
  position:fixed;left:50%;bottom:22px;transform:translateX(-50%);
  background:#1c1f2a;border:1px solid var(--line);padding:9px 16px;border-radius:999px;
  box-shadow:0 10px 30px rgba(0,0,0,.5);z-index:200;font-size:13px;
}

@media (max-width:960px){
  .layout{grid-template-columns:1fr}
  .sidebar{position:fixed;inset:52px 0 0 auto;width:min(360px,90vw);z-index:50;transform:translateX(101%);transition:.22s;box-shadow:-20px 0 50px rgba(0,0,0,.5)}
  .sidebar.open{transform:none}
  .only-narrow{display:inline-block}
  .board{padding-right:16px}
  .tier-actions{background:linear-gradient(90deg,transparent,rgba(0,0,0,.55));opacity:1;width:32px;left:auto;right:0}
  .results{max-height:none}
}

/* search result cells */
.res-wrap{min-width:0}
.res-wrap .tile{width:100%}
.res-wrap .art{width:100%;height:auto;aspect-ratio:1/1;border-radius:6px}

.credits{margin:0;padding:12px;color:var(--muted);font-size:11px;line-height:1.5}
.credits a{color:var(--accent-2);text-decoration:none}
.credits a:hover{text-decoration:underline}
