/* ---------- Header ---------- */
.site-header {
  position: sticky; inset-block-start: 0; z-index: 50;
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s1) var(--s2); min-height: var(--header-h); padding-block: 8px; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.15rem; }
.brand-logo { width: 40px; height: 40px; border-radius: 8px; }
.theme-toggle { order: 2; margin-inline-start: auto; }
.nav { order: 3; flex: 1 0 100%; overflow-x: auto; scrollbar-width: thin; }
.nav ul { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; white-space: nowrap; }
.nav a { display: inline-flex; align-items: center; min-height: 44px; padding-inline: 12px; border-radius: var(--r1); color: var(--text-muted); text-decoration: none; font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
@media (min-width: 960px) {
  .nav { order: 1; flex: 1 1 auto; overflow: visible; }
  .theme-toggle { order: 2; margin-inline-start: 0; }
}
.theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 18px;
  border: 1px solid var(--border); border-radius: var(--r1);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-icon { padding: 8px; min-width: 44px; }
.btn[aria-pressed="true"]:not(.btn-primary) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent-text); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r2); padding: var(--s3); }
.card h3 { margin-block-end: 8px; }
.card p { color: var(--text-muted); }
.cards { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.cards .card { display: flex; flex-direction: column; align-items: flex-start; }
.cards .card p { flex: 1; }

/* ---------- Hero ---------- */
.hero-inner { padding-block: var(--s6) var(--s5); text-align: center; display: flex; flex-direction: column; align-items: center; }
.eyebrow { color: var(--accent-text); font-weight: 600; letter-spacing: 0.02em; margin-block-end: 8px; }
.lead { font-size: clamp(1.05rem, 2.5vw, 1.3rem); max-width: 56ch; color: var(--text-muted); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-block: var(--s2); }
.honest { font-size: 0.95rem; color: var(--text-muted); max-width: 60ch; }
.stats { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: center; list-style: none; padding: 0; margin: var(--s3) 0 0; }
.stats li { min-width: 130px; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--r1); background: var(--surface); display: flex; flex-direction: column; align-items: center; }
.stats strong { font-size: 1.75rem; line-height: 1.2; color: var(--accent-text); min-width: 2ch; min-height: 1.2em; }
.stats span { color: var(--text-muted); font-size: 0.9rem; }

/* ---------- Forms ---------- */
.field { margin-block-end: var(--s2); border: 0; padding: 0; min-width: 0; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
label, .label { display: block; font-weight: 600; margin-block-end: 4px; padding: 0; }
.hint { font-size: 0.85rem; color: var(--text-muted); margin: 4px 0 0; }
input[type="range"] { width: 100%; height: 44px; accent-color: var(--accent); background: transparent; }
input[type="search"], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r1);
}
textarea { resize: vertical; line-height: 1.7; }
.color-input { width: 100%; height: 44px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r1); cursor: pointer; }
.checks { display: grid; gap: 4px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 500; margin: 0; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg .btn { padding-inline: 14px; }
.seg-2 { display: grid; grid-template-columns: repeat(2, 1fr); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-block-end: var(--s2); }

/* ---------- Studio ---------- */
.studio-grid { display: grid; gap: var(--s3); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) {
  .studio-grid { grid-template-columns: minmax(0, 1fr) 420px; align-items: start; }
  .prompt-panel { position: sticky; inset-block-start: calc(var(--header-h) + 16px); max-height: calc(100vh - var(--header-h) - 32px); overflow-y: auto; }
  .sheet-jump { display: none !important; }
}
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-block-end: var(--s1); }
.tool-group { display: flex; flex-wrap: wrap; gap: 6px; }

.stage-frame {
  position: relative; display: grid; place-items: center;
  min-height: 420px; padding: 12px;
  border: 1px solid var(--border); border-radius: var(--r2); overflow: hidden;
  color: #F3EEE6;
}
.stage-frame:fullscreen { min-height: 100vh; border-radius: 0; }
.stage {
  position: relative; width: min(100%, calc(70vh * var(--arn, 1.7778)));
  aspect-ratio: var(--ar, 16 / 9);
  background: #0A1024; border: 1px solid #22305E; border-radius: 4px; overflow: hidden;
}
.stage-frame:fullscreen .stage { width: min(100%, calc(88vh * var(--arn, 1.7778))); }
.stage[data-aspect="16:9"] { --ar: 16 / 9; --arn: 1.7778; }
.stage[data-aspect="9:16"] { --ar: 9 / 16; --arn: 0.5625; }
.stage[data-aspect="4:5"] { --ar: 4 / 5; --arn: 0.8; }
.stage[data-aspect="1:1"] { --ar: 1 / 1; --arn: 1; }
.stage[data-aspect="2.39:1"] { --ar: 239 / 100; --arn: 2.39; }
.stage canvas { display: block; width: 100%; height: 100%; }

.stage-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px; text-align: center; }
.ph-svg { flex: 1; min-height: 0; width: 100%; max-height: 100%; overflow: hidden; }
.ph-floor { fill: rgba(20, 39, 94, 0.45); stroke: #22305E; }
.ph-ring { fill: none; stroke: #22305E; stroke-dasharray: 4 6; }
.ph-cone { fill: rgba(255, 176, 102, 0.22); stroke: rgba(255, 176, 102, 0.6); }
.ph-camera { fill: #F47B20; stroke: #FFB066; stroke-width: 1.5; }
.ph-subject { fill: #14275E; stroke: #F3EEE6; stroke-width: 2; }
.ph-nose { fill: #F47B20; }
.ph-text { margin: 0; font-size: 0.85rem; font-family: var(--font-ar); color: #F3EEE6; }
.ph-note { margin: 0; font-size: 0.75rem; color: #9AA3BD; max-width: 60ch; }

.safe-area { position: absolute; inset: 5%; border: 1px dashed rgba(255, 176, 102, 0.85); pointer-events: none; display: none; z-index: 2; }
.safe-area::after { content: ""; position: absolute; inset: 6%; border: 1px dashed rgba(243, 238, 230, 0.55); }
.stage.show-safe .safe-area { display: block; }

.lens-readout {
  position: absolute; inset-block-end: 8px; inset-inline-start: 8px; z-index: 3;
  padding: 2px 10px; font-size: 0.8rem; color: #FFB066;
  background: rgba(7, 11, 22, 0.78); border: 1px solid #22305E; border-radius: 4px;
}
.live-description { margin: var(--s1) 0 var(--s2); padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--info); border-radius: var(--r1); }

/* ---------- Tabs ---------- */
.tabs { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r2); padding: var(--s2); }
.tablist { display: none; gap: 4px; flex-wrap: wrap; margin-block-end: var(--s2); border-block-end: 1px solid var(--border); padding-block-end: 8px; }
.tabs-js .tablist { display: flex; }
.tab { min-height: 44px; padding: 8px 18px; background: transparent; border: 1px solid transparent; border-radius: var(--r1); color: var(--text-muted); font-weight: 600; cursor: pointer; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--on-accent); background: var(--accent); }
.tabs-js .tab-panel:not(.is-active) { display: none; }
.tab-panel + .tab-panel { margin-block-start: var(--s3); padding-block-start: var(--s3); border-block-start: 1px solid var(--border); }
.tabs-js .tab-panel + .tab-panel { margin: 0; padding: 0; border: 0; }
.tabs-js .panel-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); margin: -1px; }
.joint-sliders { display: grid; gap: 0 var(--s3); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-block-end: var(--s1); }

/* ---------- Prompt panel ---------- */
.prompt-panel h3 { margin-block-end: var(--s2); }
.prompt-output { font-family: var(--font-ar); min-height: 220px; line-height: 1.8; }
.note { font-size: 0.9rem; color: var(--text); padding: 10px 14px; background: var(--surface-2); border-inline-start: 4px solid var(--accent); border-radius: var(--r1); margin: 0 0 var(--s2); }
.ref-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ref-preview img { max-width: 100%; max-height: 140px; margin-block-start: 8px; border-radius: var(--r1); border: 1px solid var(--border); }
.sheet-jump { position: fixed; inset-inline-end: 16px; inset-block-end: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 60; box-shadow: var(--shadow); }

/* ---------- Libraries ---------- */
.lib-toolbar { display: grid; gap: var(--s1); margin-block-end: var(--s2); }
@media (min-width: 768px) { .lib-toolbar { grid-template-columns: 320px 1fr; align-items: start; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-grid { display: grid; gap: var(--s1); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.lib-placeholder { grid-column: 1 / -1; color: var(--text-muted); padding: var(--s3); border: 1px dashed var(--border); border-radius: var(--r2); text-align: center; margin: 0; }

/* ---------- Steps / FAQ / footer ---------- */
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.step-num { display: inline-grid; place-items: center; width: 44px; height: 44px; margin-block-end: 8px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 1.2rem; }
details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r1); margin-block-end: 8px; }
summary { min-height: 44px; display: flex; align-items: center; padding: 8px var(--s2); font-weight: 600; cursor: pointer; }
details p { padding-inline: var(--s2); color: var(--text-muted); }
.site-footer { margin-block-start: var(--s5); padding-block-end: calc(var(--s4) + 56px); background: var(--surface); border-block-start: 1px solid var(--border); }
.footer-inner { padding-block-start: var(--s3); display: grid; gap: 4px; text-align: center; justify-items: center; }
.footer-inner p { margin: 0; color: var(--text-muted); }
.brand-static { display: flex; align-items: center; gap: 10px; }
.slogan { color: var(--accent-text) !important; font-weight: 600; }

/* ---------- Toast / debug ---------- */
.toast {
  position: fixed; inset-inline: 0; inset-block-end: calc(24px + env(safe-area-inset-bottom, 0px)); margin-inline: auto; z-index: 90;
  width: max-content; max-width: 90vw; padding: 12px 20px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-inline-start: 4px solid var(--info);
  border-radius: var(--r1); box-shadow: var(--shadow);
}
.toast:empty { display: none; }
.debug-banner { position: fixed; inset-inline: 8px; inset-block-start: 8px; z-index: 200; display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 10px 14px; background: #3A0F0F; color: #FFE3E3; border: 1px solid #FF6B6B; border-radius: var(--r1); font-family: var(--font-mono); font-size: 0.85rem; direction: rtl; }
.debug-banner button { min-height: 36px; padding: 4px 12px; background: #FFE3E3; color: #3A0F0F; border: 0; border-radius: 6px; cursor: pointer; font-family: var(--font-ar); }