/* style.css — واجهة المولّد (عربية، RTL، فاتح/داكن تلقائي) */

:root {
  --bg: #f4f1ea;
  --bg-elev: #ffffff;
  --line: #e0dacd;
  --ink: #221f1a;
  --ink-soft: #6b6457;
  --accent: #0f5f49;
  --accent-ink: #ffffff;
  --card-accent: #d9b06a;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(20, 16, 10, .06), 0 10px 30px rgba(20, 16, 10, .08);
  --font: "Tajawal", "Noto Kufi Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-display: "Reem Kufi", "Amiri", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --bg-elev: #1d2026;
    --line: #2e333c;
    --ink: #f0efea;
    --ink-soft: #9ea5b0;
    --accent: #4fbf96;
    --accent-ink: #07201a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 14px 34px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
}

.skip {
  position: absolute;
  inset-inline-start: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: .6rem 1rem;
  border-radius: 0 0 var(--radius) var(--radius);
  z-index: 10;
}
.skip:focus { inset-inline-start: 1rem; }

/* ───────── الترويسة ───────── */

.site-head {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.5rem;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
}

.brand { display: flex; align-items: center; gap: .85rem; }

.brand__mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  flex: none;
  background:
    radial-gradient(circle at 50% 42%, var(--card-accent) 0 28%, transparent 29%),
    linear-gradient(145deg, #0d3b2d, #07271f);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

.brand strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.3rem;
  line-height: 1.3;
}

.brand small { color: var(--ink-soft); font-size: .85rem; }

.site-head__note { margin: 0; color: var(--ink-soft); font-size: .85rem; }

/* ───────── شاشة الاختيار ───────── */

.start { padding: clamp(1rem, 3vw, 2.5rem); }

.sheet {
  max-width: 960px;
  margin: 0 auto;
  padding: clamp(1.1rem, 3vw, 2rem);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.sheet__title {
  margin: 0 0 .25rem;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  line-height: 1.4;
}

.sheet__grid {
  display: grid;
  gap: clamp(1rem, 3vw, 2rem);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  margin-top: 1.25rem;
}

.sheet__form { display: grid; gap: 1.25rem; }

.sheet__preview {
  display: grid;
  gap: .5rem;
  justify-items: center;
  padding: .9rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

#thumb {
  display: block;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}

@media (max-width: 760px) {
  .sheet__grid { grid-template-columns: minmax(0, 1fr); }
  .sheet__preview { order: -1; }
}

/* ───────── المحرّر ───────── */

.editor {
  display: grid;
  gap: 1rem;
  justify-items: center;
  padding: clamp(.75rem, 2.5vw, 1.75rem);
  max-width: 1100px;
  margin: 0 auto;
}

.editor__head,
.editor__foot {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
}

.editor__head { justify-content: space-between; }
.editor__head strong { font-family: var(--font-display); font-size: 1.15rem; }
.editor__actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.editor__foot { justify-content: space-between; }

.stage {
  width: 100%;
  display: grid;
  place-items: center;
  padding: clamp(.5rem, 2vw, 1.25rem);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

#card {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(70vh, 740px);
  height: auto;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .22);
}

.dims {
  color: var(--ink-soft);
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}

/* ───────── الحقول ───────── */

.field { display: grid; gap: .55rem; margin: 0; padding: 0; border: 0; }

.field__label {
  font-size: .9rem;
  font-weight: 500;
  color: var(--ink-soft);
  padding: 0;
}

.hint { margin: 0; font-size: .8rem; color: var(--ink-soft); }

.input {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .6rem .8rem;
  transition: border-color .15s, box-shadow .15s;
}

.input--select { appearance: none; padding-inline-end: 1.8rem; cursor: pointer; }

.input:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 95, 73, .14); }

/* ───────── الأزرار والشرائح ───────── */

.btn {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .55rem 1.05rem;
  transition: background .15s, border-color .15s, transform .08s;
}

.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn--ghost { background: transparent; }
.btn--sm { padding: .3rem .7rem; font-size: .83rem; }
.btn--block { width: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }

.chip {
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .38rem .85rem;
  transition: background .15s, border-color .15s, color .15s;
}

.chip:hover { border-color: var(--accent); }
.chip:disabled { opacity: .45; cursor: not-allowed; }
.chip:disabled:hover { border-color: var(--line); }

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chip--sm { font-size: .85rem; }

.swatches { display: flex; flex-wrap: wrap; gap: .5rem; }

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--sw-bg);
  position: relative;
  transition: transform .1s, box-shadow .15s;
}

.swatch::after {
  content: "";
  position: absolute;
  inset-block-end: 5px;
  inset-inline-end: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--sw-accent);
}

.swatch:hover { transform: translateY(-1px); }

.swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px var(--accent);
}

.toggles { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .9rem;
  cursor: pointer;
}

.toggle:has(input:disabled) { opacity: .45; cursor: not-allowed; }

.toggle input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); cursor: pointer; }

/* ───────── التذييل والتنبيه ───────── */

.site-foot {
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 2.5rem;
  color: var(--ink-soft);
  font-size: .85rem;
  text-align: center;
}

.site-foot code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9em;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .05rem .35rem;
}

.toast {
  position: fixed;
  inset-block-end: 1.25rem;
  inset-inline: 0;
  margin-inline: auto;
  width: fit-content;
  max-width: calc(100% - 2rem);
  background: var(--ink);
  color: var(--bg);
  padding: .6rem 1.1rem;
  border-radius: 999px;
  font-size: .9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(.6rem);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ───────── طبقة الصناديق فوق البطاقة ───────── */

.card-wrap { position: relative; display: inline-block; line-height: 0; }

.overlay {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  line-height: normal;
}

.fbox {
  position: absolute;
  min-height: 1em;
  border: 1px dashed rgba(127, 127, 127, .55);
  border-radius: 6px;
  transition: border-color .12s, background .12s;
}

.fbox:hover { border-color: var(--accent); background: rgba(127, 127, 127, .08); }

.fbox.is-selected { border: 1px solid var(--accent); box-shadow: 0 0 0 2px rgba(79, 191, 150, .25); }

.fbox--ornament { pointer-events: auto; cursor: pointer; }

.fbox__text {
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  caret-color: var(--accent);
  min-height: 1em;
}

.fbox__text:empty::before {
  content: attr(data-ph);
  color: rgba(127, 127, 127, .85);
}

.fbox__grip {
  position: absolute;
  inset-block-start: -11px;
  inset-inline-start: -11px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg-elev);
  color: var(--ink-soft);
  cursor: grab;
  opacity: 0;
  transition: opacity .12s;
  touch-action: none;
}

.fbox__grip::before { content: "✥"; font-size: .8rem; line-height: 1; }

.fbox:hover .fbox__grip,
.fbox.is-selected .fbox__grip { opacity: 1; }

.fbox__grip:active { cursor: grabbing; }

/* ───────── شريط التنسيق ───────── */

.toolbar {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  padding: .55rem .75rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar__label { font-size: .85rem; color: var(--ink-soft); }
.toolbar__label b { color: var(--ink); }

.toolbar__group { display: inline-flex; align-items: center; gap: .3rem; }
.toolbar__group.is-off { opacity: .35; pointer-events: none; }

.toolbar__width { font-size: .85rem; color: var(--ink-soft); gap: .5rem; }
.toolbar__width input { width: 110px; accent-color: var(--accent); }

.input--tiny { padding: .25rem .5rem; font-size: .85rem; width: auto; }

.btn--icon {
  min-width: 2rem;
  padding: .25rem .45rem;
  font-size: .9rem;
  line-height: 1.4;
}

.btn--icon[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.btn--danger { border-color: #c1544f; color: #c1544f; }
.btn--danger:hover { background: #c1544f; color: #fff; }

.dots { display: inline-flex; gap: .25rem; }

.dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
}

.dot[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px var(--accent); }

.color {
  width: 28px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.row--end { gap: .6rem; }
.file { display: inline-flex; cursor: pointer; }
