/* =======================================================================
   Epic Logo Forge — UI styles. Dark, dense, professional tool aesthetic.
   ======================================================================= */
:root {
  --bg: #0c0d12;
  --bg-2: #12141c;
  --panel: #161924;
  --panel-2: #1c2030;
  --line: #262b3b;
  --line-2: #313850;
  --text: #e7ebf5;
  --muted: #8b93a9;
  --accent: #ffb02e;
  --accent-2: #19e6ff;
  --accent-3: #a14fe0;
  --danger: #ff5a6e;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 700px at 70% -10%, #1a1d2b, var(--bg));
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
}

/* ---- top bar ---------------------------------------------------------- */
.topbar {
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(180deg, #181b27, #121420);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 14px rgba(0,0,0,.4);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 2px; }
.brand-mark {
  font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 8px rgba(255,176,46,.5));
}
.brand-name { background: linear-gradient(90deg,#fff,#bcd); -webkit-background-clip:text; background-clip:text; color:transparent; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.size-group, .export-group { display: flex; align-items: center; gap: 8px; }
.size-group label, .export-group label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }

/* ---- layout ----------------------------------------------------------- */
.layout { display: flex; height: calc(100% - 56px); }
.panel {
  width: 340px; min-width: 340px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 6px 0 60px;
}
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-thumb { background: #2a3045; border-radius: 8px; border: 2px solid var(--panel); }

.group { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.group h3 {
  margin: 0 0 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--accent); font-weight: 700;
}

/* ---- form controls ---------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 11px; }
.field > span { color: var(--muted); font-size: 11px; display: flex; justify-content: space-between; }
.field > span b { color: var(--text); font-weight: 600; }
.field.two { flex-direction: row; align-items: center; justify-content: space-between; }
.field.two > span { flex: 1; }
.sub-label { color: var(--muted); font-size: 11px; display: block; margin-bottom: 7px; }

input[type=text], select {
  background: var(--bg-2); border: 1px solid var(--line-2); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; width: 100%;
  outline: none; transition: border-color .15s;
}
input[type=text]:focus, select:focus { border-color: var(--accent-2); }
select { cursor: pointer; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
input[type=color] {
  -webkit-appearance: none; appearance: none; width: 42px; height: 28px;
  border: 1px solid var(--line-2); border-radius: 7px; background: none; cursor: pointer; padding: 0;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 4px; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--line-2); border-radius: 4px; outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); cursor: pointer; box-shadow: 0 0 0 3px rgba(255,176,46,.18);
}
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border: none; border-radius: 50%;
  background: var(--accent); cursor: pointer;
}
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---- presets ---------------------------------------------------------- */
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.preset {
  border: 1px solid var(--line-2); border-radius: 8px; padding: 8px; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; background: var(--bg-2);
  transition: transform .12s, border-color .12s;
}
.preset:hover { transform: translateY(-1px); border-color: var(--accent); }
.preset.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.preset .swatch { height: 26px; border-radius: 5px; border: 1px solid rgba(255,255,255,.1); }
.preset .pname { font-size: 10.5px; color: var(--muted); letter-spacing: .3px; }

/* ---- metal + bg grids ------------------------------------------------- */
.metals { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.metal {
  aspect-ratio: 1; border-radius: 6px; cursor: pointer; border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.metal:hover { transform: scale(1.08); }
.metal.active { border-color: #fff; }

.bg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.bg-cell {
  height: 42px; border-radius: 7px; cursor: pointer; border: 1px solid var(--line-2);
  display: flex; align-items: flex-end; justify-content: center; overflow: hidden; position: relative;
}
.bg-cell span {
  font-size: 9px; color: #fff; background: rgba(0,0,0,.5); width: 100%; text-align: center;
  padding: 2px 0; letter-spacing: .3px;
}
.bg-cell.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* ---- layer stack ------------------------------------------------------ */
.add-layer { display: flex; gap: 7px; margin-bottom: 10px; }
.add-layer select { flex: 1; }
.layer-list { display: flex; flex-direction: column; gap: 8px; }
.layer-hint { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 8px 0 0; }
.layer-card { background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 9px; overflow: hidden; }
.layer-card.selected { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }
.layer-head { display: flex; align-items: center; gap: 7px; padding: 8px 9px; }
.layer-head .lname { flex: 1; font-size: 12px; font-weight: 600; }
.layer-head .toggle, .layer-head .iconbtn {
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted);
  border-radius: 6px; width: 24px; height: 24px; cursor: pointer; font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.layer-head .iconbtn:hover { border-color: var(--accent); color: var(--text); }
.layer-head .iconbtn.del:hover { border-color: var(--danger); color: var(--danger); }
.layer-head .toggle.on { color: var(--accent); border-color: var(--accent); }
.layer-body { padding: 4px 10px 10px; border-top: 1px solid var(--line); display: none; }
.layer-card.open .layer-body { display: block; }
.layer-body .field { margin-bottom: 8px; }
.flavor-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin: 4px 0 10px; }
.flavor-sw { aspect-ratio: 1; border-radius: 5px; cursor: pointer; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); }
.flavor-sw:hover { transform: scale(1.1); }
.flavor-sw.active { border-color: #fff; }
.layer-head .grip { cursor: default; color: var(--muted); font-size: 12px; }
.behind-row { display: flex; gap: 6px; }
.behind-row button { flex: 1; padding: 5px; font-size: 10.5px; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted); border-radius: 6px; cursor: pointer; }
.behind-row button.active { border-color: var(--accent); color: var(--text); }

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

/* ---- stroke editor ---------------------------------------------------- */
.stroke-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 8px; }
.stroke-row input[type=color] { width: 34px; height: 26px; }
.stroke-row input[type=range] { flex: 1; }
.stroke-row .sw { font-size: 10px; color: var(--muted); width: 34px; text-align: right; }
.stroke-row .del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }

/* ---- buttons ---------------------------------------------------------- */
.btn {
  border: none; border-radius: 8px; padding: 8px 14px; font-weight: 700; cursor: pointer;
  font-size: 12px; letter-spacing: .5px; color: #0c0d12;
  background: linear-gradient(180deg, #ffd36b, var(--accent)); transition: filter .12s, transform .12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.export { min-width: 52px; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); }
.btn.ghost:hover { border-color: var(--accent); filter: none; }
.btn.small { padding: 6px 10px; font-size: 11px; width: 100%; }

/* ---- stage ------------------------------------------------------------ */
.stage-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.stage-toolbar {
  height: 42px; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.stage-toolbar .hint { color: var(--muted); font-size: 11px; flex: 1; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text);
  border-radius: 20px; padding: 5px 12px; font-size: 11px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip.active { border-color: var(--accent-2); color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }
.stage {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 30px;
  background:
    radial-gradient(900px 600px at 50% 40%, #1a1e2c, transparent),
    repeating-linear-gradient(45deg, #0e0f16 0 2px, transparent 2px 22px);
  overflow: auto;
}
.stage-inner {
  max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,.04);
  line-height: 0;
}
.stage-inner.checker {
  background-image:
    linear-gradient(45deg, #2a2e3c 25%, transparent 25%),
    linear-gradient(-45deg, #2a2e3c 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2e3c 75%),
    linear-gradient(-45deg, transparent 75%, #2a2e3c 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  background-color: #20232f;
}
#logoSvg { display: block; max-width: 78vw; max-height: calc(100vh - 160px); width: auto; height: auto; border-radius: 10px; }
/* hint that emblems are draggable when the handles overlay is enabled */
#logoSvg.handles-on .orn-layer { cursor: pointer; }
#logoSvg.handles-on #handlesOverlay { touch-action: none; }

/* ---- misc ------------------------------------------------------------- */
.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1c2030; border: 1px solid var(--line-2); color: var(--text);
  padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: all .25s; font-size: 12px; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); color: #ffd0d6; }

/* ---- image library modal --------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 7, 11, .72); padding: 30px;
}
.modal {
  width: min(960px, 94vw); max-height: 86vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1b1f2c, #161924);
}
.modal-title { font-weight: 800; letter-spacing: .5px; }
.modal-head .modal-hint { flex: 1; color: var(--muted); font-size: 11px; }
.modal-head .modal-hint code { background: var(--bg-2); padding: 1px 5px; border-radius: 4px; }
.modal-body { padding: 14px 16px 24px; overflow-y: auto; }
.lib-cat { margin-bottom: 18px; }
.lib-cat h4 {
  margin: 0 0 9px; font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--accent);
  border-bottom: 1px solid var(--line); padding-bottom: 6px;
}
.lib-cat .count { color: var(--muted); font-weight: 400; letter-spacing: 0; text-transform: none; margin-left: 6px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.lib-thumb {
  display: flex; flex-direction: column; gap: 4px; padding: 8px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 9px; transition: transform .1s, border-color .1s;
}
.lib-thumb:hover { transform: translateY(-2px); border-color: var(--accent); }
.lib-thumb .frame {
  height: 78px; border-radius: 6px; display: flex; align-items: center; justify-content: center; overflow: hidden;
  background:
    linear-gradient(45deg, #cfd4de 25%, transparent 25%), linear-gradient(-45deg, #cfd4de 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #cfd4de 75%), linear-gradient(-45deg, transparent 75%, #cfd4de 75%);
  background-size: 14px 14px; background-position: 0 0, 0 7px, 7px -7px, -7px 0; background-color: #eef1f6;
}
.lib-thumb .frame img { max-width: 86%; max-height: 86%; display: block; }
.lib-thumb .cap { font-size: 10px; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-empty { color: var(--muted); font-size: 12.5px; line-height: 1.6; }
