:root {
  color-scheme: light;
  --bg: #eceff1;
  --panel: #ffffff;
  --line: #e2e6ea;
  --gold: #d4b45a;
  --accent-ui: #4aa3e8;
  --text: #2b3137;
  --muted: #6b7680;
  --topbar-h: 64px;
  --mobile-nav-h: 0px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, sans-serif;
  overflow: hidden;
}
body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  z-index: 8;
}
.brand-block { min-width: 0; }
.kicker { margin: 0; color: var(--accent-ui); letter-spacing: .16em; font-size: 11px; font-weight: 800; }
h1 { margin: 4px 0 0; font-size: clamp(18px, 2.4vw, 26px); }
h2 { margin: 0 0 8px; font-size: 20px; font-weight: 800; }
h3 { margin: 0 0 10px; font-size: 14px; font-weight: 800; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.top-actions input { width: min(280px, 42vw); min-width: 160px; }
.history-group { display: flex; gap: 6px; align-items: center; }
.kbd {
  margin-left: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  color: var(--muted);
}
button:disabled { opacity: .42; cursor: default; filter: none; }

input, select, button {
  font: inherit;
  color: var(--text);
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.btn { cursor: pointer; font-weight: 800; white-space: nowrap; background: var(--panel); }
.btn.gold { background: var(--gold); color: #14140a; border-color: var(--gold); }
.btn.ghost { background: transparent; }
.btn.ghost.active:not(.layer) {
  background: var(--accent-ui);
  color: #fff;
  border-color: var(--accent-ui);
}
.btn:hover { filter: brightness(0.98); }

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  color-scheme: light;
  background: var(--well, #808080);
  padding: 3px;
  height: 36px;
  width: 100%;
  cursor: pointer;
  border-radius: 8px;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
  background-color: var(--well, #808080);
}
input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 6px;
  background-color: var(--well, #808080);
}

.mobile-nav { display: none; }

.shell {
  display: grid;
  grid-template-columns: 76px minmax(200px, 250px) minmax(0, 1fr) minmax(260px, 320px);
  flex: 1;
  min-height: 0;
}

.tool-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 6px;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.tool-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 12px;
}
.tool-nav button.active {
  border-color: var(--accent-ui);
  color: var(--text);
  background: #f3f9fd;
}
.tool-ic { font-size: 16px; line-height: 1; color: inherit; }

.rail, .inspector {
  padding: 16px;
  overflow: auto;
  min-width: 0;
  background: var(--panel);
}
.rail { border-right: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.45; }

.preset-list { display: grid; gap: 10px; margin-top: 14px; }
.preset-card {
  text-align: left;
  cursor: pointer;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #f7f9fa;
}
.preset-card.active { border-color: var(--accent-ui); box-shadow: 0 0 0 2px rgba(74, 163, 232, .2); }
.preset-card b { display: block; }
.preset-card span { color: var(--muted); font-size: 12px; }
.preset-new {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border-style: dashed;
  min-height: 88px;
}
.preset-new .plus {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-ui);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.shape-btn {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.shape-swatch {
  width: 22px;
  height: 16px;
  background: var(--accent, var(--gold));
  pointer-events: none;
}
.shape-swatch.circle { width: 18px; height: 18px; border-radius: 50%; }
.shape-swatch.round { border-radius: 6px; }
.shape-swatch.pill { width: 24px; height: 10px; border-radius: 999px; }
.shape-swatch.diamond { width: 16px; height: 16px; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.shape-swatch.triangle { width: 18px; height: 16px; clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.shape-swatch.line { width: 24px; height: 3px; border-radius: 2px; }
.shape-swatch.bar { width: 5px; height: 18px; border-radius: 2px; }
.shape-swatch.ring {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: transparent;
  border: 3px solid var(--accent, var(--gold));
}
.shape-swatch.hex { clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }
.shape-swatch.arrow { clip-path: polygon(0 35%, 62% 35%, 62% 0, 100% 50%, 62% 100%, 62% 65%, 0 65%); }
.shape-btn.text { font-size: 16px; font-weight: 900; color: var(--accent, var(--gold)); }
.data-list { display: grid; gap: 6px; margin-top: 12px; }
.data-list .btn { text-align: left; }

.btn.danger { border-color: #c62828; color: #c62828; }

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; position: relative; }
.workspace-chrome {
  flex-shrink: 0;
  z-index: 6;
  background: var(--bg);
}
.scene-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 12px 0;
  overflow-x: auto;
  flex-shrink: 0;
}
.scene-tabs button { flex: 0 0 auto; background: var(--panel); }
.scene-tabs button.active { background: var(--accent-ui); color: #fff; border-color: var(--accent-ui); }

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 12px;
  flex-shrink: 0;
  overflow-x: auto;
}
.select-group { display: flex; flex-wrap: nowrap; gap: 6px; align-items: center; flex: 0 0 auto; }
.sel-count, .zoom-label {
  min-width: 52px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.stage-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  overflow: auto;
  padding: 12px 12px 64px;
  background: #d8dce0;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  scrollbar-gutter: stable;
}
.stage-wrap.is-panning { cursor: grabbing; }
.stage-wrap::-webkit-scrollbar { width: 12px; height: 12px; }
.stage-wrap::-webkit-scrollbar-thumb { background: #9aa4ad; border-radius: 99px; }
.stage-wrap::-webkit-scrollbar-track { background: #cfd4d8; }

.stage-frame {
  position: relative;
  display: block;
  flex-shrink: 0;
  background: #1b1e24;
  border: 1px solid #2a3038;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(20, 30, 40, .18);
}
.canvas, .jpcl-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  transform-origin: top left;
}
.jpcl-el.is-editable { outline: 1px dashed rgba(74, 163, 232, .28); cursor: grab; }
.jpcl-el.is-selected { outline: 2px solid #4aa3e8; box-shadow: 0 0 0 1px rgba(255,255,255,.7); }
.jpcl-el.is-locked { cursor: default; outline-style: dotted; }

.handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #fff;
  border: 1.5px solid #4aa3e8;
  border-radius: 1px;
  pointer-events: auto;
  z-index: 3;
}
.handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.handle.sw { left: -5px; bottom: -5px; cursor: nesw-resize; }
.handle.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.handle.nw { left: -5px; top: -5px; cursor: nwse-resize; }
.handle.n { top: -5px; left: 50%; margin-left: -5px; cursor: ns-resize; }
.handle.s { bottom: -5px; left: 50%; margin-left: -5px; cursor: ns-resize; }
.handle.e { right: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.handle.w { left: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }

.marquee {
  position: absolute;
  border: 1px dashed #4aa3e8;
  background: rgba(74, 163, 232, 0.12);
  pointer-events: none;
  z-index: 80;
}
.hidden { display: none !important; }

.grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  mix-blend-mode: overlay;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, .22) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, .22) 1px, transparent 1px),
    linear-gradient(to right, rgba(255, 255, 255, .08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, .08) 1px, transparent 1px);
  background-size: 10% 10%, 10% 10%, 2.5% 2.5%, 2.5% 2.5%;
  background-position: 0 0;
}

.ruler {
  position: absolute;
  z-index: 55;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.78);
}
.ruler-x {
  left: 0;
  right: 0;
  top: 0;
  height: 14px;
  border-bottom: 1px solid rgba(74, 163, 232, 0.28);
  background-image: repeating-linear-gradient(
    to right,
    rgba(74, 163, 232, 0.7) 0 1px,
    transparent 1px 10%
  );
}
.ruler-y {
  left: 0;
  top: 0;
  bottom: 0;
  width: 14px;
  border-right: 1px solid rgba(74, 163, 232, 0.28);
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(74, 163, 232, 0.7) 0 1px,
    transparent 1px 10%
  );
}

.guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 70;
}
.guide-x, .guide-y {
  position: absolute;
  background: #ff4fd8;
  box-shadow: 0 0 0 1px rgba(0,0,0,.2);
}
.guide-x { top: 0; bottom: 0; width: 1px; }
.guide-y { left: 0; right: 0; height: 1px; }
.guide-tag {
  position: absolute;
  left: 6px;
  top: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #ff4fd8;
  color: #1a0414;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
}
.guide-x .guide-tag { left: 8px; top: 50%; transform: translateY(-50%); }
.guide-y .guide-tag { top: 8px; left: 50%; transform: translateX(-50%); }

.zoom-dock {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 9;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(20, 30, 40, .12);
}
.zoom-dock .btn { min-width: 36px; height: 32px; padding: 0 8px; border-radius: 999px; }

.design-block {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.design-block:last-child { border-bottom: 0; }
.size-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f9fa;
}
.size-box span { color: var(--muted); font-size: 12px; }

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0;
}
.color-row span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  min-width: 56px;
}
.color-row input[type="color"] {
  flex: 1;
  height: 36px;
}

.style-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.style-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #cfd6dc;
  padding: 0;
  cursor: pointer;
}
.style-dot.plus {
  background: #f7f9fa;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0;
  font-size: 14px;
  font-weight: 600;
}
.toggle-row.tight { font-size: 13px; font-weight: 600; color: var(--muted); }
.switch {
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #cfd6dc;
  border: 0;
  padding: 0;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.switch.on { background: var(--accent-ui); }
.switch::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: left .15s ease;
}
.switch.on::after { left: 22px; }

.theme-colors { margin-top: 10px; color: var(--muted); font-size: 13px; }
.theme-colors summary { cursor: pointer; font-weight: 700; }

.inspector label { display: grid; gap: 6px; margin: 10px 0; font-size: 12px; color: var(--muted); font-weight: 700; }
.inspector label.plain { margin: 8px 0; }
.xywh { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.xywh label { margin: 0; }
.layer-list { display: grid; gap: 6px; margin-top: 8px; }
.layer {
  text-align: left;
  font-size: 12px;
  padding: 8px 10px;
  cursor: pointer;
}
.layer.active { border-color: var(--accent-ui); color: var(--accent-ui); }
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }

@media (max-width: 1100px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: stretch; }
  .top-actions input, .top-actions .btn { flex: 1; width: auto; }
  .mobile-nav {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    padding: 8px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    z-index: 8;
  }
  .mobile-nav button.active { background: var(--accent-ui); color: #fff; border-color: var(--accent-ui); }
  .shell {
    display: block;
    overflow: hidden;
  }
  .tool-nav, .rail, .inspector, .workspace { height: 100%; }
  body.view-presets .workspace,
  body.view-presets .inspector,
  body.view-canvas .tool-nav,
  body.view-canvas .rail,
  body.view-canvas .inspector,
  body.view-design .tool-nav,
  body.view-design .rail,
  body.view-design .workspace { display: none; }
  body.view-presets {
    display: grid;
    grid-template-rows: auto auto 1fr;
  }
  body.view-presets .shell {
    display: grid;
    grid-template-columns: 76px 1fr;
  }
}

@media (max-width: 640px) {
  .zoom-dock #btn-zoom-50,
  .zoom-dock #btn-zoom-200 { display: none; }
  h1 { font-size: 20px; }
}
