/* ============================================================================
   app.css — هوية «رحلة غيث»: 60% رملي دافئ، 30% أخضر واحة، 10% تراكوتا/زعفراني.
   جوال أولًا، لمس ≥64px، أزرار «صلصالية» بظل ناعم. RTL.
   ============================================================================ */
@font-face {
  font-family: 'Baloo';
  src: url('../assets/fonts/baloo-bhaijaan-2-arabic-400-normal.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Baloo';
  src: url('../assets/fonts/baloo-bhaijaan-2-arabic-700-normal.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: 'Baloo';
  src: url('../assets/fonts/baloo-bhaijaan-2-latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-display: swap; unicode-range: U+0000-00FF;
}

:root {
  --sand: #f5e3c3; --sand-deep: #e8cf9f; --clay: #c96f4a; --clay-deep: #a8543a;
  --oasis: #2e8b57; --oasis-soft: #7fc99b; --saffron: #e8a530; --teal: #20a4a8;
  --ink: #4a3423; --ink-soft: #7a6248; --card: #fff8ec;
  --shadow: 0 6px 0 rgba(74, 52, 35, .18), 0 12px 24px rgba(74, 52, 35, .12);
  /* توكنات نظام التخطيط (المرجع: لعبة-المناهج\14-نظام-تخطيط-UI.md) */
  --touch: 64px;          /* الحد الأدنى لأهداف اللمس الرئيسية */
  --touch-min: 48px;      /* الحد الأدنى للأزرار الثانوية (إغلاق/سماع) */
  --content-max: 560px;   /* أقصى عرض لعمود المحتوى */
  --gap-1: 6px; --gap-2: 10px; --gap-3: 14px; --gap-4: 18px;
  --pad-screen: 12px;     /* حشوة حواف الشاشات */
  --radius-card: 20px; --radius-btn: 22px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: 'Baloo', 'Segoe UI', sans-serif;
  background: linear-gradient(175deg, #fdf3dd 0%, var(--sand) 45%, var(--sand-deep) 100%);
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}

#fx-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 90; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

/* ── الأزرار الصلصالية ── */
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; }
.btn-big {
  min-height: 64px; padding: 14px 30px; border-radius: 22px;
  font-size: 1.35rem; font-weight: 700; color: #fff;
  background: linear-gradient(180deg, var(--oasis-soft), var(--oasis));
  box-shadow: 0 6px 0 #1d6a40, 0 10px 18px rgba(46, 139, 87, .35);
  transition: transform .12s, box-shadow .12s;
}
.btn-big:active { transform: translateY(4px); box-shadow: 0 2px 0 #1d6a40; }
.btn-big:disabled { filter: grayscale(.7) opacity(.6); box-shadow: 0 4px 0 #999; }
.btn-round {
  width: 56px; height: 56px; border-radius: 50%; font-size: 1.5rem;
  background: var(--card); box-shadow: var(--shadow);
}

/* ═══ البداية ═══ */
#screen-splash { align-items: center; justify-content: center; text-align: center; padding: 24px 16px; }
.splash-inner { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 18px; align-items: center; }
.logo { font-size: clamp(2.6rem, 10vw, 3.6rem); line-height: 1.1; }
.logo span { color: var(--teal); }
.tagline { font-size: 1.2rem; color: var(--ink-soft); margin-top: -10px; }
.char-pick { display: flex; gap: 16px; width: 100%; justify-content: center; }
.char-card {
  flex: 1; max-width: 190px; padding: 12px; border-radius: 26px;
  background: var(--card); box-shadow: var(--shadow);
  border: 4px solid transparent; transition: transform .15s, border-color .15s;
}
.char-card img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 18px; background: var(--sand-deep); }
.char-card .char-name { display: block; font-size: 1.5rem; font-weight: 700; margin-top: 6px; }
.char-card.picked { border-color: var(--saffron); transform: scale(1.05); }
.name-row { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; font-weight: 700; }
.name-row input {
  font-family: inherit; font-size: 1.2rem; font-weight: 700; text-align: center;
  width: 170px; min-height: 64px; border: 3px solid var(--sand-deep); border-radius: 16px;
  background: var(--card); color: var(--ink); outline: none;
}
.name-row input:focus { border-color: var(--teal); }
.brand { font-size: .85rem; color: var(--ink-soft); }

/* ═══ الخريطة ═══ */
#screen-map { padding: 12px 10px calc(16px + env(safe-area-inset-bottom)); gap: 8px; }
.hud { display: flex; justify-content: space-between; align-items: center; }
.hud-avatar {
  display: flex; align-items: center; gap: 10px; padding: 6px 16px 6px 6px;
  border-radius: 40px; background: var(--card); box-shadow: var(--shadow); min-height: 64px;
}
.hud-avatar img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; object-position: top; background: var(--sand-deep); }
.hud-avatar span { font-size: 1.15rem; font-weight: 700; }
.hud-drops {
  font-size: 1.3rem; font-weight: 700; padding: 10px 20px; border-radius: 40px;
  background: linear-gradient(180deg, #d9f3f4, #b3e5e7); box-shadow: var(--shadow); min-height: 64px;
  display: flex; align-items: center; gap: 4px; color: #0d6a6d;
}
.map-title { text-align: center; font-size: 1.25rem; color: var(--ink-soft); }
.map-wrap { flex: 1; display: flex; align-items: center; justify-content: center; }
#ksa-map { width: 100%; max-width: 560px; max-height: 52dvh; }
.map-hint { text-align: center; font-size: 1.05rem; color: var(--ink-soft); }

/* عناصر الخريطة (SVG — حدود المناطق الحقيقية) */
.region { cursor: pointer; }
.region .r-shape {
  stroke: #fff8ec; stroke-width: 4; stroke-linejoin: round;
  filter: drop-shadow(0 4px 3px rgba(74, 52, 35, .25));
  transition: filter .2s;
}
.region.done .r-shape { stroke: #d4f7d4; }
.region.locked { opacity: .55; }
.region text { font-family: 'Baloo', sans-serif; pointer-events: none; }
.region .r-icon { font-size: 42px; }
.region .r-name { font-size: 28px; font-weight: 700; fill: #fff; paint-order: stroke; stroke: rgba(0,0,0,.4); stroke-width: 5px; }
.region .r-badge { font-size: 26px; }
.region.open:not(.done) .r-shape { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { filter: drop-shadow(0 4px 3px rgba(74,52,35,.25)); }
  50% { filter: drop-shadow(0 0 14px rgba(232, 165, 48, .9)); }
}

/* الشخصية المرافقة وفقاعة الحوار */
.guide { display: flex; align-items: center; gap: 10px; max-width: 560px; width: 100%; margin: 0 auto; }
.guide img {
  width: 72px; height: 72px; border-radius: 50%; object-fit: cover; object-position: top;
  background: var(--sand-deep); box-shadow: var(--shadow); flex: none;
}
.guide img.bounce { animation: bounce .6s; }
@keyframes bounce { 30% { transform: translateY(-12px) scale(1.06); } 60% { transform: translateY(0) scale(1); } 80% { transform: translateY(-5px); } }
.bubble {
  position: relative; background: var(--card); border-radius: 18px; padding: 10px 14px;
  box-shadow: var(--shadow); font-size: 1.02rem; line-height: 1.55; flex: 1; min-height: 52px;
  display: flex; align-items: center;
}
.guide .bubble::before {
  content: ''; position: absolute; right: -8px; top: 50%; transform: translateY(-50%);
  border: 9px solid transparent; border-left-color: var(--card);
}
.map-actions { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.btn-shop { background: linear-gradient(180deg, #f3c96b, var(--saffron)); box-shadow: 0 6px 0 #b57708; font-size: 1.1rem; padding: 10px 22px; }
.btn-shop.attention { animation: shoppulse 1.4s ease-in-out infinite; }
@keyframes shoppulse { 50% { transform: scale(1.07); box-shadow: 0 6px 0 #b57708, 0 0 18px rgba(232,165,48,.8); } }
.hud-id { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.hud-id small { font-size: .78rem; color: var(--saffron); font-weight: 700; }
.hud-avatar img { border: 3px solid transparent; }

/* حوار لوحة المنطقة */
.sheet-dialogue { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.sheet-dialogue img {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover; object-position: top;
  background: var(--sand-deep); box-shadow: var(--shadow); flex: none;
}
.sheet-dialogue .bubble { margin-bottom: 0; }

/* سوق القطرات */
.shop-icon { font-size: 2.6rem; line-height: 1.2; }
.shop-card.cant { opacity: .55; }
.shop-card small { display: block; margin-top: 2px; }

/* ═══ لوحة المنطقة ═══ */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(74, 52, 35, .35); }
.sheet[hidden], .modal[hidden] { display: none; }
.sheet-card {
  width: 100%; max-width: 520px; background: var(--card);
  border-radius: 30px 30px 0 0; padding: 22px 20px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(74, 52, 35, .3); position: relative;
  animation: rise .25s ease-out;
}
@keyframes rise { from { transform: translateY(60px); opacity: 0; } }
.sheet-close { position: absolute; top: 14px; left: 14px; width: 44px; height: 44px; border-radius: 50%; background: var(--sand); font-size: 1.1rem; font-weight: 700; }
.sheet-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.sheet-icon { font-size: 3rem; }
.sheet-head h3 { font-size: 1.7rem; }
.sheet-stars { font-size: 1.2rem; letter-spacing: 2px; }
.sheet-blurb { font-size: 1.1rem; line-height: 1.6; color: var(--ink-soft); margin-bottom: 14px; }
.sheet-game { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--sand); border-radius: 20px; padding: 12px 16px; }
.sheet-game-info b { display: block; font-size: 1.2rem; }
.sheet-game-info small { color: var(--ink-soft); font-size: .95rem; }
.btn-play { min-width: 130px; }
.sheet-locked-msg { text-align: center; font-size: 1.05rem; color: var(--clay); background: #f9e8dc; border-radius: 16px; padding: 12px; }

/* ═══ اللعبة ═══ */
#screen-game { padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); gap: 10px; }
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.game-progress { display: flex; gap: 6px; }
.game-progress .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--sand-deep); }
.game-progress .dot.ok { background: var(--oasis); }
.game-progress .dot.bad { background: var(--clay); }
.game-progress .dot.now { outline: 3px solid var(--saffron); outline-offset: 2px; }
.game-drops { font-size: 1.15rem; font-weight: 700; color: #0d6a6d; background: #d9f3f4; padding: 8px 16px; border-radius: 30px; }
.game-stage { flex: 1; display: flex; flex-direction: column; gap: 12px; max-width: 560px; width: 100%; margin: 0 auto; }

.g-scene { border-radius: 22px; overflow: hidden; box-shadow: var(--shadow); position: relative; min-height: 120px; max-height: 26dvh; }
.g-scene img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter 1.2s; }
.g-q {
  background: var(--card); border-radius: 20px; padding: 14px 16px; box-shadow: var(--shadow);
  font-size: 1.3rem; font-weight: 700; text-align: center; line-height: 1.5;
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
}
.btn-say { width: 48px; height: 48px; border-radius: 50%; background: var(--sand); font-size: 1.2rem; flex: none; }
.g-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; }
.g-opt {
  min-height: 72px; border-radius: 20px; font-size: 1.5rem; font-weight: 700;
  background: var(--card); box-shadow: var(--shadow); transition: transform .12s, background .2s;
}
.g-opt:active { transform: scale(.96); }
.g-opt.ok { background: #d4f7d4; }
.g-opt.bad { background: #f9d5c8; animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(6px); } 75% { transform: translateX(-6px); } }

/* المزرعة */
.farm-count { font-size: 2rem; text-align: center; font-weight: 700; }
.farm-count b { color: var(--oasis); font-size: 2.4rem; }
.farm-field {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 12px; min-height: 130px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
  font-size: 1.25rem; line-height: 1.5; overflow-y: auto; max-height: 30dvh;
}
.farm-row { background: #eef7ee; border-radius: 12px; padding: 2px 8px; }
.farm-controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.farm-controls .btn-big { font-size: 1.1rem; padding: 10px; }
.btn-undo { background: linear-gradient(180deg, #f0c9a0, var(--clay)); box-shadow: 0 6px 0 var(--clay-deep); }
.btn-gold { background: linear-gradient(180deg, #f3c96b, var(--saffron)); box-shadow: 0 6px 0 #b57708; }

/* ورشة الحروف */
.trace-wrap { position: relative; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.trace-wrap canvas { display: block; width: 100%; touch-action: none; }
.trace-word { font-size: 1.3rem; text-align: center; font-weight: 700; color: var(--ink-soft); }

/* سوق السمك */
.fish-sea {
  position: relative; border-radius: 22px; overflow: hidden; flex: 1; min-height: 300px;
  background: linear-gradient(180deg, #7fd4e8 0%, #2fa3c9 70%, #1d7fa3 100%);
  box-shadow: var(--shadow);
}
.fish {
  position: absolute; font-size: 1.35rem; font-weight: 700; color: #fff;
  min-width: 64px; min-height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; gap: 2px;
  background: transparent; animation: swim 3.5s ease-in-out infinite alternate;
}
.fish .f-body { font-size: 2.6rem; filter: drop-shadow(0 3px 3px rgba(0,0,0,.25)); }
.fish .f-tag {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; paint-order: stroke; text-shadow: 0 1px 3px rgba(0,0,0,.55); padding-bottom: 6px;
}
.fish.caught { animation: caught .5s forwards; }
@keyframes swim { from { transform: translateX(-12px) rotate(-4deg); } to { transform: translateX(12px) rotate(4deg); } }
@keyframes caught { to { transform: scale(0) rotate(360deg); opacity: 0; } }

/* لغز القَطّ (عسير) */
.qatt-wall {
  display: flex; justify-content: center; gap: 6px;
  background: #fffdf6; border: 6px solid #8d6e63; border-radius: 18px;
  padding: 14px 10px; box-shadow: var(--shadow);
}
.qatt-cell {
  width: 52px; height: 52px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.7rem; color: #fff; flex: none;
}
.qatt-cell.mid { outline: 3px dashed var(--ink-soft); outline-offset: 2px; }
.qatt-cell.gap { background: #efe2c8; color: var(--clay); border: 3px dashed var(--clay); font-weight: 700; }
.qatt-opt { color: #fff; font-size: 2.2rem; }
.qatt-opt.ok, .qatt-opt.bad { filter: brightness(1.15); }
@media (max-width: 420px) { .qatt-cell { width: 42px; height: 42px; font-size: 1.4rem; } }

/* صياد اللؤلؤ (الشرقية) */
.pearl-sea {
  background: linear-gradient(180deg, #6fc9e0 0%, #2a8db8 55%, #17618c 88%, #d9c58a 88%, #cbb478 100%);
  min-height: 260px; flex: 1;
}
.oyster {
  position: absolute; font-size: 2.4rem; background: transparent;
  min-width: 64px; min-height: 64px;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.3));
  animation: sway 3.2s ease-in-out infinite alternate;
  transition: transform .2s;
}
.oyster.open { animation: pearl-pop .45s forwards; }
@keyframes sway { from { transform: rotate(-5deg); } to { transform: rotate(5deg); } }
@keyframes pearl-pop { 50% { transform: scale(1.35); } 100% { transform: scale(1.1); } }

/* ═══ النتيجة ═══ */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(74, 52, 35, .45); padding: 18px; }
.modal-card {
  width: 100%; max-width: 440px; background: var(--card); border-radius: 28px;
  padding: 26px 22px; text-align: center; box-shadow: 0 12px 40px rgba(74,52,35,.4);
  animation: pop .3s cubic-bezier(.2, 1.4, .5, 1); max-height: 88dvh; overflow-y: auto;
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.result-stars { font-size: 2.6rem; letter-spacing: 6px; margin: 8px 0; }
.result-title { font-size: 1.7rem; }
.result-sub { font-size: 1.15rem; color: var(--ink-soft); line-height: 1.6; margin-bottom: 14px; }
.result-scene { border-radius: 18px; overflow: hidden; margin-bottom: 14px; }
.result-scene img { width: 100%; display: block; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.skin-unlock img { width: 60%; max-width: 220px; border-radius: 18px; margin: 10px auto; display: block; }

/* ═══ الخزانة ═══ */
.wardrobe-card h3 { font-size: 1.6rem; margin-bottom: 4px; }
.wardrobe-hint { color: var(--ink-soft); font-size: 1rem; margin-bottom: 14px; }
.wardrobe-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.skin-card { background: var(--sand); border-radius: 18px; padding: 10px; border: 3px solid transparent; }
.skin-card img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px; background: var(--sand-deep); }
.skin-card.locked img { filter: grayscale(1) brightness(.75); }
.skin-card b { display: block; font-size: .95rem; margin-top: 6px; }
.skin-card small { color: var(--ink-soft); font-size: .8rem; }
.skin-card.equipped { border-color: var(--saffron); }
.skin-card .skin-lock { font-size: 1.4rem; }

/* ── نقاط الانكسار (نظام التخطيط) ──
   ≤360: جوال ضيق — خطوط/عناصر أصغر درجة
   361–699: الجوال المرجعي (الافتراضي أعلاه)
   ≥700: تابلت — الشيتات تتوسّط
   ≥1024: سطح مكتب — عمود المحتوى يتسع قليلًا */
@media (max-width: 360px) {
  .logo { font-size: 2.3rem; }
  .g-q { font-size: 1.12rem; padding: 12px; }
  .guide img { width: 60px; height: 60px; }
  .bubble { font-size: .95rem; }
  .btn-big { font-size: 1.15rem; padding: 12px 18px; }
  .char-card .char-name { font-size: 1.25rem; }
  .farm-controls .btn-big { font-size: .95rem; }
}
@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 30px; }
}
@media (min-width: 1024px) {
  #ksa-map { max-width: 640px; max-height: 60dvh; }
  .game-stage, .guide { max-width: 640px; }
}
