* { box-sizing: border-box; }

:root {
  --blue: #2962ff;
  --blue-dark: #1e4fd6;
  --ink: #1d2330;
  --muted: #79818f;
  --line: #e3e6ec;
  --card: #fff;
  --bg: #f3f4f7;
  --chip: #eef1f6;
  --chip-hover: #e2e7ef;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- header ---------- */

header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.head-title h1 { margin: 0; font-size: 19px; }
.head-title p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.head-license { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  letter-spacing: .02em;
}
.badge.demo { background: #fff3da; color: #9a6700; }
.badge.ok { background: #ddf3e4; color: #1a7f37; }

/* ---------- layout ---------- */

main {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: flex-start;
  max-width: 1560px;
  margin: 0 auto;
}

#sidebar {
  width: 330px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
section h2 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #555e6e;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
section h2 select { text-transform: none; letter-spacing: 0; }

.hint { font-size: 11.5px; color: var(--muted); margin: 8px 0 0; line-height: 1.45; }
.hint.ok { color: #1a7f37; }
.hint.err { color: #c62828; }

/* ---------- buttons & inputs ---------- */

button, .file-btn {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s;
}
button:hover, .file-btn:hover { background: var(--blue-dark); }
button:disabled { opacity: .45; cursor: default; }
button:disabled:hover { background: var(--blue); }
button.ghost, .ghost {
  background: var(--chip);
  color: #2a3242;
}
button.ghost:hover { background: var(--chip-hover); }
button.ghost:disabled:hover { background: var(--chip); }
.file-btn input { display: none; }
.file-btn { margin-right: 8px; }

select {
  border: 1px solid #d6dae2;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

.slider-row { margin: 10px 0; }
.slider-row label { display: block; font-size: 12.5px; margin-bottom: 2px; }
.slider-row output { float: right; color: var(--blue); font-weight: 600; }
.slider-row input[type=range] { width: 100%; accent-color: var(--blue); }

.chk-row { display: block; font-size: 12.5px; margin: 8px 0; }
.chk-row input { accent-color: var(--blue); }

/* ---------- segmented controls ---------- */

.seg-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 12.5px; }
.seg-row > span { min-width: 46px; }
.seg { display: flex; flex: 1; background: var(--chip); border-radius: 8px; padding: 2px; }
.seg button { flex: 1; background: transparent; color: #2a3242; padding: 5px 4px; font-size: 12px; border-radius: 6px; }
.seg button:hover { background: var(--chip-hover); }
.seg button.active, .seg button.active:hover {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(20, 30, 60, .18);
  font-weight: 600;
}
.seg-mini { flex: 0 0 auto; }
.seg-mini button { padding: 4px 10px; flex: 0 0 auto; }

/* ---------- palette ---------- */

#palette-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.pal-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  background: #f7f8fa;
}
.pal-row.selected { border-color: var(--blue); background: #eef3ff; }
.pal-row input[type=color] { width: 34px; height: 28px; border: none; padding: 0; background: none; cursor: pointer; }
.pal-code { width: 42px; text-align: center; font-weight: 700; }
.pal-name { flex: 1; min-width: 0; }
.pal-row input[type=text] {
  border: 1px solid #d6dae2;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12.5px;
  font-family: inherit;
}
.pal-count { font-size: 11px; color: var(--muted); min-width: 26px; text-align: right; }
.pal-del { background: none; color: #a3aab6; padding: 2px 6px; font-size: 15px; }
.pal-del:hover { background: #fde8e8; color: #c62828; }

#adv-codes { margin-top: 10px; }
#adv-codes summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--blue);
  user-select: none;
}
#adv-codes[open] summary { margin-bottom: 4px; }
.var-row { display: flex; align-items: center; gap: 6px; margin: 5px 0; }
.var-dot { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; border: 1px solid rgba(0, 0, 0, .15); }
.var-code { font-weight: 700; font-size: 12px; min-width: 30px; text-align: center; }
.var-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid #d6dae2;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  font-family: inherit;
}

#sidebar section > input[type=text] {
  width: 100%;
  border: 1px solid #d6dae2;
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 13px;
  margin-bottom: 7px;
  font-family: inherit;
}

.export-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

/* ---------- workspace ---------- */

#workspace { flex: 1; min-width: 0; }

#ws-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
#ws-tabs { display: flex; gap: 6px; }
.ws-tab { background: #e8ebf1; color: #2a3242; font-size: 13px; padding: 8px 14px; }
.ws-tab:hover { background: #dde2ea; }
.ws-tab.active, .ws-tab.active:hover { background: var(--blue); color: #fff; }

#toolbar { display: flex; align-items: center; gap: 4px; }
.tool-btn { background: var(--chip); color: #2a3242; padding: 7px 10px; font-size: 12.5px; }
.tool-btn.active { background: var(--blue); color: #fff; }
.tb-btn {
  background: var(--chip);
  color: #2a3242;
  padding: 7px 10px;
  font-size: 14px;
  line-height: 1;
  min-width: 34px;
}
.tb-btn:hover { background: var(--chip-hover); }
.tb-btn:disabled:hover { background: var(--chip); }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 5px; }

#gap-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #f4f7ff;
  border: 1px solid #d9e2f6;
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 12.5px;
}
#gap-bar label { white-space: nowrap; }
#gap-bar output { color: var(--blue); font-weight: 600; }
#gap-bar input[type=range] { width: 120px; accent-color: var(--blue); }
#gap-bar button { padding: 6px 10px; font-size: 12px; }
#gap-bar .hint { margin: 0; flex-basis: 100%; }

#canvas-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
  overflow: hidden;
}
#canvas-wrap.drag { outline: 3px dashed var(--blue); outline-offset: -8px; }

#empty-state { text-align: center; color: #a3aab6; }
#empty-state p:first-child { font-size: 52px; margin: 0; }

#preview {
  width: 100%;
  height: clamp(420px, calc(100vh - 290px), 1100px);
  cursor: crosshair;
  border-radius: 6px;
  touch-action: none;
}

#page-preview {
  max-width: 100%;
  max-height: calc(100vh - 270px);
  box-shadow: 0 1px 6px rgba(20, 30, 60, .12);
}

#statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: #5a6372;
  padding: 8px 4px;
}
#status { flex: 1; }
#hover-info { text-align: right; }

/* ---------- license modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 40, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-card {
  background: #fff;
  border-radius: 14px;
  padding: 22px 24px;
  width: min(440px, calc(100vw - 40px));
  box-shadow: 0 12px 40px rgba(10, 16, 32, .25);
}
.modal-card h3 { margin: 0 0 8px; font-size: 17px; }
.modal-card p { font-size: 13px; color: #444c5c; line-height: 1.5; margin: 0 0 12px; }
#license-form { display: flex; gap: 8px; margin-bottom: 8px; }
#license-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid #d6dae2;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: ui-monospace, monospace;
}
.modal-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.modal-foot a { font-size: 13px; color: var(--blue); text-decoration: none; flex: 1; }
.modal-foot a:hover { text-decoration: underline; }
