/* Prevent Safari text inflation and input focus zoom while retaining manual user zoom. */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%;width:100%;max-width:100%;overflow-x:clip}
body{min-width:0;width:100%;max-width:100%;overflow-x:clip}
#shell,#main,#main>*,.reader-topbar,.book-toolbar,.toolbar,.screen-deck,.source-grid>*,.account-columns>*,.calendar-grid{min-width:0;box-sizing:border-box}
img,svg,video,canvas{max-width:100%}input,select,textarea{box-sizing:border-box;max-width:100%}
#shell{padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
body.reading-mode #main.reader-main{padding:3px!important}
.device-state-tools{display:flex;gap:8px;flex-wrap:wrap;padding-top:12px;border-top:1px solid var(--line)}
.device-state-tools .chip{font-size:13px}.device-state-tools input[type=file]{display:none}
.save-status{font-size:12px;line-height:1.7;padding:8px 10px;background:#08a39f0c;border-radius:7px}
@media(max-width:1023px){
 input:not([type=checkbox]):not([type=radio]):not([type=range]),select,textarea,
 .reader-main .book-toolbar input,.reader-main .book-toolbar select,
 .screen-main>.toolbar input,.screen-main>.toolbar select,
 .screen-main #name-search,.screen-main .prayer-toolbar select,
 .scroll-reader-bar input,.settings-card input,.settings-card select{font-size:16px!important;line-height:1.4}
 #shell,html[dir=ltr] #shell{margin-inline:0;width:100%;max-width:100%}
 #main{max-width:100%;padding:12px 10px 20px}
 .page-heading h1{font-size:26px!important;line-height:1.45}
 .page-heading p{font-size:14px;line-height:1.8}
 .page-heading .eyebrow{font-size:10px}
 .screen-main .page-heading h1{font-size:23px!important}
 .screen-main>.toolbar{min-width:0;gap:4px}
 .screen-main>.toolbar input{width:0;flex:1 1 70px;min-width:50px}
 .screen-main>.toolbar select{flex:0 1 34%;min-width:72px;max-width:36%;padding-inline:4px}
 .reader-topbar .book-toolbar select{width:0;flex:1 1 80px;min-width:55px;padding-inline:3px}
 .reader-topbar .book-toolbar input{flex:none;width:46px;min-width:46px}
 .screen-main .prayer-toolbar select{min-width:65px;flex:1 1 30%;max-width:38%;padding-inline:3px}
 .screen-main .prayer-toolbar>a{flex:0 1 28%;min-width:0;white-space:normal;text-align:center;line-height:1.4}
 .scroll-reader-bar{gap:6px}.scroll-reader-bar input{width:60px}
 .source-grid,.account-columns{grid-template-columns:minmax(0,1fr)}
 .source-card{padding:18px 16px;overflow-wrap:anywhere}.source-card h2{font-size:23px}.source-card p{font-size:15px;line-height:1.9}
 .screen-deck .dhikr-card>.arabic-text{font-size:var(--reading,26px);line-height:1.8}
 .screen-deck .name-card span{font-size:28px}
 .home-front .premium-hero h1{font-size:35px}.home-front .premium-hero .hero-copy{padding:17px 18px}
 .screen-main .counter-orbit{width:min(30dvh,230px);height:min(30dvh,230px)}
 .screen-main .counter-button strong{font-size:53px}
 .screen-deck .deed small{overflow-wrap:anywhere}
}
@media(max-width:360px){.page-heading h1,.screen-main .page-heading h1{font-size:21px!important}.home-front .premium-hero h1{font-size:31px}.reader-topbar .book-toolbar .chip{min-width:27px;padding-inline:5px}.reader-topbar .edition-tab{font-size:10px}}
@media(max-height:500px){.screen-main .page-heading h1{font-size:22px!important}.home-front .premium-hero h1{font-size:29px}.screen-main .counter-orbit{width:130px;height:130px}.screen-main .counter-button strong{font-size:43px}.screen-deck .dhikr-card>.arabic-text{font-size:22px;line-height:1.5}}

@media(max-width:1023px){input[type=number]{appearance:textfield;-moz-appearance:textfield}input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.reader-topbar .book-toolbar input{width:52px;min-width:52px}}

@font-face{font-family:SakinahOfflineHafs;src:url(assets/uthmanic-hafs.woff2) format("woff2");font-display:swap}.offline-page{height:100%;width:100%;display:flex;flex-direction:column;padding:8px 12px;gap:6px;border:1px solid #b58d5580;background:#fffef8;color:#172b25}.offline-page>.arabic-text{font-family:SakinahOfflineHafs,Amiri,serif;font-size:26px;line-height:1.8;flex:1;min-height:0;overflow:hidden;margin:0}.offline-page-label{font:10px/1.5 "IBM Plex Sans Arabic";color:#846e3d;text-align:center}.offline-tools h3{font-size:19px;margin:14px 0 6px}.offline-tools .hint{font-size:13px;line-height:1.8}

/* ——— Cross-device compatibility: phone / tablet / desktop + portrait / landscape ——— */

/* Shared fluid shell */
:root{--sakinah-gutter:clamp(10px,2.4vw,28px);--sakinah-touch:44px}
#shell>header{padding-inline:max(var(--sakinah-gutter),env(safe-area-inset-left,0px)) max(var(--sakinah-gutter),env(safe-area-inset-right,0px))}
#main{padding-inline:max(10px,env(safe-area-inset-left,0px),var(--sakinah-gutter,12px)) max(10px,env(safe-area-inset-right,0px),var(--sakinah-gutter,12px))}
.chip,.btn,.icon-button,#menu,.mobile{min-height:var(--sakinah-touch);touch-action:manipulation}
#sidebar nav a{min-height:44px}

/* Mobile drawer backdrop */
@media(max-width:1023px){
 body.menu-open::before{
  content:"";position:fixed;inset:0;z-index:15;
  background:#0d241a66;backdrop-filter:blur(2px);
 }
 #sidebar{z-index:30;max-height:100dvh;overflow:auto;-webkit-overflow-scrolling:touch;padding-bottom:max(18px,env(safe-area-inset-bottom))}
}

/* Tablet (iPad portrait / small landscape) */
@media(min-width:768px) and (max-width:1023px){
 #main{padding:18px 22px 36px}
 .page-heading h1{font-size:30px!important}
 .paths{grid-template-columns:repeat(2,minmax(0,1fr))!important}
 .landmarks-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
 .names-grid{grid-template-columns:repeat(4,minmax(0,1fr))}
 .books-grid,.books-grid.shelf-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
 .prayer-day-list{grid-template-columns:repeat(3,minmax(0,1fr))}
 .prayer-six{grid-template-columns:repeat(3,minmax(0,1fr))}
 .calendar-grid{gap:6px}
 .screen-main .counter-orbit,.tasbih .counter-orbit{width:min(34dvh,260px);height:min(34dvh,260px)}
 .qibla-dial{width:min(58vw,360px)!important}
 .adhan-actions{gap:.55rem}
 .quick-services{gap:8px}
}

/* Large phone / phablet */
@media(max-width:767px){
 .paths,.content-grid,.home-bottom,.landmarks-grid{grid-template-columns:1fr!important}
 .names-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
 .books-grid,.books-grid.shelf-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
 .prayer-six{grid-template-columns:repeat(3,minmax(0,1fr))}
 .prayer-day-list{grid-template-columns:repeat(2,minmax(0,1fr))}
 .calendar-weekdays,.calendar-grid{gap:3px}
 .calendar-day{min-height:64px;padding:6px 2px}
 .qibla-toolbar,.qibla-calibrate,.adhan-actions{gap:.4rem}
 .qibla-toolbar .chip,.qibla-calibrate .chip,.adhan-actions .chip{font-size:12px;padding:6px 10px}
 .qibla-dial{width:min(86vw,320px)!important}
 .site-prayer-smart{grid-template-columns:1fr}
 .stat-grid{grid-template-columns:1fr 1fr}
 .quick-services{justify-content:stretch}
 .quick-services a{flex:1 1 auto;text-align:center}
 .prayer-board{padding:10px}
 .prayer-schedule-table{font-size:12px;display:block;overflow-x:auto;max-width:100%}
}

/* Tiny phones */
@media(max-width:380px){
 .names-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
 .books-grid,.books-grid.shelf-grid{grid-template-columns:1fr}
 .prayer-six{grid-template-columns:repeat(2,minmax(0,1fr))}
 .header-greeting{display:none!important}
 .premium-hero h1,.home-front .premium-hero h1{font-size:28px!important}
 .btn,.chip{font-size:12px}
 .paths .path{padding:14px 12px}
}

/* Short landscape phones / foldables */
@media(orientation:landscape) and (max-height:520px){
 #shell>header{min-height:48px!important;height:auto;padding-block:4px}
 #shell>footer{display:none}
 #main{padding-block:8px 14px}
 .page-heading{margin:0 0 10px}
 .page-heading h1{font-size:22px!important;margin:0}
 .page-heading p,.page-heading .eyebrow{display:none}
 .premium-hero{min-height:min(70dvh,280px)!important}
 .premium-hero .hero-copy{padding:14px 18px!important}
 .premium-hero h1{font-size:28px!important;margin-top:8px!important}
 .screen-main .counter-orbit{width:min(42dvh,160px);height:min(42dvh,160px)}
 .screen-main .counter-button strong{font-size:36px}
 .screen-deck .dhikr-card>.arabic-text{font-size:20px;line-height:1.45}
 .qibla-board{min-height:min(78dvh,420px)!important;padding:.6rem!important}
 .qibla-dial{width:min(42dvh,220px)!important}
 .qibla-guide{display:none}
 .adhan-panel{padding:.7rem}
 .adhan-iqamah-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
 .landmarks-grid{grid-template-columns:repeat(3,minmax(0,1fr))!important}
 .library-reader-tools{flex-wrap:nowrap;overflow-x:auto}
}

/* iPad / tablet landscape with sidebar available on large widths already */
@media(orientation:landscape) and (min-width:900px) and (max-height:900px){
 .premium-hero{min-height:min(56dvh,420px)}
 .screen-main .counter-orbit{width:min(36dvh,240px);height:min(36dvh,240px)}
 .qibla-board{min-height:min(70dvh,520px)}
}

/* Desktop wide */
@media(min-width:1280px){
 .paths{grid-template-columns:repeat(4,minmax(0,1fr))}
 .landmarks-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
 .names-grid{grid-template-columns:repeat(5,minmax(0,1fr))}
 .books-grid.shelf-grid{grid-template-columns:repeat(4,minmax(0,1fr))}
 .calendar-day{min-height:92px}
 .qibla-board{max-width:720px;margin-inline:auto}
}

/* Desktop XL */
@media(min-width:1600px){
 .names-grid{grid-template-columns:repeat(6,minmax(0,1fr))}
 .books-grid.shelf-grid{grid-template-columns:repeat(5,minmax(0,1fr))}
}

/* Tasbih / beads readability */
.tasbih .counter-orbit,
.screen-main .counter-orbit,
.bead-button{max-width:100%}
@media(max-width:560px){
 .tasbih{display:grid;justify-items:center;gap:12px}
 .tasbih select{width:100%;max-width:320px}
 .dhikr-counter,.bead-track{max-width:100%;overflow:hidden}
 .bead-button{width:min(42vw,160px);height:min(42vw,160px)}
}

/* Calendar + Adhan panel */
@media(max-width:760px){
 .prayer-toolbar{flex-wrap:wrap}
 .prayer-toolbar .chip,.prayer-toolbar a.chip,.prayer-toolbar select{flex:1 1 auto}
 .adhan-panel .adhan-actions .btn{width:100%}
 .adhan-options{flex-direction:column;align-items:stretch}
 .adhan-advance{width:100%}
 .adhan-advance select{flex:1;width:100%;max-width:100%}
}

/* Library shelf cards never overflow */
.books-grid,.books-grid.shelf-grid,.library-collections,.library-path{width:100%;max-width:100%}
.book-card,.shelf-card{max-width:100%}
.library-collections-track{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;display:flex;gap:6px;padding-bottom:4px}
html[data-orientation=landscape][data-short=true] .library-collections-track{padding-bottom:2px}

/* Qibla: keep controls usable on all widths */
.qibla-toolbar,.qibla-calibrate{width:100%}
@media(max-width:560px){
 .qibla-city{width:100%}
 .qibla-city select{flex:1;width:100%}
 .qibla-meta{font-size:.75rem;gap:.35rem .55rem}
}

/* Account / favorites / deeds */
@media(max-width:560px){
 .account-banner{flex-direction:column;align-items:stretch}
 .account-banner .btn{width:100%;text-align:center}
 .settings-card form{display:grid;gap:10px}
 .settings-card form input,.settings-card form select{width:100%!important;max-width:100%}
}

/* Prefer reduced motion */
@media(prefers-reduced-motion:reduce){
 body.menu-open::before{backdrop-filter:none}
 .qibla-needle{transition:none!important}
}

/* Print: hide chrome */
@media print{
 #sidebar,#shell>header,#shell>footer,.mobile,#menu,.adhan-panel,.qibla-toolbar{display:none!important}
 #shell{margin:0!important}
 #main{max-width:100%;padding:0}
}
