/* عربي — the styles every page shares: font, colours, buttons, the code
   editor and highlighting, and program output. */

@font-face {
  font-family: 'Droid Arabic Naskh';
  src: url('fonts/DroidNaskh-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Droid Arabic Naskh';
  src: url('fonts/DroidNaskh-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --bg-page: #f4f1ea;
  --bg-panel: #ffffff;
  --bg-soft: #f8f6f1;
  --bg-hover: #efebe2;
  --text-primary: #1c2430;
  --text-secondary: #4b5563;
  --text-muted: #8a8f98;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #e3f1ef;
  --red: #c62828;
  --red-soft: #fdecec;
  --red-text: #8e1c1c;
  --on-accent: #ffffff;
  --selection: rgba(15, 118, 110, 0.18);
  --border: #e4dfd4;
  --border-strong: #d2cbbd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 36, 48, 0.05), 0 4px 16px rgba(28, 36, 48, 0.05);
  --font: 'Droid Arabic Naskh', 'Segoe UI', Tahoma, serif;
  --code-line: 1.95;

  /* syntax */
  --tok-keyword: #7c3aed;
  --tok-builtin: #0369a1;
  --tok-string: #15803d;
  --tok-number: #b45309;
  --tok-comment: #8a8f98;
  --tok-operator: #6b7280;
  --tok-boolean: #c2410c;
  --tok-atom: #c2410c;
  --tok-identifier: #1c2430;
  --tok-bracket: #6b7280;
  --tok-punct: #6b7280;
}


kbd {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78em;
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--bg-soft);
  color: var(--text-secondary);
}

/* ── Header ─────────────────────────── */

header {
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.logo { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }

.logo-icon {
  width: 38px;
  height: 38px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  padding-bottom: 4px;
  color: var(--on-accent);
}

.logo-text { font-size: 24px; font-weight: 700; line-height: 1; }
.logo-version { font-size: 12px; color: var(--text-muted); direction: ltr; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-right: auto; }

.btn {
  font-family: var(--font);
  border: 1px solid transparent;
  border-radius: 10px;
  height: 40px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

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

.btn-run { background: var(--accent); color: var(--on-accent); padding: 0 18px; }
.btn-run:hover:not(:disabled) { background: var(--accent-hover); }
.btn-stop { background: var(--red); color: var(--on-accent); padding: 0 18px; }
.btn-stop:hover { filter: brightness(0.9); }

.btn-run kbd, .btn-stop kbd {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
  color: inherit;
}

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

.btn-secondary { background: var(--bg-panel); color: var(--text-secondary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-secondary.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.btn-icon { background: transparent; color: var(--text-secondary); padding: 0; width: 40px; justify-content: center; }
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon.active { background: var(--accent-soft); color: var(--accent); }

.mini-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px 12px 4px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.mini-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.mini-btn.copied { color: var(--accent); border-color: var(--accent); }

/* ── Code editor ────────────────────── */

.code-area {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--bg-panel);
  overflow: hidden;
}

/* the line-number gutter */
.code-area::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 3.4rem;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
}

.code-surface {
  font-family: var(--font);
  font-size: 18px;
  line-height: var(--code-line);
  direction: rtl;
  text-align: right;
  tab-size: 4;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  padding: 14px 4.3rem 14px 1.25rem;
  border: none;
  margin: 0;
  /* Both layers reserve the scrollbar's space, so long lines wrap at the
     same width in the highlight and in the textarea. */
  scrollbar-gutter: stable;
}

.code-highlight {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 1;
  color: var(--text-primary);
  pointer-events: none;
  counter-reset: hl;
}

.code-input {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: transparent;
  color: transparent;
  caret-color: var(--accent);
  resize: none;
  outline: none;
  overflow: auto;
}

.code-input::placeholder { color: var(--text-muted); }
.code-input::selection { background: var(--selection); }

.hl-line { position: relative; counter-increment: hl; border-radius: 4px; }

.hl-line::before {
  content: counter(hl);
  position: absolute;
  top: 0;
  right: -4.15rem;
  width: 3rem;
  text-align: center;
  direction: ltr;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.hl-error-line { background: var(--red-soft); }
.hl-error-line::before { color: var(--red); font-weight: 700; }

/* syntax tokens */
.tok-keyword { color: var(--tok-keyword); font-weight: 700; }
.tok-builtin { color: var(--tok-builtin); font-weight: 700; }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-comment { color: var(--tok-comment); }
.tok-operator { color: var(--tok-operator); }
.tok-boolean, .tok-atom { color: var(--tok-boolean); }
.tok-identifier { color: var(--tok-identifier); }
.tok-bracket { color: var(--tok-bracket); }
.tok-punct { color: var(--tok-punct); }

.output-line { padding: 1px 0; white-space: pre-wrap; word-break: break-word; }
.output-normal { color: var(--text-primary); }

.output-error {
  color: var(--red-text);
  background: var(--red-soft);
  padding: 10px 14px;
  border-radius: 8px;
  border-right: 3px solid var(--red);
  margin: 6px 0;
  font-size: 15px;
}

.output-info { color: var(--text-muted); font-size: 14px; }

.output-input { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px; }

.input-field {
  flex: 1;
  min-width: 8rem;
  font: inherit;
  color: var(--accent);
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 2px 10px;
  outline: none;
}

.input-field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-echo { color: var(--accent); }

.en {
  display: block;
  direction: ltr;
  text-align: left;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.6;
}
/* ── Scrollbars ─────────────────────── */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid var(--bg-panel); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }


/* ── Theme menu (theme.js) ──────────── */

.theme-menu {
  position: fixed;
  z-index: 100;
  width: 320px;
  max-height: min(560px, calc(100vh - 90px));
  overflow-y: auto;
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  padding: 10px;
  font-family: var(--font);
}
.theme-menu h3 { font-size: 16px; padding: 4px 8px 8px; display: flex; align-items: baseline; gap: 8px; }
.theme-menu h3 .en { display: inline; }
.theme-menu h4 { font-size: 13px; color: var(--text-muted); padding: 10px 8px 4px; display: flex; gap: 6px; }
.theme-menu h4 .en { display: inline; font-size: 12px; }
.theme-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 15px;
  text-align: right;
  cursor: pointer;
}
.theme-item:hover, .theme-item:focus-visible { background: var(--bg-hover); outline: none; }
.theme-item[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.theme-name { flex: 1; }
.theme-name[dir="ltr"] { text-align: right; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; }
.theme-check { color: var(--accent); visibility: hidden; }
.theme-item[aria-checked="true"] .theme-check { visibility: visible; }
.theme-swatch {
  flex-shrink: 0;
  width: 46px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(128, 128, 128, 0.35);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 0 6px;
}
.theme-swatch i { display: block; height: 3px; border-radius: 2px; }

@media (max-width: 600px) {
  .theme-menu { left: 16px !important; right: 16px; width: auto; }
}
