/*
 * APP CHROME — the editor around the product (not the product itself).
 * Layout: fixed top bar · editor panel (left) · scrolling page stage (right).
 * Every color is a token; dark mode redefines the tokens only.
 */
/* Brand: Viralize — white, black extended caps, blue→pink glow, pill buttons. */
:root {
  --bg: #F7F7FA;
  --surface: #FFFFFF;
  --surface-2: #F3F3F7;
  --ink: #0A0A0B;
  --muted: #696975;
  --line: #E6E5EC;
  --accent: #0A0A0B;
  --accent-ink: #FFFFFF;
  --accent-soft: #F1EEFB;
  --focus: #8A8CF5;
  --glow-a: #C9DCFF;
  --glow-b: #FBD3E6;
  --grad: linear-gradient(90deg, #9CC3FF, #C9B4F5 50%, #F5A6CF);
  --stage: #EEEEF3;
  --good: #1B7F4B;
  --warn: #A86A00;
  --bad: #C0262D;
  --shadow: 0 1px 2px rgba(10, 10, 20, .05), 0 10px 30px rgba(60, 60, 110, .08);
  --ui: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --brand: 'Archivo', 'Arial Black', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --r: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090B; --surface: #111114; --surface-2: #18181D; --ink: #F3F3F6; --muted: #9C9CA8;
    --line: #26262D; --accent: #F3F3F6; --accent-ink: #09090B; --accent-soft: #1D1B2A; --focus: #A3A5FF;
    --glow-a: #1E2A4A; --glow-b: #3A1E33; --stage: #0D0D10;
    --good: #4CC38A; --warn: #E0A43A; --bad: #F2675B; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #09090B; --surface: #111114; --surface-2: #18181D; --ink: #F3F3F6; --muted: #9C9CA8;
  --line: #26262D; --accent: #F3F3F6; --accent-ink: #09090B; --accent-soft: #1D1B2A; --focus: #A3A5FF;
  --glow-a: #1E2A4A; --glow-b: #3A1E33; --stage: #0D0D10;
  --good: #4CC38A; --warn: #E0A43A; --bad: #F2675B; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--ui); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

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

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface); position: relative;
}
.topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--grad); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: none; }
.brand-name { font: 900 21px/1 var(--brand); font-stretch: 125%; letter-spacing: -.01em; text-transform: uppercase; }
.brand-sub { font: 500 10px/1 var(--mono); letter-spacing: .28em; text-transform: uppercase; color: var(--muted); padding-top: 3px; }
.project-name { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 16px; cursor: pointer; white-space: nowrap;
  font: 500 12px/1.2 var(--brand); font-stretch: 125%; letter-spacing: .05em; text-transform: uppercase;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: none; box-shadow: 0 0 0 3px var(--glow-a), 0 0 0 6px var(--glow-b); }
.btn.soft { border: 1px solid transparent; background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--grad) border-box; }
.btn.small { padding: 5px 11px; font-size: 10.5px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.icon { padding: 4px 9px; }

/* Workspace */
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 420px) 1fr; }
.panel { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tab {
  flex: 1; background: none; border: 0; padding: 12px 6px 10px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 500; display: flex; gap: 6px; align-items: center; justify-content: center;
}
.tab { font: 500 11px/1 var(--brand) !important; font-stretch: 125% !important; letter-spacing: .06em; text-transform: uppercase; }
.tab.on { color: var(--ink); border-bottom-color: var(--ink); }
.score-pill { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.score-pill[data-level="good"] { background: var(--good); color: var(--surface); }
.score-pill[data-level="ok"] { background: var(--warn); color: var(--surface); }
.score-pill[data-level="low"] { background: var(--bad); color: var(--surface); }
.panel-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 18px; }

.stage {
  overflow: auto; min-width: 0;
  background: radial-gradient(40% 35% at 30% 18%, var(--glow-a), transparent 70%), radial-gradient(40% 35% at 72% 30%, var(--glow-b), transparent 70%), var(--stage);
  background-attachment: local;
}
.stage-inner { padding: 24px; display: flex; justify-content: center; }

/* Forms */
.group { display: flex; flex-direction: column; gap: 12px; }
.group-title { margin: 0; font: 500 10.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .22em; color: var(--muted); }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field input[type=text], .field input[type=number], .field textarea, .field select, .add-row select, .ai-cols textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 8px 10px;
}
.field textarea, .ai-cols textarea { resize: vertical; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); outline: none; background: var(--surface); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.color-row { display: flex; gap: 6px; align-items: center; }
.color-row input[type=color] { width: 42px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.hint { margin: 0; color: var(--muted); font-size: 12.5px; }
.empty { color: var(--muted); text-align: center; padding: 20px; }
.label { font-weight: 600; font-size: 13px; }

/* Theme picker */
.theme-list { display: flex; flex-direction: column; gap: 6px; }
.theme-card {
  display: flex; align-items: center; gap: 12px; text-align: left; padding: 8px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
}
.theme-card.on { border: 1px solid transparent; background: linear-gradient(var(--accent-soft), var(--accent-soft)) padding-box, var(--grad) border-box; }
.swatch { width: 44px; height: 44px; border-radius: 6px; display: grid; place-items: center; font-size: 20px; flex: none; border: 1px solid var(--line); }
.theme-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.theme-meta small { color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }

/* Block cards */
.blist { display: flex; flex-direction: column; gap: 6px; }
.bcard { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.bcard.is-chapter { border-left: 3px solid transparent; border-image: linear-gradient(#9CC3FF, #F5A6CF) 1; border-image-slice: 0 0 0 1; }
.bcard.open { box-shadow: var(--shadow); }
.bcard-head { display: flex; align-items: center; }
.bcard-toggle { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: baseline; background: none; border: 0; padding: 10px 12px; cursor: pointer; text-align: left; }
.btype { font: 500 10px/1 var(--mono); text-transform: uppercase; letter-spacing: .14em; color: var(--muted); flex: none; }
.bsum { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bcard-tools { display: flex; padding-right: 6px; }
.tool { background: none; border: 0; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tool:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.tool:disabled { opacity: .3; }
.bcard-body { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.bcard-actions { display: flex; justify-content: flex-end; gap: 6px; }
.add-row { display: flex; gap: 8px; position: sticky; bottom: -16px; background: var(--surface); padding-block: 12px; border-top: 1px solid var(--line); }

/* Sell + quality */
.listing { margin: 0; white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; font: 13px/1.6 var(--ui); max-height: 420px; overflow: auto; }
.quality-head { flex-direction: row; align-items: center; gap: 16px; }
.big-score { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; font-weight: 600; border: 4px solid var(--line); font-variant-numeric: tabular-nums; }
.big-score[data-level="good"] { border-color: var(--good); color: var(--good); }
.big-score[data-level="ok"] { border-color: var(--warn); color: var(--warn); }
.big-score[data-level="low"] { border-color: var(--bad); color: var(--bad); }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checks li { display: flex; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: var(--r); }
.checks li span:last-child { display: flex; flex-direction: column; gap: 2px; }
.checks small { color: var(--muted); }
.mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.checks .ok .mark { background: var(--good); color: var(--surface); }
.checks .no .mark { background: var(--warn); color: var(--surface); }

/* Brand tab, images, history */
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tokens { display: flex; flex-wrap: wrap; gap: 6px; }
.token { font: 500 12px/1 var(--mono); padding: 6px 8px; border-radius: 6px; border: 1px dashed var(--line); background: var(--surface-2); cursor: pointer; }
.token:hover { border-style: solid; border-color: var(--focus); }
.color-row code { font: 12px var(--mono); color: var(--muted); }
.img-field { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-2); }
.img-field img { width: 88px; height: 64px; object-fit: contain; border-radius: 6px; background: repeating-conic-gradient(var(--line) 0 25%, transparent 0 50%) 0 0 / 12px 12px; }
.img-empty { width: 88px; height: 64px; display: grid; place-items: center; color: var(--muted); font-size: 12px; border-radius: 6px; background: var(--surface); }
.img-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.history { display: inline-flex; }
.history .btn.icon { font: 16px/1 var(--ui); padding: 6px 9px; text-transform: none; }
.add-hint { margin-top: -10px; }

/* Modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(10, 12, 16, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: min(860px, 100%); max-height: 90vh; overflow: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.modal-head h2 { margin: 0; font: 900 20px/1.1 var(--brand); font-stretch: 125%; text-transform: uppercase; letter-spacing: -.005em; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn input { display: none; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.tpl { display: flex; flex-direction: column; gap: 4px; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.tpl-cover { aspect-ratio: 8.5 / 11; max-width: 100%; border-radius: 6px; padding: 14px; display: flex; align-items: flex-end; font-size: 19px; line-height: 1.1; box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 6px; transition: transform .15s; }
.tpl:hover .tpl-cover { transform: translateY(-3px); }
.tpl small { color: var(--muted); }
.proj-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.proj-list li { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); }
.proj-list li.current { border: 1px solid transparent; background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--grad) border-box; }
.proj-meta { display: flex; flex-direction: column; min-width: 0; }
.proj-meta small { color: var(--muted); }
.proj-actions { display: flex; gap: 4px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.ai-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ai-cols > div { min-width: 0; }
.ai-cols textarea { font: 12px/1.5 ui-monospace, 'SF Mono', Menlo, monospace; }
.error { color: var(--bad); margin: 6px 0 0; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

.mobile-switch { display: none; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .panel { border-right: 0; }
  .mobile-switch { display: flex; gap: 4px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .mobile-switch button { flex: 1; border: 1px solid var(--line); background: var(--surface); padding: 7px; border-radius: 8px; cursor: pointer; }
  .mobile-switch button { border-radius: 999px; font: 500 11px/1 var(--brand); font-stretch: 125%; text-transform: uppercase; letter-spacing: .05em; }
  .mobile-switch button.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
  body[data-mobile="edit"] .stage { display: none; }
  body[data-mobile="preview"] .panel { display: none; }
  .stage-inner { padding: 16px; }
  .brand-sub, .project-name { display: none; }
  .topbar { justify-content: space-between; }
  .ai-cols, .row2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
