/* ------------------------------------------------------------------
   Tokens. Everything below reads from these; JS rewrites them on
   :root every time a theme is picked.
------------------------------------------------------------------ */
:root{
  --bg:#0d0e15; --surface:#151722; --surface-2:#1b1e2b;
  --text:#eef1f7; --muted:#9aa1b4; --border:#2a2e3d;
  --accent:#6f7bb0; --on-accent:#0b0c12;
  --grad:linear-gradient(180deg,#12121e,#2f3140);
  --grad-page:linear-gradient(168deg,#12121e,#2f3140);
  --ring:#6f7bb0;

  --rail:248px;
  --r-sm:6px; --r-md:12px; --r-lg:18px;
  --ease:cubic-bezier(.2,.7,.3,1);
  --sans:"Public Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  --display:"Bricolage Grotesque","Public Sans",sans-serif;
  --mono:"JetBrains Mono",ui-monospace,"SF Mono",Menlo,monospace;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; color:var(--text);
  background:var(--bg) var(--grad-page) fixed;
  font-family:var(--sans); font-size:15px; line-height:1.55;
  -webkit-font-smoothing:antialiased;
  transition:background-color .45s var(--ease), color .45s var(--ease);
}
button{font:inherit;color:inherit;background:none;border:0;cursor:pointer}
:focus-visible{outline:2px solid var(--ring); outline-offset:3px; border-radius:4px}

/* ---------------- shell ---------------- */
.app{display:flex; min-height:100vh}

/* ---------------- left rail = theme selector ---------------- */
.rail{
  width:var(--rail); flex:none; position:sticky; top:0; height:100vh;
  display:flex; flex-direction:column;
  background:var(--surface); border-right:1px solid var(--border);
  transition:background-color .45s var(--ease), border-color .45s var(--ease);
}
.rail-head{padding:14px 12px 10px}
.custom-btn{
  width:100%; display:flex; align-items:center; gap:11px; padding:10px;
  border:1px dashed var(--border); border-radius:var(--r-md); text-align:left;
  transition:background-color .2s var(--ease), border-color .2s var(--ease);
}
.custom-btn:hover{background:var(--surface-2); border-color:var(--accent)}
.custom-btn[aria-current="true"]{background:var(--surface-2); border-style:solid; border-color:var(--accent)}
.custom-btn .chip{width:15px; height:30px; border-radius:4px; flex:none; background:var(--grad); box-shadow:inset 0 0 0 1px rgba(127,127,127,.3)}
.custom-txt{flex:1; min-width:0}
.custom-txt b{display:block; font-family:var(--display); font-size:15px; letter-spacing:-.02em}
.custom-txt small{color:var(--muted); font-size:11.5px}
.custom-btn .plus{font-family:var(--mono); font-size:16px; color:var(--accent)}

.nav{flex:1; overflow-y:auto; padding:4px 12px 12px; scrollbar-width:thin}
.nav-label{
  font-family:var(--mono); font-size:10.5px; letter-spacing:.14em;
  text-transform:uppercase; color:var(--muted); padding:8px 8px 6px;
}
.theme-btn{
  width:100%; display:flex; align-items:center; gap:11px;
  padding:7px 9px; margin-bottom:2px; border-radius:var(--r-sm);
  text-align:left; color:var(--muted);
  transition:background-color .2s var(--ease), color .2s var(--ease);
}
.theme-btn:hover{background:var(--surface-2); color:var(--text)}
.theme-btn .chip{
  width:15px; height:30px; border-radius:4px; flex:none;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.12);
}
.theme-btn .idx{
  font-family:var(--mono); font-size:10.5px; opacity:.65;
  min-width:20px; text-align:right;
}
.theme-btn .nm{font-size:13.5px; font-weight:500; letter-spacing:-.01em}
.theme-btn[aria-current="true"]{
  background:var(--surface-2); color:var(--text);
  box-shadow:inset 2px 0 0 var(--accent);
}
.theme-btn[aria-current="true"] .nm{font-weight:600}

/* jump to the sample layout */
.rail-foot{padding:12px; border-top:1px solid var(--border)}
.foot-btn{
  width:100%; display:flex; align-items:center; gap:9px; padding:10px 11px;
  border:1px solid var(--border); border-radius:var(--r-md); color:var(--muted);
  font-size:13px; font-weight:500;
  transition:background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.foot-btn:hover{background:var(--surface-2); color:var(--text)}
.foot-btn[aria-pressed="true"]{background:var(--accent); border-color:var(--accent); color:var(--on-accent)}
.foot-btn span:first-child{font-size:14px; line-height:1}

/* ---------------- header ---------------- */
.main{flex:1; min-width:0; display:flex; flex-direction:column}
.topbar{
  padding:22px 40px 14px; border-bottom:1px solid var(--border);
  background:transparent; position:relative; overflow:hidden;
  transition:border-color .45s var(--ease);
}
.topbar::after{content:""; position:absolute; inset:auto 0 0 0; height:3px; background:var(--grad)}
.topbar-row{display:flex; align-items:flex-end; justify-content:space-between; gap:24px; flex-wrap:wrap}
/* Leaves the preview and editor views. `display` here beats the `hidden`
   attribute's UA rule, so the [hidden] pair below is required, not optional. */
.back-btn{
  display:inline-flex; align-items:center; gap:7px; margin:0 0 9px;
  padding:5px 12px 5px 10px; border:1px solid var(--border); border-radius:100px;
  color:var(--muted); font-size:12.5px; font-weight:500;
  transition:background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.back-btn:hover{background:var(--surface-2); color:var(--text); border-color:var(--accent)}
.back-btn[hidden]{display:none}
.back-btn span{font-size:14px; line-height:1}

h1{
  font-family:var(--display); font-weight:700; font-size:clamp(26px,3.2vw,36px);
  letter-spacing:-.03em; line-height:1.05; margin:0;
}
.tagline{margin:6px 0 0; color:var(--muted); max-width:52ch; font-size:14px}
.topbar-meta{display:flex; gap:8px}
.pill{
  font-family:var(--mono); font-size:11.5px; padding:5px 11px;
  border:1px solid var(--border); border-radius:100px; color:var(--muted);
}

/* Persistent page copy, below the app. Lives outside #content so render()
   cannot wipe it — see the comment on the <footer> in index.html. */
.about{
  padding:20px 20px 30px; border-top:1px solid var(--border);
  color:var(--muted); font-size:13.5px;
  transition:border-color .45s var(--ease);
}
.about h2{
  font-family:var(--display); font-weight:700; font-size:17px;
  letter-spacing:-.02em; color:var(--text); margin:0 0 9px;
}
.about p{margin:0 0 9px; max-width:80ch}
.about p:last-child{margin:0}
.about b{color:var(--text); font-weight:600}

/* ---------------- cards ---------------- */
.grid{
  flex:1; padding:18px 20px 18px;
  display:grid; grid-template-columns:repeat(auto-fit,minmax(272px,1fr));
  gap:10px; align-content:start;
}
.card{
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r-lg); padding:20px; min-width:0;
  display:flex; flex-direction:column;
  box-shadow:0 1px 2px rgba(0,0,0,.14), 0 14px 30px -18px rgba(0,0,0,.5);
  animation:rise .4s var(--ease) both;
}
.card.wide{grid-column:span 2}
.card.tall{grid-row:span 2}
@keyframes rise{from{opacity:0; transform:translateY(10px)}to{opacity:1; transform:none}}
.card:nth-child(2){animation-delay:.04s}
.card:nth-child(3){animation-delay:.08s}
.card:nth-child(4){animation-delay:.12s}
.card:nth-child(5){animation-delay:.16s}

.card h2{
  font-family:var(--mono); font-size:10.5px; letter-spacing:.15em;
  text-transform:uppercase; color:var(--muted); margin:0 0 14px;
  display:flex; justify-content:space-between; align-items:center; gap:12px;
}
.card h2 em{font-style:normal; letter-spacing:0; text-transform:none; font-size:11px}

.preview{
  flex:1; min-height:190px; border-radius:var(--r-md); background:var(--grad);
  display:flex; align-items:flex-end; padding:14px;
}
.preview span{
  font-family:var(--mono); font-size:11px; padding:4px 9px; border-radius:100px;
  background:rgba(0,0,0,.42); color:#fff; backdrop-filter:blur(6px);
}

.stops{display:flex; flex-direction:column; gap:5px}
.stop{
  display:flex; align-items:center; gap:11px; padding:6px 8px;
  border-radius:var(--r-sm); width:100%; text-align:left;
  transition:background-color .18s var(--ease);
}
.stop:hover{background:var(--surface-2)}
.stop i{width:26px;height:26px;border-radius:6px;flex:none;box-shadow:inset 0 0 0 1px rgba(127,127,127,.35)}
.stop code{font-family:var(--mono); font-size:12.5px; flex:1}
.stop small{font-family:var(--mono); font-size:10.5px; color:var(--muted)}

/* Flat swatch-and-label rows, not boxes. align-content must stay `start`:
   with the old `space-between` the six rows spread to fill the card and the
   tighter padding buys nothing. */
.tokens{display:grid; grid-template-columns:1fr 1fr; gap:2px 10px; align-content:start}
.token{
  border-radius:var(--r-sm);
  padding:3px 5px; display:flex; align-items:center; gap:8px; min-width:0;
}
.token i{width:14px;height:14px;border-radius:4px;flex:none;box-shadow:inset 0 0 0 1px rgba(127,127,127,.35)}
.token div{min-width:0; display:flex; align-items:baseline; gap:7px; flex:1}
.token b{font-size:11px; font-weight:600; letter-spacing:-.01em}
.token code{font-family:var(--mono); font-size:10px; color:var(--muted); margin-left:auto}

.ratio{display:flex; flex-direction:column; gap:7px}

/* gradient direction control */
.angle{margin-top:15px; padding-top:14px; border-top:1px solid var(--border)}
.angle-head{display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:10px}
.angle-title{
  font-family:var(--mono); font-size:10.5px; letter-spacing:.15em;
  text-transform:uppercase; color:var(--muted);
}
.angle-val{display:flex; align-items:center; gap:8px; font-family:var(--mono); font-size:14px; font-weight:500}
.arrow{
  width:18px; height:18px; border-radius:50%; display:grid; place-items:center;
  background:var(--accent); color:var(--on-accent); font-size:10px; line-height:1;
  transition:transform .18s var(--ease);
}
input[type=range]{
  -webkit-appearance:none; appearance:none; width:100%; height:4px; margin:0 0 12px;
  border-radius:100px; background:var(--border); accent-color:var(--accent); cursor:grab;
}
input[type=range]:active{cursor:grabbing}
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none; width:15px; height:15px; border-radius:50%;
  background:var(--accent); border:2px solid var(--surface); cursor:grab;
}
input[type=range]::-moz-range-thumb{
  width:15px; height:15px; border:2px solid var(--surface); border-radius:50%;
  background:var(--accent); cursor:grab;
}
.presets{display:grid; grid-template-columns:repeat(4,1fr); gap:5px}
.presets button{
  font-family:var(--mono); font-size:11px; padding:5px 0; color:var(--muted);
  border:1px solid var(--border); border-radius:var(--r-sm);
  transition:background-color .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease);
}
.presets button:hover{background:var(--surface-2); color:var(--text)}
.presets button[aria-current="true"]{background:var(--accent); color:var(--on-accent); border-color:var(--accent)}
.ratio-row{display:flex; align-items:center; justify-content:space-between; gap:12px}
.ratio-row span{font-size:13px}
.ratio-row b{font-family:var(--mono); font-size:15px; font-weight:500}
.tag{
  font-family:var(--mono); font-size:10px; letter-spacing:.08em; padding:2px 7px;
  border-radius:100px; border:1px solid currentColor; margin-left:8px;
}
.pass{color:var(--accent)} .fail{color:var(--muted)}

pre{
  margin:0; background:var(--bg); border:1px solid var(--border);
  border-radius:var(--r-md); padding:13px; overflow-x:auto;
  font-family:var(--mono); font-size:11.5px; line-height:1.75; color:var(--muted);
}
pre b{color:var(--text); font-weight:400}
.copy{
  font-family:var(--mono); font-size:10.5px; letter-spacing:.08em; text-transform:uppercase;
  color:var(--accent); padding:3px 8px; border:1px solid var(--border); border-radius:100px;
  transition:background-color .18s var(--ease);
}
.copy:hover{background:var(--surface-2)}

/* toast */
.toast{
  position:fixed; left:50%; bottom:26px; transform:translate(-50%,18px);
  background:var(--accent); color:var(--on-accent); font-family:var(--mono); font-size:12px;
  padding:8px 16px; border-radius:100px; opacity:0; pointer-events:none;
  transition:opacity .2s var(--ease), transform .2s var(--ease);
}
.toast.on{opacity:1; transform:translate(-50%,0)}

/* ---------------- layout preview ---------------- */
.grid.stack{grid-template-columns:1fr; max-width:1080px}
.card.lay h2{align-items:baseline}
.frame{
  flex:1; display:flex; flex-direction:column; overflow:hidden;
  border:1px solid var(--border); border-radius:var(--r-md);
  background:var(--bg); min-height:520px; font-size:11px; line-height:1.45;
}
.chrome{
  flex:none; display:flex; align-items:center; gap:5px; padding:7px 11px;
  background:var(--surface-2); border-bottom:1px solid var(--border);
}
.chrome i{width:7px; height:7px; border-radius:50%; background:var(--border)}
.chrome span{font-family:var(--mono); font-size:9.5px; color:var(--muted); margin-left:9px}
.frame > :last-child{flex:1; min-height:0; overflow:hidden}

/* ---------------- theme editor (custom view) ---------------- */
.edit-stop{display:flex; align-items:center; gap:10px; margin-bottom:7px}
.edit-stop input[type=color]{
  width:38px; height:32px; padding:0; border:1px solid var(--border);
  border-radius:var(--r-sm); background:none; cursor:pointer; flex:none;
}
.edit-stop input[type=color]::-webkit-color-swatch-wrapper{padding:2px}
.edit-stop input[type=color]::-webkit-color-swatch{border:0; border-radius:3px}
.edit-stop input[type=text]{
  flex:1; min-width:0; font-family:var(--mono); font-size:12.5px;
  background:var(--bg); border:1px solid var(--border); color:var(--text);
  border-radius:var(--r-sm); padding:7px 9px;
}
.edit-stop small{font-family:var(--mono); font-size:10.5px; color:var(--muted); width:34px; text-align:right}
.edit-name{
  width:100%; font:inherit; font-size:14px; margin-bottom:12px;
  background:var(--bg); border:1px solid var(--border); color:var(--text);
  border-radius:var(--r-sm); padding:9px 10px;
}

/* The editor's two actions. Both wrap rather than squash: "Start from
   Brackish Gold" carries a theme name, so its width is not fixed. */
.row{display:flex; gap:9px; flex-wrap:wrap}
.btn{
  flex:1 1 auto; min-width:0; padding:9px 14px;
  border:1px solid var(--border); border-radius:var(--r-md);
  font-size:13px; font-weight:600; text-align:center; color:var(--text);
  transition:background-color .2s var(--ease), color .2s var(--ease),
             border-color .2s var(--ease), filter .2s var(--ease);
}
.btn.primary{background:var(--accent); border-color:var(--accent); color:var(--on-accent)}
.btn.primary:hover{filter:brightness(1.09)}
.btn.solid{background:var(--surface-2); color:var(--muted)}
.btn.solid:hover{background:var(--bg); color:var(--text); border-color:var(--accent)}

/* ---------------- responsive ---------------- */
@media (max-width:1080px){ .card.wide{grid-column:span 1} .card.tall{grid-row:span 1} }
@media (max-width:860px){
  .app{flex-direction:column}
  .rail{width:auto; position:static; height:auto; border-right:0; border-bottom:1px solid var(--border)}
  .nav{display:flex; gap:6px; overflow-x:auto; padding:0 14px 14px}
  .nav-label{display:none}
  .theme-btn{width:auto; flex:none; flex-direction:column; gap:6px; align-items:flex-start; margin:0}
  .theme-btn .chip{width:44px; height:16px}
  .theme-btn .idx{display:none}
  .rail-head{padding:12px 14px 8px}
  .rail-foot{padding:0 14px 12px; border-top:0}
  body{background-attachment:scroll; background-size:100% 100vh}
  .topbar{padding:18px 20px 16px}
  .grid{padding:18px 20px 40px; gap:14px}
}
@media (prefers-reduced-motion:reduce){
  *{animation-duration:.001ms !important; transition-duration:.001ms !important}
}
