/* ============ Story Studio — app chrome design system ============ */
:root {
  --bg: #0f1113;
  --bg-2: #15181b;
  --bg-3: #1b1f24;
  --panel: #15181b;
  --border: #262b31;
  --border-2: #333a42;
  --text: #e8eaed;
  --text-dim: #9aa3ad;
  --text-faint: #6b7480;
  --accent: #7b78ff;
  --accent-2: #9f9dff;
  --accent-soft: rgba(123, 120, 255, 0.16);
  --gold: #d9b36a;
  --danger: #e5636f;
  --ok: #5fbf8a;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-1: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 16px 48px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ============ Topbar ============ */
#topbar {
  display: flex; align-items: center; gap: 8px;
  height: 52px; padding: 0 14px;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; margin-right: 10px; user-select: none; }
.brand span { color: var(--accent-2); font-weight: 500; }
.topbar-spacer { flex: 1; }
.tsep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.tbtn {
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  border-radius: var(--radius-sm); padding: 6px 10px; font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: all 0.12s;
}
.tbtn:hover { color: var(--text); background: var(--bg-3); }
.tbtn.icon { font-size: 15px; padding: 5px 9px; line-height: 1; }
.tbtn.active { color: var(--accent-2); background: var(--accent-soft); }
.tbtn:disabled { opacity: 0.35; cursor: default; }
.tbtn:disabled:hover { background: transparent; color: var(--text-dim); }
#zoom-label { font-size: 11.5px; color: var(--text-faint); min-width: 38px; text-align: center; user-select: none; }

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

#tabbar {
  width: 62px; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: stretch; padding: 8px 6px; gap: 4px;
  flex-shrink: 0;
}
.tab-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: transparent; border: none; color: var(--text-faint);
  border-radius: var(--radius-sm); padding: 9px 2px 7px; cursor: pointer; transition: all 0.12s;
}
.tab-btn .tab-ic { font-size: 17px; line-height: 1; }
.tab-btn .tab-lb { font-size: 9.5px; font-weight: 600; letter-spacing: 0.2px; }
.tab-btn:hover { color: var(--text-dim); background: var(--bg-3); }
.tab-btn.active { color: var(--accent-2); background: var(--accent-soft); }

#left-panel {
  width: 304px; background: var(--panel); border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden; flex-shrink: 0;
}
.panel { display: none; padding: 14px; }
.panel.active { display: block; }

#stage-wrap {
  flex: 1; min-width: 0; overflow: auto; display: grid; place-items: center;
  background:
    radial-gradient(1200px 800px at 50% 0%, rgba(123, 120, 255, 0.04), transparent 60%),
    var(--bg);
  padding: 32px;
}
#stage { position: relative; }
#stage .canvas-container { box-shadow: var(--shadow-2); border-radius: 4px; }
#stage.dropping .canvas-container { outline: 2px dashed var(--accent); outline-offset: 6px; }

#right-panel {
  width: 292px; background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden; flex-shrink: 0; display: flex; flex-direction: column;
}
#inspector-root { padding: 14px; border-bottom: 1px solid var(--border); }
#layers-root { padding: 14px; flex: 1; min-height: 140px; }

/* ============ UI kit (used by src/core/ui.js) ============ */
.ui-section { margin-bottom: 18px; }
.ui-section-title {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.9px;
  color: var(--text-faint); margin: 0 0 9px;
  display: flex; align-items: center; justify-content: space-between;
}
.ui-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.ui-row:last-child { margin-bottom: 0; }
.ui-label { font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.divider { height: 1px; background: var(--border); margin: 14px 0; border: none; }
.muted { color: var(--text-faint); font-size: 11.5px; line-height: 1.45; }

.btn {
  background: var(--bg-3); border: 1px solid var(--border-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 12px; font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: all 0.12s; line-height: 1.2;
}
.btn:hover { border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.btn-ghost { background: transparent; border-color: var(--border-2); color: var(--text-dim); }
.btn.btn-ghost:hover { color: var(--text); }
.btn.btn-danger { background: transparent; border-color: rgba(229, 99, 111, 0.4); color: var(--danger); }
.btn.btn-danger:hover { background: rgba(229, 99, 111, 0.12); }
.btn.small { padding: 5px 9px; font-size: 11.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: default; }

.icon-btn {
  background: var(--bg-3); border: 1px solid var(--border-2); color: var(--text-dim);
  border-radius: var(--radius-sm); width: 30px; height: 30px; font-size: 14px; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: all 0.12s;
  padding: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-faint); }
.icon-btn.active { color: var(--accent-2); background: var(--accent-soft); border-color: var(--accent); }
.icon-btn svg { width: 15px; height: 15px; }

.btn-grid { display: grid; gap: 6px; margin-bottom: 8px; }
.btn-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.btn-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.btn-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.btn-grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
.btn-grid.cols-6 { grid-template-columns: repeat(6, 1fr); }

.seg { display: inline-flex; background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.seg-btn {
  background: transparent; border: none; color: var(--text-dim); border-radius: 5px;
  padding: 5px 10px; font-size: 11.5px; font-weight: 500; cursor: pointer; transition: all 0.12s; white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.seg.full { display: flex; width: 100%; }
.seg.full .seg-btn { flex: 1; }

/* sliders */
.ui-slider { display: flex; align-items: center; gap: 8px; width: 100%; margin-bottom: 8px; }
.ui-slider .ui-label { width: 78px; }
.ui-slider input[type='range'] { flex: 1; appearance: none; -webkit-appearance: none; height: 4px; background: var(--border-2); border-radius: 2px; outline: none; }
.ui-slider input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--text); cursor: pointer; border: none; transition: background 0.12s;
}
.ui-slider input[type='range']:hover::-webkit-slider-thumb { background: var(--accent-2); }
.ui-slider .ui-slider-val { font-size: 11px; color: var(--text-faint); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

/* color input */
.ui-color { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ui-color input[type='color'] {
  width: 30px; height: 30px; border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: transparent; padding: 2px; cursor: pointer;
}
.ui-color input[type='color']::-webkit-color-swatch-wrapper { padding: 0; }
.ui-color input[type='color']::-webkit-color-swatch { border: none; border-radius: 4px; }
.ui-color .ui-color-hex { width: 74px; }

/* text / number / select inputs */
.ui-input, .ui-select {
  background: var(--bg-3); border: 1px solid var(--border-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 6px 9px; font-size: 12.5px; outline: none;
  transition: border-color 0.12s; min-width: 0;
}
.ui-input:focus, .ui-select:focus { border-color: var(--accent); }
.ui-input.grow { flex: 1; }
.ui-input[type='number'] { width: 62px; }
.ui-select { cursor: pointer; }
.ui-select option { background: var(--bg-3); }

.ui-check { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: 12.5px; color: var(--text-dim); user-select: none; margin-bottom: 8px; }
.ui-check input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }
.ui-check:hover { color: var(--text); }

/* swatches */
.swatch {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer; transition: transform 0.1s; padding: 0; flex-shrink: 0;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

.card {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: all 0.13s; overflow: hidden;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-1); }

.badge {
  display: inline-block; font-size: 9.5px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent-2); border-radius: 4px; padding: 2px 6px;
}

/* ============ Modal ============ */
#modal-root { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(5, 6, 8, 0.72); pointer-events: auto;
  display: grid; place-items: center; animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 14px;
  box-shadow: var(--shadow-2); padding: 20px; width: min(560px, calc(100vw - 48px));
  max-height: calc(100vh - 64px); overflow-y: auto; animation: popIn 0.16s ease;
}
.modal-title { font-size: 15px; font-weight: 700; margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.97) translateY(6px); } }

/* toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--border-2); color: var(--text);
  border-radius: 10px; padding: 9px 16px; font-size: 12.5px; box-shadow: var(--shadow-1);
  z-index: 200; animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ============ Layers panel ============ */
.layer-item {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px; border-radius: var(--radius-sm);
  cursor: pointer; border: 1px solid transparent; transition: background 0.1s; user-select: none;
}
.layer-item:hover { background: var(--bg-3); }
.layer-item.selected { background: var(--accent-soft); border-color: rgba(123, 120, 255, 0.35); }
.layer-item .layer-ic { width: 20px; text-align: center; font-size: 12px; color: var(--text-faint); flex-shrink: 0; }
.layer-item .layer-name { flex: 1; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-item .layer-act { display: none; gap: 2px; }
.layer-item:hover .layer-act, .layer-item.selected .layer-act { display: inline-flex; }
.layer-item .mini-btn {
  background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 12px;
  padding: 2px 4px; border-radius: 4px; line-height: 1;
}
.layer-item .mini-btn:hover { color: var(--text); background: var(--bg-2); }
.layer-item .mini-btn.on { color: var(--accent-2); }
.layer-item.dragover { border-top: 2px solid var(--accent); }

/* ============ Scrollbars ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 5px; border: 2px solid var(--bg-2); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
