/* Persian and Arabic letters only, so Latin text keeps the system font. */
@font-face {
  font-family: "Studio Persian"; src: url("/fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900; font-display: swap;
  unicode-range: U+00AB, U+00BB, U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}
:root {
  --bg: #fafaf9; --surface: #fff; --text: #1c1b1a; --muted: #77736d;
  --line: #e6e3de; --accent: #1c1b1a; --warn: #8a5a00; --error: #a12a1d;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 "Studio Persian", -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif; }
a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--line); }
a:hover { text-decoration-color: currentColor; }
h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 20px; }
h2 { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 32px 0 12px; }
.top { display: flex; align-items: center; gap: 36px; padding: 14px 32px; border-bottom: 1px solid var(--line); background: var(--surface); }
.wordmark { font-weight: 600; text-decoration: none; }
nav { display: flex; gap: 24px; flex: 1; }
nav a { text-decoration: none; color: var(--muted); }
nav a[aria-current] { color: var(--text); }
.spend { color: var(--muted); font-size: 12px; }
.page { max-width: 960px; margin: 0 auto; padding: 40px 32px; }
.page.narrow { max-width: 680px; }
.page.split { max-width: 1180px; display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 56px; }
.heading { display: flex; justify-content: space-between; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.box { border: 1px solid var(--line); background: var(--surface); padding: 16px; border-radius: 6px; }
.flash { margin: 0; padding: 10px 32px; border-bottom: 1px solid var(--line); color: var(--warn); }
.flash.error { color: var(--error); }
.flash.info { color: var(--text); }
.page .flash { padding: 8px 0; }

label { display: block; margin: 0 0 14px; font-size: 12px; color: var(--muted); }
label.inline { display: inline; margin-left: 8px; }
label.inline select { width: auto; display: inline-block; }
input, textarea, select { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .button { display: inline-block; padding: 7px 14px; font: inherit; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; }
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
button.secondary:hover { border-color: var(--muted); }
button.link { border: 0; background: none; color: var(--muted); padding: 0; font-size: 12px; text-decoration: underline; }
button:disabled { opacity: 0.55; cursor: progress; }
form input + input, form select + input, form input + textarea, form textarea + input, form textarea + .actions, form input + button, form input + .actions, form textarea + button { margin-top: 8px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.pair, .options { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.options { grid-template-columns: 1fr 1fr 1fr auto; align-items: end; }
.options button { margin-bottom: 14px; }
details { margin: 8px 0; }
summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-bottom: 8px; }

ul.rows { list-style: none; margin: 0; padding: 0; }
ul.rows li { display: flex; justify-content: space-between; gap: 24px; padding: 12px 0; border-bottom: 1px solid var(--line); }
ul.rows li .muted { text-align: right; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px; margin-bottom: 12px; align-items: start; }
.thumbs.gallery { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
figure { margin: 0; }
/* Thumbnails keep the image's real shape: never box it into a square. */
figure img { max-width: 100%; max-height: 220px; width: auto; height: auto; border: 1px solid var(--line); border-radius: 6px; display: block; }
.thumbs.gallery img { max-height: 320px; }
figure.current img { border-color: var(--accent); }
figcaption { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.hero { max-width: 100%; max-height: 70vh; display: block; border: 1px solid var(--line); border-radius: 6px; }

.workspace { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(340px, 1.5fr) minmax(360px, 1.6fr); min-height: calc(100vh - 54px); }
.column { padding: 24px; border-right: 1px solid var(--line); min-width: 0; }
.column:last-child { border-right: 0; }
.column > h2:first-child { margin-top: 0; }
.messages { max-height: 62vh; overflow-y: auto; margin-bottom: 16px; }
.message { margin-bottom: 18px; }
.message header { font-size: 11px; color: var(--muted); }
.message p { margin: 2px 0; }
.message.owner p { border-left: 2px solid var(--line); padding-left: 10px; }
.message.system p { color: var(--muted); font-size: 12px; }
ul.decisions { list-style: none; padding: 0; margin: 0; }
ul.decisions li { padding: 8px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
ul.decisions li span { display: block; }
ul.decisions li.proposed b::after { content: " ?"; color: var(--warn); }
ul.decisions form { display: flex; gap: 12px; }
.review { border-top: 1px solid var(--line); margin-bottom: 16px; }
dl.analysis dt { font-size: 11px; text-transform: uppercase; color: var(--muted); margin-top: 10px; }
dl.analysis dd { margin: 0; }
dl.analysis ul { margin: 0; padding-left: 18px; }
dl.summary { display: grid; grid-template-columns: 140px 1fr; gap: 6px 16px; }
dl.summary dt { color: var(--muted); }
dl.summary dd { margin: 0; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
form.cost { display: flex; gap: 6px; align-items: center; }
form.cost input { width: 90px; margin: 0; padding: 2px 6px; font-size: 12px; }

@media (max-width: 1150px) {
  .workspace { grid-template-columns: 260px 1fr; }
  .column.output { grid-column: 2; border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .workspace, .page.split { display: block; }
  .top { flex-wrap: wrap; gap: 12px; }
}

.column.output { display: flex; flex-direction: column; justify-content: flex-start; }
.prompt-panel > h2:first-child { margin-top: 0; }
.image-first .image-panel { order: -1; }
.image-first .image-panel > h2:first-child { margin-top: 0; }
.image-first .prompt-panel > h2:first-child { margin-top: 32px; }
.image-first .hero { max-height: 55vh; }

/* Right-to-left blocks follow their own direction. */
:dir(rtl) { line-height: 1.9; letter-spacing: 0; }
h1:dir(rtl) { line-height: 1.6; }
.message.owner p:dir(rtl) { border-left: 0; padding-left: 0; border-right: 2px solid var(--line); padding-right: 10px; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
.editor-stage { display: flex; justify-content: center; padding: 24px; position: sticky; top: 0; }
#stage { max-width: 100%; max-height: 88vh; border: 1px solid var(--line); border-radius: 6px; cursor: move; touch-action: none; }
.editor-panel { padding: 24px; border-left: 1px solid var(--line); }
label.check { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
label.check input { width: auto; margin: 0; }
input[type="color"] { height: 38px; padding: 3px; }
button.swatch { width: 24px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 50%; }
[hidden] { display: none !important; }
@media (max-width: 860px) { .editor { display: block; } .editor-stage { position: static; } }

/* Video Studio */
.subnav { display: flex; gap: 22px; padding: 10px 32px; border-bottom: 1px solid var(--line); flex: none; font-size: 13px; }
.subnav a { text-decoration: none; color: var(--muted); }
.subnav a[aria-current], a.pick[aria-current] { color: var(--text); }
a.pick { margin-right: 14px; color: var(--muted); }
h3 { font-size: 13px; font-weight: 600; margin: 18px 0 6px; }
.item { padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.item p { margin: 2px 0; }
.item img { display: block; max-width: 100%; max-height: 140px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 4px; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.spaced { margin-top: 14px; }
.chips { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 18px; }
.chips button.link { text-align: left; }
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 0 0 8px; text-decoration: none; color: var(--muted); }
.tabs a[aria-selected="true"], .tabs a[aria-current] { color: var(--text); border-bottom: 2px solid var(--accent); }
.scene { border-top: 1px solid var(--line); margin-top: 20px; }
.scene h2 { margin-top: 16px; }
.add-row { display: grid; grid-template-columns: 1fr 1.4fr 1.4fr auto; gap: 12px; align-items: end; margin-top: 16px; }
.add-row button { margin-bottom: 14px; }
select + label.check { margin-top: 8px; }
.analysis dd.pre { white-space: pre-wrap; }
@media (max-width: 760px) { .subnav { flex-wrap: wrap; } .add-row { display: block; } }

.checklist li { align-items: flex-start; gap: 14px; }
.checklist .entry { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.checklist .entry > a { display: block; font-size: 15px; text-align: left; }
.checklist .done .entry > a { color: var(--muted); }
.checklist details { margin: 2px 0 0; }
.checklist summary { margin-bottom: 0; }
.checklist details p { margin: 6px 0; }
button.tick { width: 22px; height: 22px; margin-top: 3px; padding: 0; line-height: 1; font-size: 13px; border-color: var(--muted); background: var(--surface); }
button.tick[aria-checked="true"] { border-color: var(--accent); background: var(--accent); }
form.rename { display: flex; gap: 8px; }
form.rename input { margin: 0; flex: 1; min-width: 0; }
form.rename input + button { margin: 0; }
@media (max-width: 760px) { .checklist li { flex-wrap: wrap; } .checklist li > .muted { margin-left: 36px; } }

.title-maker { margin: 0 0 18px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.row-actions details { margin: 0; }
.row-actions details[open] { flex-basis: 100%; }
.row-actions summary, button.small-button { display: inline-block; padding: 2px 10px; font-size: 12px; line-height: 1.6; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; list-style: none; }
.row-actions summary::-webkit-details-marker { display: none; }
.row-actions summary:hover, button.small-button:hover { border-color: var(--muted); }
input.pick-title { width: 18px; height: 18px; margin: 28px 0 0; flex: none; }
ul.checklist li .entry span[dir] { display: block; text-align: start; }
.row-actions form input + button.small-button, form.title-maker input + button { margin-top: 0; }
.row-actions summary { margin: 0; }

/* Login and chat */
.page.login { max-width: 380px; padding-top: 14vh; }
.workspace.chat { grid-template-columns: minmax(0, 1fr) 300px; }
.workspace.chat .conversation > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.message p.lines { unicode-bidi: plaintext; overflow-wrap: anywhere; }
.chat-options { margin-top: 12px; grid-template-columns: 1fr; gap: 0; }
.chat-list a { text-decoration: none; overflow-wrap: anywhere; }
.chat-list a[aria-current] { font-weight: 600; }

/* Tablets: the video workspace keeps its third column readable, and typing never zooms. */
@media (max-width: 1150px) {
  .workspace:not(.chat) { grid-template-rows: auto 1fr; }
  .workspace:not(.chat) > .column:first-child { grid-row: 1 / span 2; }
  .workspace.video > .column:nth-child(3) { grid-column: 2; border-top: 1px solid var(--line); }
}
/* Menu items never break inside; when the header is too narrow the menu gets its own row. */
.top nav a, .subnav a, .spend { white-space: nowrap; }
@media (max-width: 1360px) {
  .top { flex-wrap: wrap; gap: 10px 24px; }
  .top nav { flex-basis: 100%; order: 3; flex-wrap: wrap; gap: 8px 24px; }
  .spend { margin-left: auto; }
}
@media (max-width: 700px) { .spend { white-space: normal; margin-left: 0; } }
@media (max-width: 760px) { .workspace.chat { display: block; } .page { padding: 24px 18px; } }
@media (pointer: coarse) {
  input, textarea, select { font-size: 16px; }
  nav a, .tabs a, .subnav a { padding-top: 6px; padding-bottom: 8px; }
  button.link, summary { padding: 6px 0; }
  button.tick { width: 30px; height: 30px; }
}

/* Voice input */
.voice { position: fixed; z-index: 20; display: flex; gap: 4px; }
.voice button { display: inline-flex; align-items: center; gap: 6px; height: 28px; min-width: 28px; padding: 0 7px; font-size: 12px; line-height: 1; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.voice button:hover { color: var(--text); border-color: var(--muted); }
.voice .voice-main.recording { color: #fff; background: var(--error); border-color: var(--error); }
.voice-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: voice-pulse 1s infinite alternate; }
@keyframes voice-pulse { to { opacity: 0.3; } }
textarea.voice-target, input.voice-target { padding-inline-end: 42px; }
.voice-toast { position: fixed; z-index: 21; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(560px, calc(100vw - 32px)); padding: 10px 14px; background: var(--text); color: #fff; border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
.voice-toast button.link { color: #fff; font-size: 13px; }
@media (pointer: coarse) { .voice button { height: 34px; min-width: 34px; border-radius: 17px; } textarea.voice-target, input.voice-target { padding-inline-end: 48px; } }
@media (prefers-reduced-motion: reduce) { .voice-dot { animation: none; } }

[data-credit] { color: var(--text); white-space: nowrap; }
[data-credit].low { color: var(--error); }

/* Installed app: feel native, respect the iPad's screen edges and home indicator. */
html { -webkit-text-size-adjust: 100%; }
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); padding-bottom: env(safe-area-inset-bottom); -webkit-tap-highlight-color: transparent; }
.top { padding-top: max(14px, env(safe-area-inset-top)); }
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
  .top { position: sticky; top: 0; z-index: 10; }
  a, button, summary, nav { -webkit-touch-callout: none; }
}
