/* ============================================================
   phone.css — Full phone & small-screen layout
   Load AFTER landing.css / styles.css
   Domain: https://suad.site

   Breakpoints:
     ≤ 640px  phones
     ≤ 400px  compact
     ≤ 358px  very small (target)
   ============================================================ */

.rotate-overlay {
  display: none !important;
}

/* ============================================================
   PHONES ≤ 640px — structure & organization
   ============================================================ */
@media (max-width: 640px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* ---------- LANDING ---------- */
  .landing-header {
    padding: 1.15rem 3rem 1rem;
  }

  .site-settings-btn {
    top: 10px;
    left: 8px;
    width: 42px;
    height: 42px;
    font-size: 1.25rem;
    background: transparent;
    border: none;
    color: #fff;
  }

  .site-settings-card {
    max-height: 90dvh;
    overflow-y: auto;
  }

  .site-settings-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .sound-switch {
    justify-content: space-between;
  }

  .landing-header .ornament {
    font-size: 1.3rem;
    margin-bottom: 0.2rem;
  }

  .landing-header h1 {
    font-size: 1.35rem;
    line-height: 1.3;
  }

  .landing-header p {
    font-size: 0.84rem;
    line-height: 1.45;
    max-width: 28rem;
    margin-inline: auto;
  }

  .landing-main {
    padding: 0.9rem 0.7rem 5rem;
    max-width: 100%;
  }

  .toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
    padding: 0.75rem;
    margin-bottom: 0.9rem;
    border-radius: 14px;
  }

  .toolbar-label {
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
  }

  .search-wrap {
    max-width: none;
    width: 100%;
    flex: none;
  }

  .search-wrap input {
    font-size: 1rem;
    min-height: 46px;
    border-radius: 12px;
  }

  .surah-count {
    font-size: 0.84rem;
    text-align: center;
    padding-top: 0.15rem;
  }

  .surah-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .surah-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.65rem;
    min-height: 64px;
    padding: 0.7rem 0.75rem;
    border-radius: 14px;
  }

  .surah-number {
    width: 2.3rem;
    height: 2.3rem;
    font-size: 0.9rem;
  }

  .surah-body {
    min-width: 0;
  }

  .surah-name {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .surah-meta {
    font-size: 0.76rem;
    flex-wrap: wrap;
  }

  .surah-badge {
    font-size: 0.68rem;
    padding: 0.2rem 0.5rem;
    white-space: nowrap;
  }

  .landing-note {
    font-size: 0.8rem;
    line-height: 1.5;
    margin-top: 1.2rem;
    padding: 0 0.4rem;
  }

  .coming-soon-toast {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    max-width: min(94vw, 360px);
    font-size: 0.86rem;
    padding: 0.7rem 1rem;
  }

  /* ---------- ACTIVITY: HEADER (organized grid) ---------- */
  .header-band {
    display: grid !important;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 0.35rem;
    padding: 0.75rem 0.55rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0));
    border-bottom-width: 3px;
  }

  .header-band .home-btn {
    position: static !important;
    transform: none !important;
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    width: 42px;
    height: 42px;
    font-size: 1.05rem;
  }

  .header-band .settings-btn {
    position: static !important;
    transform: none !important;
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    width: 42px;
    height: 42px;
    font-size: 1.05rem;
  }

  .header-band .settings-btn:hover,
  .header-band .home-btn:hover {
    transform: none !important;
  }

  .header-content {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    padding: 0 0.15rem;
  }

  .header-band h1 {
    font-size: 1.15rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-band p {
    font-size: 0.72rem;
    line-height: 1.3;
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ---------- ACTIVITY: MAIN FLOW ---------- */
  .container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem 0.65rem 6.5rem;
    max-width: 100%;
  }

  .container > * {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
  }

  /* Info bar: name on top, timer row below */
  .info-bar {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.7rem !important;
    padding: 0.8rem !important;
    border-radius: 14px !important;
  }

  .info-bar > div {
    width: 100% !important;
    max-width: 100% !important;
  }

  .info-bar label {
    font-size: 0.84rem !important;
  }

  .info-bar .text-xs {
    font-size: 0.7rem !important;
  }

  .info-bar .flex.items-center {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    width: 100%;
    gap: 0.5rem;
    padding-top: 0.15rem;
    border-top: 1px solid rgba(201, 169, 97, 0.25);
  }

  .input-box,
  .form-select {
    width: 100%;
    min-height: 46px;
    font-size: 1rem;
    padding: 0.6rem 0.85rem;
    border-radius: 12px;
  }

  .timer-wrap {
    width: 54px;
    height: 54px;
    flex-shrink: 0;
  }

  .timer-text {
    font-size: 0.88rem;
  }

  /* Mushaf block */
  .mushaf-page {
    padding: 0.85rem 0.65rem 0.75rem;
    border-radius: 12px;
    order: 0;
  }

  .mushaf-frame {
    inset: 6px;
  }

  .surah-header {
    font-size: 0.86rem;
    padding: 0.25rem 1rem;
    margin-bottom: 0.55rem;
  }

  .quran-text {
    font-size: clamp(1.05rem, 4.4vw, 1.28rem);
    line-height: 2.1;
    text-align: center;
    text-align-last: center;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .q-word {
    padding: 0 0.14rem;
  }

  .game-active .q-word.empty {
    min-width: 1.8rem;
  }

  .game-active .q-word.empty.q-chunk {
    min-width: 3.2rem;
  }

  .ayah-end {
    width: 1.35rem;
    height: 1.35rem;
    font-size: 0.65rem;
  }

  /* Word bank */
  .word-bank {
    min-height: 76px;
    padding: 1.3rem 0.6rem 0.85rem;
    gap: 0.5rem;
    border-radius: 14px;
    justify-content: center;
  }

  .word-bank h3 {
    right: 12px;
    top: -11px;
    font-size: 0.76rem;
    padding: 0.18rem 0.7rem;
  }

  .word-bank #bankPlaceholder,
  .word-bank .text-sm {
    font-size: 0.82rem !important;
    text-align: center;
    width: 100%;
    padding: 0.25rem 0.4rem;
  }

  .word-chip {
    font-size: 1.1rem;
    padding: 0.45rem 0.75rem;
    border-radius: 11px;
    max-width: 100%;
  }

  .ghost-chip {
    font-size: 1.05rem !important;
    padding: 0.4rem 0.65rem !important;
  }

  .feedback {
    padding: 0.8rem 0.7rem;
    font-size: 0.9rem;
    border-radius: 12px;
  }

  /* Sticky action bar — always reachable on phone */
  .action-bar {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.45rem !important;
    justify-content: stretch !important;
    margin: 0 !important;
    padding: 0.55rem 0.65rem calc(0.55rem + env(safe-area-inset-bottom, 0)) !important;
    background: linear-gradient(180deg, rgba(243, 233, 210, 0.92) 0%, #f3e9d2 35%);
    border-top: 1px solid rgba(201, 169, 97, 0.45);
    box-shadow: 0 -6px 20px rgba(45, 24, 16, 0.08);
    backdrop-filter: blur(8px);
  }

  .action-bar .btn {
    flex: 1 1 calc(50% - 0.3rem);
    min-width: 0;
    min-height: 48px;
    font-size: 0.86rem;
    padding: 0.65rem 0.4rem;
    border-radius: 12px;
  }

  /* When only one visible button, full width */
  .action-bar .btn:only-child,
  .action-bar .btn:not(.hidden):first-child:nth-last-child(1) {
    flex: 1 1 100%;
  }

  .btn {
    min-height: 46px;
    font-size: 0.9rem;
    padding: 0.65rem 0.9rem;
    border-radius: 12px;
  }

  .btn-chip {
    min-height: 36px;
    font-size: 0.78rem;
  }

  /* ---------- MODALS (bottom sheet style) ---------- */
  .overlay {
    padding: 0;
    align-items: flex-end;
  }

  .popup-card {
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 92vh);
    margin: 0;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    padding: 1.15rem 0.9rem calc(1.15rem + env(safe-area-inset-bottom, 0));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #settingsOverlay .popup-card {
    max-width: 100%;
    padding: 1rem 0.85rem calc(1rem + env(safe-area-inset-bottom, 0));
  }

  #settingsTitle,
  .settings-header h2 {
    font-size: 1.2rem !important;
  }

  .responses-icon-btn {
    width: 44px;
    height: 44px;
  }

  .settings-row {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .verse-range-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }

  .verse-range-apply {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 44px;
  }

  .verse-picker-list {
    max-height: min(28vh, 180px);
  }

  .verse-picker-item .verse-picker-preview {
    font-size: 0.88rem;
  }

  .responses-list {
    max-height: min(45vh, 340px);
  }

  .response-item {
    grid-template-columns: auto 1fr;
    gap: 0.5rem 0.6rem;
    padding: 0.7rem 0.65rem;
  }

  .response-score-wrap {
    grid-column: 2;
    text-align: right;
  }

  .response-name {
    font-size: 0.95rem;
  }

  .response-meta {
    font-size: 0.72rem;
    line-height: 1.45;
  }

  .score-display {
    font-size: 2.85rem;
  }

  .popup-card .flex.gap-3 {
    flex-direction: column;
    gap: 0.5rem !important;
  }

  .popup-card .flex.gap-3 .btn {
    width: 100%;
    flex: none;
  }

  /* Voice panel */
  .voice-panel {
    padding: 0.35rem 0.1rem 0.5rem;
  }

  .voice-panel-icon {
    width: 3rem;
    height: 3rem;
    font-size: 1.25rem;
  }

  .voice-panel h3 {
    font-size: 1.05rem;
  }

  .voice-status {
    font-size: 0.88rem;
  }

  .voice-hint {
    font-size: 0.76rem;
    max-width: 100%;
  }

  .voice-encourage-card {
    max-width: 100%;
  }

  .voice-encourage-title {
    font-size: 1.4rem;
  }

  .voice-encourage-message {
    font-size: 0.95rem;
    line-height: 1.7;
  }

  .memorize-panel .memorize-actions {
    gap: 0.45rem;
    margin-top: 0.65rem;
  }

  .memorize-panel .memorize-btn {
    flex: 1 1 100%;
    min-width: 0;
    min-height: 48px;
    font-size: 0.86rem;
  }
}

/* ============================================================
   COMPACT ≤ 400px
   ============================================================ */
@media (max-width: 400px) {
  .landing-header h1 {
    font-size: 1.22rem;
  }

  .landing-header p {
    font-size: 0.78rem;
  }

  .landing-main {
    padding: 0.75rem 0.55rem 5rem;
  }

  .surah-card {
    min-height: 60px;
    padding: 0.6rem 0.65rem;
    gap: 0.5rem;
  }

  .header-band {
    grid-template-columns: 40px 1fr 40px;
    padding: 0.65rem 0.45rem;
  }

  .header-band .home-btn,
  .header-band .settings-btn {
    width: 38px;
    height: 38px;
    font-size: 0.98rem;
  }

  .header-band h1 {
    font-size: 1.05rem;
  }

  .header-band p {
    font-size: 0.66rem;
  }

  .container {
    padding: 0.65rem 0.5rem 6.25rem;
    gap: 0.65rem;
  }

  .action-bar {
    flex-direction: column !important;
  }

  .action-bar .btn {
    flex: 1 1 auto;
    width: 100%;
    font-size: 0.88rem;
  }

  .word-chip {
    font-size: 1.02rem;
    padding: 0.38rem 0.6rem;
  }

  .quran-text {
    font-size: 1.05rem;
    line-height: 2;
  }

  .score-display {
    font-size: 2.5rem;
  }
}

/* ============================================================
   VERY SMALL ≤ 358px
   ============================================================ */
@media (max-width: 358px) {
  .landing-header {
    padding: 0.85rem 2.6rem 0.75rem;
  }

  .site-settings-btn {
    top: 8px;
    left: 6px;
    width: 40px;
    height: 40px;
    font-size: 1.15rem;
    background: transparent;
    border: none;
    color: #fff;
  }

  .landing-header .ornament {
    font-size: 1.1rem;
  }

  .landing-header h1 {
    font-size: 1.08rem;
  }

  .landing-header p {
    font-size: 0.72rem;
  }

  .landing-main {
    padding: 0.6rem 0.4rem 4.75rem;
  }

  .toolbar {
    padding: 0.55rem;
    gap: 0.45rem;
  }

  .toolbar-label {
    font-size: 0.84rem;
  }

  .search-wrap input {
    min-height: 42px;
    font-size: 0.92rem;
    padding: 0.5rem 2rem 0.5rem 0.55rem;
  }

  .surah-card {
    min-height: 56px;
    padding: 0.5rem 0.5rem;
    gap: 0.45rem;
    border-radius: 12px;
  }

  .surah-number {
    width: 1.95rem;
    height: 1.95rem;
    font-size: 0.78rem;
  }

  .surah-name {
    font-size: 0.9rem;
  }

  .surah-meta {
    font-size: 0.66rem;
  }

  .surah-badge {
    font-size: 0.58rem;
    padding: 0.12rem 0.35rem;
  }

  .landing-note {
    font-size: 0.72rem;
  }

  .header-band {
    grid-template-columns: 36px 1fr 36px;
    gap: 0.25rem;
    padding: 0.55rem 0.35rem;
  }

  .header-band .home-btn,
  .header-band .settings-btn {
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }

  .header-band h1 {
    font-size: 0.98rem;
  }

  .header-band p {
    font-size: 0.62rem;
  }

  .container {
    padding: 0.55rem 0.4rem 6rem;
    gap: 0.55rem;
  }

  .info-bar {
    padding: 0.6rem !important;
    gap: 0.55rem !important;
  }

  .info-bar label {
    font-size: 0.76rem !important;
  }

  .input-box,
  .form-select {
    min-height: 42px;
    font-size: 0.92rem;
    padding: 0.5rem 0.65rem;
  }

  .timer-wrap {
    width: 46px;
    height: 46px;
  }

  .timer-text {
    font-size: 0.76rem;
  }

  .mushaf-page {
    padding: 0.6rem 0.4rem 0.55rem;
    border-width: 2px;
  }

  .mushaf-frame {
    inset: 4px;
  }

  .surah-header {
    font-size: 0.74rem;
    padding: 0.15rem 0.65rem;
  }

  .quran-text {
    font-size: 0.98rem;
    line-height: 1.9;
  }

  .game-active .q-word.empty {
    min-width: 1.45rem;
  }

  .game-active .q-word.empty.q-chunk {
    min-width: 2.55rem;
  }

  .ayah-end {
    width: 1.15rem;
    height: 1.15rem;
    font-size: 0.55rem;
  }

  .word-bank {
    min-height: 58px;
    padding: 1.05rem 0.35rem 0.55rem;
    gap: 0.35rem;
  }

  .word-bank h3 {
    font-size: 0.66rem;
    right: 8px;
  }

  .word-chip {
    font-size: 0.92rem;
    padding: 0.32rem 0.48rem;
    border-radius: 8px;
  }

  .action-bar {
    padding: 0.45rem 0.45rem calc(0.45rem + env(safe-area-inset-bottom, 0)) !important;
    gap: 0.4rem !important;
  }

  .action-bar .btn {
    min-height: 46px;
    font-size: 0.82rem;
    padding: 0.55rem 0.4rem;
  }

  .popup-card {
    padding: 0.9rem 0.65rem calc(0.9rem + env(safe-area-inset-bottom, 0));
    border-radius: 16px 16px 0 0;
  }

  #settingsTitle,
  .settings-header h2 {
    font-size: 1.05rem !important;
  }

  .responses-icon-btn {
    width: 38px;
    height: 38px;
    font-size: 0.95rem;
  }

  .verse-picker-list {
    max-height: min(24vh, 140px);
  }

  .responses-list {
    max-height: min(38vh, 260px);
  }

  .response-name {
    font-size: 0.88rem;
  }

  .response-meta {
    font-size: 0.66rem;
  }

  .score-display {
    font-size: 2.25rem;
  }

  .voice-panel-icon {
    width: 2.55rem;
    height: 2.55rem;
    font-size: 1.1rem;
  }

  .voice-panel h3 {
    font-size: 0.95rem;
  }

  .voice-status {
    font-size: 0.8rem;
  }

  .voice-hint {
    font-size: 0.7rem;
  }

  .voice-encourage-title {
    font-size: 1.15rem;
  }

  .voice-encourage-message {
    font-size: 0.88rem;
  }
}

/* Landscape phones: compact, usable */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 480px) {
  .header-band {
    padding: 0.4rem 0.5rem;
  }

  .header-band p {
    display: none;
  }

  .container {
    padding: 0.5rem 0.65rem 4.5rem;
    gap: 0.5rem;
  }

  .action-bar {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
  }

  .action-bar .btn {
    flex: 1 1 0;
    min-height: 42px;
    font-size: 0.78rem;
  }

  .mushaf-page {
    padding: 0.5rem 0.55rem;
  }

  .quran-text {
    font-size: 0.98rem;
    line-height: 1.7;
  }

  .word-bank {
    min-height: 48px;
    padding: 0.85rem 0.5rem 0.45rem;
  }

  .overlay {
    align-items: center;
    padding: 0.35rem;
  }

  .popup-card {
    border-radius: 14px;
    max-height: 94vh;
  }
}
