/* ===== Design tokens ===== */
:root {
  --bg: #0b0e13;
  --surface: #12161d;
  --surface-2: #171c25;
  --border: #232a35;
  --text: #e7ecf3;
  --muted: #93a0b4;
  --accent: #2ee6a8;
  --accent-2: #7aa2ff;
  --danger: #ff6b6b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

[data-theme='light'] {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e7ef;
  --text: #141a22;
  --muted: #5d6b80;
  --accent: #0ea97a;
  --accent-2: #3b6cf6;
  --shadow: 0 10px 30px rgba(20, 26, 34, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px 64px; }

/* ===== Header ===== */
.site-header {
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  margin-bottom: 28px;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 22px;
  padding-bottom: 22px;
}
.logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06110d;
  font-size: 24px; font-weight: 700;
  flex: none;
}
.titles h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.2px; }
.titles p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

/* ===== Buttons ===== */
.btn {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.05s ease, background 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06110d;
  border-color: transparent;
  font-weight: 600;
}
.btn.ghost { background: transparent; }
.btn.tiny { padding: 4px 10px; font-size: 12px; border-radius: 8px; }

/* ===== Layout ===== */
.grid { display: grid; grid-template-columns: 1.05fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card > header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card .hint { color: var(--muted); font-size: 12px; }

/* ===== Editor ===== */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
textarea#input {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  font: inherit;
  font-size: 15px;
  line-height: 1.9;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.15s ease;
}
textarea#input:focus { border-color: var(--accent); }
.editor-meta {
  display: flex; gap: 14px; flex-wrap: wrap;
  margin-top: 10px; color: var(--muted); font-size: 12px;
}
.editor-meta b { color: var(--text); font-weight: 600; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.stat .v {
  font-size: 22px; font-weight: 700; line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.stat .k { color: var(--muted); font-size: 12px; }

/* ===== Word chart ===== */
.words { display: flex; flex-direction: column; gap: 9px; }
.word-row { display: grid; grid-template-columns: 110px 1fr 42px; align-items: center; gap: 10px; }
.word-row .w { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.word-row .c { color: var(--muted); font-size: 12px; text-align: left; font-variant-numeric: tabular-nums; }
.track {
  display: block;
  height: 9px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s ease;
}
.bar.over { background: linear-gradient(90deg, var(--danger), #ff9f43); }

/* ===== Platforms ===== */
.platform { margin-bottom: 12px; }
.platform .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.platform .num { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.platform .num.over { color: var(--danger); font-weight: 600; }

/* ===== Transforms ===== */
.card.wide { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.card.wide > header,
.card.wide > .options { grid-column: 1 / -1; }
@media (max-width: 700px) { .card.wide { display: block; } }

.options { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.options label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); cursor: pointer;
}
.options input { accent-color: var(--accent); }
.out { margin-bottom: 14px; }
.out .row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.out .row h3 { margin: 0; font-size: 13px; font-weight: 600; }
.out pre {
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  max-height: 150px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  min-height: 42px;
}
.out pre:empty::after { content: 'لا يوجد نص بعد…'; color: var(--muted); }

.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

/* ===== Footer ===== */
footer.site {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  padding: 18px 0;
  display: flex; gap: 10px; flex-wrap: wrap;
}
footer.site a { color: var(--accent-2); text-decoration: none; }
footer.site a:hover { text-decoration: underline; }

.toast {
  position: fixed;
  inset-block-end: 24px; inset-inline-start: 24px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
