:root{
  --bg: #0c0d10;
  --panel: #15171b;
  --panel-2: #1c1f24;
  --line: #2a2d33;
  --text: #ece8e0;
  --text-dim: #b1b1b1;
  --accent: #d8702f;
  --accent-2: #4f9bc9;
  --accent-contrast: #15120d;
  --preview-height-mobile: 40dvh;
  --basic-gap: 10px;
}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  background:var(--bg);
  color:var(--text);
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  display:flex;
  min-height:100dvh;
}
#sidebar{
  width:380px;
  min-width:380px;
  background:var(--panel);
  border-right:1px solid var(--line);
  padding:22px 20px 30px;
  display:flex;
  flex-direction:column;
  gap:22px;
  overflow-y:auto;
  max-height:100dvh;
  scrollbar-width:thin;
  scrollbar-color: var(--accent-2) transparent;
}
#sidebar::-webkit-scrollbar{
  width:8px;
}
#sidebar::-webkit-scrollbar-track{
  background:transparent;
  margin:8px 0;
}
#sidebar::-webkit-scrollbar-thumb{
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-radius:8px;
  border:2px solid var(--panel);
  background-clip:padding-box;
}
#sidebar::-webkit-scrollbar-thumb:hover{
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  background-clip:padding-box;
}
.brand{
  display:flex;
  flex-direction:column;
  gap:2px;
  margin-bottom:2px;
}
.brand .mark{
  width:26px;height:26px;border-radius:7px;
  margin-bottom:10px;
  border:1px solid rgba(255,255,255,0.08);
  transition: background 0.2s ease;
}
.brand h1{
  font-size:14px;
  letter-spacing:0.02em;
  margin:0;
  font-weight:600;
  color:var(--text);
}
.brand p{
  font-size:11px;
  color:var(--text-dim);
  margin:2px 0 0;
  letter-spacing:0.01em;
}
.row {
  display: flex;
  flex-direction: row;
  gap: var(--basic-gap);
}
.block{
  display:flex;
  flex-direction:column;
  gap: var(--basic-gap);
  padding-top:16px;
  border-top:1px solid var(--line);
}
.block:first-of-type{border-top:none;padding-top:0;}
.label-row{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  font-size:10.5px;
  text-transform:uppercase;
  letter-spacing:0.08em;
  color:var(--text-dim);
}
.label-row .val{
  color:var(--accent-2);
  font-variant-numeric: tabular-nums;
}
input[type=range]{
  -webkit-appearance:none;
  width:100%;
  height:2px;
  background:var(--line);
  border-radius:2px;
  outline:none;
}
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none;
  box-sizing:border-box;
  width:13px;height:13px;
  border-radius:50%;
  background:var(--accent-2);
  cursor:pointer;
  border:2px solid var(--panel);
  box-shadow:0 0 0 1px var(--accent-2);
}
input[type=range]::-moz-range-thumb{
  width:13px;height:13px;
  box-sizing:border-box;
  border-radius:50%;
  background:var(--accent-2);
  cursor:pointer;
  border:2px solid var(--panel);
  box-shadow:0 0 0 1px var(--accent-2);
}
#swatches{
  display:flex;
  flex-direction:column;
  gap:8px;
}
.swatch-row{
  display:flex;
  align-items:center;
  gap:7px;
  background:var(--panel-2);
  border:1px solid var(--line);
  border-radius:8px;
  padding:6px 8px;
}
.swatch-row .handle{
  color:var(--text-dim);
  font-size:11px;
  width:14px;
  text-align:center;
}
.swatch-row input[type=color]{
  width:28px;height:28px;
  border:none;
  border-radius:6px;
  padding:0;
  background:none;
  cursor:pointer;
}
.swatch-row input[type=color]::-webkit-color-swatch-wrapper{padding:0;}
.swatch-row input[type=color]::-webkit-color-swatch{border:1px solid var(--line);border-radius:6px;}
.swatch-row input[type="color"]::-moz-color-swatch {border: 1px solid var(--line);border-radius:6px;}
.swatch-row .hex-input{
  height: 28px;
  flex:1;
  min-width:0;
  background:none;
  border:none;
  outline:none;
  color:var(--text-dim);
  font-family:inherit;
  font-size:11px;
  letter-spacing:0.02em;
  padding:2px 4px;
  border-radius:4px;
  transition: background 0.15s, color 0.15s;
}
.swatch-row .hex-input:focus{
  background:var(--panel);
  color:var(--text);
}
.swatch-row .hex-input.invalid{
  background:rgba(192,80,58,0.25);
  color:#e8a08c;
}
.swatch-row button{
  background:none;
  border:none;
  color:var(--text-dim);
  cursor:pointer;
  font-size:14px;
  padding:2px 4px;
  line-height:1;
}
.swatch-row button:hover{color:var(--accent);}
#addColor{
  background:none;
  border:1px dashed var(--line);
  color:var(--text-dim);
  border-radius:8px;
  padding:8px;
  font-size:11px;
  cursor:pointer;
  font-family:inherit;
  letter-spacing:0.03em;
}
#addColor:hover{border-color:var(--accent-2);color:var(--accent-2);}

.segmented{
  display:flex;
  background:var(--panel-2);
  border:1px solid var(--line);
  border-radius:8px;
  overflow:hidden;
}
.segmented button{
  flex:1;
  background:none;
  border:none;
  color:var(--text-dim);
  font-family:inherit;
  font-size:11px;
  padding:9px 4px;
  cursor:pointer;
  letter-spacing:0.02em;
  border-right:1px solid var(--line);
}
.segmented button:last-child{border-right:none;}
.segmented button.active{
  background:var(--accent);
  color:var(--accent-contrast);
  font-weight:600;
}

#resolution-container
{
  display: flex;
  flex-direction: column;
  row-gap: var(--basic-gap)
}

#resolutions
{
  display: flex;
  column-gap: calc(var(--basic-gap) / 2);
}

#resolutions button{
  background:none;
  border: 1px solid var(--line);
  border-radius: 12px;
  color:var(--text-dim);
  font-family:inherit;
  font-size:11px;
  padding:9px 6px;
  cursor:pointer;
  letter-spacing:0.02em;
}

#resolutions button.active{
  background:var(--accent);
  color:var(--accent-contrast);
  font-weight:600;
}

.btn{
  display:flex;
  flex: 1;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:11px;
  border-radius:8px;
  font-family:inherit;
  font-size:11.5px;
  letter-spacing:0.03em;
  cursor:pointer;
  border:1px solid var(--line);
  background:var(--panel-2);
  color:var(--text);
}
.btn:hover{border-color:var(--accent-2);}
.btn.primary{
  background:var(--accent);
  border-color:var(--accent);
  color:var(--accent-contrast);
  font-weight:700;
}
.btn.primary:hover{filter:brightness(1.08);}
.btn svg{width:13px;height:13px;flex-shrink:0;}

#main{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:36px;
  position:relative;
  background:
    radial-gradient(circle at 30% 20%, #14161a 0%, var(--bg) 60%);
}
#stage{
  position:relative;
  border-radius:14px;
  overflow:hidden;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7), 0 0 0 1px var(--line);
  max-width:100%;
  max-height:calc(100vh - 72px);
}
#stage canvas{
  display:block;
  height:auto;
  width: 100%;
  max-height:calc(100vh - 72px);
}
#loading{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background:rgba(12,13,16,0.55);
  color:var(--text-dim);
  font-size:11px;
  letter-spacing:0.05em;
  opacity:0;
  pointer-events:none;
  transition:opacity .15s;
}
#loading.show{opacity:1;}

.seed-row{
  display:flex;
  flex: 1;
  min-width: 0;
  align-items:center;
  gap:8px;
  border:1px solid var(--line);
  border-radius:8px;
  padding:8px 10px;
}

.seed-btn {
  cursor: pointer;
  background:none;
  border:1px dashed var(--line);
  color:var(--text-dim);
}
.seed-btn:hover{border-color:var(--accent-2);color:var(--accent-2);}
.seed-btn:hover .icon-btn {color:var(--accent-2);}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.seed-row span{
  flex:1;
  font-size:11px;
  color:var(--text-dim);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.seed-row input{
  flex:1;
  background:none;
  border:none;
  outline:none;
  color:var(--text);
  font-family:inherit;
  font-size:11px;
  min-width:0;
}
.seed-row input::placeholder{color:var(--text-dim);}
.icon-btn{
  background:none;
  border:none;
  color:var(--text-dim);
  cursor:pointer;
  font-size:20px;
  padding:2px 4px;
  line-height:1;
  flex-shrink:0;
}
.icon-btn:hover{color:var(--accent-2);}

#toast{
  position:fixed;
  bottom:24px;
  left:50%;
  transform:translateX(-50%) translateY(10px);
  background:var(--panel-2);
  border:1px solid var(--line);
  color:var(--text);
  padding:10px 18px;
  border-radius:8px;
  font-family:inherit;
  font-size:12px;
  letter-spacing:0.02em;
  opacity:0;
  pointer-events:none;
  transition:opacity .2s ease, transform .2s ease;
  z-index:1000;
  box-shadow:0 12px 30px -10px rgba(0,0,0,0.6);
}
#toast.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}
#toast.error{
  border-color:#c0503a;
  color:#e8a08c;
}

#libraryModal{
  position:fixed;
  inset:0;
  background:rgba(6,7,9,0.72);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
  opacity:0;
  pointer-events:none;
  transition:opacity .18s ease;
  z-index:200;
  scrollbar-width:thin;
  scrollbar-color: var(--accent-2) transparent;
}
#libraryModal::-webkit-scrollbar{
  width:8px;
}
#libraryModal::-webkit-scrollbar-track{
  background:transparent;
  margin:8px 0;
}
#libraryModal::-webkit-scrollbar-thumb{
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-radius:8px;
  border:2px solid var(--panel);
  background-clip:padding-box;
}
#libraryModal::-webkit-scrollbar-thumb:hover{
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  background-clip:padding-box;
}

#libraryModal.show{
  opacity:1;
  pointer-events:auto;
}
.library-modal-inner{
  width:100%;
  height:100%;
  max-width:1500px;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:14px;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  box-shadow:0 30px 80px -20px rgba(0,0,0,0.7);
}
.library-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:18px 22px;
  border-bottom:1px solid var(--line);
  flex-shrink:0;
}
.library-header-actions{
  display:flex;
  align-items:center;
  gap:8px;
}
.header-action-btn{
  flex:none;
  padding:8px 12px;
  font-size:11px;
}
.header-action-btn.danger:hover{
  border-color:#c0503a;
  color:#e8a08c;
}

@media (max-width: 640px){
  .library-header{
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 16px;
  }
  .library-header h2{
    font-size: 15px;
  }
  .library-header-actions{
    flex-wrap: wrap;
    gap: 6px;
  }
  .header-action-btn{
    padding: 8px 10px;
    font-size: 10px;
  }
  .header-action-btn span{
    display: none;
  }
  .header-action-btn svg{
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 380px){

  .library-header{
    justify-content: center;
  }
  .library-header h2{
    width: 100%;
    text-align: center;
  }
  .library-header-actions{
    justify-content: center;
    width: 100%;
  }
}

#importModal{
  position:fixed;
  inset:0;
  background:rgba(6,7,9,0.72);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
  opacity:0;
  pointer-events:none;
  transition:opacity .18s ease;
  z-index:300;
}
#importModal.show{
  opacity:1;
  pointer-events:auto;
}
.import-modal-inner{
  width:100%;
  max-width:440px;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:14px;
  display:flex;
  flex-direction:column;
  gap:12px;
  padding:20px;
  box-shadow:0 30px 80px -20px rgba(0,0,0,0.7);
}
#importTextarea{
  width:100%;
  min-height:110px;
  resize:vertical;
  background:var(--panel-2);
  border:1px solid var(--line);
  border-radius:8px;
  color:var(--text);
  font-family:inherit;
  font-size:11.5px;
  padding:10px;
  outline:none;
}
#importTextarea:focus{border-color:var(--accent-2);}
#importTextarea::placeholder{color:var(--text-dim);}

.import-progress{
  display:none;
  flex-direction:column;
  gap:8px;
}
.import-progress.show{
  display:flex;
}
.import-progress-bar-outer{
  width:100%;
  height:6px;
  border-radius:4px;
  background:var(--line);
  overflow:hidden;
}
.import-progress-bar-inner{
  width:0%;
  height:100%;
  border-radius:4px;
  background:linear-gradient(90deg, var(--accent-2), var(--accent));
  transition:width .12s ease;
}
.import-progress-label{
  font-size:10.5px;
  color:var(--text-dim);
  letter-spacing:0.04em;
  text-align:center;
}

.library-header h2{
  margin:0;
  font-size:13.5px;
  letter-spacing:0.03em;
  color:var(--text);
  font-weight:600;
  text-transform:uppercase;
}
.library-grid{
  flex:1;
  overflow-y:auto;
  padding:22px;
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(190px, 1fr));
  gap:18px;
  align-content:start;
}
#saveSeedBtn.liked{
  color: var(--accent-2);
  border-color: var(--accent-2);
}
#saveSeedBtn.liked #saveSeedIcon{
  fill: currentColor;
}

.library-loading{
  grid-column:1 / -1;
  text-align:center;
  padding:90px 20px;
  color:var(--text-dim);
  font-size:11px;
  letter-spacing:0.06em;
  text-transform:uppercase;
  animation: library-pulse 1.2s ease-in-out infinite;
}
@keyframes library-pulse{
  0%, 100%{ opacity:0.35; }
  50%{ opacity:1; }
}

.library-empty{
  grid-column:1 / -1;
  color:var(--text-dim);
  font-size:12px;
  text-align:center;
  padding:80px 20px;
  letter-spacing:0.02em;
}
.library-item{
  position:relative;
  background:var(--panel-2);
  border:1px solid var(--line);
  border-radius:10px;
  padding:8px;
  cursor:pointer;
  display:flex;
  flex-direction:column;
  gap:8px;
}
.library-item:hover{border-color:var(--accent-2);}
.library-thumb{
  width:100%;
  aspect-ratio:1/1;
  border-radius:6px;
  overflow:hidden;
  background:var(--bg);
}
.library-thumb canvas{
  width:100%;
  height:100%;
  display:block;
}
.library-thumb-invalid{
  width:100%;
  height:100%;
  display:flex;
  align-items:center;
  justify-content:center;
  color:var(--text-dim);
  font-size:10px;
  text-align:center;
  padding:8px;
}
.library-code-row{
  display:flex;
  align-items:center;
  gap:6px;
}
.library-code-row .library-code{
  flex:1;
  min-width:0;
}
.library-copy{
  flex-shrink:0;
  background:none;
  border:none;
  color:var(--text-dim);
  cursor:pointer;
  padding:2px;
  line-height:1;
}
.library-copy svg{
  width:13px;
  height:13px;
  display:block;
}
.library-copy:hover{color:var(--accent-2);}

.library-code{
  font-size:10px;
  color:var(--text-dim);
  text-align:center;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  letter-spacing:0.02em;
}
.library-del{
  position:absolute;
  top:10px;
  right:10px;
  width:22px;
  height:22px;
  border-radius:50%;
  border:1px solid var(--line);
  background:rgba(12,13,16,0.8);
  color:var(--text-dim);
  cursor:pointer;
  font-size:12px;
  line-height:1;
  display:flex;
  align-items:center;
  justify-content:center;
}
.library-del:hover{color:#e8a08c;border-color:#c0503a;}

@media (max-width: 760px){
  .library-grid{
    grid-template-columns:repeat(auto-fill, minmax(130px, 1fr));
    padding:16px;
    gap:12px;
  }
  .library-header{padding:14px 16px;}
}

.drag-handle{
  display:flex;
  align-items:center;
  color:var(--text-dim);
  cursor:grab;
  flex-shrink:0;
  touch-action:none;
}
.drag-handle:active{cursor:grabbing;}

.swatch-row.dragging{
  box-shadow:0 8px 20px -6px rgba(0,0,0,75);
  cursor:grabbing;
}

@media (max-width: 760px){
  body
  {
    flex-direction:column;
  }
  #sidebar{
    width:100%;
    min-width:0;
    max-height:calc(100dvh - var(--preview-height-mobile));
    overflow: scroll;
    border-right:none;
    border-bottom:1px solid var(--line);
    padding:18px 16px 22px;
    gap:18px;
    order:2;
  }
  #main{
    max-height:var(--preview-height-mobile);
    padding: 1em;
    order:1;
  }
  #stage canvas
  {
    max-width:100%;
    max-height:calc(var(--preview-height-mobile) - 5dvh);
  }

  .btn, #addColor, #applyColors{padding:12px;font-size:12px;}
  .swatch-row{padding:8px 10px;}
  .segmented button{padding:11px 4px;font-size:11.5px;}
  input[type=range]::-webkit-slider-thumb{width:16px;height:16px;}
  input[type=range]::-moz-range-thumb{width:16px;height:16px;}
}

@media (max-width: 420px){
  .brand h1{font-size:13px;}
  .brand p{font-size:10px;}
  .label-row{font-size:10px;}
  .block{padding-top:14px;gap:8px;}
}