:root {
  --bg: #1a1c20;
  --panel: #24272e;
  --panel-2: #2d313a;
  --line: #3a3f4b;
  --ink: #e8eaed;
  --ink-dim: #9aa0ab;
  --accent: #e0a458;
  --accent-soft: rgba(224,164,88,0.15);
  --canvas-bg: #4a4f5a;
  --paper: #ffffff;
  --danger: #d65a5a;
  --ok: #6aa86a;
  --shadow: 0 8px 30px rgba(0,0,0,0.4);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  font-size: 13px;
}
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
header h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
header h1 .mark { color: var(--accent); }
header .hint { color: var(--ink-dim); font-size: 11px; margin-left: auto; }

.main { display: flex; flex: 1; overflow: hidden; }

/* ---- Left panel ---- */
.sidebar {
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar .section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}
.sidebar .section h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  margin-bottom: 10px;
  font-weight: 600;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: all 0.12s ease;
  width: 100%;
}
.btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1c20;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; }

.source-list { flex: 1; overflow-y: auto; padding: 8px; }
.source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: grab;
  margin-bottom: 4px;
  background: var(--panel-2);
  transition: border-color 0.12s;
}
.source-item:hover { border-color: var(--accent); }
.source-item .thumb {
  width: 38px; height: 50px;
  background: var(--paper);
  border-radius: 3px;
  flex-shrink: 0;
  object-fit: contain;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.source-item .meta { overflow: hidden; }
.source-item .meta .name {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.source-item .meta .dim { font-size: 10px; color: var(--ink-dim); margin-top: 2px; }
.source-item .add {
  margin-left: auto;
  font-size: 16px;
  color: var(--accent);
  flex-shrink: 0;
  padding: 0 4px;
}
.source-item .expand-toggle {
  width: 14px;
  font-size: 9px;
  color: var(--ink-dim);
  cursor: pointer;
  text-align: center;
  user-select: none;
  flex-shrink: 0;
  padding: 4px 0;
}
.source-item .expand-toggle:hover { color: var(--accent); }
.source-item .expand-spacer { width: 14px; flex-shrink: 0; }

.source-subitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 28px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: grab;
  margin-bottom: 3px;
  background: var(--panel-2);
  transition: border-color 0.12s;
}
.source-subitem:hover { border-color: var(--accent); }
.source-subitem .thumb {
  width: 28px; height: 36px;
  background: var(--paper);
  border-radius: 2px;
  flex-shrink: 0;
  object-fit: contain;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.source-subitem .label { font-size: 11px; color: var(--ink-dim); }
.source-subitem .add { margin-left: auto; font-size: 14px; color: var(--accent); padding: 0 4px; flex-shrink: 0; }
.empty-note { color: var(--ink-dim); font-size: 11px; text-align: center; padding: 20px 8px; line-height: 1.6; }

/* ---- Canvas area ---- */
.canvas-wrap {
  flex: 1;
  background: var(--canvas-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  position: relative;
}
#paper {
  background: var(--paper);
  box-shadow: var(--shadow);
  position: relative;
  flex-shrink: 0;
}
.placed {
  position: absolute;
  cursor: move;
  outline: 1.5px solid transparent;
}
.placed .clip-frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.placed.cropping .clip-frame { overflow: visible; }
.placed .clip-frame canvas {
  position: absolute;
  display: block;
  pointer-events: none;
}
.placed.selected { outline-color: var(--accent); }
.placed .border-overlay {
  position: absolute;
  inset: 0;
  border: 1px solid #000;
  pointer-events: none;
  display: none;
}
.placed.has-border .border-overlay { display: block; }
.placed .crop-veil {
  position: absolute;
  background: rgba(0, 0, 0, 0.45);
  pointer-events: none;
  display: none;
}
.placed.cropping .crop-veil { display: block; }
.check-row { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.check-row input { margin: 0; }
.placed .handle {
  position: absolute;
  width: 12px; height: 12px;
  background: var(--accent);
  border: 1.5px solid #1a1c20;
  border-radius: 2px;
  display: none;
}
.placed.selected .handle { display: block; }
.placed .handle-nw { left: -7px;  top:    -7px; cursor: nwse-resize; }
.placed .handle-ne { right: -7px; top:    -7px; cursor: nesw-resize; }
.placed .handle-sw { left: -7px;  bottom: -7px; cursor: nesw-resize; }
.placed .handle-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.placed .edge-handle {
  position: absolute;
  background: rgba(224, 164, 88, 0.7);
  border: 1px solid #1a1c20;
  border-radius: 2px;
  display: none;
  z-index: 2;
}
.placed.selected .edge-handle { display: block; }
.placed .edge-l { left: -4px;  top: 50%; transform: translateY(-50%); width: 6px;  height: 24px; cursor: ew-resize; }
.placed .edge-r { right: -4px; top: 50%; transform: translateY(-50%); width: 6px;  height: 24px; cursor: ew-resize; }
.placed .edge-t { top: -4px;    left: 50%; transform: translateX(-50%); width: 24px; height: 6px;  cursor: ns-resize; }
.placed .edge-b { bottom: -4px; left: 50%; transform: translateX(-50%); width: 24px; height: 6px;  cursor: ns-resize; }
.placed .rot-handle {
  position: absolute;
  width: 12px; height: 12px;
  background: #6aa8d6;
  border: 1.5px solid #1a1c20;
  border-radius: 50%;
  left: 50%; top: -22px;
  margin-left: -6px;
  cursor: grab;
  display: none;
}
.placed.selected .rot-handle { display: block; }
.placed .badge {
  position: absolute;
  top: 2px; left: 2px;
  background: var(--accent);
  color: #1a1c20;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  pointer-events: none;
}

/* ---- Right inspector ---- */
.inspector {
  width: 240px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 14px;
  flex-shrink: 0;
  overflow-y: auto;
}
.inspector h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  margin-bottom: 12px;
  font-weight: 600;
}
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 10px;
  color: var(--ink-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; }
input[type="number"], select {
  width: 100%;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  font-size: 12px;
  font-family: inherit;
}
input[type="number"]:focus, select:focus { outline: none; border-color: var(--accent); }
.inspector .no-sel { color: var(--ink-dim); font-size: 11px; line-height: 1.6; }
.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.slider-row .val { font-size: 11px; width: 42px; text-align: right; color: var(--accent); }
.danger-btn { color: var(--danger); border-color: var(--danger); }
.danger-btn:hover { background: rgba(214,90,90,0.12); border-color: var(--danger); }

.page-size-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition: transform 0.25s ease;
  z-index: 100;
  font-size: 12px;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }
.zoom-ctrl {
  position: absolute;
  bottom: 14px; right: 14px;
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  box-shadow: var(--shadow);
}
.zoom-ctrl button {
  width: 28px; height: 28px;
  border: none;
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 5px;
  cursor: pointer;
  font-size: 15px;
}
.zoom-ctrl button:hover { background: var(--accent-soft); }
.zoom-ctrl .zlabel { display: flex; align-items: center; padding: 0 6px; font-size: 11px; color: var(--ink-dim); min-width: 46px; justify-content: center; }
.hidden { display: none !important; }
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 28, 32, 0.78);
  border: 3px dashed var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
}
.drop-overlay.active { display: flex; }
.drop-overlay-inner { text-align: center; color: var(--ink); }
.drop-icon { font-size: 64px; color: var(--accent); margin-bottom: 12px; }
.drop-msg { font-size: 18px; font-weight: 600; letter-spacing: 0.04em; }
.drop-sub { font-size: 12px; color: var(--ink-dim); margin-top: 6px; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

.site-footer {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 18px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  font-size: 11px;
}
.footer-nav { display: flex; gap: 14px; }
.footer-nav a {
  color: var(--ink-dim);
  text-decoration: none;
  transition: color 0.12s ease;
}
.footer-nav a:hover { color: var(--accent); }
.footer-copy { margin-left: auto; color: var(--ink-dim); }
