:root {
  --font: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius-sm: 0.75rem;
  --radius: 1rem;
  --radius-lg: 1.5rem;

  color-scheme: light;
  --bg: #f4f5fb;
  --glow-1: rgb(124 92 255 / 0.14);
  --glow-2: rgb(46 233 166 / 0.1);
  --surface: #ffffff;
  --surface-2: #f1f2f9;
  --surface-3: #e7e9f4;
  --text: #12152b;
  --muted: #5a6079;
  --border: #e0e3ef;
  --border-strong: #c7cbe0;

  --accent: #6f4cff;
  --accent-hover: #5d3be8;
  --on-accent: #ffffff;
  --accent-soft: rgb(111 76 255 / 0.12);
  --accent-text: #5a38f0;

  --success: #0c8f64;
  --success-soft: rgb(12 143 100 / 0.12);
  --warning: #9a5b00;
  --warning-soft: rgb(217 119 6 / 0.14);
  --danger: #d62f2f;
  --danger-soft: rgb(214 47 47 / 0.1);
  --info: #1769c8;
  --info-soft: rgb(23 105 200 / 0.1);

  --shadow-sm: 0 1px 2px rgb(18 24 40 / 0.06);
  --shadow: 0 10px 30px rgb(18 24 40 / 0.08);
  --focus-ring: 0 0 0 3px rgb(111 76 255 / 0.35);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1020;
  --glow-1: rgb(124 92 255 / 0.2);
  --glow-2: rgb(46 233 166 / 0.08);
  --surface: #131c3a;
  --surface-2: #1a2347;
  --surface-3: #232d58;
  --text: #f2f4ff;
  --muted: #a9b0d0;
  --border: rgb(255 255 255 / 0.12);
  --border-strong: rgb(255 255 255 / 0.22);

  --accent: #7c5cff;
  --accent-hover: #6b49f5;
  --accent-soft: rgb(124 92 255 / 0.22);
  --accent-text: #b0a3ff;

  --success: #2ee9a6;
  --success-soft: rgb(46 233 166 / 0.14);
  --warning: #fbbf24;
  --warning-soft: rgb(251 191 36 / 0.14);
  --danger: #ff8a8a;
  --danger-soft: rgb(255 122 122 / 0.14);
  --info: #7db8ff;
  --info-soft: rgb(125 184 255 / 0.14);

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow: 0 16px 40px rgb(0 0 0 / 0.4);
  --focus-ring: 0 0 0 3px rgb(124 92 255 / 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0b1020;
    --glow-1: rgb(124 92 255 / 0.2);
    --glow-2: rgb(46 233 166 / 0.08);
    --surface: #131c3a;
    --surface-2: #1a2347;
    --surface-3: #232d58;
    --text: #f2f4ff;
    --muted: #a9b0d0;
    --border: rgb(255 255 255 / 0.12);
    --border-strong: rgb(255 255 255 / 0.22);
    --accent: #7c5cff;
    --accent-hover: #6b49f5;
    --accent-soft: rgb(124 92 255 / 0.22);
    --accent-text: #b0a3ff;
    --success: #2ee9a6;
    --success-soft: rgb(46 233 166 / 0.14);
    --warning: #fbbf24;
    --warning-soft: rgb(251 191 36 / 0.14);
    --danger: #ff8a8a;
    --danger-soft: rgb(255 122 122 / 0.14);
    --info: #7db8ff;
    --info-soft: rgb(125 184 255 / 0.14);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow: 0 16px 40px rgb(0 0 0 / 0.4);
    --focus-ring: 0 0 0 3px rgb(124 92 255 / 0.5);
  }
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(60rem 28rem at 15% -5%, var(--glow-1), transparent 60%),
    radial-gradient(48rem 26rem at 95% 0%, var(--glow-2), transparent 55%);
  background-repeat: no-repeat;
  overflow-wrap: anywhere;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
figure {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

img,
svg,
canvas,
video {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent-text);
  text-underline-offset: 0.2em;
}

::selection {
  background: var(--accent-soft);
}

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

[hidden] {
  display: none !important;
}

/* ---------- Layout ---------- */
.page {
  width: min(100%, 72rem);
  margin-inline: auto;
  padding: calc(1.25rem + 0.5rem) max(1rem, env(safe-area-inset-right))
    calc(2rem + env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

.page--narrow {
  width: min(100%, 48rem);
}

.page-header {
  margin-bottom: 1.25rem;
}

.page-title {
  font-size: clamp(1.375rem, 1.1rem + 1.4vw, 2rem);
  line-height: 1.35;
  font-weight: 800;
}

.page-lead {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

.page-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.grid-cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
}

.grid-cards--sm {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
}

/* ---------- Card ---------- */
.card {
  padding: 1.125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.card--lg {
  padding: clamp(1.125rem, 4vw, 1.75rem);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.card-title {
  margin-bottom: 0.75rem;
  font-size: 1.0625rem;
  font-weight: 700;
}

@media (hover: hover) {
  .card--hover {
    transition:
      transform 0.15s ease,
      border-color 0.15s ease,
      box-shadow 0.15s ease;
  }

  .card--hover:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: var(--shadow);
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 1.125rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    transform 0.1s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn--secondary {
  border-color: var(--border-strong);
  background: var(--surface);
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
}

.btn--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn--sm {
  min-height: 2.25rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

.btn--block {
  width: 100%;
}

@media (hover: hover) {
  .btn:hover:not(:disabled) {
    border-color: var(--accent);
  }

  .btn--primary:hover:not(:disabled) {
    background: var(--accent-hover);
  }

  .btn--ghost:hover:not(:disabled) {
    background: var(--accent-soft);
    color: var(--text);
  }
}

/* ---------- Forms ---------- */
.label {
  display: block;
  margin-bottom: 0.375rem;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.hint {
  margin-top: 0.375rem;
  color: var(--muted);
  font-size: 0.8125rem;
}

/* 16px font on inputs prevents the iOS zoom-on-focus */
.field {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 1rem;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background-color 0.15s ease;
}

.field::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.field:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--focus-ring);
}

textarea.field {
  min-height: 7rem;
  resize: vertical;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
}

.search .field {
  padding-inline: 2.75rem;
  border-radius: 999px;
}

.search .field::-webkit-search-cancel-button {
  display: none;
}

.search-icon {
  position: absolute;
  inset-inline-start: 0.9rem;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  inset-inline-end: 0.375rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.search-clear:hover {
  background: var(--accent-soft);
  color: var(--text);
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 1 0 auto;
  min-height: 2.75rem;
  padding: 0.5rem 1.125rem;
  border: 0;
  border-radius: calc(var(--radius) - 0.25rem);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-sm);
}

@media (hover: hover) {
  .tab:hover:not([aria-selected="true"]) {
    color: var(--text);
  }
}

/* ---------- Badges, chips, alerts ---------- */
.badge,
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.badge {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.badge--success {
  background: var(--success-soft);
  color: var(--success);
}

.badge--warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
}

.alert {
  padding: 0.75rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
}

.alert--info {
  border-color: var(--info);
  background: var(--info-soft);
  color: var(--info);
}

.alert--success {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.alert--warning {
  border-color: var(--warning);
  background: var(--warning-soft);
  color: var(--warning);
}

.alert--danger {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.empty {
  padding: 2.5rem 1rem;
  color: var(--muted);
  text-align: center;
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.table th,
.table td {
  padding: 0.625rem 0.875rem;
  text-align: start;
}

.table th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.table td {
  border-top: 1px solid var(--border);
}

/* ---------- Utilities ---------- */
.divider {
  height: 1px;
  margin-block: 1rem;
  border: 0;
  background: var(--border);
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: var(--mono);
}

.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

.text-center {
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  .page {
    padding-inline: max(0.75rem, env(safe-area-inset-right))
      max(0.75rem, env(safe-area-inset-left));
  }

  .card {
    padding: 1rem;
  }

  .row > .btn {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Append to assets/tools.css: segmented radio group ---------- */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segmented-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0.375rem 0.75rem;
  border-radius: calc(var(--radius) - 0.25rem);
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.segmented-item input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented-item:has(input:checked) {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-sm);
}

.segmented-item:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Append to assets/tools.css: modal built on <dialog> ---------- */
.modal {
  width: min(92vw, 32rem);
  max-height: 85dvh;
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal[open] {
  display: flex;
  flex-direction: column;
}

.modal::backdrop {
  background: rgb(8 12 28 / 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
}

.modal-header {
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  justify-content: center;
  border-top: 1px solid var(--border);
}

.modal-title {
  color: var(--accent-text);
  font-size: 1.125rem;
  font-weight: 800;
}

.modal-body {
  flex: 1;
  min-height: 0;
  padding: 1rem;
  overflow-y: auto;
}

/* ---------- Append to assets/tools.css (after tools-additions.css) ---------- */

.eyebrow {
  color: var(--accent-text);
  font-size: 0.8125rem;
  font-weight: 700;
}

.btn--icon {
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
}

/* Input + submit button on one line */
.input-row {
  display: flex;
  gap: 0.5rem;
}

.input-row .field {
  flex: 1;
  min-width: 0;
}

.field::file-selector-button {
  margin-inline-end: 0.75rem;
  padding: 0.25rem 0.75rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--accent-soft);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* Round checkbox */
.checkbox {
  display: inline-grid;
  flex: none;
  place-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.checkbox::after {
  content: "";
  width: 0.375rem;
  height: 0.7rem;
  margin-top: -0.1rem;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.12s ease;
}

.checkbox:checked {
  border-color: var(--success);
  background: var(--success);
}

.checkbox:checked::after {
  transform: rotate(45deg) scale(1);
}

/* Progress bar */
.progress {
  height: 0.5rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.25s ease;
}

/* Toast */
.toast {
  position: fixed;
  inset-inline: 0;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 10000;
  width: fit-content;
  max-width: min(92vw, 28rem);
  margin-inline: auto;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
  animation: toast-in 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* <dialog> that wraps a <form> */
.modal-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-footer--split {
  justify-content: flex-end;
}
