/* ============================================================
   مسابقة حكيم — الهوية البصرية: لوحة ورقية نهارية
   ============================================================ */
:root{
  --bg:#FBF6EC;
  --paper:#FFFFFF;
  --paper-2:#FFFDF8;
  --emerald:#0E6B5C;
  --emerald-d:#0A5449;
  --emerald-soft:#E4F0EC;
  --gold:#DFA43C;
  --gold-d:#C48C25;
  --brick:#C2543C;
  --brick-soft:#FBEDE9;
  --green:#2E9E7E;
  --green-soft:#E9F6F1;
  --ink:#1E2A2C;
  --muted:#77837F;
  --line:#E7DFCF;
  --radius:20px;
  --shadow:0 8px 24px rgba(30,42,44,.08);
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;padding:0}
html{-webkit-text-size-adjust:100%}
body{
  background:var(--bg);
  color:var(--ink);
  font-family:'Cairo','Segoe UI',system-ui,-apple-system,sans-serif;
  font-size:17px;
  line-height:1.7;
  min-height:100vh;
  overflow-x:hidden;
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3{font-family:'Noto Kufi Arabic','Cairo',sans-serif;letter-spacing:0;line-height:1.4}
button{font-family:inherit}
svg{display:block}
::selection{background:rgba(223,164,60,.3)}

/* ---------- نمط الجِرِه في الخلفية ---------- */
.girih-layer{
  position:fixed;inset:0;z-index:0;pointer-events:none;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23DFA43C' stroke-opacity='0.09' stroke-width='1'%3E%3Cpath d='M32 2 L62 32 L32 62 L2 32 Z'/%3E%3Cpath d='M32 13 L51 32 L32 51 L13 32 Z'/%3E%3Ccircle cx='32' cy='32' r='4'/%3E%3Cpath d='M0 0 L64 64 M64 0 L0 64'/%3E%3C/g%3E%3C/svg%3E");
  background-size:64px 64px;
  opacity:.85;
}

.app{
  position:relative;z-index:1;
  max-width:720px;
  margin-inline:auto;
  padding:14px 16px 40px;
  transition:padding-bottom .2s ease-out;
}
body.sheet-open .app{padding-bottom:300px}

.screen{animation:fadeUp .24s ease-out both}
.hidden{display:none !important}

@keyframes fadeUp{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}

/* ---------- أزرار عامة ---------- */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:10px;
  min-height:56px;padding:14px 20px;
  border-radius:var(--radius);
  border:1px solid transparent;
  font-size:19px;font-weight:700;line-height:1.3;
  cursor:pointer;text-align:center;
  transition:transform .18s ease-out,background-color .18s ease-out,box-shadow .18s ease-out,border-color .18s ease-out,color .18s ease-out;
  user-select:none;
}
.btn svg{width:22px;height:22px;flex:none}
.btn:active{transform:scale(.98)}
.btn:focus-visible{outline:3px solid rgba(14,107,92,.35);outline-offset:3px}
.btn[disabled]{opacity:.55;cursor:not-allowed}

.btn-gold{
  background:var(--gold);color:#25200F;
  box-shadow:0 6px 0 rgba(196,140,37,.35),0 10px 22px rgba(223,164,60,.28);
}
.btn-gold:hover{background:#E5AD४A}
.btn-gold:hover{background:#E5AD4A}
.btn-gold:active{box-shadow:0 2px 0 rgba(196,140,37,.35)}

.btn-green{
  background:var(--emerald);color:#F7FBF9;
  box-shadow:0 6px 18px rgba(14,107,92,.24);
  width:100%;
}
.btn-green:hover{background:var(--emerald-d)}

.btn-ghost{
  background:var(--paper);color:var(--emerald);
  border-color:var(--line);
  box-shadow:var(--shadow);
}
.btn-ghost:hover{border-color:#CFC4AC;background:#FFFDF7}
.btn-ghost.small{min-height:48px;font-size:16px;padding:10px 16px;flex:1}

.icon-btn{
  width:46px;height:46px;flex:none;
  display:grid;place-items:center;
  border-radius:14px;
  background:var(--paper);
  border:1px solid var(--line);
  color:var(--emerald);
  cursor:pointer;
  box-shadow:var(--shadow);
  transition:transform .18s ease-out,border-color .18s ease-out,background-color .18s ease-out;
}
.icon-btn svg{width:22px;height:22px}
.icon-btn:hover{border-color:#CFC4AC;background:#FFFDF7}
.icon-btn:active{transform:scale(.94)}
.icon-btn:focus-visible{outline:3px solid rgba(14,107,92,.35);outline-offset:2px}

/* ============================================================
   الرئيسية
   ============================================================ */
.home-top{display:flex;align-items:center;gap:10px;padding-top:6px}
.home-brand{flex:1;min-width:0}
.home-brand h1{margin:0;font-size:27px;color:var(--emerald);font-weight:700}
.home-brand p{margin:4px 0 0;font-size:12.5px;color:var(--muted);line-height:1.6}

.best-row{display:flex;gap:8px;flex-wrap:wrap;margin-top:14px}
.best-chip{
  display:inline-flex;align-items:center;gap:6px;
  background:var(--paper);border:1px solid var(--line);
  border-radius:999px;padding:7px 14px;
  font-size:14px;font-weight:600;color:var(--emerald);
  box-shadow:var(--shadow);
}
.best-chip svg{width:17px;height:17px;color:var(--gold)}
.best-chip b{color:var(--ink);font-size:15px}
.best-chip.ghost{background:transparent;box-shadow:none;color:var(--muted);font-weight:600}

.btn-start{
  width:100%;margin-top:16px;min-height:66px;font-size:22px;
  border-radius:22px;
}

.sec-title{
  font-size:15.5px;font-weight:700;color:var(--emerald);
  margin:24px 0 10px;display:flex;align-items:center;gap:8px;
}
.sec-title::before{content:'';width:8px;height:8px;border-radius:50%;background:var(--gold);flex:none}

/* الصعوبة */
.diff-row{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.diff-chip{
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
  min-height:62px;padding:8px 4px;
  background:var(--paper);border:1.5px solid var(--line);border-radius:16px;
  cursor:pointer;color:var(--ink);
  box-shadow:0 3px 10px rgba(30,42,44,.04);
  transition:border-color .18s ease-out,background-color .18s ease-out,transform .18s ease-out,box-shadow .18s ease-out;
}
.diff-chip .d-name{font-size:17px;font-weight:700}
.diff-chip .d-sub{font-size:11.5px;color:var(--muted);font-weight:600}
.diff-chip:active{transform:scale(.97)}
.diff-chip:focus-visible{outline:3px solid rgba(14,107,92,.35);outline-offset:2px}
.diff-chip.active{
  border-color:var(--emerald);background:var(--emerald-soft);
  box-shadow:0 0 0 2px rgba(14,107,92,.14),0 6px 16px rgba(14,107,92,.10);
}
.diff-chip.active .d-name{color:var(--emerald)}
.diff-chip.active .d-sub{color:var(--emerald)}

/* الأقسام */
.cat-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:10px}
.cat-card{
  display:flex;align-items:center;gap:10px;
  min-height:64px;padding:10px 12px;
  background:var(--paper);border:1.5px solid var(--line);border-radius:18px;
  cursor:pointer;text-align:start;color:var(--ink);
  box-shadow:0 3px 10px rgba(30,42,44,.05);
  transition:border-color .18s ease-out,transform .18s ease-out,box-shadow .18s ease-out,background-color .18s ease-out;
  position:relative;overflow:hidden;
}
.cat-card::before{
  content:'';position:absolute;inset-inline-start:0;top:0;bottom:0;width:4px;
  background:var(--cat-color,var(--emerald));opacity:0;transition:opacity .18s ease-out;
}
.cat-card .cat-icon{
  width:38px;height:38px;flex:none;display:grid;place-items:center;
  border-radius:12px;background:var(--cat-tint,#E4F0EC);color:var(--cat-color,var(--emerald));
}
.cat-card .cat-icon svg{width:21px;height:21px}
.cat-card .cat-name{font-size:16px;font-weight:700;line-height:1.3}
.cat-card:active{transform:scale(.98)}
.cat-card:focus-visible{outline:3px solid rgba(14,107,92,.35);outline-offset:2px}
.cat-card.active{
  border-color:var(--cat-color,var(--emerald));
  background:#FFFDF7;
  box-shadow:0 0 0 2px color-mix(in srgb,var(--cat-color,#0E6B5C) 18%,transparent),0 6px 16px rgba(30,42,44,.08);
}
.cat-card.active::before{opacity:1}

.home-note{
  margin:22px 0 0;font-size:12.5px;color:var(--muted);text-align:center;line-height:1.8;
}

/* ============================================================
   شاشة اللعب
   ============================================================ */
.hud{
  background:var(--paper);border:1px solid var(--line);border-radius:18px;
  padding:10px 12px 12px;box-shadow:var(--shadow);
}
.hud-row{display:flex;align-items:center;gap:10px}
.hud-row .icon-btn{box-shadow:none;width:42px;height:42px;border-radius:12px}
.stats{display:flex;gap:6px;flex:1;justify-content:flex-end;flex-wrap:nowrap}
.stat{
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  min-width:0;flex:1;max-width:104px;
  padding:4px 6px;border-radius:12px;background:#F7F3E8;
  line-height:1.2;
}
.stat span{font-size:11px;color:var(--muted);font-weight:600;white-space:nowrap}
.stat b{font-size:18px;font-weight:700;color:var(--ink);font-variant-numeric:tabular-nums}
.stat.ok{background:var(--green-soft)}
.stat.ok b{color:#1F7A61}
.stat.bad{background:var(--brick-soft)}
.stat.bad b{color:#A3432F}

.hud-progress{display:flex;align-items:center;gap:10px;margin-top:10px}
.pbar{flex:1;height:8px;border-radius:99px;background:#F0EADA;overflow:hidden}
.pbar i{
  display:block;height:100%;width:0;border-radius:99px;
  background:linear-gradient(90deg,#2E9E7E,#0E6B5C);
  transition:width .3s ease-out;
}
.hud-progress b{font-size:13px;color:var(--emerald);font-variant-numeric:tabular-nums;white-space:nowrap}

/* صف المؤقت + الشارة + البومة */
.q-head{
  display:flex;align-items:center;justify-content:space-between;
  gap:10px;margin:12px 2px 0;
}
.q-meta{display:flex;flex-direction:column;align-items:center;gap:6px;flex:1;min-width:0}
.cat-chip{
  display:inline-block;padding:5px 14px;border-radius:999px;
  background:var(--paper);border:1px solid var(--line);
  font-size:13px;font-weight:700;color:var(--emerald);
  box-shadow:0 3px 8px rgba(30,42,44,.05);
  max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
.streak-chip{
  display:inline-block;padding:3px 10px;border-radius:999px;
  background:#FBEED3;color:#8A6417;font-size:11.5px;font-weight:700;
}

.timer{position:relative;width:78px;height:78px;flex:none}
.timer-ring{width:100%;height:100%;transform:rotate(-90deg)}
.ring-track{fill:none;stroke:#EFE8D8;stroke-width:8}
.ring-fill{
  fill:none;stroke:var(--emerald);stroke-width:8;stroke-linecap:round;
  stroke-dasharray:276.46;stroke-dashoffset:0;
  transition:stroke .3s ease-out,filter .3s ease-out;
}
.timer-num{
  position:absolute;inset:0;display:grid;place-items:center;
  font-family:'Noto Kufi Arabic','Cairo',sans-serif;
  font-size:23px;font-weight:700;color:var(--emerald);
  font-variant-numeric:tabular-nums;
}
.timer.low .ring-fill{stroke:var(--brick)}
.timer.low .timer-num{color:var(--brick)}
.timer.low{animation:timerPulse .9s ease-in-out infinite}
.timer.win .ring-fill{stroke:var(--green);filter:drop-shadow(0 0 6px rgba(46,158,126,.55))}
@keyframes timerPulse{0%,100%{transform:scale(1)}50%{transform:scale(1.06)}}

/* بطاقة السؤال */
.qcard{
  background:var(--paper);border:1px solid var(--line);
  border-radius:var(--radius);box-shadow:var(--shadow);
  padding:18px 16px 16px;margin-top:12px;
}
.qcard.shake{animation:cardShake .38s ease-out}
@keyframes cardShake{0%,100%{transform:translateX(0)}20%{transform:translateX(-4px)}50%{transform:translateX(4px)}80%{transform:translateX(-3px)}}

.qtext{
  margin:0 0 16px;font-size:19.5px;font-weight:700;line-height:1.75;
  color:var(--ink);text-align:start;
}

.options{display:flex;flex-direction:column;gap:9px}
.opt{
  display:flex;align-items:center;gap:11px;
  width:100%;min-height:58px;padding:11px 13px;
  background:var(--paper-2);
  border:1.5px solid var(--line);border-radius:16px;
  font-size:17.5px;font-weight:600;color:var(--ink);
  text-align:start;cursor:pointer;line-height:1.5;
  transition:border-color .18s ease-out,background-color .18s ease-out,transform .12s ease-out,box-shadow .18s ease-out;
}
.opt .badge{
  width:32px;height:32px;flex:none;display:grid;place-items:center;
  border-radius:10px;background:#F3EEE1;color:#6E6450;
  font-size:14px;font-weight:700;
  transition:background-color .18s ease-out,color .18s ease-out;
}
.opt .opt-text{flex:1;min-width:0;overflow-wrap:anywhere}
.opt .mark{width:22px;height:22px;flex:none;display:none}
.opt:hover:not(:disabled){border-color:#CFC4AC;background:#FFFEFA}
.opt:active:not(:disabled){transform:scale(.99)}
.opt:focus-visible{outline:3px solid rgba(14,107,92,.35);outline-offset:2px}
.opt:disabled{cursor:default}

.opt.correct{
  background:var(--green-soft);border-color:var(--green);color:#146B52;
  box-shadow:0 0 0 3px rgba(46,158,126,.13);
}
.opt.correct .badge{background:var(--green);color:#fff}
.opt.correct .mark{display:block;color:var(--green)}
.opt.wrong{
  background:var(--brick-soft);border-color:var(--brick);color:#9C3E2A;
  box-shadow:0 0 0 3px rgba(194,84,60,.12);
}
.opt.wrong .badge{background:var(--brick);color:#fff}
.opt.wrong .mark{display:block;color:var(--brick)}
.opt.dimmed{opacity:.52}

/* ورقة الشرح */
.sheet{
  position:fixed;inset-inline:0;bottom:0;z-index:40;
  max-width:640px;margin-inline:auto;
  background:var(--paper-2);
  border:1px solid var(--line);border-bottom:none;
  border-radius:24px 24px 0 0;
  box-shadow:0 -14px 44px rgba(30,42,44,.18);
  padding:16px 18px 20px;
  animation:sheetUp .26s ease-out both;
}
@keyframes sheetUp{from{transform:translateY(100%)}to{transform:translateY(0)}}
.sheet-head{display:flex;align-items:center;gap:9px;margin-bottom:6px}
.sheet-badge{
  width:30px;height:30px;flex:none;display:grid;place-items:center;
  border-radius:50%;font-size:16px;font-weight:700;
  background:var(--green-soft);color:var(--green);
}
.sheet-badge.bad{background:var(--brick-soft);color:var(--brick)}
.sheet-head b{font-size:18px;font-weight:700;color:var(--ink)}
.sheet-points{
  margin-inline-start:auto;font-size:14px;font-weight:700;color:var(--green);
  background:var(--green-soft);padding:3px 10px;border-radius:999px;
}
.sheet-points.bad{color:var(--brick);background:var(--brick-soft)}
.sheet-text{
  margin:4px 0 14px;font-size:16px;line-height:1.75;color:#3D4A49;
  max-height:34vh;overflow-y:auto;
}

/* ============================================================
   النتائج
   ============================================================ */
.res-card{
  background:var(--paper);border:1px solid var(--line);
  border-radius:26px;box-shadow:var(--shadow);
  padding:22px 16px 20px;margin-top:6px;text-align:center;
}
.res-card .owl-slot{margin:0 auto}
.res-rating{
  font-size:26px;color:var(--emerald);margin:2px 0 4px;
}
.new-best{
  display:inline-block;margin:0 auto 8px;padding:4px 14px;border-radius:999px;
  background:#FBEED3;color:#8A6417;font-size:13px;font-weight:700;
}
.res-score{display:flex;flex-direction:column;align-items:center;gap:0;margin:6px 0 16px}
.res-score b{
  font-family:'Noto Kufi Arabic','Cairo',sans-serif;
  font-size:52px;line-height:1.1;color:var(--gold);font-variant-numeric:tabular-nums;
}
.res-score span{font-size:13.5px;color:var(--muted);font-weight:600}
.res-score i{font-style:normal;font-weight:700;color:var(--emerald)}

.res-stats{display:grid;grid-template-columns:repeat(2,1fr);gap:9px;margin-bottom:14px}
.res-stat{
  background:#F8F4E9;border-radius:16px;padding:10px 8px;
  display:flex;flex-direction:column;gap:2px;align-items:center;
}
.res-stat span{font-size:12.5px;color:var(--muted);font-weight:600}
.res-stat b{font-size:20px;color:var(--ink);font-variant-numeric:tabular-nums}
.res-stat.ok{background:var(--green-soft)}
.res-stat.ok b{color:#1F7A61}
.res-stat.bad{background:var(--brick-soft)}
.res-stat.bad b{color:#A3432F}

.best-line{font-size:13.5px;color:var(--muted);margin:0 0 16px}
.best-line b{color:var(--emerald)}

.res-actions{display:flex;flex-direction:column;gap:9px}
.res-actions .btn{width:100%}

/* صندوق المنافسة */
.games-box{
  border:1px dashed #DCD2BC;border-radius:18px;
  padding:12px;margin-bottom:16px;text-align:start;background:#FCF9F0;
}
.games-box h3{margin:0 0 4px;font-size:15px;color:var(--emerald)}
.games-hint{margin:0 0 10px;font-size:12.5px;color:var(--muted);line-height:1.7}
.games-actions{display:flex;gap:8px;margin-bottom:8px}
.lb-list{display:flex;flex-direction:column;gap:6px;margin-top:8px}
.lb-row{
  display:flex;align-items:center;gap:10px;
  background:#fff;border:1px solid var(--line);border-radius:12px;
  padding:7px 10px;font-size:14px;
}
.lb-row.me{border-color:var(--gold);background:#FFFBEF}
.lb-rank{width:24px;color:var(--gold);font-weight:700;flex:none}
.lb-handle{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ink);font-weight:600}
.lb-score{font-weight:700;color:var(--emerald);font-variant-numeric:tabular-nums}
.lb-note{margin:4px 0 0;font-size:12px;color:var(--muted)}

/* ============================================================
   البومة حكيم
   ============================================================ */
.owl-slot{position:relative;width:104px;height:114px;flex:none}
.owl-slot.small{width:86px;height:96px}
.owl-slot .owl{width:100%;height:100%;animation:owlBreath 4.5s ease-in-out infinite;transform-origin:50% 80%}
@keyframes owlBreath{0%,100%{transform:translateY(0)}50%{transform:translateY(-3px)}}

.owl-eyes{transform-box:fill-box;transform-origin:center;animation:owlBlink 5.2s infinite}
@keyframes owlBlink{0%,94%,100%{transform:scaleY(1)}96%{transform:scaleY(.12)}}

.owl-bubble{
  display:none;position:absolute;top:-4px;inset-inline-start:-8px;
  width:34px;height:34px;border-radius:50%;
  background:var(--paper);border:2px solid var(--gold);color:var(--emerald);
  font-family:'Noto Kufi Arabic','Cairo',sans-serif;font-weight:700;font-size:18px;
  place-items:center;box-shadow:0 4px 12px rgba(30,42,44,.12);
}
.owl-stars{display:none;position:absolute;inset:0;pointer-events:none;color:var(--gold)}
.owl-stars svg{width:100%;height:100%}
.owl-shield{display:none;position:absolute;bottom:-4px;inset-inline-start:-6px;width:30px;height:34px}

.owl-slot[data-state="thinking"] .owl-bubble{display:grid}
.owl-slot[data-state="thinking"] .owl{animation:owlTilt 3s ease-in-out infinite}
@keyframes owlTilt{0%,100%{transform:rotate(-2deg)}50%{transform:rotate(2deg)}}

.owl-slot[data-state="happy"] .owl-stars{display:block}
.owl-slot[data-state="happy"] .owl{animation:owlJump .62s ease-out}
@keyframes owlJump{
  0%{transform:translateY(0) scale(1)}
  32%{transform:translateY(-15px) scale(1.05)}
  62%{transform:translateY(0) scale(.97)}
  82%{transform:translateY(-4px) scale(1.01)}
  100%{transform:translateY(0) scale(1)}
}

.owl-slot[data-state="sad"] .owl{animation:owlShake .5s ease-out}
@keyframes owlShake{0%,100%{transform:rotate(0)}22%{transform:rotate(-4deg)}55%{transform:rotate(4deg)}80%{transform:rotate(-2deg)}}

.owl-slot[data-state="shield"] .owl-shield{display:block}

/* ============================================================
   استجابة الشاشات
   ============================================================ */
@media (min-width:640px){
  .app{padding:24px 24px 48px}
  .home-brand h1{font-size:32px}
  .cat-grid{grid-template-columns:repeat(4,1fr)}
  .qtext{font-size:21px}
  .opt{font-size:18px}
  .timer{width:88px;height:88px}
  .res-stats{grid-template-columns:repeat(4,1fr)}
  .res-actions{flex-direction:row}
  .res-actions .btn{flex:1}
}
@media (min-width:900px){
  .app{max-width:780px}
}

@media (max-width:400px){
  .app{padding:12px 12px 36px}
  .home-brand h1{font-size:23px}
  .home-brand p{font-size:11.5px}
  .owl-slot{width:88px;height:98px}
  .owl-slot.small{width:74px;height:84px}
  .btn-start{min-height:60px;font-size:20px}
  .stat{max-width:78px}
  .stat b{font-size:16px}
  .qtext{font-size:18px}
  .opt{font-size:16.5px}
  .timer{width:70px;height:70px}
  .timer-num{font-size:20px}
  .res-score b{font-size:44px}
}

@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{
    animation-duration:.001ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.001ms !important;
  }
}