/* ============================================
   Pixia — Arabic Calligraphy Studio
   Scoped to body.at-calligraphy
   ============================================ */

body.at-calligraphy {
  --ac-jade: #0f766e;
  --ac-jade-deep: #0b5a53;
  --ac-jade-soft: rgba(15, 118, 110, .12);
  --ac-gold: #b48a3c;
  --ac-gold-soft: #d9be86;
  --ac-accent: #0f766e;
  --ac-cream: #f6efe2;
  --ac-radius: 14px;
  --ac-ease: cubic-bezier(.22, .61, .36, 1);
}

html[data-theme="dark"] body.at-calligraphy {
  --ac-accent: #5eead4;
  --ac-gold: #d6b879;
  --ac-jade-soft: rgba(45, 212, 191, .14);
}

body.at-calligraphy .at-bg {
  background:
    radial-gradient(980px 560px at 82% -6%, rgba(15, 118, 110, .20), transparent 62%),
    radial-gradient(820px 520px at 4% 8%, rgba(180, 138, 60, .16), transparent 62%),
    radial-gradient(720px 520px at 52% 108%, rgba(6, 182, 212, .10), transparent 64%);
}

body.at-calligraphy [hidden] {
  display: none !important;
}

body.at-calligraphy .at-kicker {
  background: linear-gradient(135deg, #0f766e, #b48a3c);
  color: #fff;
  gap: 7px;
}

body.at-calligraphy .at-kicker svg {
  width: 15px;
  height: 15px;
}

body.at-calligraphy .at-btn {
  background: linear-gradient(135deg, var(--ac-jade), var(--ac-jade-deep));
  box-shadow: 0 16px 34px -18px rgba(15, 118, 110, .9);
}

body.at-calligraphy .at-badge svg {
  color: var(--ac-jade);
}

html[data-theme="dark"] body.at-calligraphy .at-badge svg {
  color: var(--ac-accent);
}

/* ---------- Hero ---------- */
.ac-hero {
  position: relative;
  isolation: isolate;
}

.ac-hero-mark {
  position: absolute;
  z-index: -1;
  inset-block-start: -.38em;
  inset-inline-end: -10px;
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: clamp(90px, 14vw, 210px);
  font-weight: 700;
  line-height: 1;
  color: var(--ac-jade);
  opacity: .055;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  transform: rotate(-4deg);
}

html[data-theme="dark"] .ac-hero-mark {
  color: var(--ac-gold-soft);
  opacity: .08;
}

.ac-noscript {
  padding: 16px 18px;
  border-radius: var(--at-radius-lg);
  border: 1px solid rgba(239, 68, 68, .35);
  background: rgba(239, 68, 68, .08);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- Toolbar ---------- */
.ac-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-block: 14px 0;
  padding: 13px 4px 0;
  border-block-start: 1px solid var(--glass-border);
}

.ac-topbar-left,
.ac-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ac-history {
  display: inline-flex;
  gap: 6px;
}

.ac-icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 11px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color .2s var(--ac-ease), border-color .2s var(--ac-ease), background .2s var(--ac-ease), transform .2s var(--ac-ease);
}

.ac-icon-btn svg {
  width: 17px;
  height: 17px;
}

.ac-icon-btn:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: var(--ac-accent);
  transform: translateY(-1px);
}

.ac-icon-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.ac-save-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-inline: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
  min-height: 26px;
}

.ac-save-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .13);
  transition: background .2s, box-shadow .2s;
}

.ac-save-status.is-saving i {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .16);
  animation: ac-pulse 1.1s ease-in-out infinite;
}

.ac-save-status.is-error i {
  background: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, .16);
}

.ac-save-status.is-restored {
  color: var(--ac-gold);
}

@keyframes ac-pulse {
  50% { opacity: .4; }
}

.ac-ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color .2s var(--ac-ease), border-color .2s var(--ac-ease), background .2s var(--ac-ease), transform .2s var(--ac-ease);
}

.ac-ghost-btn svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.ac-ghost-btn:hover {
  color: var(--text-primary);
  border-color: var(--glass-border-hover);
  transform: translateY(-1px);
}

.ac-export-btn {
  min-height: 40px;
  padding: 11px 18px;
  font-size: 14px;
  border-radius: 11px;
}

.ac-export-btn svg {
  width: 16px;
  height: 16px;
}

/* ---------- Layout ---------- */
.ac-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 412px;
  gap: 20px;
  align-items: start;
  overflow-anchor: none;
}

.ac-stage-col {
  min-width: 0;
  /* Gives the sticky preview room to travel to the end of the grid row. */
  align-self: stretch;
}

.ac-side {
  min-width: 0;
}

.ac-stage-panel {
  position: sticky;
  inset-block-start: calc(var(--nav-height) + 12px);
  scroll-margin-block-start: calc(var(--nav-height) + 12px);
  padding: 14px;
  border-radius: var(--at-radius-xl);
  transition: box-shadow .25s var(--ac-ease);
}

/* ---------- Stage ---------- */
.ac-stage {
  position: relative;
  height: clamp(380px, 54vh, 660px);
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  background-color: color-mix(in srgb, var(--bg-secondary) 84%, #5b6b66);
  background-image:
    linear-gradient(45deg, rgba(120, 130, 126, .09) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(120, 130, 126, .09) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(120, 130, 126, .09) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(120, 130, 126, .09) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--glass-border-hover) transparent;
}

.ac-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 0%, transparent 55%, rgba(0, 0, 0, .13));
  z-index: 0;
}

.ac-stage::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

.ac-stage::-webkit-scrollbar-thumb {
  background: var(--glass-border-hover);
  border-radius: 99px;
}

.ac-stage-inner {
  position: relative;
  z-index: 1;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
  box-sizing: border-box;
}

.ac-canvas-shell {
  position: relative;
  display: block;
  flex: 0 0 auto;
  border-radius: 2px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  box-shadow:
    0 34px 70px -30px rgba(4, 16, 12, .65),
    0 0 0 1px rgba(72, 60, 38, .18);
  outline: none;
  touch-action: none;
  cursor: default;
  transition: box-shadow .25s var(--ac-ease);
}

.ac-canvas-shell:focus-visible {
  box-shadow:
    0 34px 70px -30px rgba(4, 16, 12, .65),
    0 0 0 2px var(--ac-accent),
    0 0 0 5px color-mix(in srgb, var(--ac-accent) 22%, transparent);
}

.ac-canvas-shell canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
}

.ac-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ac-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 18%;
  border-radius: 14px;
  border: 1.5px dashed rgba(120, 113, 90, .5);
  background: color-mix(in srgb, var(--bg-card) 78%, transparent);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  text-align: center;
  pointer-events: none;
  color: var(--text-secondary);
}

.ac-empty svg {
  width: 26px;
  height: 26px;
  color: var(--ac-gold);
  margin-block-end: 4px;
}

.ac-empty strong {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--text-primary);
}

.ac-empty span {
  font-size: 12px;
  color: var(--text-tertiary);
  max-width: 26ch;
}

.ac-overflow {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-block-start: 10px;
  padding: 9px 13px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, #f59e0b 42%, transparent);
  background: color-mix(in srgb, #f59e0b 10%, transparent);
  color: color-mix(in srgb, #b45309 82%, var(--text-primary));
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  text-align: start;
  cursor: pointer;
  transition: background .2s var(--ac-ease);
}

html[data-theme="dark"] .ac-overflow {
  color: #fbbf24;
}

.ac-overflow:hover {
  background: color-mix(in srgb, #f59e0b 18%, transparent);
}

.ac-overflow svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.ac-stage-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 13px 5px 2px;
}

.ac-stage-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.ac-meta-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 7px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  font-size: 11.5px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ac-meta-chip b {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.ac-view-tools {
  display: flex;
  align-items: center;
  gap: 13px;
  flex-wrap: wrap;
}

.ac-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  position: relative;
}

.ac-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.ac-switch i {
  position: relative;
  width: 34px;
  height: 20px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  transition: background .22s var(--ac-ease), border-color .22s var(--ac-ease);
}

.ac-switch i::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
  transition: transform .22s var(--ac-ease);
}

[dir="rtl"] .ac-switch i::after {
  transform: translateX(0);
}

.ac-switch input:checked + i {
  background: var(--ac-jade);
  border-color: var(--ac-jade);
}

.ac-switch input:checked + i::after {
  transform: translateX(14px);
}

[dir="rtl"] .ac-switch input:checked + i::after {
  transform: translateX(-14px);
}

html[data-theme="dark"] .ac-switch input:checked + i {
  background: var(--ac-action, #0f766e);
}

.ac-switch input:focus-visible + i {
  outline: 2px solid var(--ac-accent);
  outline-offset: 2px;
}

.ac-switch-compact {
  font-size: 11.5px;
  gap: 7px;
}

.ac-switch-compact i {
  width: 30px;
  height: 18px;
}

.ac-switch-compact i::after {
  width: 12px;
  height: 12px;
}

.ac-switch-compact input:checked + i::after {
  transform: translateX(12px);
}

[dir="rtl"] .ac-switch-compact input:checked + i::after {
  transform: translateX(-12px);
}

.ac-zoom {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  direction: ltr;
}

.ac-zoom-btn {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}

.ac-zoom-btn:hover {
  color: var(--text-primary);
  border-color: var(--ac-accent);
}

.ac-zoom-range {
  width: 78px;
  margin: 0;
}

.ac-zoom-val {
  min-width: 34px;
  text-align: end;
  font-size: 11px;
  color: var(--text-tertiary);
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: tabular-nums;
}

.ac-fit-btn {
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.ac-fit-btn:hover {
  color: var(--text-primary);
  border-color: var(--ac-accent);
}

.ac-stage-hint {
  margin: 7px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.5;
}

/* ---------- Inspector shell ---------- */
.ac-inspector {
  position: sticky;
  inset-block-start: calc(var(--nav-height) + 12px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: fit-content;
  border-radius: var(--at-radius-xl);
}

.ac-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 10px 12px 0;
  border-block-end: 1px solid var(--glass-border);
  background: color-mix(in srgb, var(--bg-card) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.ac-tab {
  flex: 1;
  padding: 10px 8px 11px;
  border: 0;
  border-block-end: 2px solid transparent;
  background: transparent;
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color .2s var(--ac-ease), border-color .2s var(--ac-ease);
}

.ac-tab:hover {
  color: var(--text-secondary);
}

.ac-tab.is-active {
  color: var(--ac-accent);
  border-block-end-color: var(--ac-accent);
}

.ac-tab-panels {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--glass-border-hover) transparent;
}

.ac-tab-panels::-webkit-scrollbar {
  width: 8px;
}

.ac-tab-panels::-webkit-scrollbar-thumb {
  background: var(--glass-border-hover);
  border-radius: 99px;
}

.ac-panel {
  padding: 4px 18px 8px;
}

.ac-section {
  padding-block: 16px;
  border-block-end: 1px solid var(--glass-border);
}

.ac-section:last-child {
  border-block-end: 0;
}

.ac-section h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -.01em;
}

.ac-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-block-end: 12px;
  flex-wrap: wrap;
}

.ac-section-head h2 {
  margin: 0;
}

.ac-section-note {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.ac-subhead {
  margin: 16px 0 8px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: .02em;
}

.ac-counter {
  font-size: 10.5px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.ac-hint {
  margin: 7px 0 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-tertiary);
}

.ac-hint-top {
  margin: 7px 0 0;
}

.ac-shortcuts {
  flex: 0 0 auto;
  margin: 0;
  padding: 9px 18px 11px;
  border-block-start: 1px solid var(--glass-border);
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
  background: color-mix(in srgb, var(--bg-card) 92%, transparent);
}

/* ---------- Inputs ---------- */
.ac-textarea,
.ac-input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  outline: 0;
  transition: border-color .2s var(--ac-ease), box-shadow .2s var(--ac-ease);
  color-scheme: light dark;
}

.ac-textarea {
  min-height: 96px;
  padding: 12px 14px;
  font-family: "Amiri", "Scheherazade New", var(--font-primary), serif;
  font-size: 21px;
  line-height: 1.9;
  resize: vertical;
  text-align: start;
}

.ac-input {
  padding: 9px 12px;
  min-height: 36px;
}

.ac-textarea:focus,
.ac-input:focus {
  border-color: var(--ac-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac-accent) 16%, transparent);
}

.ac-textarea::placeholder,
.ac-input::placeholder {
  color: var(--text-muted);
}

.ac-input[type="search"]::-webkit-search-cancel-button {
  cursor: pointer;
}

.ac-num-input {
  font-variant-numeric: tabular-nums;
}

.ac-field {
  margin-block-start: 12px;
}

.ac-field-gap {
  margin-block-end: 10px;
}

.ac-label {
  display: block;
  margin-block-end: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .01em;
}

.ac-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-block-end: 6px;
}

.ac-label-row .ac-label {
  margin-block-end: 0;
}

.ac-out {
  font-size: 11px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

.ac-range {
  width: 100%;
  margin: 0;
  accent-color: var(--ac-jade);
  height: 20px;
  direction: ltr;
  cursor: pointer;
}

html[data-theme="dark"] .ac-range {
  accent-color: #2dd4bf;
}

.ac-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

.ac-two-col .ac-field {
  margin-block-start: 12px;
}

.ac-switch-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-block-start: 12px;
}

.ac-small-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color .2s, border-color .2s, transform .2s;
}

.ac-small-btn svg {
  width: 13px;
  height: 13px;
}

.ac-small-btn:hover {
  color: var(--text-primary);
  border-color: var(--ac-accent);
  transform: translateY(-1px);
}

/* Quick diacritic keys */
.ac-quickkeys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-block-start: 9px;
}

.ac-quickkeys-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-inline-end: 3px;
}

.ac-key {
  width: 27px;
  height: 27px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 7px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}

.ac-key:hover {
  color: var(--ac-accent);
  border-color: var(--ac-accent);
  background: var(--ac-jade-soft);
}

/* Segmented controls */
.ac-seg {
  display: flex;
  gap: 5px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
}

.ac-full {
  display: flex;
  width: 100%;
  margin-block-end: 12px;
}

.ac-seg-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color .2s var(--ac-ease), background .2s var(--ac-ease), box-shadow .2s var(--ac-ease);
}

.ac-seg-btn:hover {
  color: var(--text-primary);
}

.ac-seg-btn.is-active {
  background: linear-gradient(135deg, var(--ac-jade), var(--ac-jade-deep));
  color: #fff;
  box-shadow: 0 4px 10px -6px rgba(15, 118, 110, .9);
}

.ac-seg-sm {
  padding: 3px;
}

.ac-seg-sm .ac-seg-btn {
  padding: 6px 4px;
  font-size: 11.5px;
}

.ac-seg-icons {
  padding: 3px;
  gap: 3px;
}

.ac-seg-icons .ac-seg-btn {
  display: grid;
  place-items: center;
  padding: 7px 0;
}

.ac-seg-icons svg {
  width: 15px;
  height: 15px;
}

.ac-seg-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

/* Colors */
.ac-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-block-start: 10px;
}

.ac-color-row .ac-label {
  margin-block-end: 0;
}

.ac-color-controls {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.ac-color {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--glass-border);
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  flex: 0 0 auto;
}

.ac-color::-webkit-color-swatch-wrapper {
  padding: 0;
}

.ac-color::-webkit-color-swatch {
  border: 0;
  border-radius: 8px;
}

.ac-color::-moz-color-swatch {
  border: 0;
  border-radius: 8px;
}

.ac-color:focus-visible {
  outline: 2px solid var(--ac-accent);
  outline-offset: 2px;
}

.ac-hex {
  width: 84px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  letter-spacing: .03em;
  text-transform: uppercase;
  direction: ltr;
  outline: 0;
}

.ac-hex:focus {
  border-color: var(--ac-accent);
}

.ac-hex.is-invalid {
  border-color: #ef4444;
}

.ac-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-block-start: 11px;
}

.ac-swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(128, 128, 128, .35);
  cursor: pointer;
  transition: transform .15s var(--ac-ease), box-shadow .15s var(--ac-ease);
}

.ac-swatch:hover {
  transform: scale(1.12);
}

.ac-swatch.is-active {
  box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px var(--ac-gold);
}

/* ---------- Phrase library ---------- */
.ac-library {
  margin: 4px 18px 8px;
  border-radius: 13px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  overflow: hidden;
}

.ac-library summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  cursor: pointer;
  user-select: none;
}

.ac-library summary::-webkit-details-marker {
  display: none;
}

.ac-library-icon {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ac-jade-soft);
  color: var(--ac-jade);
  flex: 0 0 auto;
}

html[data-theme="dark"] .ac-library-icon {
  color: var(--ac-accent);
}

.ac-library-icon svg {
  width: 16px;
  height: 16px;
}

.ac-library summary > span:nth-child(2) {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
}

.ac-library-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.ac-library-sub {
  font-size: 10.5px;
  color: var(--text-tertiary);
}

.ac-library-chevron {
  width: 15px;
  height: 15px;
  color: var(--text-tertiary);
  transition: transform .22s var(--ac-ease);
}

.ac-library[open] .ac-library-chevron {
  transform: rotate(180deg);
}

.ac-library-body {
  padding: 0 11px 11px;
  display: grid;
  gap: 8px;
}

.ac-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ac-chip {
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}

.ac-chip:hover {
  color: var(--text-primary);
}

.ac-chip.is-active {
  color: var(--text-primary);
  border-color: var(--ac-accent);
  background: var(--ac-jade-soft);
}

.ac-phrase-list {
  max-height: 248px;
  overflow-y: auto;
  border-radius: 9px;
  border: 1px solid var(--glass-border);
  background: var(--bg-card);
  scrollbar-width: thin;
  scrollbar-color: var(--glass-border-hover) transparent;
}

.ac-phrase-list::-webkit-scrollbar {
  width: 6px;
}

.ac-phrase-list::-webkit-scrollbar-thumb {
  background: var(--glass-border-hover);
  border-radius: 99px;
}

.ac-phrase {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-block-end: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-primary);
  text-align: start;
  cursor: pointer;
  transition: background .15s;
}

.ac-phrase:last-child {
  border-block-end: 0;
}

.ac-phrase:hover {
  background: var(--ac-jade-soft);
}

.ac-phrase-ar {
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: 19px;
  line-height: 1.55;
  direction: rtl;
  color: var(--text-primary);
}

.ac-phrase-en {
  font-size: 10.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.ac-phrase-empty {
  padding: 18px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ---------- Fonts ---------- */
.ac-font-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  max-height: 286px;
  overflow-y: auto;
  padding: 2px 3px 2px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--glass-border-hover) transparent;
}

.ac-font-grid::-webkit-scrollbar {
  width: 6px;
}

.ac-font-grid::-webkit-scrollbar-thumb {
  background: var(--glass-border-hover);
  border-radius: 99px;
}

.ac-font-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 9px 10px 8px;
  border-radius: 9px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  text-align: start;
  cursor: pointer;
  transition: border-color .18s var(--ac-ease), background .18s var(--ac-ease), transform .18s var(--ac-ease);
}

.ac-font-card:hover {
  border-color: var(--glass-border-hover);
  transform: translateY(-1px);
}

.ac-font-card.is-active {
  border-color: var(--ac-accent);
  background: var(--ac-jade-soft);
  box-shadow: inset 0 0 0 1px var(--ac-accent);
}

.ac-font-sample {
  display: block;
  font-size: 20px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
}

.ac-font-name {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-font-cat {
  display: block;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.ac-font-card.is-active .ac-font-name {
  color: var(--text-primary);
}

.ac-font-empty {
  grid-column: 1 / -1;
  padding: 16px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ---------- Placement / fields ---------- */
.ac-num-input::-webkit-outer-spin-button,
.ac-num-input::-webkit-inner-spin-button {
  opacity: .5;
}

/* ---------- Presets ---------- */
.ac-preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.ac-preset-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 5px 5px 7px;
  border-radius: 11px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  cursor: pointer;
  text-align: start;
  transition: transform .2s var(--ac-ease), border-color .2s var(--ac-ease), box-shadow .2s var(--ac-ease);
}

.ac-preset-card:hover {
  transform: translateY(-2px);
  border-color: var(--glass-border-hover);
}

.ac-preset-card.is-active {
  border-color: var(--ac-gold);
  box-shadow: 0 0 0 1px var(--ac-gold);
}

.ac-preset-visual {
  position: relative;
  display: grid;
  place-items: center;
  height: 64px;
  border-radius: 7px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--p-bg1, #f6efe2), var(--p-bg2, #e7d7ba));
}

.ac-preset-visual::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid var(--p-frame, #b08d57);
  border-radius: 2px;
  opacity: .85;
  pointer-events: none;
}

.ac-preset-word {
  position: relative;
  z-index: 1;
  font-family: var(--p-font, "Amiri"), serif;
  font-size: 26px;
  line-height: 1;
  font-weight: var(--p-weight, 400);
  background-image: linear-gradient(135deg, var(--p-ink1, #14342b), var(--p-ink2, #14342b));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--p-ink1, #14342b);
  max-width: 88%;
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
}

.ac-preset-name {
  display: block;
  padding-inline: 3px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.35;
}

.ac-preset-card.is-active .ac-preset-name {
  color: var(--text-primary);
}

.ac-preset-check {
  position: absolute;
  inset-block-start: 9px;
  inset-inline-end: 9px;
  z-index: 2;
  width: 15px;
  height: 15px;
  display: none;
  place-items: center;
  border-radius: 50%;
  background: var(--ac-gold);
  color: #211708;
}

.ac-preset-check svg {
  width: 9px;
  height: 9px;
}

.ac-preset-card.is-active .ac-preset-check {
  display: grid;
}

/* ---------- Artboards ---------- */
.ac-artboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.ac-board-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 9px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  cursor: pointer;
  text-align: start;
  transition: border-color .18s, background .18s;
}

.ac-board-card:hover {
  border-color: var(--glass-border-hover);
}

.ac-board-card.is-active {
  border-color: var(--ac-accent);
  background: var(--ac-jade-soft);
}

.ac-board-shape {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
}

.ac-board-shape span {
  display: block;
  width: calc(20px * var(--ar-w, 1));
  height: calc(20px * var(--ar-h, 1));
  max-width: 22px;
  max-height: 22px;
  border-radius: 2px;
  border: 1.5px solid var(--text-tertiary);
  background: color-mix(in srgb, var(--ac-jade) 12%, transparent);
}

.ac-board-card.is-active .ac-board-shape span {
  border-color: var(--ac-accent);
}

.ac-board-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.ac-board-name {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-board-card.is-active .ac-board-name {
  color: var(--text-primary);
}

.ac-board-dim {
  font-size: 9.5px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ac-custom-size {
  margin-block-start: 12px;
  padding: 11px;
  border-radius: 10px;
  border: 1px dashed var(--glass-border-hover);
  background: var(--glass-bg);
}

.ac-custom-size .ac-field {
  margin-block-start: 0;
}

.ac-apply-btn {
  width: 100%;
  margin-block-start: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--ac-accent);
  background: transparent;
  color: var(--ac-accent);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, color .2s;
}

.ac-apply-btn:hover {
  background: var(--ac-jade-soft);
}

/* ---------- Texture tiles ---------- */
.ac-texture-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.ac-texture-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 4px 6px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  cursor: pointer;
  transition: border-color .18s, background .18s;
}

.ac-texture-card:hover {
  border-color: var(--glass-border-hover);
}

.ac-texture-card.is-active {
  border-color: var(--ac-accent);
  background: var(--ac-jade-soft);
}

.ac-texture-visual {
  display: block;
  height: 34px;
  border-radius: 5px;
  border: 1px solid rgba(128, 128, 128, .18);
  background-color: #efe7d6;
}

.ac-texture-card[data-texture="none"] .ac-texture-visual {
  background-image: linear-gradient(135deg, transparent 46%, rgba(120, 113, 90, .5) 46%, rgba(120, 113, 90, .5) 54%, transparent 54%);
  background-color: transparent;
}

.ac-texture-card[data-texture="paper"] .ac-texture-visual {
  background-color: #f2e9d8;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(112, 89, 49, .14) 0 1px, transparent 1.5px),
    radial-gradient(circle at 70% 60%, rgba(112, 89, 49, .11) 0 1px, transparent 1.5px),
    radial-gradient(circle at 45% 80%, rgba(255, 255, 255, .6) 0 1px, transparent 1.5px);
  background-size: 9px 9px, 13px 13px, 17px 17px;
}

.ac-texture-card[data-texture="grain"] .ac-texture-visual {
  background-color: #111a17;
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .1) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .07) 0 1px, transparent 1px 3px);
}

.ac-texture-card[data-texture="geometric"] .ac-texture-visual {
  background-color: #0b3b34;
  background-image:
    linear-gradient(45deg, transparent 46%, rgba(217, 190, 134, .5) 46%, rgba(217, 190, 134, .5) 54%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, rgba(217, 190, 134, .3) 46%, rgba(217, 190, 134, .3) 54%, transparent 54%);
  background-size: 14px 14px;
}

.ac-texture-label {
  font-size: 9px;
  font-weight: 600;
  text-align: center;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Frame tiles ---------- */
.ac-frame-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-block-end: 12px;
}

.ac-frame-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  cursor: pointer;
  transition: border-color .18s, background .18s;
  text-align: start;
}

.ac-frame-card:hover {
  border-color: var(--glass-border-hover);
}

.ac-frame-card.is-active {
  border-color: var(--ac-accent);
  background: var(--ac-jade-soft);
}

.ac-frame-visual {
  position: relative;
  flex: 0 0 auto;
  width: 30px;
  height: 24px;
  border-radius: 2px;
  background: #efe7d6;
}

.ac-frame-card[data-frame="none"] .ac-frame-visual {
  border: 1px dashed rgba(120, 113, 90, .45);
  background: transparent;
}

.ac-frame-visual svg {
  width: 100%;
  height: 100%;
  display: block;
}

.ac-frame-label {
  font-size: 9.5px;
  font-weight: 600;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-frame-card.is-active .ac-frame-label {
  color: var(--text-primary);
}

/* ---------- Ornament choices ---------- */
.ac-choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.ac-choice {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color .18s, border-color .18s, background .18s;
  text-align: start;
}

.ac-choice:hover {
  color: var(--text-primary);
  border-color: var(--glass-border-hover);
}

.ac-choice.is-active {
  color: var(--text-primary);
  border-color: var(--ac-accent);
  background: var(--ac-jade-soft);
}

.ac-choice-icon {
  width: 21px;
  height: 18px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--ac-gold);
}

.ac-choice-icon svg {
  width: 19px;
  height: 16px;
  display: block;
}

/* ---------- Script styles section ---------- */
.ac-scripts .at-section-title {
  margin-block-end: 10px;
}

.ac-eyebrow {
  display: inline-block;
  margin-block-end: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ac-gold);
}

.ac-section-lead {
  max-width: 68ch;
  margin: 0 0 22px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.ac-script-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(238px, 1fr));
  gap: 14px;
}

.ac-script-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  border-radius: var(--at-radius-lg);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-primary);
  text-align: start;
  cursor: pointer;
  overflow: hidden;
  transition: transform .25s var(--ac-ease), border-color .25s var(--ac-ease), box-shadow .25s var(--ac-ease);
}

.ac-script-card:hover {
  transform: translateY(-4px);
  border-color: var(--ac-gold);
  box-shadow: 0 22px 44px -30px rgba(0, 0, 0, .55);
}

.ac-script-sample {
  display: grid;
  place-items: center;
  min-height: 100px;
  padding: 16px 10px 20px;
  font-size: clamp(34px, 3.6vw, 44px);
  line-height: 1;
  color: var(--ac-jade);
  background:
    radial-gradient(120% 100% at 50% 0%, color-mix(in srgb, var(--ac-gold) 16%, transparent), transparent 68%),
    color-mix(in srgb, var(--bg-secondary) 55%, transparent);
  border-block-end: 1px solid var(--glass-border);
  direction: rtl;
}

html[data-theme="dark"] .ac-script-sample {
  color: var(--ac-accent);
}

.ac-script-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 15px 16px 16px;
  flex: 1;
}

.ac-script-name {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -.01em;
}

.ac-script-desc {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-secondary);
  flex: 1;
}

.ac-script-cta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-block-start: 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ac-gold);
}

.ac-script-cta svg {
  width: 13px;
  height: 13px;
  transition: transform .2s var(--ac-ease);
}

.ac-script-card:hover .ac-script-cta svg {
  transform: translateX(3px);
}

[dir="rtl"] .ac-script-cta svg {
  transform: scaleX(-1);
}

[dir="rtl"] .ac-script-card:hover .ac-script-cta svg {
  transform: scaleX(-1) translateX(3px);
}

.ac-scripts-note {
  margin: 16px 0 0;
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.6;
}

/* ---------- How-to accents ---------- */
.ac-step .at-step-num {
  background: var(--ac-jade-soft);
  color: var(--ac-jade);
}

html[data-theme="dark"] .ac-step .at-step-num {
  color: var(--ac-accent);
}

/* ---------- CTA accent ---------- */
body.at-calligraphy .at-cta {
  background: linear-gradient(135deg, #0f766e, #115e59 56%, #b48a3c);
  color: #fdfaf1;
  box-shadow: 0 40px 90px -46px rgba(15, 118, 110, .9);
}

body.at-calligraphy .at-cta p {
  color: rgba(253, 250, 241, .82);
}

body.at-calligraphy .at-cta .at-btn {
  background: #0b2823;
  color: #f4e3bd;
  box-shadow: 0 16px 34px -18px rgba(11, 40, 35, .9);
}

body.at-calligraphy .at-cta::before,
body.at-calligraphy .at-cta::after {
  background: rgba(255, 255, 255, .16);
}

/* ---------- Dialog / export ---------- */
.ac-modal {
  width: min(600px, calc(100vw - 28px));
  max-height: min(90vh, 880px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--glass-border);
  border-radius: 22px;
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 50px 120px -40px rgba(0, 0, 0, .7);
  overflow: hidden;
}

.ac-modal[open] {
  display: flex;
  flex-direction: column;
  animation: ac-modal-in .24s var(--ac-ease);
}

.ac-modal::backdrop {
  background: rgba(8, 14, 12, .62);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.ac-modal-sm {
  width: min(440px, calc(100vw - 28px));
}

@keyframes ac-modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ac-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 12px;
  flex: 0 0 auto;
}

.ac-modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  letter-spacing: -.02em;
}

.ac-modal-head p {
  margin: 5px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-tertiary);
  max-width: 46ch;
}

.ac-modal-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
}

.ac-modal-body {
  padding: 6px 24px 18px;
  overflow-y: auto;
  min-height: 0;
}

.ac-format-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-block-end: 16px;
}

.ac-format {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 9px;
  row-gap: 1px;
  align-items: center;
  padding: 10px 11px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-primary);
  text-align: start;
  cursor: pointer;
  transition: border-color .18s var(--ac-ease), background .18s var(--ac-ease);
}

.ac-format:hover {
  border-color: var(--glass-border-hover);
}

.ac-format.is-active {
  border-color: var(--ac-accent);
  background: var(--ac-jade-soft);
  box-shadow: inset 0 0 0 1px var(--ac-accent);
}

.ac-format-icon {
  grid-row: 1 / 3;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
}

.ac-format.is-active .ac-format-icon {
  color: var(--ac-accent);
  border-color: color-mix(in srgb, var(--ac-accent) 40%, transparent);
}

.ac-format-icon svg {
  width: 17px;
  height: 17px;
}

.ac-format-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}

.ac-format-hint {
  font-size: 9.5px;
  line-height: 1.35;
  color: var(--text-tertiary);
}

.ac-modal-options {
  display: grid;
  gap: 2px;
}

.ac-modal-options .ac-field:first-child {
  margin-block-start: 0;
}

.ac-modal-switch {
  margin-block-start: 14px;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
}

.ac-modal-badge {
  font-size: 9.5px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
}

.ac-export-summary {
  margin: 14px 0 0;
  padding: 9px 11px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--ac-gold) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--ac-gold) 28%, transparent);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  unicode-bidi: isolate;
}

[dir="rtl"] #acExportScale {
  text-align: right;
}

.ac-svg-note {
  margin: 9px 0 0;
  font-size: 11px;
  line-height: 1.55;
  color: var(--text-tertiary);
}

.ac-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px 20px;
  border-block-start: 1px solid var(--glass-border);
  background: color-mix(in srgb, var(--bg-card) 94%, transparent);
  flex: 0 0 auto;
}

.ac-modal-foot-simple {
  border: 0;
  padding-block-start: 6px;
}

.ac-download-btn {
  min-height: 40px;
  padding: 10px 20px;
  font-size: 13.5px;
  border-radius: 10px;
}

.ac-download-btn[disabled] {
  opacity: .6;
  cursor: progress;
}

.ac-danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid color-mix(in srgb, #ef4444 45%, transparent);
  background: color-mix(in srgb, #ef4444 12%, transparent);
  color: #b91c1c;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

html[data-theme="dark"] .ac-danger-btn {
  color: #fca5a5;
}

.ac-danger-btn:hover {
  background: color-mix(in srgb, #ef4444 20%, transparent);
}

/* ---------- Toast above dialogs ---------- */
body.at-calligraphy .toast {
  z-index: 100000;
}

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .ac-grid {
    grid-template-columns: minmax(0, 1fr) 372px;
  }
}

@media (max-width: 1100px) {
  .ac-grid {
    display: block;
  }

  /* Drop the column box so the sticky preview is contained by the whole grid. */
  .ac-stage-col {
    display: contents;
  }

  .ac-side {
    margin-block-start: 16px;
  }

  .ac-stage-panel {
    position: sticky;
    inset-block-start: calc(var(--nav-height) + 12px);
    z-index: 30;
  }

  .ac-inspector {
    position: static;
    max-height: none;
  }

  .ac-tab-panels {
    overflow: visible;
  }

  .ac-stage {
    height: clamp(340px, 56vh, 620px);
    transition: height .22s var(--ac-ease);
  }

  .ac-stage-panel.is-docked {
    background-color: var(--bg-primary);
    background-image: linear-gradient(var(--bg-card), var(--bg-card));
    box-shadow: 0 22px 48px -24px rgba(3, 12, 9, .55);
  }

  .ac-stage-panel.is-docked .ac-stage {
    height: clamp(190px, 30vh, 320px);
  }

  .ac-stage-panel.is-docked .ac-stage-hint {
    display: none;
  }

  .ac-hero-mark {
    font-size: clamp(80px, 16vw, 150px);
  }
}

@media (max-width: 760px) {
  .ac-topbar {
    padding: 11px 0 0;
  }

  .ac-topbar-right {
    width: 100%;
    justify-content: flex-end;
  }

  .ac-save-status {
    font-size: 11px;
  }

  .ac-export-btn {
    flex: 1;
  }

  .ac-stage {
    height: clamp(300px, 48vh, 500px);
  }

  .ac-stage-inner {
    padding: 16px;
  }

  .ac-stage-foot {
    align-items: flex-start;
    gap: 10px;
  }

  .ac-stage-panel.is-docked .ac-stage-meta {
    display: none;
  }

  .ac-view-tools {
    width: 100%;
    justify-content: space-between;
  }

  .ac-stage-hint {
    text-align: start;
  }

  .ac-font-grid {
    max-height: 250px;
  }

  .ac-script-grid {
    grid-template-columns: 1fr 1fr;
  }

  .ac-script-desc {
    font-size: 12px;
  }

  .ac-modal-head {
    padding: 18px 16px 10px;
  }

  .ac-modal-body {
    padding: 4px 16px 14px;
  }

  .ac-modal-foot {
    padding: 12px 16px 16px;
  }

  .ac-format-grid {
    gap: 6px;
  }

  .ac-format-hint {
    display: none;
  }

  .ac-export-btn {
    padding-inline: 14px;
  }
}

@media (max-width: 560px) {
  .ac-topbar-left {
    width: 100%;
    justify-content: space-between;
  }

  .ac-icon-btn {
    width: 35px;
    height: 35px;
  }

  .ac-ghost-btn span {
    display: none;
  }

  .ac-ghost-btn {
    padding: 8px 10px;
    min-height: 36px;
  }

  .ac-export-btn span {
    display: inline;
  }

  .ac-stage-panel {
    padding: 9px;
  }

  .ac-stage {
    height: clamp(270px, 42vh, 420px);
  }

  .ac-stage-inner {
    padding: 10px;
  }

  .ac-panel {
    padding-inline: 13px;
  }

  .ac-library {
    margin-inline: 13px;
  }

  .ac-two-col {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .ac-two-col .ac-field {
    margin-block-start: 12px;
  }

  .ac-font-grid {
    grid-template-columns: 1fr 1fr;
  }

  .ac-preset-grid {
    grid-template-columns: 1fr 1fr;
  }

  .ac-script-grid {
    grid-template-columns: 1fr;
  }

  .ac-script-sample {
    min-height: 84px;
  }

  .ac-modal {
    width: calc(100vw - 16px);
    max-height: 92vh;
    border-radius: 18px;
  }

  .ac-format-grid {
    grid-template-columns: 1fr 1fr;
  }

  .ac-format {
    grid-template-columns: auto 1fr;
    padding: 8px 9px;
  }

  .ac-format-icon {
    width: 27px;
    height: 27px;
  }

  .ac-format-name {
    font-size: 12px;
  }

  .ac-stage-meta .ac-meta-chip:nth-child(2) {
    display: none;
  }

  .ac-zoom-range {
    width: 64px;
  }

  .ac-shortcuts {
    display: none;
  }

  .ac-hero-mark {
    display: none;
  }

  .ac-textarea {
    font-size: 19px;
  }
}

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  body.at-calligraphy *,
  body.at-calligraphy *::before,
  body.at-calligraphy *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
