/* عالم كل يوم — الأنماط
   Layout: one centred column (max 600px). Kufi wordmark in a header, a strip of three clue cards,
   an ink-drawn hangman on parchment beside the lives counter, letter tiles grouped per word,
   and an Arabic keyboard at the bottom. Dialogs carry the scientist's story. */

:root {
  --bg: #ecdfc3;          /* رقّ قديم */
  --paper: #f8f1e1;       /* ورق فاتح للبطاقات */
  --paper-2: #efe5cc;
  --ink: #2b2117;         /* حبر */
  --ink-soft: #6f5d47;
  --line: #c8b58d;
  --accent: #1f3f72;      /* لازورد */
  --accent-2: #2f5ea8;
  --gold: #b48a2d;        /* ذهب */
  --gold-2: #e3c470;
  --hit: #2d7a4f;
  --miss: #a63a2a;
  --on-accent: #f8f1e1;
  --shadow: 0 12px 32px rgba(43, 33, 23, .18);
  --font-display: "Reem Kufi", "Noto Kufi Arabic", "Cairo", sans-serif;
  --font-body: "Amiri", "Noto Naskh Arabic", "Scheherazade New", "Times New Roman", serif;
  --tile: clamp(2rem, 8.4vw, 2.75rem);
  --radius: .35rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131a2b;
    --paper: #1c2438;
    --paper-2: #243049;
    --ink: #efe5cc;
    --ink-soft: #b9ac92;
    --line: #3d4a6a;
    --accent: #9db8ec;
    --accent-2: #7f9fdc;
    --gold: #d8b45c;
    --gold-2: #efd38a;
    --hit: #3f9a63;
    --miss: #c7513f;
    --on-accent: #131a2b;
    --shadow: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131a2b;
  --paper: #1c2438;
  --paper-2: #243049;
  --ink: #efe5cc;
  --ink-soft: #b9ac92;
  --line: #3d4a6a;
  --accent: #9db8ec;
  --accent-2: #7f9fdc;
  --gold: #d8b45c;
  --gold-2: #efd38a;
  --hit: #3f9a63;
  --miss: #c7513f;
  --on-accent: #131a2b;
  --shadow: 0 12px 32px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { direction: rtl; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.75;
  padding-inline: 16px;
  padding-block: 0 2.5rem;
  -webkit-font-smoothing: antialiased;
}

/* زخرفة هندسية خفيفة فوق الخلفية (نجمة ثمانية) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--gold);
  opacity: .14;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 72'%3E%3Cg fill='none' stroke='%23fff' stroke-width='1.1'%3E%3Crect x='14' y='14' width='44' height='44'/%3E%3Crect x='14' y='14' width='44' height='44' transform='rotate(45 36 36)'/%3E%3Ccircle cx='36' cy='36' r='4'/%3E%3Cpath d='M0 36h14M58 36h14M36 0v14M36 58v14'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 72px 72px repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 72'%3E%3Cg fill='none' stroke='%23fff' stroke-width='1.1'%3E%3Crect x='14' y='14' width='44' height='44'/%3E%3Crect x='14' y='14' width='44' height='44' transform='rotate(45 36 36)'/%3E%3Ccircle cx='36' cy='36' r='4'/%3E%3Cpath d='M0 36h14M58 36h14M36 0v14M36 58v14'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 72px 72px repeat;
}

a { color: var(--accent); text-underline-offset: .2em; }
b, strong { font-weight: 700; }
p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }

/* ---------- Header ---------- */
.site-header {
  max-width: 600px;
  margin: 0 auto;
  padding-block: 1rem .75rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.header-actions { display: flex; gap: .35rem; }
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.55rem, 6vw, 2.4rem);
  color: var(--accent);
  margin: 0;
  line-height: 1.4;
  min-width: 0;
}
.orn { color: var(--gold); font-weight: 400; margin-inline: .12em; }
.tagline { color: var(--ink-soft); font-style: italic; margin-top: .5rem; }
.day-line {
  font-family: var(--font-display);
  font-size: .85rem;
  color: var(--gold);
  margin-top: .25rem;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.sep { margin-inline: .5em; }

.icon-btn {
  width: 2.3rem;
  height: 2.3rem;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  flex: none;
}
.icon-btn:hover { background: var(--paper-2); }

/* ---------- Game ---------- */
.game {
  max-width: 600px;
  margin: 0 auto;
  display: grid;
  gap: 1rem;
  padding-top: 1rem;
}

.clues {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
}
.clue {
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 3px double var(--gold);
  padding: .45rem .75rem .5rem;
  display: grid;
  gap: 0;
  min-width: 0;
  line-height: 1.5;
}
.clue-key {
  font-family: var(--font-display);
  font-size: .72rem;
  color: var(--gold);
  letter-spacing: .04em;
}
.clue-val { font-weight: 700; color: var(--accent); overflow-wrap: anywhere; }
.clue.is-locked .clue-val {
  color: var(--ink-soft);
  font-weight: 400;
  font-style: italic;
  font-size: .92rem;
}
.clue.just-revealed { animation: glow 1.2s ease; }
@keyframes glow {
  0% { box-shadow: 0 0 0 0 var(--gold-2); }
  100% { box-shadow: 0 0 0 10px transparent; }
}

.stage {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  padding: .75rem 1.25rem;
}
.hangman {
  width: clamp(110px, 32vw, 150px);
  height: auto;
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.hangman .frame { stroke: var(--ink-soft); stroke-width: 2.5; }
.hangman .orn { stroke: var(--gold); stroke-width: 1.5; fill: var(--gold-2); }
.hangman .part { opacity: 0; transition: opacity .4s ease; }
.hangman .part.shown { opacity: 1; }

.lives { display: grid; gap: .1rem; text-align: center; min-width: 0; }
.lives-label { font-family: var(--font-display); font-size: .8rem; color: var(--ink-soft); }
.lives-count {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.lives-marks { font-size: 1.1rem; letter-spacing: .25em; color: var(--gold); }
.lives-marks .spent { color: var(--line); }

.word {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .6rem 1.4rem;
  padding: .5rem 0;
}
.word-group { display: flex; gap: .3rem; }
.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: calc(var(--tile) * .6);
  font-weight: 600;
  line-height: 1;
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  transition: background .3s, color .3s, border-color .3s;
}
.tile.hit {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.tile.just-hit { animation: flip .5s ease; }
.tile.reveal-miss {
  background: var(--miss);
  border-color: var(--miss);
  color: #fff;
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

.message {
  min-height: 1.75em;
  text-align: center;
  color: var(--ink-soft);
  font-style: italic;
}
.message.good { color: var(--hit); }
.message.bad { color: var(--miss); }

.keyboard { display: grid; gap: .4rem; }
.kb-row { display: flex; justify-content: center; gap: .3rem; }
.key {
  flex: 1 1 0;
  max-width: 2.9rem;
  min-width: 0;
  height: 3rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  background: var(--paper);
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
  transition: background .2s, color .2s, opacity .2s;
}
.key:hover:not(:disabled) { background: var(--paper-2); }
.key.hit { background: var(--hit); border-color: var(--hit); color: #fff; }
.key.miss { background: var(--miss); border-color: var(--miss); color: #fff; opacity: .5; }
.key:disabled { cursor: default; }

.mode-row { display: flex; justify-content: center; flex-wrap: wrap; gap: .5rem 1.5rem; }
.text-btn {
  background: none;
  border: 0;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 1rem;
  text-decoration: underline;
  text-underline-offset: .25em;
  cursor: pointer;
  padding: .25rem;
}

.btn {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--on-accent);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: .55rem 1.4rem;
  cursor: pointer;
}
.btn:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.secondary { background: transparent; color: var(--accent); }
.btn.secondary:hover { background: var(--paper-2); }

:is(.key, .icon-btn, .btn, .text-btn, a):focus-visible {
  outline: 3px solid var(--gold-2);
  outline-offset: 2px;
}

/* ---------- Footer ---------- */
.site-footer {
  max-width: 600px;
  margin: 2.5rem auto 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: .95rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  display: grid;
  gap: .25rem;
}
.author-link { display: inline-flex; align-items: center; gap: .35em; font-weight: 700; }

/* ---------- Dialogs ---------- */
dialog {
  background: var(--paper);
  color: var(--ink);
  border: 3px double var(--gold);
  border-radius: .5rem;
  padding: 1.25rem 1.5rem;
  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  box-shadow: var(--shadow);
  direction: rtl;
  font-family: var(--font-body);
}
dialog::backdrop { background: rgba(14, 18, 30, .6); }
.dlg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: .75rem;
}
.dlg-head h2 {
  font-family: var(--font-display);
  color: var(--accent);
  margin: 0;
  font-size: 1.45rem;
}
.dlg-body { display: grid; gap: .75rem; }
.dlg-actions { display: flex; justify-content: center; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.muted { color: var(--ink-soft); font-size: .95rem; }
.help-list { margin: 0; padding-inline-start: 1.25rem; display: grid; gap: .25rem; }
.help-example { display: flex; justify-content: center; gap: 1.2rem; flex-wrap: wrap; padding: .5rem 0; }
.help-example .tile { --tile: 2.2rem; }
.sub-title {
  font-family: var(--font-display);
  font-size: .9rem;
  color: var(--gold);
  margin: .75rem 0 0;
  letter-spacing: .03em;
}

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; text-align: center; }
.stat { display: grid; gap: 0; background: var(--paper-2); padding: .5rem .25rem; border-radius: var(--radius); }
.stat-num {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.stat-lbl { font-size: .8rem; color: var(--ink-soft); }
.dist { display: grid; gap: .3rem; }
.dist-row {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  align-items: center;
  gap: .5rem;
  font-size: .92rem;
}
.dist-bar {
  background: var(--line);
  color: var(--ink);
  min-width: 1.6rem;
  padding: .05rem .45rem;
  font-family: var(--font-display);
  font-size: .8rem;
  text-align: start;
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
}
.dist-bar.me { background: var(--accent); color: var(--on-accent); }

.res-name {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  line-height: 1.4;
}
.res-full { text-align: center; color: var(--ink-soft); margin-top: -.25rem; }
.res-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }
.chip {
  font-family: var(--font-display);
  font-size: .78rem;
  background: var(--paper-2);
  border: 1px solid var(--line);
  padding: .1rem .65rem;
  border-radius: 999px;
  color: var(--ink-soft);
}
.chip:empty { display: none; }
.res-bio {
  font-size: 1.05rem;
  line-height: 1.95;
  border-inline-start: 3px solid var(--gold);
  padding-inline-start: .85rem;
}
.res-link { text-align: center; font-size: .95rem; }
.share-grid {
  text-align: center;
  font-size: 1.3rem;
  letter-spacing: .1em;
  direction: ltr;
  line-height: 1.4;
}
.res-actions { margin-top: .25rem; }
.share-text {
  width: 100%;
  font-family: var(--font-body);
  font-size: .95rem;
  line-height: 1.6;
  background: var(--paper-2);
  color: var(--ink);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  resize: none;
  direction: rtl;
}
.countdown {
  text-align: center;
  font-family: var(--font-display);
  color: var(--ink-soft);
  font-size: .9rem;
  margin-top: .5rem;
}
.countdown b { color: var(--accent); font-variant-numeric: tabular-nums; }

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
  .clues { grid-template-columns: 1fr; }
  .clue { grid-template-columns: auto 1fr; gap: .6rem; align-items: baseline; padding-block: .3rem; }
  .stage { padding: .5rem .75rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  dialog { padding: 1rem; }
}

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