:root {
  color-scheme: dark;
  --ink: #f8f7ff;
  --muted: #bdb4d7;
  --violet: #a855f7;
  --pink: #ff4fd8;
  --cyan: #35e7ff;
  --gold: #ffd45c;
  --panel: rgba(15, 7, 34, .91);
  --line: rgba(178, 113, 255, .45);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background: #090213 !important;
  color: var(--ink);
  font-family: Tahoma, Arial, system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
button, a { font-family: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.sky-wash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 20%, rgba(118, 71, 255, .07), transparent 38%), linear-gradient(to bottom, transparent 60%, rgba(5, 0, 15, .42));
  z-index: 1;
}
#impactFlash {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,.38), rgba(53,231,255,.12) 28%, transparent 58%);
}
#impactFlash.hit { animation: impact-flash .28s ease-out; }
@keyframes impact-flash { 0% { opacity: .92; } 100% { opacity: 0; } }

.is-hidden { display: none !important; }
.hud {
  position: fixed;
  z-index: 9;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  display: grid;
  grid-template-columns: minmax(76px, 1fr) auto minmax(76px, 1fr);
  align-items: start;
  gap: 8px;
  pointer-events: none;
}
.hud-card {
  min-width: 76px;
  max-width: 128px;
  padding: 7px 11px 8px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(31,13,64,.84), rgba(7,3,19,.72));
  box-shadow: 0 8px 28px rgba(0,0,0,.27), inset 0 1px rgba(255,255,255,.08);
  backdrop-filter: blur(8px);
}
.hud-card span { display: block; color: #d8cdf1; font-size: 13px; font-weight: 700; }
.hud-card b { display: block; color: #fff; font-size: clamp(28px, 8vw, 42px); line-height: 1; font-variant-numeric: tabular-nums; text-shadow: 0 0 14px rgba(168,85,247,.65); }
.floor-card { justify-self: start; }
.floor-card.bump b { animation: floor-bump .32s cubic-bezier(.2,.9,.2,1.4); }
@keyframes floor-bump { 50% { transform: scale(1.28); color: var(--cyan); } }
.score-card { justify-self: end; text-align: left; }
.score-card b { font-size: clamp(21px, 5.7vw, 30px); color: var(--gold); }
.score-card small { display: block; margin-top: 2px; font-size: 13px; color: #fff0ad; }
.hud-center { display: grid; place-items: center; gap: 7px; }
.mode-pill, .wind {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  background: rgba(9,3,26,.78);
  border: 1px solid rgba(196,137,255,.4);
  backdrop-filter: blur(8px);
}
.wind[hidden] { display: none !important; }
.wind { color: #dffaff; border-color: rgba(53,231,255,.65); box-shadow: 0 0 16px rgba(53,231,255,.25); }
.wind span { font-size: 18px; color: var(--cyan); filter: drop-shadow(0 0 6px var(--cyan)); transition: transform .25s; }
.wind.warn { animation: wind-in .8s ease-out 2; }
@keyframes wind-in { 50% { transform: scale(1.08); box-shadow: 0 0 24px rgba(53,231,255,.55); } }

.combo {
  position: fixed;
  z-index: 10;
  top: 17%;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  font-weight: 900;
  font-size: clamp(20px, 5.4vw, 34px);
  color: #fff;
  opacity: 0;
  text-shadow: 0 2px 6px rgba(0,0,0,.65);
}
/* شريط غامق شفاف هادي (يناسب المدينة الواقعية ويبين على الغيوم) */
.combo span {
  display: inline-block; padding: 8px 20px; border-radius: 14px;
  background: rgba(10,12,20,.58); border: 1px solid rgba(255,255,255,.18);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.combo.perfect span { color: #ffd45c; background: rgba(22,16,4,.55); border-color: rgba(255,212,92,.45); }
.combo.record { font-size: clamp(24px, 6.6vw, 42px); }
.combo.record span { color: #ffd45c; border-color: #ffd45c; box-shadow: 0 0 18px rgba(255,212,92,.35); }
.combo.pop { animation: combo-pop .9s cubic-bezier(.17,.85,.24,1); }
@keyframes combo-pop {
  0% { opacity: 0; transform: translateY(24px) scale(.42); }
  18% { opacity: 1; transform: translateY(0) scale(1.18); }
  38% { transform: scale(.98); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-48px) scale(1.06); }
}
.tap-hint {
  position: fixed;
  z-index: 8;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 16px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  background: rgba(8,3,22,.64);
  color: #eeeaff;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  animation: hint-pulse 1.55s ease-in-out infinite;
}
@keyframes hint-pulse { 50% { transform: translateX(-50%) scale(1.04); box-shadow: 0 0 16px rgba(168,85,247,.45); } }

.round-btn {
  position: fixed;
  z-index: 24;
  top: calc(12px + env(safe-area-inset-top));
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 50%;
  background: rgba(10,4,28,.74);
  color: white;
  text-decoration: none;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 7px 18px rgba(0,0,0,.28);
  backdrop-filter: blur(8px);
}
.round-btn:active { transform: scale(.91); }
.sound-btn { left: calc(12px + env(safe-area-inset-left)); }
.home-btn { right: calc(12px + env(safe-area-inset-right)); }
body.playing .round-btn { top: calc(118px + env(safe-area-inset-top)); }
.share-hud {
  position: fixed;
  z-index: 12;
  bottom: calc(22px + env(safe-area-inset-bottom));
  right: calc(14px + env(safe-area-inset-right));
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid rgba(255,212,92,.7);
  border-radius: 999px;
  background: rgba(31,12,49,.84);
  color: #fff4c7;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(255,212,92,.22);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(66px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
  overflow: auto;
  background: radial-gradient(circle at 50% 18%, rgba(119,42,204,.38), transparent 40%), rgba(6,1,17,.76);
  backdrop-filter: blur(8px);
}
.panel {
  position: relative;
  width: min(100%, 480px);
  max-height: 100%;
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(155deg, rgba(30,12,61,.95), rgba(10,4,25,.96));
  box-shadow: 0 25px 70px rgba(0,0,0,.55), 0 0 38px rgba(168,85,247,.22), inset 0 1px rgba(255,255,255,.08);
  text-align: center;
  scrollbar-width: thin;
}
.eyebrow { margin: 0 0 5px; color: #d5b7ff; font-size: 13px; font-weight: 900; letter-spacing: .04em; }
.panel h1, .panel h2 {
  margin: 0;
  color: #fff;
  font-weight: 900;
  text-shadow: 0 0 16px rgba(255,79,216,.65);
}
.panel h1 { font-size: clamp(34px, 10vw, 50px); }
.panel h2 { font-size: clamp(27px, 8vw, 38px); }
.lead { margin: 8px auto 15px; max-width: 360px; color: #d4cde4; font-size: 16px; line-height: 1.7; }
.brand-icon { position: relative; width: 64px; height: 56px; margin: 0 auto 3px; display: flex; align-items: end; justify-content: center; gap: 3px; filter: drop-shadow(0 0 10px rgba(53,231,255,.55)); }
.brand-icon i { display: block; width: 38px; height: 10px; border-radius: 4px; background: linear-gradient(90deg, var(--violet), var(--cyan)); border: 1px solid rgba(255,255,255,.55); }
.brand-icon i:nth-child(1) { width: 14px; height: 46px; }
.brand-icon i:nth-child(2) { position: absolute; width: 30px; transform: translateY(-12px); }
.brand-icon i:nth-child(3) { position: absolute; width: 42px; transform: translateY(-25px); }
.brand-icon i:nth-child(4) { position: absolute; width: 28px; transform: translateY(-38px); background: linear-gradient(90deg, var(--gold), var(--pink)); }
.offline-badge, .join-notice, .guest-note {
  margin: 9px 0;
  padding: 8px 11px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
}
.offline-badge { color: #fff1b5; border: 1px solid rgba(255,212,92,.4); background: rgba(255,212,92,.09); }
.join-notice { color: #dffbff; border: 1px solid rgba(53,231,255,.38); background: rgba(53,231,255,.09); }
.guest-note { color: #ffd7dc; border: 1px solid rgba(255,95,123,.35); background: rgba(255,95,123,.1); }

.modes { display: grid; gap: 9px; }
.mode-card {
  width: 100%;
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 17px;
  background: rgba(255,255,255,.055);
  color: #fff;
  text-align: right;
  cursor: pointer;
  transition: transform .12s, border-color .12s, background .12s;
}
.mode-card:hover { border-color: rgba(255,255,255,.38); background: rgba(255,255,255,.09); }
.mode-card:active { transform: scale(.975); }
.mode-card.solo { border-inline-start: 4px solid var(--violet); }
.mode-card.daily { border-inline-start: 4px solid var(--gold); }
.mode-card.challenge { border-inline-start: 4px solid var(--cyan); }
.mode-icon { flex: 0 0 44px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: rgba(0,0,0,.22); font-size: 24px; }
.mode-card b, .mode-card small { display: block; }
.mode-card b { font-size: 17px; }
.mode-card small { margin-top: 4px; color: var(--muted); font-size: 13px; font-weight: 700; }
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 14px; }
.how span { padding: 8px 4px; border-radius: 12px; background: rgba(255,255,255,.045); color: #cfc7dd; font-size: 12px; line-height: 1.45; }
.how b { width: 22px; height: 22px; display: grid; place-items: center; margin: 0 auto 4px; border-radius: 50%; background: rgba(168,85,247,.24); color: #fff; }
.status { min-height: 1.5em; margin: 12px 0 0; color: #c7bddb; font-size: 13px; line-height: 1.6; }

.end-overlay { background: radial-gradient(circle at 50% 28%, rgba(100,61,190,.4), transparent 42%), rgba(5,1,16,.66); }
.end-panel { animation: end-rise .42s cubic-bezier(.18,.9,.25,1.1); }
@keyframes end-rise { from { opacity: 0; transform: translateY(25px) scale(.94); } }
.height-result { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 7px 0 13px; }
.height-result b { font-size: clamp(62px, 20vw, 94px); line-height: .95; color: #fff; text-shadow: 0 0 12px #fff, 0 0 34px var(--violet); }
.height-result span { color: #d9d1e8; font-size: 18px; font-weight: 800; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.result-grid div { padding: 10px 8px; border-radius: 14px; background: rgba(255,255,255,.055); border: 1px solid rgba(255,255,255,.1); }
.result-grid span, .result-grid b { display: block; }
.result-grid span { color: #c9bfdc; font-size: 13px; font-weight: 700; }
.result-grid b { margin-top: 3px; color: #fff; font-size: 22px; }
.end-note { margin: 10px 0; min-height: 1.6em; color: #e1d9ee; font-size: 14px; line-height: 1.6; }
.challenge-result { margin: 10px 0; padding: 10px; border-radius: 14px; background: rgba(53,231,255,.07); border: 1px solid rgba(53,231,255,.28); font-size: 14px; line-height: 1.65; }
.end-actions, .share-panel { display: grid; gap: 9px; }
.end-actions button, .end-actions a, .share-panel > button:not(.close) {
  width: 100%;
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 10px 13px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  background: rgba(255,255,255,.07);
  color: #fff;
  text-decoration: none;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}
.end-actions .primary, .share-panel .primary { border: 0 !important; background: linear-gradient(90deg, #7c3aed, #d946ef) !important; box-shadow: 0 8px 22px rgba(217,70,239,.28); }
.end-actions button:active, .share-panel > button:active { transform: scale(.975); }

.share-overlay { z-index: 32; background: rgba(4,0,14,.82); }
.share-panel { padding-top: 27px; }
.share-panel p { margin: 3px 0 8px; color: #cec4df; line-height: 1.65; }
.share-panel .close { position: absolute; top: 8px; left: 10px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: rgba(255,255,255,.08); color: #fff; font-size: 28px; cursor: pointer; }
.share-code { margin: 4px auto 7px; padding: 9px 16px; border: 1px dashed rgba(255,212,92,.65); border-radius: 14px; color: var(--gold); font-size: 30px; font-weight: 900; letter-spacing: .12em; direction: ltr; }
.load-error { position: fixed; z-index: 50; inset: 20px; margin: auto; max-width: 420px; height: max-content; padding: 18px; border-radius: 16px; background: #2b0b24; border: 1px solid #ff7da8; color: white; text-align: center; font-weight: 800; line-height: 1.7; }

@media (max-height: 690px) {
  .overlay { align-items: flex-start; }
  .panel { padding: 17px; }
  .brand-icon { transform: scale(.82); margin-top: -6px; margin-bottom: -5px; }
  .panel h1 { font-size: 34px; }
  .lead { margin: 4px auto 9px; font-size: 14px; }
  .mode-card { min-height: 58px; padding-block: 7px; }
  .how { margin-top: 9px; }
}
@media (min-width: 720px) {
  .hud { left: 24px; right: 24px; }
  body.playing .round-btn { top: calc(70px + env(safe-area-inset-top)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}


/* ===== الأدوات المساعدة ===== */
.tool-bar {
  position: fixed; z-index: 9; left: 0; right: 0;
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; justify-content: center; gap: 10px; pointer-events: none;
}
.tool-btn {
  pointer-events: auto; position: relative; width: 78px; height: 70px;
  display: grid; place-items: center; align-content: center; gap: 1px;
  border-radius: 18px; border: 2px solid var(--line);
  background: rgba(20, 8, 44, .82); color: var(--ink);
  font: inherit; cursor: pointer; touch-action: manipulation;
  box-shadow: 0 0 14px rgba(168,85,247,.28); transition: transform .15s, opacity .2s, box-shadow .2s;
}
.tool-btn i { font-style: normal; font-size: 26px; line-height: 1; }
.tool-btn span { font-size: 12px; font-weight: 700; color: var(--muted); }
.tool-btn b {
  position: absolute; top: -8px; left: -8px; min-width: 24px; height: 24px; border-radius: 12px;
  display: grid; place-items: center; font-size: 13px; background: var(--pink); color: #fff;
  box-shadow: 0 0 10px var(--pink);
}
.tool-btn[data-tool="s"] { border-color: rgba(53,231,255,.7); }
.tool-btn[data-tool="m"] { border-color: rgba(255,79,216,.7); }
.tool-btn.passive { border-color: rgba(255,212,92,.7); cursor: default; }
.tool-btn:active:not(.empty):not(.passive) { transform: scale(.92); }
.tool-btn.empty { opacity: .35; }
.tool-btn.empty b { background: #4b3b6b; box-shadow: none; }
.tool-btn.armed { transform: translateY(-6px) scale(1.06); box-shadow: 0 0 26px var(--cyan); background: rgba(20,60,90,.9); }
.tool-btn[data-tool="m"].armed { box-shadow: 0 0 26px var(--pink); background: rgba(80,10,70,.9); }
.tool-btn.gain { animation: tool-gain .9s ease-out; }
@keyframes tool-gain { 30% { transform: scale(1.3); box-shadow: 0 0 34px var(--gold); } }
.slow-tint {
  position: fixed; inset: 0; z-index: 6; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 50%, transparent 45%, rgba(53,231,255,.28) 100%);
  transition: opacity .25s;
}
.slow-tint.on { opacity: 1; }
body.playing .tap-hint { bottom: calc(100px + env(safe-area-inset-bottom)); }

/* ===== أشكال القطع ===== */
.skins-box { margin: 10px 0 4px; }
.skins-title { margin: 0 0 8px; font-weight: 800; font-size: 14px; }
.skins-title small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); margin-top: 2px; }
.skin-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 6px; scrollbar-width: none; }
.skin-row::-webkit-scrollbar { display: none; }
.skin-chip {
  flex: 0 0 auto; min-width: 74px; padding: 8px 6px; border-radius: 14px;
  border: 2px solid var(--line); background: rgba(25,10,52,.8); color: var(--ink);
  font: inherit; display: grid; place-items: center; gap: 3px; cursor: pointer;
}
.skin-chip i { font-style: normal; font-size: 22px; }
.skin-chip span { font-size: 12px; font-weight: 700; }
.skin-chip small { font-size: 10px; color: var(--muted); }
.skin-chip.on { border-color: var(--cyan); box-shadow: 0 0 14px rgba(53,231,255,.5); background: rgba(20,50,80,.85); }
.skin-chip.locked { opacity: .45; cursor: default; }
.skin-chip.locked i { filter: grayscale(1); }

/* ===== بطاقة التفاخر ===== */
.card-panel { max-width: 380px; }
.card-img { width: 100%; border-radius: 14px; display: block; margin: 4px 0 12px; box-shadow: 0 0 22px rgba(168,85,247,.4); }
.card-save { display: block; text-align: center; padding: 12px; margin-top: 8px; border-radius: 14px; border: 1px solid var(--line); color: var(--ink); text-decoration: none; }

/* ===== الشبح ===== */
.ghost-pill { color: #e9f6ff; border-color: rgba(200,230,255,.6); }

/* ===== الاختيار كل 7 طوابق ===== */
.choice-sheet {
  position: fixed; z-index: 12; left: 0; right: 0; top: 30%;
  display: grid; justify-items: center; gap: 12px; padding: 0 12px;
  animation: choice-in .35s cubic-bezier(.17,.85,.24,1);
}
@keyframes choice-in { from { opacity: 0; transform: translateY(30px) scale(.9); } }
.choice-title { margin: 0; font-size: 22px; font-weight: 900; text-shadow: 0 0 12px var(--pink), 0 0 26px var(--violet); }
.choice-row { display: flex; gap: 10px; justify-content: center; width: 100%; max-width: 420px; }
.choice-card {
  flex: 1 1 0; min-width: 0; padding: 14px 6px 12px; border-radius: 18px;
  border: 2px solid var(--line); background: rgba(20,8,44,.92); color: var(--ink);
  font: inherit; display: grid; justify-items: center; gap: 6px; cursor: pointer;
  box-shadow: 0 0 18px rgba(168,85,247,.35); touch-action: manipulation;
}
.choice-card i { font-style: normal; font-size: 34px; line-height: 1; }
.choice-card b { font-size: 14px; }
.choice-card small { font-size: 11px; color: var(--muted); line-height: 1.4; }
.choice-card:active { transform: scale(.94); }
.choice-card.risk { border-color: rgba(255,79,216,.8); }
.choice-card.wide { border-color: rgba(53,231,255,.8); }
.mode-pill[hidden] { display: none !important; }
.risk-pill { color: #ffe3f7; border-color: rgba(255,79,216,.7); box-shadow: 0 0 14px rgba(255,79,216,.35); }

/* 👁️ علي 27/11: زر المشاهدة فوق جنب زر الصوت بدل ما يطوف وسط اللعبة */
.tw-eye { position: fixed; z-index: 24; top: calc(16px + env(safe-area-inset-top)); left: calc(62px + env(safe-area-inset-left)); }
body.playing .tw-eye { top: calc(122px + env(safe-area-inset-top)); }
@media (min-width: 720px) { body.playing .tw-eye { top: calc(74px + env(safe-area-inset-top)); } }
