/* ============================================================================
   COVERS BY HIS SUPER AFFILIATES — "Midnight Print Shop" neon theme
   Design tokens
   ========================================================================== */
:root {
  --ink: #0A0B14;
  --ink-2: #05060C;
  --panel: #14162A;
  --panel-2: #1C1F3B;
  --panel-3: #262A4D;
  --line: #33375E;
  --pink: #FF2E88;
  --cyan: #2EF2FF;
  --yellow: #FFE93E;
  --violet: #A855F7;
  --paper: #F4F1EA;
  --ink-soft: #9498C4;
  --danger: #FF5A5A;
  --ok: #38F2A6;

  --font-display: 'Bungee', cursive;
  --font-ui: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'Space Mono', monospace;

  --radius: 10px;
  --glow-pink: 0 0 18px rgba(255,46,136,.55), 0 0 2px rgba(255,46,136,.9);
  --glow-cyan: 0 0 18px rgba(46,242,255,.5), 0 0 2px rgba(46,242,255,.9);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ink); color: var(--paper);
  font-family: var(--font-body); overflow: hidden;
  background-image:
    radial-gradient(circle at 15% 0%, rgba(168,85,247,.10), transparent 40%),
    radial-gradient(circle at 85% 100%, rgba(46,242,255,.08), transparent 45%);
}
button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--pink); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

#app { height: 100vh; display: flex; flex-direction: column; }

/* --------------------------------------------------------------- topbar */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: linear-gradient(180deg, var(--panel), var(--ink-2));
  border-bottom: 1px solid var(--line); flex: 0 0 auto; gap: 16px;
}
.logo {
  font-family: var(--font-display); font-size: 17px; letter-spacing: .5px;
  color: var(--pink); text-shadow: var(--glow-pink); white-space: nowrap;
}
.logo em { font-style: normal; color: var(--cyan); text-shadow: var(--glow-cyan); font-size: 12px; display: block; margin-top: 2px; }
#coverTypeTabs { display: flex; gap: 6px; background: var(--ink-2); padding: 5px; border-radius: 999px; border: 1px solid var(--line); }
#coverTypeTabs button {
  background: transparent; border: none; color: var(--ink-soft); font-family: var(--font-ui);
  font-size: 12.5px; font-weight: 500; padding: 8px 14px; border-radius: 999px; transition: .15s;
}
#coverTypeTabs button.active { background: var(--pink); color: #fff; box-shadow: var(--glow-pink); }
#coverTypeTabs button:hover:not(.active) { color: var(--paper); background: var(--panel-3); }
.topbar-right { display: flex; gap: 8px; }

.btn {
  background: var(--panel-3); border: 1px solid var(--line); color: var(--paper);
  padding: 9px 14px; border-radius: 8px; font-family: var(--font-ui); font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; transition: .15s;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan); }
.btn-primary { background: var(--pink); border-color: var(--pink); color: #fff; box-shadow: var(--glow-pink); }
.btn-primary:hover { filter: brightness(1.1); color: #fff; }
.btn-cyan { background: var(--cyan); border-color: var(--cyan); color: var(--ink-2); box-shadow: var(--glow-cyan); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* -------------------------------------------------------------- specbar */
#specbar {
  display: flex; align-items: center; gap: 18px; padding: 9px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: 0 0 auto;
  font-family: var(--font-ui); font-size: 12.5px; flex-wrap: wrap;
}
#specbar label { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }
#specbar select, #specbar input[type=number] {
  background: var(--ink-2); border: 1px solid var(--line); color: var(--paper);
  padding: 6px 8px; border-radius: 6px; font-family: var(--font-mono); font-size: 12px;
}
#specbar input[type=number] { width: 68px; }
.chk { cursor: pointer; }
.readout {
  font-family: var(--font-mono); font-size: 12px; color: var(--yellow);
  background: rgba(255,233,62,.08); border: 1px dashed rgba(255,233,62,.4);
  padding: 6px 10px; border-radius: 6px;
}
.readout .warn { color: var(--danger); }
.spacer { flex: 1; }

/* ------------------------------------------------------------ workspace */
#workspace { flex: 1; display: flex; min-height: 0; }
aside { background: var(--panel); flex: 0 0 auto; overflow-y: auto; }
#leftPanel { width: 250px; border-right: 1px solid var(--line); padding: 14px; }
#rightPanel { width: 270px; border-left: 1px solid var(--line); padding: 14px; }
.panel-section { margin-bottom: 22px; }
.panel-section h3 {
  font-family: var(--font-ui); font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--violet); margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px dotted var(--line);
}
.panel-section .btn, .panel-section > button { width: 100%; margin-bottom: 6px; justify-content: flex-start; }
#bgSwatches { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 2px solid var(--line); cursor: pointer; }
.swatch:hover { border-color: var(--cyan); transform: scale(1.08); }
#proceduralGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.proc-thumb { aspect-ratio: 3/4; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; background-size: cover; background-position: center; position: relative; }
.proc-thumb span { position: absolute; bottom: 3px; left: 5px; font-size: 9px; font-family: var(--font-mono); background: rgba(0,0,0,.55); padding: 1px 4px; border-radius: 3px; }
.proc-thumb:hover { border-color: var(--yellow); }

/* --------------------------------------------------------------- layers */
#layersList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.layer-row {
  display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid transparent; font-size: 12px; font-family: var(--font-ui);
}
.layer-row.active { border-color: var(--pink); box-shadow: 0 0 0 1px var(--pink) inset; }
.layer-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.layer-row button { background: none; border: none; color: var(--ink-soft); padding: 2px 4px; font-size: 12px; }
.layer-row button:hover { color: var(--cyan); }
.layer-row.locked .name { color: var(--ink-soft); }

/* ----------------------------------------------------------------- stage */
#stageViewport {
  flex: 1; position: relative; overflow: auto; display: flex; align-items: center; justify-content: center;
  background:
    linear-gradient(var(--ink-2) 1px, transparent 1px) 0 0/28px 28px,
    linear-gradient(90deg, var(--ink-2) 1px, transparent 1px) 0 0/28px 28px,
    var(--ink);
}
#stage {
  position: relative; background: #1a1a1a; transform-origin: center center;
  box-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 30px 80px rgba(0,0,0,.6), 0 0 120px rgba(255,46,136,.08);
}
#layerRoot, #guideRoot, #selRoot { position: absolute; inset: 0; }
#layerRoot, #guideRoot, #selRoot { pointer-events: none; } /* each .layer opts back in via inline style so empty canvas area still falls through to #stage for deselect-on-click */

.layer { position: absolute; overflow: hidden; }
.layer img { width: 100%; height: 100%; display: block; }
.layer-text-inner { width: 100%; height: 100%; display: flex; align-items: center; outline: none; white-space: pre-wrap; word-break: break-word; }
.layer-text-inner[contenteditable=true] { cursor: text; box-shadow: 0 0 0 2px var(--cyan) inset; }
.layer:hover { outline: 1px dashed rgba(46,242,255,.5); }
.layer-selected { outline: 1px solid var(--cyan) !important; }

.guide { position: absolute; pointer-events: none; }
.guide-bleed { border: 1.5px dashed rgba(255,90,90,.85); }
.guide-trim { border: 1.5px solid rgba(255,255,255,.7); }
.guide-safe { border: 1.5px dashed rgba(46,242,255,.7); }
.guide-spine { background: rgba(168,85,247,.10); border-left: 1px dashed rgba(168,85,247,.7); border-right: 1px dashed rgba(168,85,247,.7); }
.guide-spine-warn { background: repeating-linear-gradient(45deg, rgba(255,90,90,.12), rgba(255,90,90,.12) 6px, transparent 6px, transparent 12px); border-left: 1px dashed rgba(255,90,90,.8); border-right: 1px dashed rgba(255,90,90,.8); }
.guide-barcode { background: repeating-linear-gradient(45deg, rgba(255,233,62,.14), rgba(255,233,62,.14) 5px, transparent 5px, transparent 10px); border: 1.5px dashed rgba(255,233,62,.8); }

.sel-box { position: absolute; border: 1px solid var(--cyan); pointer-events: none; }
.sel-handle {
  position: absolute; width: 11px; height: 11px; background: var(--ink-2); border: 2px solid var(--cyan);
  border-radius: 3px; pointer-events: auto; transform: translate(-50%, -50%);
}
.sel-nw { left: 0; top: 0; cursor: nwse-resize; } .sel-n { left: 50%; top: 0; cursor: ns-resize; }
.sel-ne { left: 100%; top: 0; cursor: nesw-resize; } .sel-e { left: 100%; top: 50%; cursor: ew-resize; }
.sel-se { left: 100%; top: 100%; cursor: nwse-resize; } .sel-s { left: 50%; top: 100%; cursor: ns-resize; }
.sel-sw { left: 0; top: 100%; cursor: nesw-resize; } .sel-w { left: 0; top: 50%; cursor: ew-resize; }
.sel-rotate {
  position: absolute; left: 50%; top: -28px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--pink); border: 2px solid #fff; transform: translateX(-50%); pointer-events: auto;
  box-shadow: var(--glow-pink); cursor: grab;
}
.sel-rotate::after { content:''; position:absolute; left:50%; top:100%; width:1px; height:16px; background: var(--cyan); transform: translateX(-50%); }

/* ------------------------------------------------------------- inspector */
#inspector { font-family: var(--font-ui); font-size: 12.5px; }
.field { margin-bottom: 12px; }
.field label { display: block; color: var(--ink-soft); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; margin-bottom: 5px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%; background: var(--ink-2); border: 1px solid var(--line); color: var(--paper);
  padding: 8px 9px; border-radius: 6px; font-family: var(--font-body); font-size: 13px;
}
.field textarea { resize: vertical; min-height: 54px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
input[type=color] { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 6px; background: var(--ink-2); padding: 2px; }
input[type=range] { width: 100%; accent-color: var(--pink); }
.toggle-row { display: flex; gap: 6px; }
.toggle-row button { flex: 1; }
.toggle-row button.on { background: var(--violet); border-color: var(--violet); color: #fff; }
.empty-hint { color: var(--ink-soft); font-size: 12.5px; line-height: 1.6; padding: 10px 2px; }

/* ------------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,6,12,.75); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: min(720px, 92vw); max-height: 84vh; display: flex; flex-direction: column;
  box-shadow: 0 30px 100px rgba(0,0,0,.6), 0 0 60px rgba(168,85,247,.15);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-family: var(--font-ui); font-size: 15px; margin: 0; color: var(--paper); }
.modal-close { background: none; border: none; color: var(--ink-soft); font-size: 18px; }
.modal-close:hover { color: var(--pink); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.search-row input { flex: 1; background: var(--ink-2); border: 1px solid var(--line); color: var(--paper); padding: 10px 12px; border-radius: 8px; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.result-card { cursor: pointer; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--ink-2); }
.result-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.result-card .meta { font-size: 10px; padding: 5px 6px; color: var(--ink-soft); font-family: var(--font-mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-card:hover { border-color: var(--cyan); }
.source-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.source-tabs button.active { color: var(--cyan); border-color: var(--cyan); }
.proj-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; border: 1px solid var(--line); margin-bottom: 8px; }
.proj-row img { width: 46px; height: 60px; object-fit: cover; border-radius: 4px; background: var(--ink-2); }
.proj-row .info { flex: 1; }
.proj-row .info .n { font-family: var(--font-ui); font-size: 13px; }
.proj-row .info .t { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-soft); }
.warn-box { background: rgba(255,90,90,.08); border: 1px solid rgba(255,90,90,.4); color: #FFB3B3; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; line-height: 1.5; }
.hint-box { background: rgba(46,242,255,.07); border: 1px solid rgba(46,242,255,.3); color: var(--cyan); padding: 10px 12px; border-radius: 8px; font-size: 12px; margin-bottom: 12px; line-height: 1.5; }

/* ------------------------------------------------------------------ toast */
#toastRoot { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel-3); border: 1px solid var(--line); border-left: 4px solid var(--cyan);
  padding: 12px 16px; border-radius: 8px; font-size: 12.5px; max-width: 320px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: slideIn .2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* -------------------------------------------------------------- loading */
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.25); border-top-color: var(--cyan); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ responsive */
@media (max-width: 980px) {
  #leftPanel, #rightPanel { width: 210px; }
  .logo em { display: none; }
}
@media (max-width: 760px) {
  #coverTypeTabs { display: none; }
  #leftPanel { display: none; }
  body::after {
    content: 'Covers By His Super Affiliates is built for a larger screen — open on a tablet, laptop, or desktop for the full editor.';
    position: fixed; inset: 0; background: var(--ink); color: var(--paper); z-index: 999;
    display: flex; align-items: center; justify-content: center; text-align: center;
    padding: 40px; font-family: var(--font-ui); font-size: 15px; line-height: 1.6;
  }
}
