/* ============================================================
   Flagsmith — stylesheet
   Warm atelier light theme: cream ground, ink text, signal red.
   ============================================================ */

:root {
  --ink: #232936;
  --ink-soft: #5b6472;
  --ink-faint: #8b93a3;
  --paper: #f6f1e7;
  --paper-deep: #efe8da;
  --card: #fffdf8;
  --line: #e3dbc9;
  --line-strong: #cfc5ae;
  --red: #d64545;
  --red-deep: #b93a3a;
  --navy: #2b4a7f;
  --gold: #f2c94c;
  --green: #2e7d5b;
  --sel: #2b6fd6;
  --sel-soft: rgba(43, 111, 214, 0.14);
  --shadow-sm: 0 1px 2px rgba(35, 41, 54, 0.08), 0 2px 8px rgba(35, 41, 54, 0.06);
  --shadow-md: 0 2px 6px rgba(35, 41, 54, 0.10), 0 10px 28px rgba(35, 41, 54, 0.12);
  --shadow-lg: 0 4px 14px rgba(35, 41, 54, 0.14), 0 24px 60px rgba(35, 41, 54, 0.22);
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --font: "Avenir Next", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --panel-w-left: 316px;
  --panel-w-right: 292px;
  --topbar-h: 62px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(242, 201, 76, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(43, 74, 127, 0.07), transparent 60%),
    var(--paper);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; color: inherit; background: none; border: none; }
button:disabled { cursor: default; opacity: 0.38; }
[hidden] { display: none !important; }
svg { display: block; }
:focus-visible { outline: 2.5px solid var(--sel); outline-offset: 2px; border-radius: 4px; }

.app { display: flex; flex-direction: column; height: 100dvh; }

/* ============ Topbar ============ */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; color: var(--ink); flex: 0 0 auto; }
.brand-flag { fill: var(--red); transition: fill 0.4s; }
.brand-text h1 { font-size: 19px; letter-spacing: 0.02em; font-weight: 700; line-height: 1.1; }
.tagline { font-size: 11.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 230px; }

.topbar-actions { display: flex; align-items: center; gap: 6px; }
.tb-sep { width: 1px; height: 26px; background: var(--line-strong); margin: 0 4px; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; min-width: 38px; padding: 0 9px;
  border-radius: var(--r-sm);
  color: var(--ink-soft);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.tb-btn svg { width: 19px; height: 19px; }
.tb-btn:hover:not(:disabled) { background: var(--paper-deep); color: var(--ink); }
.tb-btn:active:not(:disabled) { transform: scale(0.94); }
.tb-btn-label { padding: 0 13px; font-size: 13.5px; font-weight: 600; }
.tb-btn-fun { color: var(--navy); }
.tb-btn-fun:hover:not(:disabled) { background: rgba(43, 74, 127, 0.1); color: var(--navy); }
.tb-btn-primary { background: var(--red); color: #fff; box-shadow: var(--shadow-sm); }
.tb-btn-primary:hover:not(:disabled) { background: var(--red-deep); color: #fff; }

/* ============ Main columns ============ */
.main { flex: 1; display: flex; min-height: 0; }

.panel {
  background: var(--card);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.panel-left { width: var(--panel-w-left); flex: 0 0 auto; display: flex; flex-direction: column; }
.panel-right { width: var(--panel-w-right); flex: 0 0 auto; border-right: 0; border-left: 1px solid var(--line); padding: 14px; }

/* Tabs */
.tabs {
  display: flex; gap: 2px; padding: 10px 10px 0;
  position: sticky; top: 0; z-index: 5;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1; padding: 9px 6px 11px; font-size: 13.5px; font-weight: 600;
  color: var(--ink-soft); border-bottom: 2.5px solid transparent;
  margin-bottom: -1px; border-radius: 6px 6px 0 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tab:hover { background: var(--paper-deep); color: var(--ink); }
.tab.is-active { color: var(--red-deep); border-bottom-color: var(--red); }
.layer-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--navy); color: #fff; font-size: 11px;
  display: inline-flex; align-items: center; justify-content: center;
}
.pane { display: none; padding: 14px; flex: 1; }
.pane.is-active { display: block; }

.lib-section { margin-bottom: 22px; }
.lib-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-soft); margin-bottom: 4px; }
.lib-hint { font-size: 12px; color: var(--ink-faint); margin-bottom: 10px; line-height: 1.45; }

/* Layout grid */
.layout-cat { font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-faint); margin: 14px 0 7px; grid-column: 1 / -1; }
.layout-cat:first-child { margin-top: 0; }
.layout-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.layout-btn {
  position: relative;
  border-radius: var(--r-sm);
  padding: 4px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  transition: transform 0.13s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.13s, box-shadow 0.13s;
}
.layout-btn svg { width: 100%; height: auto; border-radius: 4px; display: block; box-shadow: inset 0 0 0 1px rgba(35,41,54,0.09); }
.layout-btn:hover { transform: translateY(-2px) scale(1.04); border-color: var(--line-strong); box-shadow: var(--shadow-sm); z-index: 2; }
.layout-btn:active { transform: scale(0.96); }
.layout-btn.is-active { border-color: var(--red); box-shadow: 0 0 0 2.5px rgba(214, 69, 69, 0.25); }
.layout-btn.is-active::after {
  content: "✓"; position: absolute; top: -7px; right: -7px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}

/* Emblem grid */
.emblem-cat-title { font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-faint); margin: 16px 0 7px; }
#emblem-groups > .emblem-grid:first-of-type { margin-top: 0; }
.emblem-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.emblem-btn {
  aspect-ratio: 1; border-radius: var(--r-sm);
  background: var(--paper);
  border: 1.5px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink);
  transition: transform 0.13s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.13s, box-shadow 0.13s, color 0.13s;
  touch-action: none;
}
.emblem-btn svg { width: 74%; height: 74%; pointer-events: none; }
.emblem-btn:hover { transform: translateY(-2px) scale(1.07) rotate(-3deg); color: var(--red-deep); border-color: var(--line-strong); box-shadow: var(--shadow-sm); z-index: 2; }
.emblem-btn:active { transform: scale(0.9); }
.emblem-btn.is-dragging { opacity: 0.4; }

/* Field colors */
.field-colors { display: flex; flex-direction: column; gap: 8px; }
.fc-row { display: flex; align-items: center; gap: 10px; }
.fc-label { font-size: 12.5px; color: var(--ink-soft); flex: 1; }
.swatch-btn {
  width: 34px; height: 34px; border-radius: 9px;
  border: 2px solid rgba(35, 41, 54, 0.18);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55), var(--shadow-sm);
  transition: transform 0.12s;
  flex: 0 0 auto;
}
.swatch-btn:hover { transform: scale(1.1); }
.swatch-btn:active { transform: scale(0.94); }

/* Ratio */
.ratio-row { display: flex; gap: 7px; flex-wrap: wrap; }
.ratio-btn {
  padding: 7px 10px; font-size: 12.5px; font-weight: 600;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--line);
  background: var(--paper); color: var(--ink-soft);
  display: flex; align-items: center; gap: 7px;
  transition: border-color 0.13s, color 0.13s, transform 0.1s;
}
.ratio-btn .ratio-shape { background: currentColor; opacity: 0.55; border-radius: 1.5px; height: 12px; }
.ratio-btn:hover { color: var(--ink); transform: translateY(-1px); }
.ratio-btn.is-active { border-color: var(--red); color: var(--red-deep); background: #fff; box-shadow: 0 0 0 2px rgba(214, 69, 69, 0.14); }

/* Layers */
.layer-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.layer-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: var(--r-sm);
  background: var(--paper); border: 1.5px solid var(--line);
  transition: border-color 0.13s, background 0.13s;
}
.layer-item.is-selected { border-color: var(--sel); background: var(--sel-soft); }
.layer-thumb { width: 30px; height: 30px; border-radius: 6px; background: #fff; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.layer-thumb svg { width: 78%; height: 78%; }
.layer-name { flex: 1; font-size: 13px; font-weight: 600; text-align: left; background: none; border: none; padding: 4px 2px; cursor: pointer; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-actions { display: flex; gap: 2px; }
.layer-mini {
  width: 26px; height: 26px; border-radius: 6px; color: var(--ink-faint);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.layer-mini svg { width: 15px; height: 15px; }
.layer-mini:hover:not(:disabled) { background: var(--paper-deep); color: var(--ink); }
.layers-empty { font-size: 12.5px; color: var(--ink-faint); line-height: 1.5; padding: 10px 4px; }
.layer-list:not(:empty) + .layers-empty { display: none; }

/* ============ Stage ============ */
.stage {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  padding: 14px 18px 12px;
  position: relative;
}
.stage-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.view-toggle {
  display: inline-flex; background: var(--card); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 3px; box-shadow: var(--shadow-sm);
}
.vt-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 15px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-soft);
  transition: background 0.16s, color 0.16s;
}
.vt-btn svg { width: 17px; height: 17px; }
.vt-btn.is-active { background: var(--ink); color: var(--paper); box-shadow: var(--shadow-sm); }
.stage-status { font-size: 12.5px; color: var(--ink-faint); font-style: italic; text-align: right; min-height: 1em; transition: opacity 0.3s; }

.canvas-wrap {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.flag-frame { position: relative; max-width: 100%; max-height: 100%; }
.flag-holder {
  position: relative;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  background:
    repeating-conic-gradient(#e9e2d2 0% 25%, #f7f3ea 0% 50%) 0 0 / 22px 22px;
  touch-action: none;
  transition: box-shadow 0.2s;
}
.flag-holder.is-drop-target { box-shadow: 0 0 0 3px var(--sel), var(--shadow-md); }
.flag-svg-mount, .flag-svg-mount svg { display: block; width: 100%; height: 100%; border-radius: 6px; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; border-radius: 6px; }
.wave-canvas { display: block; max-width: 100%; max-height: 100%; border-radius: var(--r-md); }

/* Selection overlay marks (SVG inside #overlay) */
.sel-box { fill: none; stroke: var(--sel); stroke-width: 1.6; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; }
.sel-handle { fill: #fff; stroke: var(--sel); stroke-width: 1.8; vector-effect: non-scaling-stroke; }
.hit-region { cursor: grab; }
.hit-region:active { cursor: grabbing; }

/* Selection bar */
.selection-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 10px; padding: 8px 12px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  animation: rise-in 0.22s cubic-bezier(0.34, 1.4, 0.64, 1);
}
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }
.sel-name { font-size: 13.5px; font-weight: 700; margin-right: 2px; }
.sel-group { display: flex; gap: 3px; padding-left: 10px; border-left: 1px solid var(--line); }
.sel-btn {
  width: 32px; height: 32px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft);
  transition: background 0.13s, color 0.13s, transform 0.1s;
}
.sel-btn svg { width: 17px; height: 17px; }
.sel-btn:hover { background: var(--paper-deep); color: var(--ink); }
.sel-btn:active { transform: scale(0.9); }
.sel-btn-danger:hover { background: rgba(214, 69, 69, 0.12); color: var(--red-deep); }

/* ============ Advisor ============ */
.advisor {
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--r-md);
  margin-bottom: 18px; overflow: hidden;
}
.advisor-summary {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; cursor: pointer; list-style: none; user-select: none;
}
.advisor-summary::-webkit-details-marker { display: none; }
.advisor-face { width: 40px; height: 40px; flex: 0 0 auto; filter: drop-shadow(0 1px 2px rgba(35,41,54,0.2)); }
.advisor-face svg { width: 100%; height: 100%; }
#advisor-flag-shape { transition: fill 0.4s; }
.advisor-heading { flex: 1; font-size: 13px; line-height: 1.25; }
.advisor-heading em { display: block; font-size: 11px; color: var(--ink-faint); font-style: normal; }
.advisor-chev { width: 18px; height: 18px; color: var(--ink-faint); transition: transform 0.2s; }
.advisor[open] .advisor-chev { transform: rotate(180deg); }
.advisor-body { padding: 2px 13px 13px; }
.advisor-msg { font-size: 13px; line-height: 1.5; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 10px; border-top-left-radius: 2px; padding: 9px 11px; margin-bottom: 10px; min-height: 40px; }
.advisor-checks { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.advisor-checks li { display: flex; gap: 8px; font-size: 12px; line-height: 1.4; color: var(--ink-soft); align-items: baseline; }
.advisor-checks .chk { flex: 0 0 auto; width: 16px; height: 16px; border-radius: 50%; font-size: 10px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; transform: translateY(2.5px); }
.advisor-checks .chk.ok { background: rgba(46, 125, 91, 0.16); color: var(--green); }
.advisor-checks .chk.hm { background: rgba(242, 201, 76, 0.3); color: #8a6d1a; }
.advisor-foot { font-size: 11px; color: var(--ink-faint); margin-top: 10px; line-height: 1.45; }

/* Palettes */
.palette-list { display: flex; flex-direction: column; gap: 7px; }
.palette-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line); background: var(--card);
  transition: transform 0.13s, border-color 0.13s, box-shadow 0.13s;
  width: 100%;
}
.palette-btn:hover { transform: translateY(-1.5px); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.palette-btn:active { transform: scale(0.97); }
.palette-chips { display: flex; flex: 0 0 auto; border-radius: 6px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(35,41,54,0.14); }
.palette-chips i { width: 17px; height: 24px; display: block; }
.palette-name { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); text-align: left; }

/* ============ Modals ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(35, 41, 54, 0.45);
  backdrop-filter: blur(3px); z-index: 60;
  animation: fade-in 0.18s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  position: fixed; z-index: 61;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(680px, calc(100vw - 28px));
  max-height: min(84dvh, 720px);
  overflow-y: auto;
  background: var(--card); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px 22px 22px;
  animation: pop-in 0.24s cubic-bezier(0.34, 1.3, 0.64, 1);
}
@keyframes pop-in { from { opacity: 0; transform: translate(-50%, -47%) scale(0.96); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal-head h2 { font-size: 21px; font-weight: 700; }
.modal-close {
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 15px; color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.13s, transform 0.13s;
}
.modal-close:hover { background: var(--paper-deep); transform: rotate(90deg); }
.modal-sub { font-size: 13.5px; color: var(--ink-soft); margin-bottom: 16px; line-height: 1.45; }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.template-btn {
  border-radius: var(--r-md); padding: 8px;
  background: var(--paper); border: 1.5px solid var(--line);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.13s, box-shadow 0.15s;
  text-align: center;
}
.template-btn svg { width: 100%; height: auto; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(35,41,54,0.10), var(--shadow-sm); }
.template-btn:hover { transform: translateY(-3px) rotate(-0.7deg); border-color: var(--line-strong); box-shadow: var(--shadow-md); }
.template-btn:active { transform: scale(0.96); }
.template-name { display: block; margin-top: 7px; font-size: 12.5px; font-weight: 700; }
.template-desc { display: block; font-size: 11px; color: var(--ink-faint); margin-top: 1px; }

/* Export modal */
.export-preview {
  display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(#e9e2d2 0% 25%, #f7f3ea 0% 50%) 0 0 / 20px 20px;
  border-radius: var(--r-md); padding: 18px; margin-bottom: 16px;
  border: 1px solid var(--line);
}
.export-preview svg { max-width: 100%; height: auto; max-height: 240px; box-shadow: var(--shadow-md); border-radius: 3px; }
.export-controls { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 16px; }
.export-field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 170px; }
.export-field label, .export-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-soft); }
.export-field input[type="text"] {
  font: inherit; font-size: 14px; padding: 9px 11px;
  border: 1.5px solid var(--line); border-radius: var(--r-sm);
  background: #fff; color: var(--ink);
}
.export-field input[type="text"]:focus { outline: none; border-color: var(--sel); box-shadow: 0 0 0 3px var(--sel-soft); }
.seg { display: flex; gap: 5px; }
.seg-btn {
  flex: 1; padding: 7px 4px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line); background: var(--paper);
  font-size: 14px; font-weight: 700; color: var(--ink-soft);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: border-color 0.13s, color 0.13s;
}
.seg-btn small { font-size: 10px; font-weight: 600; color: var(--ink-faint); }
.seg-btn.is-active { border-color: var(--red); color: var(--red-deep); background: #fff; box-shadow: 0 0 0 2px rgba(214,69,69,0.13); }
.export-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 600;
  background: var(--paper); border: 1.5px solid var(--line); color: var(--ink);
  transition: transform 0.12s, background 0.14s, border-color 0.14s, box-shadow 0.14s;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-deep); border-color: var(--red-deep); }
.export-note { margin-top: 12px; font-size: 12px; color: var(--ink-faint); font-style: italic; min-height: 1em; }

/* ============ Color popover ============ */
.color-pop {
  position: fixed; z-index: 70;
  width: 258px;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: 12px;
  animation: pop-in-sm 0.16s cubic-bezier(0.34, 1.4, 0.64, 1);
}
@keyframes pop-in-sm { from { opacity: 0; transform: scale(0.93) translateY(-4px); } }
.cp-swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 11px; }
.cp-sw {
  aspect-ratio: 1; border-radius: 7px;
  border: 1.5px solid rgba(35, 41, 54, 0.16);
  box-shadow: inset 0 0 0 1.5px rgba(255,255,255,0.5);
  transition: transform 0.11s;
}
.cp-sw:hover { transform: scale(1.18); z-index: 2; }
.cp-sw:active { transform: scale(0.92); }
.cp-sw.is-current { outline: 2.5px solid var(--sel); outline-offset: 1.5px; }
.cp-custom-label {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-soft);
}
.cp-custom-label input[type="color"] {
  width: 34px; height: 34px; border: none; border-radius: 8px; padding: 0;
  background: none; cursor: pointer;
}
.cp-custom-label input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.cp-custom-label input[type="color"]::-webkit-color-swatch { border-radius: 6px; border: 1.5px solid rgba(35,41,54,0.2); }
.cp-custom-label code { margin-left: auto; font-size: 12px; color: var(--ink-faint); }

/* ============ Toast & confetti ============ */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 80;
  background: var(--ink); color: var(--paper);
  font-size: 13.5px; font-weight: 600;
  padding: 11px 18px; border-radius: 999px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
  max-width: min(86vw, 480px); text-align: center;
  pointer-events: none;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.94); } }
.toast.is-leaving { transition: opacity 0.3s, transform 0.3s; opacity: 0; transform: translateX(-50%) translateY(10px); }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 75; }

/* ============ Welcome ============ */
.welcome {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(35, 41, 54, 0.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade-in 0.3s ease;
}
.welcome.is-leaving { transition: opacity 0.35s; opacity: 0; }
.welcome-card {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow-lg);
  padding: 30px 34px; max-width: 430px; text-align: center;
  animation: pop-in-w 0.45s cubic-bezier(0.34, 1.3, 0.64, 1);
}
@keyframes pop-in-w { from { opacity: 0; transform: scale(0.9) translateY(16px); } }
.welcome-flag { width: 130px; margin: 0 auto 14px; overflow: visible; }
.welcome-flag g { transform-origin: 13px 8px; animation: flag-sway 3.4s ease-in-out infinite; }
@keyframes flag-sway { 0%, 100% { transform: rotate(0deg) } 50% { transform: rotate(-2.5deg) } }
.welcome-card h2 { font-size: 23px; margin-bottom: 9px; }
.welcome-card p { font-size: 14px; line-height: 1.55; color: var(--ink-soft); margin-bottom: 18px; }
.welcome-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ============ Ghost drag preview ============ */
.drag-ghost {
  position: fixed; z-index: 100; pointer-events: none;
  width: 58px; height: 58px;
  filter: drop-shadow(0 3px 8px rgba(35, 41, 54, 0.35));
  transform: translate(-50%, -50%) scale(1.05);
}
.drag-ghost svg { width: 100%; height: 100%; }

/* ============ Mobile nav ============ */
.mobile-nav { display: none; }

/* ============ Responsive ============ */
@media (max-width: 1180px) {
  :root { --panel-w-left: 280px; --panel-w-right: 250px; }
}
@media (max-width: 1010px) {
  .panel-right { display: none; }
  .panel-right.is-mobile-open { display: block; }
}
@media (max-width: 760px) {
  body { overflow: auto; }
  .app { height: 100dvh; }
  .main { flex-direction: column; overflow: hidden; position: relative; }
  .tagline { display: none; }
  .tb-btn-label span { display: none; }
  .tb-btn-label { padding: 0 9px; }
  .tb-btn-primary span { display: inline; }
  .tb-btn-primary { padding: 0 13px; }
  .topbar { padding: 0 10px; }
  .topbar-actions { gap: 2px; }
  .tb-sep { display: none; }
  .brand-text h1 { font-size: 16px; }
  .brand-mark { width: 30px; height: 30px; }

  .stage { display: none; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
  .stage.is-mobile-active { display: flex; flex: 1; min-height: 0; }
  .panel-left, .panel-right { display: none; width: 100%; border: none; flex: 1; min-height: 0; }
  .panel-left.is-mobile-active, .panel-right.is-mobile-active { display: flex; flex-direction: column; }
  .panel-right.is-mobile-active { display: block; }

  .selection-bar { gap: 6px; padding: 7px 9px; }
  .sel-group { padding-left: 7px; }
  .sel-name { display: none; }

  .mobile-nav {
    display: flex; flex: 0 0 auto;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    z-index: 40;
  }
  .mn-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 4px; font-size: 11px; font-weight: 600; color: var(--ink-faint);
    border-radius: var(--r-sm);
    transition: color 0.15s, background 0.15s;
  }
  .mn-btn svg { width: 21px; height: 21px; }
  .mn-btn.is-active { color: var(--red-deep); }
  .mn-btn:active { background: var(--paper-deep); }

  .view-toggle { box-shadow: none; }
  .vt-btn { padding: 6px 11px; font-size: 12.5px; }
  .modal { padding: 16px; }
  .export-actions .btn { flex: 1; justify-content: center; }
}

@media (max-width: 430px) {
  .brand-text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
