/* حلبة الطباعة — هوية مدونة إثراء العرب (التركوازي والذهبي) */

/* ---------- الخطوط (Tajawal، رخصة OFL) ---------- */
@font-face { font-family: "Tajawal"; font-weight: 400; font-display: swap; src: url(fonts/tajawal-arabic-400-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Tajawal"; font-weight: 500; font-display: swap; src: url(fonts/tajawal-arabic-500-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Tajawal"; font-weight: 700; font-display: swap; src: url(fonts/tajawal-arabic-700-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Tajawal"; font-weight: 800; font-display: swap; src: url(fonts/tajawal-arabic-800-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Tajawal"; font-weight: 400; font-display: swap; src: url(fonts/tajawal-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Tajawal"; font-weight: 500; font-display: swap; src: url(fonts/tajawal-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Tajawal"; font-weight: 700; font-display: swap; src: url(fonts/tajawal-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Tajawal"; font-weight: 800; font-display: swap; src: url(fonts/tajawal-latin-800-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- الألوان والمقاسات ---------- */
:root {
  --brand: #00636e;
  --brand-600: #00525b;
  --brand-700: #003f46;
  --brand-100: #d6ebed;
  --brand-50: #edf6f7;
  --gold: #b48c5c;
  --gold-600: #96703f;
  --gold-100: #f1e4d2;
  --gold-50: #faf5ee;
  --bg: #f2f6f6;
  --surface: #ffffff;
  --line: #dbe4e5;
  --line-2: #c4d1d3;
  --text: #13282b;
  --text-2: #4a6064;
  --muted: #7c8f92;
  --ok: #10805a;
  --ok-bg: #e0f3ea;
  --err: #cc3333;
  --err-bg: #fde6e6;
  --warn-bg: #fff3dc;
  --warn: #8a5a00;
  --road: #2a3137;
  --silver: #8c9aa0;
  --bronze: #b6764a;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(10, 40, 44, 0.06);
  --shadow: 0 1px 2px rgba(10, 40, 44, 0.05), 0 14px 36px -12px rgba(10, 40, 44, 0.22);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Tajawal", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 800; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px; background: var(--brand); color: #fff;
  min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2em; color: inherit; text-decoration: none; white-space: nowrap; }
.keycap {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  background: var(--gold); color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 20px; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}
.topbar .sub { opacity: 0.8; font-weight: 500; font-size: 0.85em; }
.topbar .spacer { flex: 1; }
.topbar .btn.ghost { color: #fff; }
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, 0.14); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); font-weight: 700; white-space: nowrap; }
.pill .car { width: 34px; }
.standings-mini .car { width: 40px; flex: none; }

/* ---------- الأزرار والحقول ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  border: 0; border-radius: 12px; padding: 0.62em 1.15em; font-weight: 700;
  background: var(--brand-50); color: var(--brand-700);
  transition: background 0.15s, transform 0.08s; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--brand-100); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible, .seg button:focus-visible, .mode:focus-visible, .swatch:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.gold { background: var(--gold); color: #fff; }
.btn.gold:hover { background: var(--gold-600); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.05); }
.btn.danger { background: var(--err-bg); color: var(--err); }
.btn.big { font-size: 1.25em; padding: 0.75em 1.6em; border-radius: 16px; }
.btn.block { width: 100%; }
.btn.icon { padding: 0.5em 0.7em; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-weight: 700; font-size: 0.92em; color: var(--text-2); }
.input, textarea.input {
  width: 100%; border: 1.5px solid var(--line-2); border-radius: 12px;
  padding: 0.6em 0.85em; background: #fff;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-100); }
textarea.input { resize: vertical; min-height: 110px; line-height: 1.7; }
.field-error { color: var(--err); font-size: 0.9em; font-weight: 700; min-height: 1.4em; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 12px; background: var(--brand-50); }
.seg button { border: 0; background: transparent; padding: 0.4em 0.85em; border-radius: 9px; font-weight: 700; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--brand-700); box-shadow: var(--shadow-sm); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: var(--shadow-sm); }
.card h2 { font-size: 1.15em; margin-bottom: 12px; }

/* ---------- السيارة والطريق ---------- */
.car { display: block; overflow: visible; }
.road { position: relative; height: 100%; background: var(--road); border-radius: 10px; overflow: hidden; }
.road::before {
  content: ""; position: absolute; top: 50%; height: 2px; transform: translateY(-50%);
  inset-inline: 14px 20px;
  background: repeating-linear-gradient(to left, rgba(255, 255, 255, 0.5) 0 16px, transparent 16px 32px);
}
.road::after {
  content: ""; position: absolute; inset-block: 0; inset-inline-end: 0; width: 14px;
  background: repeating-conic-gradient(#fff 0 25%, #1b1f23 0 50%) 0 0 / 7px 7px;
}
.road .start { position: absolute; inset-block: 0; inset-inline-start: 6px; width: 3px; background: rgba(255, 255, 255, 0.3); }
.road .goal { position: absolute; inset-inline-end: 20px; top: 1px; font-size: 11px; font-weight: 700; color: rgba(255, 255, 255, 0.75); }
.road .car {
  --car-w: calc((var(--lane-h) - 8px) * 64 / 30);
  position: absolute; top: 50%; height: calc(var(--lane-h) - 8px); width: var(--car-w);
  inset-inline-start: calc(var(--p, 0) * (100% - 18px - var(--car-w)) + 4px);
  transform: translateY(-50%);
  transition: inset-inline-start 0.32s linear;
}

/* ---------- لوحة المعلم: الانتظار ---------- */
.host-main { padding: 20px; }
.lobby { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(330px, 1fr); gap: 20px; align-items: start; }
.join {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: center;
  background: var(--brand); color: #fff; border-radius: 24px; padding: 22px 28px; box-shadow: var(--shadow);
}
.join .lead { font-size: 1.1em; opacity: 0.9; }
.join .url { font-size: clamp(18px, 1.8vw, 26px); font-weight: 800; direction: ltr; text-align: right; word-break: break-all; }
.join .code { font-size: clamp(64px, 8.5vw, 132px); font-weight: 800; letter-spacing: 0.12em; line-height: 1.05; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.join .code-label { font-weight: 700; opacity: 0.85; }
.qr { background: #fff; border-radius: 16px; padding: 10px; width: clamp(140px, 14vw, 220px); }
.qr svg { width: 100%; height: auto; display: block; }
.qr-cap { text-align: center; font-size: 0.85em; opacity: 0.85; margin-top: 6px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 0 12px; }
.section-head h2 { font-size: 1.25em; }
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 10px; }
.pchip {
  position: relative; display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 10px; animation: pop 0.35s ease both;
}
.pchip .car { width: 46px; flex: none; }
.pchip .info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.pchip .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip .pts { font-size: 0.8em; color: var(--gold-600); font-weight: 800; }
.pchip .pts:empty { display: none; }
.pchip.off { opacity: 0.45; }
.pchip .x { position: absolute; top: 3px; inset-inline-end: 3px; border: 0; background: #fff; color: var(--muted); width: 24px; height: 24px; border-radius: 7px; font-size: 16px; line-height: 1; opacity: 0; }
.pchip:hover .x, .pchip .x:focus-visible { opacity: 1; }
.pchip .x:hover { background: var(--err-bg); color: var(--err); }
.empty { text-align: center; padding: 34px 20px; color: var(--text-2); border: 2px dashed var(--line-2); border-radius: 18px; }

.settings { display: grid; gap: 16px; position: sticky; top: 16px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { border: 2px solid var(--line); border-radius: 14px; padding: 12px; background: #fff; text-align: start; display: grid; gap: 2px; }
.mode .ico { font-size: 1.6em; line-height: 1.2; }
.mode b { font-size: 1.05em; }
.mode small { color: var(--text-2); line-height: 1.45; }
.mode[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-50); }
.preview { background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 0.95em; color: var(--text-2); max-height: 6.6em; overflow: hidden; line-height: 1.65; }
.preview[dir="ltr"] { text-align: left; }
.standings-mini { display: grid; gap: 6px; }
.standings-mini .r { display: flex; gap: 10px; align-items: center; }
.standings-mini .r b { width: 24px; text-align: center; color: var(--gold-600); }
.standings-mini .r .pts { font-weight: 800; }

/* ---------- لوحة المعلم: السباق ---------- */
.race-head { display: flex; align-items: center; gap: 16px; padding: 10px 20px; flex-wrap: wrap; }
.race-head .title { font-size: 1.25em; font-weight: 800; }
.race-head .title small { font-weight: 500; color: var(--text-2); font-size: 0.8em; }
.timer { font-size: clamp(30px, 3.6vw, 54px); font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; line-height: 1; color: var(--brand-700); }
.timer.low { color: var(--err); animation: pulse 1s ease-in-out infinite; }
.lanes { --lane-h: 44px; display: flex; flex-direction: column; gap: 6px; padding: 0 20px 14px; }
.lane { display: grid; grid-template-columns: 40px minmax(90px, 180px) minmax(0, 1fr) 96px; align-items: center; gap: 10px; height: var(--lane-h); }
.lane .rk { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-700); font-weight: 800; font-size: 0.9em; }
.lane.done .rk { background: var(--gold); color: #fff; }
.lane.done.r1 .rk { box-shadow: 0 0 0 3px var(--gold-100); }
.lane .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: clamp(14px, calc(var(--lane-h) * 0.42), 22px); }
.lane .fire { color: #e8590c; font-weight: 800; margin-inline-start: 4px; }
.lane .sp { font-weight: 800; font-variant-numeric: tabular-nums; text-align: end; font-size: clamp(14px, calc(var(--lane-h) * 0.42), 22px); }
.lane .sp small { font-weight: 500; color: var(--text-2); font-size: 0.7em; }
.lane.gone { opacity: 0.35; }
.race-foot { display: flex; gap: 10px; justify-content: center; padding: 0 20px 18px; }

.countdown { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 45, 50, 0.6); z-index: 40; }
.countdown .n { font-size: min(42vw, 320px); font-weight: 800; color: #fff; line-height: 1; animation: zoom 0.9s ease-out both; text-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); }
.countdown .n.go { color: var(--gold-100); font-size: min(24vw, 200px); }
.countdown .cap { position: absolute; bottom: 12vh; color: #fff; font-size: 1.4em; font-weight: 700; }

/* ---------- النتائج والتتويج ---------- */
.results { padding: 18px 20px 26px; display: grid; gap: 18px; }
.results .head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.results .head h1 { font-size: 1.6em; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: clamp(10px, 2vw, 22px); }
.pod { width: min(230px, 28vw); text-align: center; }
.pod .car { width: 72%; margin: 0 auto 4px; }
.pod .who { font-weight: 800; font-size: 1.25em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pod .meta { color: var(--text-2); font-weight: 700; }
.pod .block { margin-top: 8px; border-radius: 14px 14px 0 0; display: grid; place-items: center; color: #fff; font-size: 2.4em; font-weight: 800; transform-origin: bottom; animation: rise 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.15) both; }
.pod.p1 .block { height: 170px; background: var(--gold); }
.pod.p2 .block { height: 125px; background: var(--silver); animation-delay: 0.15s; }
.pod.p3 .block { height: 95px; background: var(--bronze); animation-delay: 0.3s; }
.pod.p1 .crown { font-size: 2em; line-height: 1; animation: bob 2s ease-in-out infinite; }
.awards { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.award { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; font-weight: 700; box-shadow: var(--shadow-sm); }
.award .ico { font-size: 1.3em; }
.award small { color: var(--gold-600); font-weight: 800; }

.tbl-wrap { overflow-x: auto; border-radius: 16px; border: 1px solid var(--line); background: #fff; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { background: var(--brand-50); color: var(--brand-700); font-weight: 800; text-align: start; padding: 10px 12px; font-size: 0.88em; white-space: nowrap; }
.tbl td { padding: 9px 12px; border-top: 1px solid var(--line); white-space: nowrap; }
.tbl tr.me td { background: var(--gold-50); }
.tbl .car { width: 40px; display: inline-block; vertical-align: middle; margin-inline-end: 8px; }
.miss { display: inline-flex; gap: 4px; }
.miss span { background: var(--err-bg); color: var(--err); border-radius: 6px; padding: 0 7px; font-weight: 800; }
.flag { color: var(--warn); background: var(--warn-bg); border-radius: 6px; padding: 0 6px; font-size: 0.85em; font-weight: 700; }
.plus { color: var(--ok); font-weight: 800; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.final { text-align: center; padding: 26px 20px; display: grid; gap: 14px; justify-items: center; }
.final .crown { font-size: 76px; line-height: 1; animation: bob 2s ease-in-out infinite; }
.final .champ { font-size: clamp(40px, 6vw, 84px); font-weight: 800; color: var(--brand-700); line-height: 1.1; }
.final > .car { width: min(300px, 60vw); }
.final .stats-line { font-size: 1.2em; font-weight: 700; color: var(--text-2); }

/* ---------- نوافذ وتنبيهات ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 30, 34, 0.45); display: grid; place-items: center; z-index: 60; padding: 20px; }
.modal { background: #fff; border-radius: 20px; width: min(760px, 100%); max-height: 86vh; overflow: auto; padding: 20px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.modal .row.end { justify-content: flex-end; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { background: var(--text); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 700; animation: pop 0.25s ease both; box-shadow: var(--shadow); }
.net { position: fixed; top: 0; left: 0; right: 0; background: var(--gold-600); color: #fff; text-align: center; padding: 6px; z-index: 70; font-weight: 700; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* ---------- صفحة الطالب ---------- */
.narrow { max-width: 560px; margin: 5vh auto; padding: 0 16px; }
.code-input { font-size: 2.1em; letter-spacing: 0.35em; text-align: center; direction: ltr; font-weight: 800; padding: 0.35em; }
.code-input::placeholder { color: var(--line-2); }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.swatch { border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 6px 4px; }
.swatch[aria-checked="true"] { border-color: var(--brand); background: var(--brand-50); }
.swatch .car { width: 100%; }
.stack { display: grid; gap: 14px; }

.wait { text-align: center; padding: 6vh 20px; display: grid; gap: 12px; justify-items: center; }
.wait > .car { width: min(260px, 60vw); animation: idle 0.5s ease-in-out infinite alternate; }
.wait h1 { font-size: clamp(26px, 3vw, 38px); }
.next-info { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.tag { background: var(--brand-50); color: var(--brand-700); border-radius: 999px; padding: 4px 14px; font-weight: 700; }
.tip { max-width: 640px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 12px 18px; color: var(--text-2); }
.dots::after { content: ""; animation: dots 1.5s steps(4) infinite; }

.play-main { max-width: 1120px; margin: 0 auto; padding: 14px 18px 22px; display: grid; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 6px 12px; }
.stat .l { font-size: 0.8em; color: var(--text-2); font-weight: 700; }
.stat .v { font-size: 1.55em; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.25; }
.stat .v small { font-size: 0.5em; color: var(--text-2); font-weight: 700; }
.stat.timer-box .v.low { color: var(--err); }
.mini { --lane-h: 42px; height: var(--lane-h); }

.textbox {
  --lh: 1.95;
  background: #fff; border: 1px solid var(--line); border-radius: 18px;
  padding: 12px 22px; font-size: clamp(22px, 2.3vw, 31px); line-height: var(--lh);
  max-height: calc(var(--lh) * 1em * 3 + 24px); overflow: hidden; position: relative;
  user-select: none; -webkit-user-select: none; cursor: text;
}
.textbox[dir="ltr"] { text-align: left; }
.textbox .inner { position: relative; transition: transform 0.2s ease; }
.textbox .w { border-radius: 6px; }
.textbox .w.done { color: var(--ok); }
.textbox .w.cur { background: var(--brand-50); box-shadow: 0 0 0 3px var(--brand-50); }
.textbox .ok { color: var(--ok); }
.textbox .bad { color: var(--err); background: var(--err-bg); text-decoration: underline wavy var(--err); }
.textbox .caret { box-shadow: inset 0 -3px 0 var(--brand); }
.textbox.blurred::after {
  content: "اضغط هنا لمتابعة الكتابة"; position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.82); font-size: 0.7em; font-weight: 800; color: var(--brand-700);
}
.typein { font-size: clamp(22px, 2.1vw, 29px); padding: 0.42em 0.8em; border-radius: 16px; border: 2px solid var(--line-2); width: 100%; background: #fff; }
.typein:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-100); }
.typein.err { border-color: var(--err); background: var(--err-bg); animation: shake 0.22s; }
.typein:disabled { background: #eef2f2; }
.hint-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 38px; font-weight: 700; color: var(--text-2); }
.hint-line .k { display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 8px; border-radius: 9px; background: var(--brand); color: #fff; font-weight: 800; font-size: 1.15em; }
.warnbox { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 6px 14px; font-weight: 800; }
.done-box { background: var(--gold-50); border: 2px solid var(--gold-100); border-radius: 18px; padding: 14px 18px; text-align: center; font-size: 1.25em; font-weight: 800; color: var(--gold-600); }

/* لوحة المفاتيح على الشاشة */
.kb { --u: min(44px, calc((100vw - 70px) / 15.4)); display: grid; gap: 5px; justify-content: center; direction: ltr; user-select: none; }
.kb-row { display: flex; gap: 5px; }
.key {
  width: calc(var(--u) * var(--w, 1) + 5px * (var(--w, 1) - 1)); height: calc(var(--u) * 0.9);
  border-radius: 8px; display: grid; place-items: center; position: relative;
  font-weight: 700; font-size: calc(var(--u) * 0.44); color: #2f4346;
  background: var(--f, #eef2f2); border: 1px solid rgba(0, 0, 0, 0.06); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}
.key.fn { color: var(--muted); font-size: calc(var(--u) * 0.27); }
.key.home::after { content: ""; position: absolute; bottom: 4px; width: 28%; height: 2px; border-radius: 2px; background: currentColor; opacity: 0.45; }
.key.on { background: var(--brand); color: #fff; box-shadow: 0 0 0 3px var(--gold), inset 0 -2px 0 rgba(0, 0, 0, 0.2); animation: keypulse 1s ease-in-out infinite; }
.f-LP, .f-RP { --f: #fde3e6; }
.f-LR, .f-RR { --f: #fff1c4; }
.f-LM, .f-RM { --f: #ddf4e4; }
.f-LI { --f: #d9e9ff; }
.f-RI { --f: #e8defc; }
.f-TH { --f: #eceff1; }

.me-rank { font-size: clamp(64px, 10vw, 120px); font-weight: 800; color: var(--brand); line-height: 1; }
.cards4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; width: 100%; }
.mine-award { background: var(--gold-50); border: 2px solid var(--gold-100); border-radius: 16px; padding: 10px 16px; font-weight: 800; color: var(--gold-600); }
.msg-screen { text-align: center; padding: 10vh 20px; display: grid; gap: 14px; justify-items: center; }
.msg-screen .ico { font-size: 64px; }

/* ---------- الصفحة الرئيسية ---------- */
.hero { text-align: center; padding: 6vh 20px 3vh; display: grid; gap: 12px; justify-items: center; }
.hero h1 { font-size: clamp(38px, 6vw, 68px); color: var(--brand-700); }
.hero p { color: var(--text-2); font-size: 1.15em; max-width: 640px; }
.hero .cars { display: flex; gap: 6px; }
.hero .cars .car { width: 72px; animation: idle 0.5s ease-in-out infinite alternate; }
.hero .cars .car:nth-child(2) { animation-delay: 0.15s; }
.hero .cars .car:nth-child(3) { animation-delay: 0.3s; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; max-width: 920px; margin: 0 auto; padding: 0 20px; }
.choice { display: grid; gap: 12px; align-content: start; }
.choice .ico { font-size: 34px; }
.steps { max-width: 920px; margin: 26px auto 0; padding: 0 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.step { display: flex; gap: 12px; align-items: flex-start; }
.step b.n { width: 34px; height: 34px; border-radius: 50%; background: var(--gold); color: #fff; display: grid; place-items: center; flex: none; }
.foot { text-align: center; color: var(--muted); padding: 30px 20px 24px; font-size: 0.9em; }
body.embed .hero { padding-top: 22px; }
body.embed .steps, body.embed .foot { display: none; }

/* ---------- الأنماط الجماعية: الفرق، شد الحبل، الزعيم ---------- */
.modes .mode:last-child:nth-child(odd) { grid-column: 1 / -1; }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.team-col { border: 2px solid var(--team); border-radius: 18px; padding: 12px; background: #fff; background: color-mix(in srgb, var(--team) 7%, #fff); }
.team-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--team); font-size: 1.1em; }
.team-head .muted { font-size: 0.8em; }
.team-ico { font-size: 1.6em; line-height: 1; }
.team-members { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.pchip.static { animation: none; }
.pchip.clickable { cursor: pointer; }
.pchip.clickable:hover { border-color: var(--team, var(--brand)); }
.pchip.clickable:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.tug { display: grid; grid-template-columns: minmax(140px, 220px) minmax(0, 1fr) minmax(140px, 220px); align-items: center; gap: 16px; padding: 6px 20px 12px; }
.tug-team { text-align: center; border: 3px solid var(--team); border-radius: 20px; padding: 10px; background: #fff; transition: transform 0.3s, background 0.3s; }
.tug-team.lead { background: color-mix(in srgb, var(--team) 13%, #fff); transform: scale(1.05); }
.tug-ico { font-size: clamp(40px, 4vw, 60px); line-height: 1.1; }
.tug-team.lead .tug-ico { animation: pull 0.6s ease-in-out infinite alternate; }
.tug-name { font-weight: 800; font-size: 1.25em; color: var(--team); }
.tug-team .pull { display: block; font-size: 2.1em; color: var(--team); line-height: 1.1; }
.tug-field { position: relative; height: 150px; border-radius: 20px; background: #fff; border: 1px solid var(--line); overflow: hidden; }
.tug-zone { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--team) 11%, #fff); }
.tug-zone.z0 { left: 50%; right: 0; }
.tug-zone.z1 { left: 0; right: 50%; }
.tug-zone::after { content: ""; position: absolute; top: 12%; bottom: 12%; width: 4px; border-radius: 2px; background: var(--team); }
.tug-zone.z0::after { right: 16%; }
.tug-zone.z1::after { left: 16%; }
.tug-mid { position: absolute; left: 50%; top: 10px; bottom: 10px; border-left: 2px dashed rgba(0, 0, 0, 0.3); }
.rope { position: absolute; left: 1%; right: 1%; top: 50%; height: 14px; transform: translateY(-50%); border-radius: 7px; background: repeating-linear-gradient(60deg, #b8834a 0 8px, #8a5a2b 8px 16px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2); }
.knot { position: absolute; top: 50%; left: calc(50% + var(--x, 0) * 42%); width: 26px; height: 64px; transform: translate(-50%, -38%); transition: left 0.35s ease-out; background: #e63946; clip-path: polygon(0 0, 100% 0, 100% 78%, 50% 100%, 0 78%); }
.tug-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 0 20px 12px; }
.tug-col { display: grid; gap: 6px; align-content: start; }
.member { display: grid; grid-template-columns: 40px minmax(70px, 140px) minmax(0, 1fr) 52px; align-items: center; gap: 8px; }
.member .car { width: 40px; }
.member .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .bar { height: 12px; background: #e9eff0; border-radius: 6px; overflow: hidden; }
.member .fill { display: block; height: 100%; width: 0; background: var(--team); border-radius: 6px; transition: width 0.3s; }
.member b { text-align: end; color: var(--team); }

.boss-arena { display: grid; grid-template-columns: minmax(0, 1fr) minmax(250px, 330px); gap: 18px; padding: 4px 20px 12px; align-items: start; }
.boss-main { display: grid; gap: 10px; justify-items: center; }
.boss-name { font-size: 1.5em; font-weight: 800; color: #5b2a86; }
.hp { position: relative; width: min(760px, 100%); height: 34px; background: #efe6f6; border-radius: 17px; overflow: hidden; border: 2px solid #dccbea; }
.hp-fill { display: block; height: 100%; width: 100%; background: #7b4fd6; transition: width 0.35s ease, background 0.3s; }
.hp-fill.mid { background: #e07a1f; }
.hp-fill.low { background: #d6334a; }
.hp-label { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; }
.hp-pill { background: rgba(255, 255, 255, 0.92); color: #2a1642; padding: 0 12px; border-radius: 999px; line-height: 1.6; }
.boss-stage { position: relative; width: min(380px, 55vh); aspect-ratio: 1; }
.boss-wrap { width: 100%; height: 100%; animation: bossIdle 2.4s ease-in-out infinite; }
.boss { --boss: #7b4fd6; width: 100%; height: 100%; display: block; overflow: visible; }
.boss .brows, .boss .cracks { display: none; }
.boss.p2 { --boss: #e07a1f; }
.boss.p3 { --boss: #d6334a; }
.boss.p2 .brows, .boss.p3 .brows, .boss.p3 .cracks { display: block; }
.boss.hit { animation: bossHit 0.28s ease; }
.boss.dead { --boss: #8a8f94; animation: bossDie 1.2s ease forwards; }
.floats { position: absolute; inset: 0; pointer-events: none; }
.float { position: absolute; font-weight: 800; font-size: 1.6em; color: #d6334a; white-space: nowrap; text-shadow: 0 2px 0 #fff; animation: floatUp 1.3s ease-out forwards; }
.float small { font-size: 0.55em; color: var(--text-2); }

.banner { --team: var(--brand); background: var(--team); color: #fff; border-radius: 20px; padding: 14px 22px; text-align: center; display: grid; gap: 4px; font-weight: 700; box-shadow: var(--shadow); }
.banner .big { font-size: 1.8em; font-weight: 800; line-height: 1.3; }
.banner.win { background: #12805a; }
.banner.lose { background: #5b2a86; }

.mini-tug { position: relative; height: 46px; border-radius: 12px; overflow: hidden; background: #fff; border: 1px solid var(--line); }
.mini-tug .rope { height: 8px; }
.mini-tug .knot { width: 16px; height: 34px; }
.mini-tug .tug-mid { top: 4px; bottom: 4px; }
.mini-hp { width: 100%; height: 30px; }
.mini-label { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; font-size: 0.95em; color: var(--text-2); }
.team-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 16px; border-radius: 999px; background: var(--team); color: #fff; font-weight: 800; font-size: 1.15em; }
.flash { color: var(--err); font-weight: 800; }

/* ---------- الحركة ---------- */
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes zoom { from { transform: scale(1.7); opacity: 0; } 35% { opacity: 1; } to { transform: scale(1); opacity: 1; } }
@keyframes rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes idle { from { transform: translateY(0); } to { transform: translateY(-3px); } }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-5deg); } }
@keyframes keypulse { 50% { box-shadow: 0 0 0 6px var(--gold-100), inset 0 -2px 0 rgba(0, 0, 0, 0.2); } }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
@keyframes pull { from { transform: translateX(0) rotate(0); } to { transform: translateX(4px) rotate(-6deg); } }
@keyframes bossIdle { 50% { transform: translateY(-8px); } }
@keyframes bossHit { 25% { transform: translateX(-7px) rotate(-2deg); } 75% { transform: translateX(7px) rotate(2deg); } }
@keyframes bossDie { to { transform: translateY(30px) rotate(-18deg) scale(0.7); opacity: 0.3; } }
@keyframes floatUp { from { transform: translateY(0) scale(0.8); opacity: 0; } 15% { opacity: 1; transform: translateY(-6px) scale(1.1); } to { transform: translateY(-60px) scale(1); opacity: 0; } }

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

@media (max-width: 980px) {
  .lobby { grid-template-columns: 1fr; }
  .boss-arena { grid-template-columns: 1fr; }
  .tug { grid-template-columns: 1fr 1fr; }
  .tug-field { grid-column: 1 / -1; order: 3; }
  .settings { position: static; }
  .join { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .join .url, .join .code { text-align: center; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar .sub { display: none; }
  .lane { grid-template-columns: 30px minmax(60px, 100px) minmax(0, 1fr) 60px; gap: 6px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modes { grid-template-columns: 1fr; }
}
