:root {
  --bg: #e6e8ec;
  --panel: #f5f6f8;
  --panel-2: #ffffff;
  --border: #c9cdd4;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #1473e6;
  --accent-soft: #dbeafe;
  --hover: #e3e8f0;
  --menubar: #2b2f36;
  --menubar-text: #e5e7eb;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font: 12px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  user-select: none;
}

#app { display: grid; grid-template-rows: auto auto auto 1fr auto auto; grid-template-columns: minmax(0, 1fr); height: 100vh; }

/* ---------- menu bar ---------- */
#menubar {
  display: flex; align-items: center; gap: 8px;
  background: var(--menubar); color: var(--menubar-text);
  height: 30px; padding: 0 8px;
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 700; letter-spacing: .3px; margin-right: 8px; }
.logo { width: 18px; height: 18px; background: url(logo.svg) center / contain no-repeat; }
#menus { display: flex; height: 100%; }
.menu { position: relative; height: 100%; }
.menu > button {
  height: 100%; padding: 0 10px; background: none; border: 0; color: inherit; font: inherit; cursor: default;
}
.menu > button:hover, .menu.open > button { background: #3d434d; }
.menu-list {
  display: none; position: absolute; top: 100%; left: 0; z-index: 50; min-width: 240px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 4px 0; border-radius: 0 0 6px 6px;
}
.menu.open > .menu-list { display: block; }
/* Submenus: beside their item while it's pointed at (on the left near the window's edge). */
.menu-item.has-sub { position: relative; }
.menu-list.submenu { top: -5px; left: 100%; border-radius: 6px; }
.menu-list.submenu.left { left: auto; right: 100%; }
.menu-item.has-sub:hover > .menu-list.submenu { display: block; }
.menu-item.has-sub:hover { background: var(--accent); color: #fff; }
.menu-item { display: flex; justify-content: space-between; gap: 24px; padding: 5px 14px; cursor: default; white-space: nowrap; }
.menu-item:hover { background: var(--accent); color: #fff; }
.menu-item .key { color: var(--muted); }
.menu-item:hover > .key { color: #dbeafe; }
.menu-item.checked::before { content: "✓"; position: absolute; left: 4px; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.doc-title { margin-left: auto; color: #9ca3af; }

/* ---------- bars ---------- */
.bar {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 3px 8px; min-height: 34px;
}
.bar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.bar label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.bar input[type=number], .bar input[type=text], .bar select {
  height: 24px; border: 1px solid var(--border); border-radius: 4px; background: #fff;
  font: inherit; padding: 0 4px; color: var(--text);
}
.bar input[type=number] { width: 70px; }
.bar input.short { width: 52px; }
.bar .group-title { font-weight: 600; color: var(--text); margin-right: 4px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 28px; height: 26px; padding: 0 5px; border: 1px solid transparent; border-radius: 4px;
  background: none; color: var(--text); font: inherit; cursor: default;
}
.icon-btn:hover { background: var(--hover); border-color: var(--border); }
.icon-btn.active { background: var(--accent-soft); border-color: var(--accent); }
.icon-btn:disabled { opacity: .35; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.text { font-weight: 700; }

/* ---------- workspace ---------- */
#workspace { display: grid; grid-template-columns: 44px minmax(0, 1fr) 26px 250px; min-height: 0; }
#toolbox {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 6px 0; gap: 2px; overflow-y: auto;
}
#toolbox .icon-btn { width: 34px; height: 32px; }
#toolbox .icon-btn svg { width: 20px; height: 20px; }
#toolbox .tsep { width: 26px; height: 1px; background: var(--border); margin: 3px 0; }
#toolbox .colors { margin-top: auto; position: relative; width: 30px; height: 30px; }
#toolbox .colors .sw { position: absolute; width: 18px; height: 18px; border: 1px solid #555; }
#toolbox .colors .sw.fill { left: 0; top: 0; z-index: 1; }
#toolbox .colors .sw.out { right: 0; bottom: 0; border-width: 4px; background: #fff !important; }

#canvas-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
/* Start-up splash */
#splash { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px; background: var(--bg); transition: opacity .4s ease; }
#splash.done { opacity: 0; pointer-events: none; }
.splash-card { position: relative; width: min(760px, 100%); aspect-ratio: 5 / 3; border-radius: 14px; overflow: hidden; background: #0f172a; box-shadow: 0 24px 60px rgba(15, 23, 42, .35), 0 2px 8px rgba(15, 23, 42, .2); animation: splash-in .5s ease both; }
.splash-card img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.splash-head { position: absolute; left: 6%; top: 8%; color: #fff; text-shadow: 0 2px 12px rgba(2, 6, 23, .6); }
.splash-title { display: flex; align-items: center; gap: 12px; font: 700 clamp(28px, 6vw, 46px)/1.1 system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: -.02em; }
.splash-title .logo { width: clamp(30px, 5.5vw, 46px); height: clamp(30px, 5.5vw, 46px); filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .35)); }
.splash-tag { margin-top: 8px; font: 400 clamp(12px, 2vw, 15px)/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: #cbd5e1; max-width: 30ch; }
.splash-card::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 26%; background: linear-gradient(to top, rgba(2, 6, 23, .75), rgba(2, 6, 23, 0)); pointer-events: none; }
.splash-foot { position: absolute; z-index: 1; left: 6%; right: 6%; bottom: 6%; color: #94a3b8; font: 400 12px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
.splash-bar { height: 3px; border-radius: 3px; background: rgba(148, 163, 184, .25); overflow: hidden; margin-bottom: 8px; }
.splash-bar i { display: block; height: 100%; width: 35%; border-radius: 3px; background: linear-gradient(90deg, #fb923c, #a3e635, #22d3ee, #a855f7); animation: splash-run 1.3s ease-in-out infinite; }
.splash-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
#splash.failed .splash-bar { display: none; }
#splash.failed #splash-status { color: #fecaca; }
/* Narrow screens: the name on top, the whole artwork below it, then the progress. */
@media (max-width: 560px) {
  .splash-card { aspect-ratio: auto; display: flex; flex-direction: column; background: #070b1f; }
  .splash-card img { position: static; height: auto; order: 1; }
  .splash-head { position: static; order: 0; padding: 22px 20px 16px; }
  .splash-foot { position: static; order: 2; padding: 14px 20px 18px; }
  .splash-card::after { display: none; }
}
@keyframes splash-run { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@keyframes splash-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .splash-bar i, .splash-card { animation: none; } #splash { transition: none; } }

#palette {
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 4px 0; gap: 1px; overflow-y: auto;
}
#palette .chip { width: 18px; height: 14px; border: 1px solid rgba(0,0,0,.35); cursor: pointer; flex: none; }
#palette .chip:hover { transform: scale(1.25); z-index: 1; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
#palette .chip.none {
  background: #fff linear-gradient(to top right, transparent 45%, #d00 45%, #d00 55%, transparent 55%);
  height: 18px; margin-bottom: 3px;
}

/* ---------- docker ---------- */
#docker { background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
#docker .tabs { display: flex; border-bottom: 1px solid var(--border); }
#docker .tabs button {
  flex: 1; padding: 7px 0; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; cursor: default;
}
#docker .tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 10px; }
.hidden { display: none !important; }

.section { margin-bottom: 16px; }
.section h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
.row > span:first-child { width: 58px; color: var(--muted); flex: none; }
.row input[type=number], .row select { height: 24px; border: 1px solid var(--border); border-radius: 4px; font: inherit; padding: 0 4px; width: 80px; }
.row input[type=color] { width: 40px; height: 24px; border: 1px solid var(--border); border-radius: 4px; padding: 1px; background: #fff; }
.row input[type=range] { flex: 1; }
.row.wide select, .row.wide input[type=number] { flex: 1; width: auto; min-width: 0; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 5px; overflow: hidden; width: 100%; }
.seg button { flex: 1; border: 0; background: #fff; padding: 5px 0; font: inherit; cursor: default; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: #fff; }
.seg button svg { width: 16px; height: 16px; display: block; margin: auto; }
.fill-preview { height: 34px; border: 1px solid var(--border); border-radius: 5px; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 11px; line-height: 1.5; }

.obj-list { list-style: none; margin: 0; padding: 0; }
.obj-list li {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 4px; cursor: default;
  border: 1px solid transparent;
}
.obj-list li:hover { background: var(--hover); }
.obj-list li.sel { background: var(--accent-soft); border-color: #93c5fd; }
.obj-list li.dragover { border-top: 2px solid var(--accent); }
.obj-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.obj-list .type { color: var(--muted); font-size: 10px; }
.obj-list .flag { width: 20px; height: 20px; border: 0; background: none; padding: 0; opacity: .75; cursor: pointer; }
.obj-list .flag.off { opacity: .25; }
.obj-list .flag svg { width: 15px; height: 15px; }
.obj-list li.hidden-obj .name { color: var(--muted); font-style: italic; }
.layer-head { font-weight: 600; padding: 4px 6px; display: flex; gap: 6px; align-items: center; }

/* ---------- status bar ---------- */
#statusbar {
  display: flex; min-width: 0; overflow: hidden; align-items: center; gap: 16px; padding: 0 10px; height: 26px;
  background: var(--panel); border-top: 1px solid var(--border); color: var(--muted);
}
#coords { min-width: 140px; font-variant-numeric: tabular-nums; }
#sb-phonetic { border: 1px solid var(--accent, #1473e6); color: var(--accent, #1473e6); background: transparent; border-radius: 10px; padding: 0 8px; font-size: 12px; cursor: pointer; white-space: nowrap; }
#status-text { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--text); }
.style-indicator { display: flex; align-items: center; gap: 6px; }
.swatch { width: 18px; height: 14px; border: 1px solid #555; display: inline-block; }
.swatch.none { background: #fff linear-gradient(to top right, transparent 45%, #d00 45%, #d00 55%, transparent 55%) !important; }

@media (max-width: 900px) {
  #workspace { grid-template-columns: 44px minmax(0, 1fr) 26px; }
  #coords { min-width: 0; }
  .style-indicator > span:not(.swatch) { display: none; }
  #docker { display: none; }
}

/* ---------- page navigator ---------- */
#pagebar {
  display: flex; align-items: center; gap: 2px; height: 30px; padding: 0 6px;
  background: var(--panel); border-top: 1px solid var(--border); min-width: 0; overflow: hidden;
}
#pagebar .icon-btn { min-width: 22px; height: 22px; padding: 0 3px; }
#pagebar .icon-btn svg { width: 14px; height: 14px; }
#pagebar .pos { padding: 0 6px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
#pagebar .tabs { display: flex; gap: 2px; overflow-x: auto; min-width: 0; flex: 1; margin-left: 6px; scrollbar-width: none; }
#pagebar .tab {
  flex: none; padding: 3px 12px; border: 1px solid var(--border); border-radius: 5px 5px 0 0; border-bottom-width: 2px;
  background: #e9ebef; cursor: default; white-space: nowrap; color: var(--muted);
}
#pagebar .tab:hover { background: #fff; }
#pagebar .tab.current { background: #fff; color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
#pagebar .tab.dragover { box-shadow: inset 2px 0 0 var(--accent); }
#pagebar .layer-chip { flex: none; margin-left: 8px; color: var(--muted); white-space: nowrap; }
#pagebar .layer-chip b { color: var(--text); }

/* ---------- context menu ---------- */
.ctx-menu { position: fixed; z-index: 100; display: block; border-radius: 6px; }

/* ---------- object manager tree ---------- */
.om-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; }
.om-tools { display: flex; gap: 2px; margin-bottom: 8px; flex-wrap: wrap; }
.om-tools .icon-btn svg { width: 16px; height: 16px; }
.layer-row {
  display: flex; align-items: center; gap: 4px; padding: 4px 4px; border-radius: 4px; margin-top: 4px;
  border: 1px solid transparent; font-weight: 600;
}
.layer-row:hover { background: var(--hover); }
.layer-row.active { background: #eef2ff; border-color: #c7d2fe; }
.layer-row.active .lname::after { content: " (active)"; color: var(--accent); font-weight: 400; font-size: 11px; }
.layer-row.dragover, .obj-list li.dragover { outline: 2px solid var(--accent); outline-offset: -2px; }
.layer-row .caret { width: 14px; text-align: center; color: var(--muted); cursor: pointer; }
.layer-row .lname { flex: 1; min-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row .count { color: var(--muted); font-weight: 400; font-size: 11px; }
.layer-row.hidden-layer .lname { color: var(--muted); font-style: italic; }
.layer-row .flag, .obj-list .flag { width: 20px; height: 20px; border: 0; background: none; padding: 0; opacity: .75; cursor: pointer; }
.layer-row .flag.off { opacity: .25; }
.layer-row .flag svg { width: 15px; height: 15px; }
.obj-list { margin-left: 18px !important; }
.obj-list .empty { color: var(--muted); font-style: italic; padding: 3px 6px; }

/* ---------- master page ---------- */
.om-head.master-head { margin-top: 14px; padding-top: 8px; border-top: 1px dashed var(--border); color: #7c3aed; }
.om-head.master-head svg { width: 14px; height: 14px; vertical-align: -2px; }
.badge { flex: none; font-size: 10px; font-weight: 500; padding: 0 5px; border-radius: 8px; background: #ede9fe; color: #6d28d9; white-space: nowrap; }
.layer-row.off-page .lname, .obj-list.off-page .name { color: var(--muted); text-decoration: line-through; }
.om-tools .sep { width: 1px; height: 20px; background: var(--border); margin: 0 3px; align-self: center; }
.om-tools .scope-sel { height: 24px; border: 1px solid var(--border); border-radius: 4px; font: inherit; }

/* ---------- modal dialog ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); display: grid; place-items: center; z-index: 200; }
.modal-back.clear { background: transparent; place-items: start end; padding: 90px 300px 0 0; }
.mask-modal { width: min(520px, calc(100vw - 32px)); }
.mask-row { gap: 6px; }
.mask-row input[type=range] { flex: 1; min-width: 0; }
.mask-row input[type=color] { width: 34px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 4px; }
.mask-row .hval { width: 38px; text-align: right; }
.modal { background: var(--panel-2); border-radius: 10px; padding: 18px 20px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 14px; font-size: 15px; }
.modal .row > span:first-child { width: 100px; }
.modal input[type=number], .modal select { width: 140px; }
.modal .code-data { flex: 1; font: inherit; padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; resize: vertical; }
.modal .code-err { color: #b91c1c; min-height: 1em; }
.modal input.short { width: 70px; }
.modal .hint { margin: 8px 0; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-btns button { padding: 6px 16px; border: 1px solid var(--border); border-radius: 5px; background: #fff; font: inherit; }
.modal-btns button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.radios { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.radio { display: flex; align-items: center; gap: 8px; }
.radio input[type=text] { height: 24px; border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; font: inherit; width: 140px; }
.modal-btns button:disabled { opacity: .5; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 70px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(640px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 8px;
  background: #1f2937; color: #f9fafb; box-shadow: 0 10px 30px rgba(0,0,0,.25); transition: all .2s; z-index: 300;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

/* ---------- PowerClip ---------- */
#canvas-banner {
  position: absolute; top: 28px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px; border-radius: 999px;
  background: #1f2937; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.25); white-space: nowrap;
}
#canvas-banner button { border: 0; border-radius: 999px; padding: 4px 12px; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.icon-btn.finish-pc { background: #1f2937; color: #fff; padding: 0 10px; }
.icon-btn.finish-pc:hover { background: #374151; }
.obj-list li.pc-content { padding-left: 52px; color: var(--muted); font-style: italic; }

/* ---------- snapping & guidelines ---------- */
.ctx-menu .check { display: inline-block; width: 16px; color: var(--accent); }
.ctx-menu .menu-item:hover .check { color: #fff; }
#btn-snap.snap-off { opacity: .55; text-decoration: line-through; }
.guide-list { max-height: 260px; overflow-y: auto; margin: 10px 0; }
.guide-list h4 { margin: 8px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.guide-list .row > span:first-child { width: 20px; }
/* Text ▸ Fonts…: the font browser */
.modal.font-browser { width: min(680px, calc(100vw - 32px)); }
.font-browser .row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.font-browser .row > span:first-child { width: auto; }
.font-browser input[type=search], .font-browser input[type=text] { padding: 5px 8px; border: 1px solid var(--border); border-radius: 5px; font: inherit; }
.font-browser select { width: 200px; }
.font-list { height: min(380px, 50vh); overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
.font-row { display: flex; align-items: center; gap: 12px; padding: 6px 10px; border-bottom: 1px solid var(--hover); cursor: pointer; }
.font-row:hover { background: var(--hover); }
.font-row.current { background: var(--accent-soft); }
.font-name { width: 190px; flex: none; display: flex; flex-direction: column; overflow: hidden; }
.font-name b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.font-name .hint { margin: 0 !important; font-size: 11px; }
.font-preview { flex: 1; font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 560px) { .font-name { width: 120px; } .font-preview { font-size: 18px; } }
.small-btn { padding: 3px 8px; border: 1px solid var(--border); border-radius: 4px; background: #fff; font: inherit; }

#canvas-wrap.drop::after {
  content: "Drop to import (SVG, images, fonts)"; position: absolute; inset: 12px; display: grid; place-items: center;
  border: 3px dashed var(--accent); border-radius: 12px; background: rgba(20,115,230,.08);
  color: var(--accent); font-size: 18px; font-weight: 600; pointer-events: none;
}

/* Fountain-fill editor */
#dk-ftype { margin-bottom: 8px; }
#dk-ftype button { font-size: 11px; }
.gbar-wrap { position: relative; margin: 2px 6px 18px; }
/* Two-color pattern cell editor: 16 × 16, on a checkerboard so "no background" shows. */
.pat-grid { display: grid; grid-template-columns: repeat(16, 1fr); width: 160px; height: 160px; margin: 6px 0 6px 64px; border: 1px solid var(--border); cursor: crosshair; touch-action: none;
  background: conic-gradient(#e5e7eb 25%, #fff 0 50%, #e5e7eb 0 75%, #fff 0) 0 0 / 10px 10px; }
.pat-grid > div { box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.12); }
.gbar { height: 18px; border: 1px solid var(--border); border-radius: 3px; cursor: copy; }
.gnodes { position: absolute; left: 0; right: 0; top: 20px; height: 14px; }
.gnode { position: absolute; width: 10px; height: 12px; margin-left: -5px; border: 1px solid #6b7280; border-radius: 2px; cursor: ew-resize; box-sizing: border-box; touch-action: none; }
.gnode::before { content: ""; position: absolute; left: 2px; top: -5px; border: 2px solid transparent; border-bottom: 3px solid #6b7280; }
.gnode.sel { border: 2px solid var(--accent, #1473e6); }
.gnode.sel::before { border-bottom-color: var(--accent, #1473e6); }

/* Bitmap effects list */
.fx-row { gap: 4px; }
.fx-row .fx-name { flex: 1; width: auto !important; color: inherit !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Color swatch buttons and the color picker */
.cswatch { width: 40px; height: 24px; border: 1px solid var(--border); border-radius: 4px; padding: 0; cursor: pointer; background: #000; flex: none; }
.cswatch.none { background: repeating-linear-gradient(45deg, #fff 0 4px, #f3f4f6 4px 8px); }
.color-picker { position: fixed; z-index: 300; width: 250px; background: var(--panel-2, #fff); border: 1px solid var(--border); border-radius: 8px; padding: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.25); font-size: 12px; }
.color-picker .seg { margin-bottom: 8px; }
.color-picker .cp-preview { height: 34px; border-radius: 4px; border: 1px solid var(--border); margin-bottom: 8px; display: grid; place-items: center; font: 600 11px system-ui; color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.7); }
.color-picker .row input[type=number] { width: 52px; }
.color-picker .modal-btns { margin-top: 8px; }

/* ---------- toolbox flyouts ---------- */
#toolbox .flyout-btn { position: relative; }
#toolbox .flyout-btn .ico { display: contents; }
#toolbox .flyout-btn .corner {
  position: absolute; right: 2px; bottom: 2px; width: 0; height: 0;
  border-left: 5px solid transparent; border-bottom: 5px solid currentColor; opacity: .7;
}
.ctx-menu.flyout .menu-item > span:first-child { display: inline-flex; align-items: center; gap: 8px; }
.ctx-menu.flyout .ico { display: inline-flex; width: 18px; height: 18px; }
.ctx-menu.flyout .ico svg { width: 18px; height: 18px; }
.ctx-menu.flyout .menu-item.current { font-weight: 600; }
.ctx-menu.flyout .menu-item .key { margin-left: 24px; }

/* ---------- document palette ---------- */
#palette .doc-palette { display: contents; }
#palette .doc-palette .sep { width: 18px; height: 1px; background: var(--border); margin: 3px 0; flex: none; }
/* The docker's fill types: five fit in narrow dockers too. */
#dk-fill-type { flex-wrap: wrap; }
#dk-fill-type button { flex: 1 1 30%; padding: 5px 4px; font-size: 12px; white-space: nowrap; }

/* ---------- context menus: submenus, disabled items; Edit Text ---------- */
.menu-item.disabled { color: var(--muted); opacity: .55; }
.menu-item.disabled:hover { background: none; color: var(--muted); }
.menu-item.disabled:hover .key { color: var(--muted); }
.menu-item.has-sub .key { font-size: 10px; }
.modal.wide { width: min(560px, calc(100vw - 32px)); }
.modal textarea.edit-text {
  width: 100%; box-sizing: border-box; min-height: 180px; resize: vertical; font: 14px/1.45 system-ui, sans-serif;
  padding: 8px; border: 1px solid var(--border); border-radius: 6px; margin: 4px 0 8px;
}

/* ---------- PowerTrace ---------- */
.modal.trace { width: min(860px, calc(100vw - 32px)); }
.trace-body { display: flex; gap: 16px; align-items: stretch; }
.trace-controls { width: 250px; flex: none; display: flex; flex-direction: column; gap: 8px; }
.trace-controls .row.wide > span:first-child { width: 80px; }
.trace-controls input[type=range] { flex: 1; min-width: 0; }
.trace-preview {
  flex: 1; min-height: 320px; max-height: 60vh; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 6px;
  background: #fff repeating-conic-gradient(#e9ecf1 0 25%, #fff 0 50%) 0 0 / 16px 16px; overflow: hidden;
}
.trace-preview svg { width: 100%; height: 100%; max-height: 60vh; }
.tr-colors { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 6px; }
.tr-chip { width: 14px; height: 14px; border: 1px solid rgba(0,0,0,.25); }
@media (max-width: 640px) { .trace-body { flex-direction: column; } .trace-controls { width: auto; } }

/* ---------- Print ---------- */
.modal.print { width: min(780px, calc(100vw - 32px)); }
.print-body { display: flex; gap: 16px; }
.print-controls { width: 300px; flex: none; display: flex; flex-direction: column; gap: 6px; }
.print-controls .row.wide > span:first-child { width: 80px; flex: none; }
.print-preview-wrap { flex: 1; display: grid; place-items: center; background: #b9bec7; border-radius: 6px; padding: 12px; min-height: 380px; }
.print-preview { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.3); max-width: 100%; }
.pr-nav { margin-left: 8px; }
#print-sheets { display: none; }
@media print {
  body > *:not(#print-sheets) { display: none !important; }
  #print-sheets { display: block !important; }
  #print-sheets img { display: block; page-break-after: always; break-after: page; }
}
@media (max-width: 640px) { .print-body { flex-direction: column; } .print-controls { width: auto; } }

/* ---------- Styles docker ---------- */
#tab-styles .style-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
#tab-styles .style-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: default; }
#tab-styles .style-name.current { font-weight: 600; color: var(--accent); }
#tab-styles .harmony { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
#tab-styles .harmony-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
#tab-styles .harmony-strip { display: flex; border-radius: 3px; overflow: hidden; border: 1px solid var(--border); flex: none; }
#tab-styles .harmony-strip i { width: 10px; height: 16px; }
#tab-styles .hslider { display: flex; align-items: center; gap: 6px; font-size: 11px; }
#tab-styles .hslider > span:first-child { width: 62px; }
#tab-styles .hslider input { flex: 1; min-width: 0; }
#tab-styles .hval { width: 38px; text-align: right; }
#tab-styles .harmony-new { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
#tab-styles .harmony-new select { flex: 1 1 100%; min-width: 0; }
#tab-styles .style-chip { width: 18px; height: 18px; border: 2px solid #bbb; border-radius: 3px; flex: none; }
#tab-styles .symbol-thumb { width: 32px; height: 32px; flex: none; display: grid; place-items: center; background: #fff; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
#tab-styles .symbol-thumb svg { width: 100%; height: 100%; }
#tab-styles .style-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.icon-btn.text.small { padding: 2px 6px; font-size: 11px; min-width: 0; }

/* ---------- Transform docker ---------- */
#docker .tabs button[data-tab="transform"], #docker .tabs button[data-tab="glyphs"] { flex: 0 0 26px; font-size: 15px; }
#docker .tabs button { flex: 1 1 auto; padding-left: 3px; padding-right: 3px; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
#tab-transform .tf-modes { flex-wrap: wrap; margin-bottom: 10px; }
#tab-transform .tf-modes button { flex: 1 1 30%; padding: 5px 2px; font-size: 12px; }
#tab-transform .row.wide > span:first-child { width: 86px; flex: none; }
.tf-anchor { display: grid; grid-template-columns: repeat(3, 16px); gap: 6px; padding: 4px; border: 1px dashed var(--border); border-radius: 4px; }
.tf-anchor button { width: 16px; height: 16px; border-radius: 50%; border: 1px solid #8a93a3; background: #fff; padding: 0; cursor: default; }
.tf-anchor button.on { background: var(--accent); border-color: var(--accent); }
.tf-apply { margin-top: 10px; width: 100%; padding: 7px; }

/* ---------- Glyphs docker ---------- */
#tab-glyphs .glyph-top .row > span:first-child { width: 74px; }
#tab-glyphs .glyph-top select { flex: 1; min-width: 0; }
#tab-glyphs input[type=search] { width: 100%; box-sizing: border-box; margin: 4px 0; padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; font: inherit; }
#tab-glyphs .glyph-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 2px; }
#tab-glyphs .glyph-grid.main { max-height: 36vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 4px; padding: 2px; }
#tab-glyphs .glyph { height: 30px; font-size: 18px; line-height: 1; border: 1px solid transparent; border-radius: 3px; background: var(--panel-2, #fff); cursor: pointer; padding: 0; overflow: hidden; }
#tab-glyphs .glyph:hover { border-color: var(--border); }
#tab-glyphs .glyph.on { border-color: var(--accent); background: rgba(59, 130, 246, .12); }
#tab-glyphs .glyph-info { display: flex; align-items: center; gap: 10px; margin-top: 8px; min-height: 56px; }
#tab-glyphs .glyph-big { font-size: 40px; width: 56px; height: 56px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 6px; }
#tab-glyphs .glyph-info button { margin-left: auto; }

/* ---------- Preflight ---------- */
.modal.preflight { width: min(560px, calc(100vw - 32px)); }
.preflight-list { max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.pf-item { border: 1px solid var(--border); border-left-width: 4px; border-radius: 6px; padding: 8px 10px; }
.pf-item.error { border-left-color: #dc2626; }
.pf-item.warning { border-left-color: #f59e0b; }
.pf-item.info { border-left-color: #3b82f6; }
.pf-item .hint { margin: 4px 0; }
.pf-head { display: flex; gap: 6px; align-items: center; }
.pf-count { margin-left: auto; color: var(--muted); font-size: 12px; }
.pf-pages { display: flex; flex-wrap: wrap; gap: 4px; }
.preflight-ok { padding: 16px 4px; }
.preflight-line { justify-content: space-between; margin-top: 6px; }

/* ---------- OpenType ---------- */
.ot-modal { width: min(520px, calc(100vw - 32px)); }
.ot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; max-height: 50vh; overflow-y: auto; margin: 6px 0; }
.ot-modal .hval { width: 40px; text-align: right; }

.curve-wrap { display: grid; place-items: center; margin: 8px 0; }
.curve-canvas { width: 256px; height: 256px; border: 1px solid var(--border); border-radius: 4px; cursor: crosshair; touch-action: none; }

/* ---------- Multi-page view ---------- */
.multipage { position: fixed; inset: 40px 0 0 0; background: #b9bec7; z-index: 150; display: flex; flex-direction: column; }
.mp-bar { display: flex; gap: 8px; align-items: center; padding: 8px 14px; background: var(--panel-2, #fff); border-bottom: 1px solid var(--border); }
.mp-grid { flex: 1; overflow: auto; display: flex; flex-wrap: wrap; gap: 18px; padding: 18px; align-content: flex-start; }
.mp-card { display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.mp-card canvas { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); border: 2px solid transparent; }
.mp-card.current canvas { border-color: var(--accent); }
.mp-card:hover canvas { box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.mp-name { font-size: 12px; }

.merge-modal { width: min(560px, calc(100vw - 32px)); }
.merge-fields { flex-wrap: wrap; gap: 4px; }

/* ---------- templates, versions, shortcuts ---------- */
.tpl-modal { width: min(720px, calc(100vw - 32px)); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 6px 0 10px; }
.tpl-card { position: relative; border: 1px solid var(--border); border-radius: 8px; padding: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; background: var(--panel); }
.tpl-card:hover { border-color: var(--accent); }
.tpl-del { position: absolute; top: 2px; right: 2px; }
.ver-list { max-height: 50vh; overflow-y: auto; }
.ver-row { gap: 10px; border-bottom: 1px solid var(--border); padding: 4px 0; }
.sc-modal { width: min(620px, calc(100vw - 32px)); }
.sc-list { max-height: 50vh; overflow-y: auto; margin: 8px 0; }
.sc-row { gap: 8px; padding: 2px 0; }
.sc-key { min-width: 110px; }

/* ---------- dark theme ---------- */
:root[data-theme=dark] {
  --bg: #1c1e22;
  --panel: #23262b;
  --panel-2: #2a2d33;
  --border: #3a3f47;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #4c8df6;
  --accent-soft: #1e3a5f;
  --hover: #333842;
  --menubar: #15171a;
  --menubar-text: #e5e7eb;
  color-scheme: dark;
}
:root[data-theme=dark] input, :root[data-theme=dark] select, :root[data-theme=dark] textarea, :root[data-theme=dark] button:not(.primary):not(.icon-btn) {
  background: #1f2227; color: var(--text); border-color: var(--border);
}
:root[data-theme=dark] .modal-btns button:not(.primary) { background: #1f2227; color: var(--text); }
:root[data-theme=dark] .icon-btn { color: var(--text); }
:root[data-theme=dark] .icon-btn:hover { background: var(--hover); }
:root[data-theme=dark] .menu-list, :root[data-theme=dark] .ctx-menu { background: var(--panel-2); color: var(--text); }
:root[data-theme=dark] .hint { color: var(--muted); }
:root[data-theme=dark] .seg button:not(.active) { background: #1f2227; color: var(--text); }
:root[data-theme=dark] #pagebar .tab { background: var(--panel); color: var(--text); }
:root[data-theme=dark] #pagebar .tab.current { background: var(--panel-2); color: var(--text); }

/* Spot colors and color management */
#palette .chip.spot { position: relative; }
#palette .chip.spot::after { content: ""; position: absolute; right: 1px; bottom: 1px; width: 4px; height: 4px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.6); }
.color-picker .cp-gamut { width: 100%; margin: -4px 0 8px; padding: 3px 6px; border: 1px solid #f59e0b; background: #fef3c7; color: #92400e; border-radius: 4px; font: 600 11px system-ui; cursor: pointer; }
.color-picker .cp-gamut[hidden] { display: none; }
.palette-row { gap: 8px; align-items: center; }
.palette-row .palette-name { width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-row .harmony-strip { flex: 1; display: flex; border-radius: 3px; overflow: hidden; border: 1px solid var(--border); }
.palette-row .harmony-strip i { flex: 1; height: 16px; max-width: 12px; }
.palette-row.active .palette-name { font-weight: 600; }
.style-row .icon-btn.small.active { background: var(--accent, #2563eb); color: #fff; }

/* Bitmap editing dialogs */
.modal.bm-modal.wide { width: min(820px, calc(100vw - 32px)); }
.bm-wrap { display: grid; place-items: center; background: var(--panel-2, #f3f4f6); border: 1px solid var(--border); border-radius: 4px; padding: 6px; margin: 6px 0; max-height: 60vh; overflow: auto; }
.bm-wrap.checker { background: repeating-conic-gradient(#d4d4d8 0% 25%, #fff 0% 50%) 0 0 / 16px 16px; }
.bm-wrap canvas { display: block; }
.bm-paint { cursor: crosshair; touch-action: none; }

/* Text styles */
#tab-styles .style-chip.text-chip { display: inline-grid; place-items: center; font: 600 12px Georgia, serif; background: var(--panel-2, #f3f4f6); }
#tab-styles .hint.sub { margin-top: 6px; font-weight: 600; }

/* Kruti Dev converter */
.modal.kruti-modal { width: min(560px, calc(100vw - 32px)); }
.kruti-modal textarea { width: 100%; box-sizing: border-box; margin: 6px 0; font-size: 16px; resize: vertical; }

/* Passport photos */
.modal.pp-modal { width: min(640px, calc(100vw - 32px)); }
.pp-body { display: flex; gap: 16px; flex-wrap: wrap; }
.pp-left { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pp-view { border: 1px solid var(--border); cursor: grab; touch-action: none; background: #fff; }
.pp-right { flex: 1; min-width: 240px; }
.pp-modal [hidden], .merge-modal [hidden] { display: none !important; }

/* Help ▸ About Kraftoz */
.modal.about-modal { width: min(640px, calc(100vw - 32px)); padding: 0; overflow: hidden; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.about-hero { position: relative; display: flex; align-items: center; gap: 16px; padding: 30px 24px 26px; color: #fff; background: linear-gradient(90deg, rgba(5, 8, 22, .82), rgba(5, 8, 22, .2)), url(splash.svg) 70% 45% / cover; }
.about-logo { width: 64px; height: 64px; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .4)); }
.about-name { font: 700 30px/1.1 system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: -.02em; }
.about-version { margin-top: 4px; font-size: 12px; color: #cbd5e1; }
.about-x { position: absolute; top: 10px; right: 12px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .14); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }
.about-x:hover { background: rgba(255, 255, 255, .26); }
.about-body { padding: 18px 24px 6px; overflow: auto; font-size: 13px; line-height: 1.5; }
.about-body p { margin: 0 0 10px; }
.about-lead { font-size: 14px; font-weight: 600; }
.about-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; margin: 14px 0; }
.about-feature { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); }
.about-feature b { font-size: 12.5px; }
.about-feature span { color: var(--muted); font-size: 12px; }
.about-section { margin: 4px 0 10px; }
.about-section h4 { margin: 0 0 4px; font-size: 12.5px; }
.about-section p { margin: 0; color: var(--muted); font-size: 12px; }
.about-credits { margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.about-credits summary { cursor: pointer; color: var(--text); font-weight: 600; margin-bottom: 6px; }
.about-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px 16px; border-top: 1px solid var(--border); }
.about-foot .modal-btns { margin: 0; }
@media (max-width: 520px) { .about-grid { grid-template-columns: 1fr; } .about-hero { padding: 24px 18px 20px; } }
