:root {
  --bg: #fcfcf9;
  --surface: #fffffd;
  --text: #13343b;
  --muted: #626c71;
  --primary: #21808d;
  --primary-hover: #1d7480;
  --accent: #5ccb7c;
  --border: rgba(94, 82, 64, 0.16);
  --soft: rgba(33, 128, 141, 0.08);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(19, 52, 59, 0.05), 0 6px 20px rgba(19, 52, 59, 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11191b;
    --surface: #182326;
    --text: #e8f0ef;
    --muted: #9db0b3;
    --primary: #45b3c1;
    --primary-hover: #5cc3d0;
    --border: rgba(255, 255, 255, 0.1);
    --soft: rgba(69, 179, 193, 0.12);
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11191b;
  --surface: #182326;
  --text: #e8f0ef;
  --muted: #9db0b3;
  --primary: #45b3c1;
  --primary-hover: #5cc3d0;
  --border: rgba(255, 255, 255, 0.1);
  --soft: rgba(69, 179, 193, 0.12);
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", Tahoma, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }
h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); line-height: 1.25; margin: 0.4em 0 0.3em; }
h2 { font-size: 1.2rem; margin: 0 0 0.8em; }
h3 { font-size: 1rem; margin: 1.2em 0 0.5em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--soft); padding: 0.1em 0.45em; border-radius: 6px; }
sup { font-size: 0.7em; }

.wrap { max-width: 1040px; margin: 0 auto; padding-inline: 16px; }
main.wrap { padding-block: 8px 48px; min-height: 60vh; }

/* header */
.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; }
.top-in { display: flex; align-items: center; gap: 20px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 1.3rem; font-weight: 600; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; color: var(--text); }
.brand b { color: var(--primary); }
.brand span { direction: ltr; }
.nav { display: flex; gap: 18px; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); text-decoration: none; }
.theme { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: transparent; cursor: pointer; font-size: 1.05rem; line-height: 1; padding: 0; }
.theme:hover { background: var(--soft); }
.langs { position: relative; }
.langs summary { list-style: none; cursor: pointer; border: 1px solid var(--border); border-radius: 999px; padding: 4px 14px; font-weight: 600; color: var(--primary); user-select: none; }
.langs summary::-webkit-details-marker { display: none; }
.langs summary:hover, .langs[open] summary { background: var(--soft); }
.langs-menu { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); min-width: 150px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 20; display: flex; flex-direction: column; }
.langs-menu a { padding: 8px 12px; border-radius: 8px; color: var(--text); }
.langs-menu a:hover { background: var(--soft); text-decoration: none; }
.langs-menu a[aria-current] { color: var(--primary); font-weight: 600; }

/* cards & text */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin: 18px 0; }
.lead { font-size: 1.1rem; color: var(--muted); margin: 0 0 8px; }
.lead strong { color: var(--text); }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 0.85rem; margin: -6px 4px 0; }
.prose p { margin: 0.4em 0; }
.more { margin: 14px 0 0; }
.crumbs { font-size: 0.85rem; color: var(--muted); margin-top: 18px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }
.crumbs .sep { opacity: 0.6; }
[dir="rtl"] .crumbs .sep { transform: scaleX(-1); display: inline-block; }

/* converter */
.conv { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.conv-row { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.conv input, .conv select, .conv output, .search input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; width: 100%; min-width: 0;
}
.conv input, .conv output { font-size: 1.5rem; font-weight: 600; direction: ltr; text-align: start; }
[dir="rtl"] .conv input { text-align: end; }
.conv input:focus, .conv select:focus, .search input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.swap { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--soft); color: var(--primary); font-size: 1.3rem; cursor: pointer; transform: rotate(90deg); }
.swap:hover { background: var(--primary); color: #fff; }
.conv-out { grid-column: 1 / -1; margin: 4px 0 0; color: var(--muted); text-align: center; min-height: 1.6em; }
#crypto-conv { grid-template-columns: 1fr 1fr; }
.out-big { display: block; }

/* tables */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: start; }
.tbl td { direction: ltr; unicode-bidi: plaintext; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.tbl tbody tr:hover { background: var(--soft); }
.tbl .num { font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }

/* link grids */
.links { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px 16px; }
.links a { padding: 4px 0; }
.group h3 { color: var(--muted); }

/* home */
.hero { text-align: center; padding: 36px 0 12px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.1rem); }
.search { position: relative; max-width: 640px; margin: 22px auto 0; text-align: start; }
.search input { font-size: 1.1rem; padding: 16px 18px; border-radius: 14px; box-shadow: var(--shadow); background: var(--surface); }
.q-results { position: absolute; inset-inline: 0; top: calc(100% + 6px); list-style: none; margin: 0; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 5; }
.q-results a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); }
.q-results a:hover, .q-results a.on { background: var(--soft); text-decoration: none; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 12px 0 8px; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-weight: 600; text-align: center; transition: transform 0.12s, border-color 0.12s; }
.tile:hover { text-decoration: none; border-color: var(--primary); transform: translateY(-2px); color: var(--text); }
.tile .ico { font-size: 1.8rem; }
#units h2 { margin-top: 28px; }

/* footer */
.foot { border-top: 1px solid var(--border); background: var(--surface); padding: 28px 0 calc(28px + env(safe-area-inset-bottom, 0px)); font-size: 0.9rem; }
.foot-cats { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 14px; }
.foot-cats a, .foot-meta a { color: var(--muted); }
.foot-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); }

/* file converters */
.fc-drop { display: flex; align-items: center; justify-content: center; min-height: 130px; padding: 20px; border: 2px dashed var(--border); border-radius: var(--radius); background: var(--soft); color: var(--primary); font-weight: 600; text-align: center; cursor: pointer; transition: border-color 0.12s, background 0.12s; }
.fc-drop:hover, .fc-drop.over { border-color: var(--primary); }
.fc-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.fc-drop:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.fc-opts { display: flex; flex-wrap: wrap; gap: 10px 22px; margin: 16px 0 4px; }
.fc-opt { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.95rem; }
.fc-opt select, .fc-opt input[type="number"], .fc-opt input[type="text"] { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; max-width: 12em; }
.fc-opt input[type="number"] { width: 7em; }
.fc-opt input:disabled { opacity: 0.5; }
.fc-opt output { min-width: 2.2em; color: var(--text); font-weight: 600; }
.fc-list { list-style: none; margin: 14px 0 0; padding: 0; }
.fc-list li, .fc-res { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.fc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: start; }
.fc-mini { width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; }
.fc-mini:hover:not(:disabled) { color: var(--primary); border-color: var(--primary); }
.fc-mini:disabled { opacity: 0.35; cursor: default; }
.fc-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn { display: inline-block; font: inherit; font-weight: 600; padding: 10px 22px; border: 1px solid var(--primary); border-radius: 10px; background: var(--primary); color: #fff; cursor: pointer; text-decoration: none; }
.btn:hover { text-decoration: none; filter: brightness(1.08); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn[hidden] { display: none; }
.fc-res .btn { padding: 6px 14px; font-size: 0.9rem; }
.fc-res img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.fc-status { margin: 12px 0 0; font-weight: 600; color: var(--primary); }
.fc-status:empty { display: none; }
.fc-out:empty { display: none; }
.fc-out { margin-top: 8px; }
.fc-all { margin: 4px 0 10px; }
.fc-err { color: #c0392b; margin: 10px 0 0; }
.fc-opt[hidden], .fc-player[hidden] { display: none; }
.fc-player { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; flex-basis: 100%; }
.fc-player audio, .fc-res audio { flex-basis: 100%; width: 100%; height: 40px; }
.fc-player video, .fc-res video, .fc-live { flex-basis: 100%; width: 100%; max-height: 360px; background: #000; border-radius: 8px; }
.fc-live { display: block; margin-top: 14px; }
.fc-live[hidden] { display: none; }
.fc-player .btn { padding: 6px 14px; font-size: 0.9rem; }
.fc-res { flex-wrap: wrap; }
.fc-rec { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.fc-timer { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--primary); }

@media (max-width: 680px) {
  .conv { grid-template-columns: 1fr; }
  .swap { justify-self: center; transform: none; }
  #crypto-conv { grid-template-columns: 1fr; }
  .two { grid-template-columns: 1fr; }
  .nav { order: 3; flex-basis: 100%; gap: 14px; padding-bottom: 8px; }
  .top-in { gap: 10px 16px; }
  .theme { margin-inline-start: auto; }
  .fc-res { flex-wrap: wrap; }
  .fc-res .fc-name { flex-basis: calc(100% - 60px); }
}
/* hash generator & OCR results */
.fc-wide { flex-direction: column; align-items: stretch; margin-bottom: 14px; }
.fc-wide textarea, .fc-res textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; box-sizing: border-box; resize: vertical; }
.fc-res textarea { flex-basis: 100%; min-height: 160px; }
.fc-hash:empty { display: none; }
.fc-hash { margin-bottom: 14px; }
.fc-hash table, .fc-res table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.fc-res table { flex-basis: 100%; }
.fc-hash th, .fc-res th { text-align: start; padding: 4px 10px 4px 0; color: var(--muted); font-weight: 600; white-space: nowrap; width: 1%; }
.fc-hash td, .fc-res td { padding: 4px 0; font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; direction: ltr; text-align: left; }
.fc-hash td.c, .fc-res td.c { width: 1%; padding-inline-start: 8px; }
.fc-hash td.c .btn, .fc-res td.c .btn { white-space: nowrap; padding: 4px 10px; font-size: 0.85rem; }
