:root {
  --bg: #fbfaf8; --fg: #16161a; --muted: #5f5f6b; --line: #e6e3de; --card: #ffffff; --accent: #1f6feb;
  --max: 720px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111214; --fg: #ececef; --muted: #9c9ca8; --line: #26272b; --card: #18191c; --accent: #6ea8ff; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg);
       font: 17px/1.65 "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif; }
h1, .card h3, .cols h3, .brand, .lead { font-family: "Literata", Georgia, serif; }
h1 { font-weight: 500; }
.card h3, .cols h3 { font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 20px; }

nav { border-bottom: 1px solid var(--line); }
nav .wrap { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
nav .brand { color: var(--fg); font-weight: 600; }
nav ul { display: flex; gap: 20px; list-style: none; margin: 0; padding: 0; }
nav ul a { color: var(--muted); }
nav ul a[aria-current="page"] { color: var(--fg); }
nav ul a.lang { font-size: 13px; letter-spacing: .06em; border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px; }

main { padding: 56px 0 80px; }
h1 { font-size: 34px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 0 0 16px; }
section { margin-top: 56px; }
.lead { font-size: 20px; margin: 0 0 24px; }
.muted { color: var(--muted); }

.hero { display: flex; gap: 28px; align-items: center; }
.hero img { width: 132px; height: 132px; border-radius: 50%; object-fit: cover; flex: none; border: 1px solid var(--line); }
.role { color: var(--muted); margin: 0 0 6px; }

.cta { display: flex; gap: 12px; flex-wrap: wrap; }
.btn { display: inline-block; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); color: var(--fg); background: var(--card); }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn:hover { text-decoration: none; opacity: .9; }

.cards { display: grid; gap: 14px; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; color: var(--fg); }
a.card:hover { text-decoration: none; border-color: var(--muted); }
.card h3 { margin: 0 0 4px; font-size: 18px; }
.card p { margin: 0; color: var(--muted); }
.badge { font-size: 12px; border-radius: 6px; padding: 2px 8px; margin-left: 8px; vertical-align: 2px;
         border: 1px solid var(--line); color: var(--muted); font-weight: 500; }

ul.plain { margin: 0; padding-left: 20px; }
ul.plain li { margin: 8px 0; }

.motto { margin: 0; padding: 24px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-align: center; }
.motto .ar { font-family: "Amiri Quran", "Amiri", serif; font-size: 30px; line-height: 2; margin: 0 0 8px; }
.motto .en { margin: 0; font-style: italic; }
.motto cite { display: block; margin-top: 8px; font-style: normal; font-size: 14px; color: var(--muted); }

footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
footer .wrap { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding-top: 20px; padding-bottom: 32px; }

@media (max-width: 560px) {
  .wrap { padding: 0 16px; }
  main { padding: 36px 0 56px; }
  h1 { font-size: 28px; } .lead { font-size: 18px; }
  .hero { flex-direction: column; align-items: flex-start; gap: 18px; }
  .hero img { width: 104px; height: 104px; }
  nav ul { gap: 14px; font-size: 15px; }
  .motto .ar { font-size: 24px; }
}

/* projects & case study */
.card .more { margin-top: 10px; color: var(--accent); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 28px; }
.cols h3 { font-size: 17px; margin: 0 0 4px; }
.cols p { margin: 0; color: var(--muted); }
.crumbs { margin: 0 0 12px; font-size: 15px; }
.facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 28px 0 0; }
.facts div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.facts dt { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.facts dd { margin: 4px 0 0; font-weight: 600; }
.cta-block { padding: 24px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.cta-block p { color: var(--muted); }
@media (max-width: 560px) {
  .cols { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr 1fr; }
}

/* language menu */
.lang-menu { position: relative; }
.lang-menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 14px; border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; }
.lang-menu summary::-webkit-details-marker { display: none; }
.lang-menu summary::after { content: "▾"; font-size: 11px; }
.lang-menu img { border-radius: 2px; display: block; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.lang-menu ul { position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; list-style: none; margin: 0; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-width: 170px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
nav .lang-menu ul { display: block; }
.lang-menu li a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--fg); }
.lang-menu li a:hover { background: var(--bg); text-decoration: none; }
.lang-menu li a[aria-current] { font-weight: 600; }

/* compact nav on phones: one line, no wrapping */
nav .brand, nav ul a { white-space: nowrap; }
@media (max-width: 560px) {
  nav .wrap { gap: 10px; }
  nav .brand { font-size: 15px; }
  nav ul { gap: 12px; font-size: 14px; }
  .lang-menu summary span { display: none; }
  .lang-menu summary { padding: 4px 6px; }
}

/* tools */
.controls { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0 20px; }
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.controls select, .controls input, .controls button { font: inherit; font-size: 16px; color: var(--fg); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; }
.controls button { cursor: pointer; align-self: flex-end; }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
table.data td.num { text-align: right; font-weight: 500; }
table.data tr.now td { color: var(--accent); font-weight: 600; }
.note { font-size: 14px; color: var(--muted); margin-top: 16px; }
.result { font-family: "Literata", Georgia, serif; font-size: 28px; margin: 4px 0 24px; }

@media (max-width: 560px) { nav li.by { display: none; } }

.lang-menu img { object-fit: cover; }

/* tables: logical alignment works for LTR and RTL */
table.data th, table.data td { text-align: start; }
table.data td.num, table.data th.num { text-align: end; }

/* city search */
.controls label.search { position: relative; }
#hits { position: absolute; top: 100%; inset-inline-start: 0; z-index: 20; min-width: 260px; margin: 4px 0 0; padding: 4px;
  list-style: none; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
#hits button { all: unset; display: block; width: 100%; box-sizing: border-box; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--fg); font-size: 15px; }
#hits button:hover, #hits button:focus { background: var(--bg); }
#hits small { display: block; color: var(--muted); font-size: 12px; }
#hits li.none { padding: 8px 10px; color: var(--muted); font-size: 14px; }
.note.warn { color: #b26b00; }
@media (prefers-color-scheme: dark) { .note.warn { color: #e6a23c; } }

/* ayah */
.motto { margin: 0; padding: 24px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-align: center; }
.motto .ar { font-family: "Amiri Quran", "Amiri", serif; font-size: 30px; line-height: 2.1; margin: 0 0 12px; }
.motto .tr { margin: 0; font-style: italic; }
.motto cite { display: block; margin-top: 10px; font-style: normal; font-size: 14px; color: var(--muted); }
@media (max-width: 560px) { .motto .ar { font-size: 24px; } }

/* 404 */
.nf-wrap { text-align: center; padding: 24px 0; }
.nf-art { max-width: 100%; height: auto; margin: 0 auto 8px; display: block; border-radius: 14px; border: 1px solid var(--line); }
.nf { margin: 20px 0; }
.nf h2 { font-family: "Literata", Georgia, serif; text-transform: none; letter-spacing: 0; font-size: 22px; color: var(--fg); font-weight: 500; margin: 0 0 6px; }
.nf p { margin: 4px 0; color: var(--muted); }

/* Arabic (RTL) */
[dir="rtl"] body, html[dir="rtl"] body { font-family: "IBM Plex Sans Arabic", "IBM Plex Sans", sans-serif; }
html[dir="rtl"] h1, html[dir="rtl"] .card h3, html[dir="rtl"] .lead, html[dir="rtl"] .brand, html[dir="rtl"] .result { font-family: "IBM Plex Sans Arabic", sans-serif; }
html[dir="rtl"] h2 { letter-spacing: 0; }
html[dir="rtl"] .lang-menu ul { right: auto; left: 0; }
.nf[dir="rtl"] h2 { font-family: "IBM Plex Sans Arabic", sans-serif; }

/* ---------- wide screens ---------- */
.lead, main p { max-width: 72ch; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.tool-grid { display: grid; gap: 8px 56px; align-items: start; }
@media (min-width: 1000px) {
  :root { --max: 1080px; }
  .tool-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
  .tool-grid .note { margin-top: 0; }
  h1 { font-size: 40px; }
  .lead { font-size: 21px; }
}
@media (min-width: 1600px) { :root { --max: 1240px; } body { font-size: 18px; } }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .25s ease;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Beam ---------- */
:root { --beam: #ff5a3c; --crystal: #6ea8ff; --crystal-lit: #ffc94a; --wall: #2a2c33; }
@media (prefers-color-scheme: light) { :root { --wall: #c9c4bb; --crystal: #1f6feb; --crystal-lit: #e0a100; --beam: #e8452a; } }
.game-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.game-head h1 { margin: 0; }
.modes { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--card); }
.mode { all: unset; cursor: pointer; padding: 6px 14px; border-radius: 7px; color: var(--muted); font-size: 15px; }
.mode.on { background: var(--fg); color: var(--bg); }
.mode:focus-visible { outline: 2px solid var(--accent); }
.rule { color: var(--muted); margin: 12px 0 16px; }
.hud { display: flex; gap: 22px; align-items: center; font-variant-numeric: tabular-nums; color: var(--muted); margin-bottom: 10px; }
.hud b { color: var(--fg); font-weight: 600; }
.hud #label { font-weight: 600; color: var(--fg); }
.mirror-icon { display: inline-block; width: 14px; height: 14px; border-radius: 2px; background: linear-gradient(135deg, transparent 44%, var(--fg) 44%, var(--fg) 56%, transparent 56%); vertical-align: -2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.board-wrap { width: min(100%, 560px, calc(100vh - 300px)); min-width: min(100%, 300px); margin: 0 auto; }
#board { width: 100%; height: auto; display: block; touch-action: manipulation; user-select: none; -webkit-tap-highlight-color: transparent; }
#board .cell { fill: var(--card); stroke: var(--line); stroke-width: 1; cursor: pointer; transition: fill .15s; }
#board .cell:hover, #board .cell:focus { fill: var(--line); outline: none; }
#board .cell.wall { fill: var(--wall); stroke: none; cursor: default; }
#board .source { fill: var(--beam); }
#board .beam { fill: none; stroke: var(--beam); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#board .beam-glow { fill: none; stroke: var(--beam); stroke-width: 12; opacity: .22; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#board .beam.fresh { stroke-dasharray: 2000; stroke-dashoffset: 2000; animation: beamIn .9s ease forwards; }
@keyframes beamIn { to { stroke-dashoffset: 0; } }
#board .crystal { fill: none; stroke: var(--crystal); stroke-width: 3; pointer-events: none; transition: fill .2s, stroke .2s; }
#board .crystal.lit { fill: var(--crystal-lit); stroke: var(--crystal-lit); }
#board .mirror { stroke: var(--fg); stroke-width: 5; stroke-linecap: round; pointer-events: none; }
#board.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
#board.won .crystal.lit { animation: pulse .6s ease 2; }
@keyframes pulse { 50% { transform-origin: center; opacity: .5; } }
.game-actions { display: flex; gap: 10px; justify-content: center; margin: 16px 0; }
.game-actions .btn { cursor: pointer; font: inherit; }
.game-actions .btn:disabled { opacity: .4; cursor: default; }
.win { text-align: center; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); max-width: 560px; margin: 0 auto; }
.win-title { font-family: "Literata", Georgia, serif; font-size: 26px; margin: 0 0 6px; max-width: none; }
.win-stats { color: var(--muted); font-variant-numeric: tabular-nums; margin: 0 0 14px; max-width: none; }
.win .cta { justify-content: center; }
.win .btn { cursor: pointer; font: inherit; }
@media (prefers-reduced-motion: reduce) { #board .beam.fresh { animation: none; stroke-dasharray: none; stroke-dashoffset: 0; } #board.shake, #board.won .crystal.lit { animation: none; } }

/* share sheet */
dialog.share { border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--fg); padding: 22px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog.share::backdrop { background: rgba(0,0,0,.45); }
.share-title { font-family: "Literata", Georgia, serif; font-size: 20px; margin: 0 0 10px; }
.share-preview { white-space: pre-wrap; word-break: break-all; font: 13px/1.5 ui-monospace, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; color: var(--muted); }
.share-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-bottom: 16px; }
.net { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--fg); font-size: 15px; }
.net:hover { text-decoration: none; background: var(--bg); }
.net-dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 13px; flex: none; }
dialog.share .cta { justify-content: flex-end; }
dialog.share .btn { cursor: pointer; font: inherit; }
.net-dot { box-shadow: 0 0 0 1px rgba(255,255,255,.25); }
