/* نسخة الهاتف كتطبيق (PWA): شريط تبويب سفلي، قائمة منزلقة، ترويسة تختفي مع التمرير، ودعوة التثبيت. */

.tabbar, .hd-srch, .inst { display: none; }
html { -webkit-tap-highlight-color: transparent; }

/* قائمة الأقسام المنزلقة */
dialog.msheet { position: fixed; inset: auto 0 0; width: 100%; max-width: 560px; max-height: 90dvh; margin: 0 auto; padding: 0 0 env(safe-area-inset-bottom); border: 0; border-radius: 24px 24px 0 0; overflow: auto; overscroll-behavior: contain; background: var(--bg); color: var(--ink); box-shadow: 0 -20px 60px rgb(0 0 0 / .25); }
dialog.msheet[open] { animation: sheetup var(--spring-d) var(--spring); }
dialog.msheet::backdrop { background: rgb(12 10 9 / .5); animation: fadein .3s ease-out; }
.ms-top { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 20px 16px 8px; background: var(--bg); touch-action: none; cursor: grab; }
.ms-top .grab { position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line); }
.ms-top h2 { flex: 1; font-size: var(--t-lg); }
.ms-srch { position: relative; margin: 8px 16px 16px; }
.ms-srch input { width: 100%; min-height: 48px; padding-inline: 16px 52px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); font-size: var(--t-md); }
.ms-srch input:focus-visible { outline: 0; border-color: var(--brand); background: var(--bg); }
.ms-srch button { position: absolute; inset-block: 2px; inset-inline-end: 2px; width: 44px; border: 0; border-radius: 22px; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; }
.ms-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 0 16px 16px; }
.ms-grid a, .ms-grid button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 92px; padding: 12px 6px; border: 0; border-radius: 16px; background: var(--surface); color: var(--ink); font: 700 var(--t-xs)/1.35 var(--f); text-align: center; transition: transform var(--snap-d) var(--snap), background .2s; }
.ms-grid a:active, .ms-grid button:active { transform: scale(.94); }
.ms-grid .mi { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--brand-t); color: var(--brand-tx); }
.ms-quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 0 16px 12px; }
.ms-quick button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 64px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--ink2); font: 700 var(--t-xs)/1.3 var(--f); }
.ms-quick button:active { transform: scale(.95); }
.ms-foot { padding: 4px 16px 20px; text-align: center; font-size: var(--t-xs); color: var(--muted); }

/* دعوة التثبيت */
.inst { position: fixed; inset-inline: 12px; inset-block-end: calc(var(--tb, 0px) + 12px + env(safe-area-inset-bottom)); z-index: 58; align-items: center; gap: 12px; padding: 12px; border-radius: 18px; background: var(--deep); color: var(--on-deep); box-shadow: 0 16px 40px rgb(0 0 0 / .3); animation: sheetup var(--spring-d) var(--spring); }
.inst:not([hidden]) { display: flex; }
.inst img { width: 48px; height: 48px; flex: none; border-radius: 12px; }
.inst div { flex: 1; display: grid; min-width: 0; }
.inst b { font-size: var(--t-sm); line-height: 1.5; }
.inst small { font-size: var(--t-xs); line-height: 1.6; color: var(--on-deep-m); }
.inst .btn { flex: none; background: var(--gold-d); color: var(--on-gold); min-height: 40px; }
.inst .ib { color: var(--on-deep); }
body.has-ap .inst { inset-block-end: calc(var(--tb, 0px) + 76px + env(safe-area-inset-bottom)); }

@keyframes sheetup { from { transform: translateY(100%); } }

@media (max-width: 999px) {
  :root { --tb: 64px; }
  .util, .nav, .menu, .fab, .hd .live { display: none !important; }
  .hd-srch { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: var(--surface); color: var(--ink); }
  .hd { position: sticky; top: 0; z-index: 40; padding-block-start: env(safe-area-inset-top); background: color-mix(in srgb, var(--bg) 94%, transparent); -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4); border-block-end: 1px solid var(--line); transition: transform var(--spring-d) var(--spring); }
  .hd.hide { transform: translateY(-110%); }
  .hd .wrap { padding-block: 8px; }
  html { scroll-padding-top: 76px; }
  body { padding-block-end: calc(var(--tb) + env(safe-area-inset-bottom)); }
  body.has-ap { padding-block-end: calc(var(--tb) + 64px + env(safe-area-inset-bottom)); }

  .tabbar { position: fixed; inset-inline: 0; inset-block-end: 0; z-index: 60; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); height: calc(var(--tb) + env(safe-area-inset-bottom)); padding-block-end: env(safe-area-inset-bottom); background: color-mix(in srgb, var(--bg) 92%, transparent); -webkit-backdrop-filter: blur(20px) saturate(1.5); backdrop-filter: blur(20px) saturate(1.5); border-block-start: 1px solid var(--line); }
  .tabbar > a, .tabbar > button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; padding: 0; border: 0; background: none; color: var(--muted); font: 700 12px/1.2 var(--f); text-decoration: none; cursor: pointer; }
  .tabbar svg { transition: transform var(--spring-d) var(--spring); }
  .tabbar [aria-current] { color: var(--brand-tx); }
  .tabbar [aria-current] svg { transform: translateY(-2px) scale(1.1); }
  .tabbar > :active svg { transform: scale(.85); }
  .tb-ind { position: absolute; top: 0; left: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--brand); transition: transform var(--spring-d) var(--spring), opacity .2s; pointer-events: none; }
  .tb-live .c { position: relative; display: grid; place-items: center; width: 54px; height: 54px; margin-block: -26px 0; border: 4px solid var(--bg); border-radius: 50%; background: var(--red-f); color: #fff; box-shadow: 0 8px 20px color-mix(in srgb, var(--red-f) 40%, transparent); transition: transform var(--snap-d) var(--snap); }
  .tb-live:active .c { transform: scale(.9); }
  .tb-live .c .i + .i { display: none; }
  .tb-live.is-playing .c .i:first-child { display: none; }
  .tb-live.is-playing .c .i + .i { display: block; }
  .tb-live.is-playing .c::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--red-f); animation: ping 1.8s var(--ease) infinite; }
  .tb-live { color: var(--red) !important; }

  .ap { inset-block-end: calc(var(--tb) + env(safe-area-inset-bottom)); border-radius: 16px 16px 0 0; }
  .ap-in { min-height: 64px; }
  .ap-tools { display: flex; }
  .ap-tools > :not([data-ap="stop"]) { display: none; }
  .toast { inset-block-end: calc(var(--tb) + 24px + env(safe-area-inset-bottom)); }
  body.has-ap .toast { inset-block-end: calc(var(--tb) + 88px + env(safe-area-inset-bottom)); }
  .vp.float { inset-block-end: calc(var(--tb) + 12px + env(safe-area-inset-bottom)); }
  body.has-ap .vp.float { inset-block-end: calc(var(--tb) + 76px + env(safe-area-inset-bottom)); }
  .sheet-panel { padding-block-end: env(safe-area-inset-bottom); }
}
/* الرئيسية على الهاتف: دوائر الملفات أولاً، والأقسام الطويلة شرائط أفقية تُسحب بالإصبع */
@media (max-width: 759px) {
  #home { display: flex; flex-direction: column; }
  #s-files { order: -1; padding-block-start: 16px; }
  #s-files + #s-hero, #s-hero { padding-block-start: 16px; }
  #progCards, #photoRow, #infoRow, #bookRow, #beats, #s-rec .g3, #repCols, #glList, #sched, #prList {
    display: flex !important; gap: 12px; margin-inline: calc(var(--pad) * -1); padding: 2px var(--pad) 6px; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory; scroll-padding-inline: var(--pad); scrollbar-width: none;
  }
  :is(#progCards, #photoRow, #infoRow, #bookRow, #beats, #s-rec .g3, #repCols, #glList, #sched, #prList)::-webkit-scrollbar { display: none; }
  :is(#progCards, #photoRow, #infoRow, #bookRow, #beats, #s-rec .g3, #repCols, #glList, #sched, #prList) > * { flex: 0 0 auto; min-width: 0; scroll-snap-align: start; }
  #beats { margin-inline: 0; scroll-padding-inline: var(--pad); }
  #progCards > *, #bookRow > * { width: 64%; }
  #photoRow > *, #infoRow > * { width: 76%; }
  #beats > *, #repCols > * { width: 88%; }
  #s-rec .g3 > * { width: 82%; }
  #glList > * { width: 74%; padding: 16px; border-radius: var(--r); border-start-end-radius: 18px; background: var(--surface); }
  #sched { margin-block-start: 12px; }
  #sched > * { width: 136px; }
  #prList > * { width: auto; }
  #progCards .card > .meta, #bookRow .card > span:not(.thumb) { order: 3; margin-block-start: auto; }
  #progCards .card, #bookRow .card { justify-content: flex-start; }
  .beat, #repCols > * { display: flex; flex-direction: column; }
  .beat > ul, #repCols > * > ul { flex: 1; display: flex; flex-direction: column; }
  .beat > ul > li, #repCols > * > ul > li { flex: 1; display: grid; }
  .beat .card, #repCols .feat2 { margin-block-end: 8px; }
  .wing { gap: 16px; }
  .wing-i figure { min-height: 160px; }
}

@media (display-mode: standalone) {
  .inst { display: none !important; }
  .tick { -webkit-user-select: none; user-select: none; }
}
@media (prefers-reduced-motion: reduce) {
  dialog.msheet[open], .inst, .tb-live.is-playing .c::after { animation: none; }
}
