/* ============ editor shell ============ */
#editor { display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar .title-input {
  border: 1px solid transparent; background: transparent;
  font: 600 14.5px var(--font-display);
  min-width: 40px; width: 170px; padding: 6px 9px; height: 36px;
}
.topbar .title-input:hover, .topbar .title-input:focus { border-color: var(--line); background: var(--surface); }
.topbar .spacer { flex: 1; }
.topbar .divider { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }
.topbar button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.editor-body { flex: 1; display: flex; min-height: 0; position: relative; }

/* ============ panels (desktop: sidebars) ============ */
.panel { width: 256px; background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); width: 272px; }
.panel-head { display: none; }

.panel-tabs { display: flex; border-bottom: 1px solid var(--line); padding: 6px 6px 0; gap: 2px; }
.panel-tabs button {
  flex: 1; flex-direction: column; gap: 3px;
  border: none; border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: transparent; height: 52px; padding: 6px 2px;
  font-size: 11px; font-weight: 500; color: var(--text-dim);
}
.panel-tabs button .ic { width: 19px; height: 19px; }
.panel-tabs button[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); }
.panel-body { flex: 1; overflow-y: auto; padding: 14px; overscroll-behavior: contain; }
.panel h3 {
  font-size: 11px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint); margin: 18px 0 9px; font-weight: 600;
}
.panel h3:first-child { margin-top: 0; }

/* pages tab */
.page-list { display: flex; flex-direction: column; gap: 12px; }
.page-item {
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--surface-2); cursor: pointer; padding: 7px; text-align: center;
  transition: border-color var(--t-fast);
}
.page-item:hover { border-color: var(--line-strong); }
.page-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.page-item .pv { aspect-ratio: 5/7; background: #fff; border-radius: 5px; overflow: hidden; pointer-events: none; }
.page-item .pv svg { width: 100%; height: 100%; display: block; }
.page-item .nm { font-size: 11.5px; font-weight: 500; color: var(--text-dim); margin-top: 6px; }
.page-item.active .nm { color: var(--accent); }

/* photos tab */
.photo-drop {
  border: 1.5px dashed var(--line-strong); border-radius: var(--r-md);
  padding: 18px 10px; text-align: center;
  color: var(--text-dim); font-size: 12.5px; cursor: pointer; margin-bottom: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.photo-drop:hover, .photo-drop.dragover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 8px; }
.photo-cell {
  position: relative; aspect-ratio: 1; border-radius: var(--r-sm); overflow: hidden;
  border: 2px solid transparent; cursor: pointer; background: var(--surface-2); padding: 0; height: auto;
}
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell.excluded img { opacity: .3; filter: grayscale(1); }
.photo-cell .badge {
  position: absolute; top: 3px; right: 3px;
  background: rgba(12, 10, 5, .62); color: #fff; backdrop-filter: blur(2px);
  border-radius: 5px; font-size: 9.5px; font-weight: 600; padding: 2px 5px;
  pointer-events: none; display: flex; align-items: center; gap: 3px;
}
.photo-cell .badge .ic { width: 10px; height: 10px; stroke-width: 2.2; }
.photo-cell.selected { border-color: var(--accent); }
.photo-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.photo-actions button { font-size: 12px; padding: 0 10px; height: 34px; }

/* decorations tab */
.decor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.decor-cell {
  aspect-ratio: 1; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); cursor: pointer; padding: 9px; height: auto;
}
.decor-cell:hover { border-color: var(--accent); background: var(--accent-soft); }
.decor-cell svg { width: 100%; height: 100%; display: block; pointer-events: none; }

/* style tab */
.palette-list { display: flex; flex-direction: column; gap: 8px; }
.palette-row {
  display: flex; align-items: center; gap: 9px;
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  padding: 8px 10px; cursor: pointer; background: var(--surface);
  transition: border-color var(--t-fast);
}
.palette-row:hover { border-color: var(--line-strong); }
.palette-row.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.palette-row .sw { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0,0,0,.1); flex: none; margin-right: -4px; }
.palette-row .nm { font-size: 12.5px; font-weight: 500; margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 28px; height: 28px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); cursor: pointer; padding: 0; }

/* ============ stage ============ */
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.page-tabs { display: flex; gap: 4px; justify-content: center; padding: 10px 8px 0; flex-wrap: wrap; }
.page-tabs button {
  font-size: 12.5px; height: 34px; padding: 0 14px; border-radius: 999px;
  background: transparent; border-color: transparent; color: var(--text-dim);
}
.page-tabs button:hover { background: var(--surface-2); }
.page-tabs button.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.canvas-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 18px; overflow: hidden; position: relative; }
.page-canvas { position: relative; box-shadow: var(--elev-2); background: #fff; touch-action: none; border-radius: 2px; }
.page-canvas > svg { display: block; width: 100%; height: 100%; user-select: none; }

/* selection overlay */
.overlay { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.overlay .sel-box { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.overlay .handle { fill: var(--accent); stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: all; }
.overlay .rot-handle { cursor: grab; }
.print-guide { pointer-events: none; opacity: 0; transition: opacity var(--t-fast); }
#editor[data-guides="on"] .print-guide { opacity: 1; }
.print-guide .safe { fill: none; stroke: #58a6dd; stroke-dasharray: 4 4; stroke-width: 1; vector-effect: non-scaling-stroke; opacity: .65; }

/* variants strip */
.variant-bar { display: flex; align-items: center; gap: 10px; padding: 6px 14px 10px; }
.variant-bar .vlabel { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); flex: none; }
.variant-strip { display: flex; gap: 8px; overflow-x: auto; }
.variant-strip .vt {
  width: 46px; flex: none; aspect-ratio: 5/7; border: 2px solid var(--line);
  border-radius: 6px; overflow: hidden; cursor: pointer; background: #fff; padding: 0; height: auto;
}
.variant-strip .vt.active { border-color: var(--accent); }
.variant-strip .vt svg { width: 100%; height: 100%; display: block; pointer-events: none; }

/* ============ props panel ============ */
.props .btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.props .btn-row button { font-size: 12px; height: 34px; padding: 0 10px; }
.props .btn-row button .ic { width: 15px; height: 15px; }
.props .row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; min-height: 30px; }
.props .row > label { flex: none; width: 72px; }
.props .row input[type="range"] { flex: 1; min-width: 0; }
.props .row .val { flex: none; width: 38px; text-align: right; font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.props .row select { flex: 1; min-width: 0; height: 36px; padding: 0 10px; }
.props textarea { width: 100%; min-height: 92px; resize: vertical; margin-bottom: 8px; line-height: 1.45; }
.mic-btn { width: 100%; margin-bottom: 12px; height: 38px; }
.mic-btn.listening { background: var(--danger); color: #fff; border-color: transparent; }
.mic-btn.listening .ic { animation: mic-pulse 1.1s ease-in-out infinite; }
@keyframes mic-pulse { 50% { opacity: .45; } }
.props .empty {
  color: var(--text-faint); font-size: 13px; padding: 26px 12px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.props .empty .ic { width: 26px; height: 26px; opacity: .6; }

/* ============ preview overlay ============ */
#preview-screen { position: fixed; inset: 0; background: var(--bg); z-index: 200; display: flex; flex-direction: column; }
#preview-screen .topbar { justify-content: center; gap: 6px; flex-wrap: wrap; }
#preview-screen .topbar button { height: 34px; font-size: 12.5px; }
#preview-screen .pv-body { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 20px; }
.spread { display: flex; box-shadow: var(--elev-2); position: relative; }
.spread .fold-line { position: absolute; top: 0; bottom: 0; left: 50%; border-left: 1.5px dashed rgba(120, 110, 90, .55); pointer-events: none; }
.folded-wrap { perspective: 1400px; }
.folded-card { position: relative; transform-style: preserve-3d; transition: transform .5s var(--ease); }

.pv-toggles { display: flex; gap: 14px; justify-content: center; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); color: var(--text-dim); font-size: 13px; flex-wrap: wrap; }
.pv-toggles label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.pv-toggles input[type="checkbox"] { accent-color: var(--accent); }

/* ============ mobile ============ */
.bottom-nav { display: none; }
.sheet-scrim { display: none; }
.btn-label { display: inline; }

body[data-device="mobile"] {
  /* topbar: compact, primary actions always visible */
}
body[data-device="mobile"] .topbar { padding: 6px 8px calc(6px); gap: 4px; }
body[data-device="mobile"] .topbar .btn-label { display: none; }
body[data-device="mobile"] .topbar button { width: 40px; height: 40px; padding: 0; }
body[data-device="mobile"] .topbar .title-input { width: auto; flex: 1; min-width: 60px; }
body[data-device="mobile"] .topbar .divider { display: none; }
body[data-device="mobile"] .topbar [data-act="guides"] { display: none; }
body[data-device="mobile"] .topbar [data-act="shuffle"] { display: none; } /* lives in the bottom nav */

body[data-device="mobile"] .editor-body { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
body[data-device="mobile"] .page-tabs button { height: 38px; }

/* panels become bottom sheets */
body[data-device="mobile"] .panel {
  position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: 100%;
  max-height: 66dvh; z-index: 320;
  border: none; border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--elev-2);
  transform: translateY(105%);
  transition: transform var(--t-med) var(--ease);
  padding-bottom: env(safe-area-inset-bottom);
}
body[data-device="mobile"] .panel.open { transform: translateY(0); }
body[data-device="mobile"] .panel-head {
  display: flex; align-items: center; justify-content: center; padding: 10px 14px 4px; position: relative;
  min-height: 30px;
}
body[data-device="mobile"] .panel-head::before {
  content: ""; width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong);
}
body[data-device="mobile"] .panel-head .sheet-close {
  position: absolute; right: 2px; top: 0; width: 52px; height: 52px; padding: 0;
  background: transparent; border: none; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  z-index: 2; /* above panel-body content it overhangs */
}
body[data-device="mobile"] .panel-head .sheet-close:active { color: var(--text); }
body[data-device="mobile"] .panel-head .sheet-close .ic { width: 22px; height: 22px; }
body[data-device="mobile"] .panel-tabs { display: none; }
body[data-device="mobile"] .panel-body { padding: 12px 16px 16px; }
body[data-device="mobile"] .sheet-scrim {
  display: block; position: fixed; inset: 0; z-index: 310;
  background: var(--scrim); opacity: 0; pointer-events: none;
  transition: opacity var(--t-med) var(--ease);
}
body[data-device="mobile"] .sheet-scrim.on { opacity: 1; pointer-events: auto; }

/* bottom navigation */
body[data-device="mobile"] .bottom-nav {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 300;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
}
.bottom-nav button {
  flex: 1; flex-direction: column; gap: 2px;
  background: transparent; border: none; border-radius: var(--r-sm);
  height: 52px; font-size: 10.5px; font-weight: 500; color: var(--text-dim); padding: 4px 0;
}
.bottom-nav button .ic { width: 21px; height: 21px; }
.bottom-nav button[aria-selected="true"] { color: var(--accent); }

/* preview on phones: the interactive card IS the preview — just Close */
body[data-device="mobile"] #preview-screen [data-mode] { display: none; }
body[data-device="mobile"] #preview-screen .topbar { justify-content: flex-end; }
body[data-device="mobile"] #preview-screen [data-close] { height: 40px; padding: 0 18px; }

/* touch targets */
body[data-device="mobile"] .photo-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
body[data-device="mobile"] .decor-grid { grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); }
body[data-device="mobile"] .photo-actions button { height: 40px; }
body[data-device="mobile"] .props .btn-row button { height: 40px; }
body[data-device="mobile"] .props .row select { height: 40px; }
body[data-device="mobile"] .page-list { flex-direction: row; overflow-x: auto; }
body[data-device="mobile"] .page-item { flex: none; width: 96px; }
body[data-device="mobile"] dialog { margin: auto auto 0; border-radius: var(--r-lg) var(--r-lg) 0 0; max-width: 100vw; width: 100vw; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* narrow desktop fallback keeps sidebars usable */
@media (max-width: 980px) {
  body:not([data-device="mobile"]) .panel { width: 220px; }
  body:not([data-device="mobile"]) .panel.right { width: 240px; }
}
