/* Mobile-first overrides loaded last to keep TinyStride usable on touch screens. */
html, body { max-width: 100%; overflow-x: hidden; }
button, input, select { touch-action: manipulation; }

@media (max-width: 900px) {
  .app-container { padding: 16px 14px 40px; gap: 16px; }
  .app-header { padding: 14px; align-items: flex-start; }
  .main-nav-tabs { order: 3; width: 100%; max-width: 100%; border-radius: var(--radius-md); }
  .header-controls { margin-left: auto; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
  .brand-text p { display: none; }
  .partner-invite-banner, .focus-launch-card { align-items: stretch; }
  .focus-launch-card .select-field { margin-left: 0; }
  .routine-packs-grid, .body-doubling-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}

@media (max-width: 640px) {
  .app-container { padding: 10px 10px 28px; gap: 12px; }
  .app-header { gap: 10px; padding: 12px; border-radius: var(--radius-md); }
  .brand-logo { width: 38px; height: 38px; font-size: 18px; }
  .brand-section { gap: 9px; min-width: 0; }
  .brand-text h1 { font-size: 1.1rem; }
  .header-controls { width: 100%; margin-left: 0; justify-content: space-between; }
  .cloud-sync-badge, .btn-upgrade-pro, .brown-noise-pill { font-size: .72rem; }
  .main-nav-tabs { gap: 4px; padding: 4px; scrollbar-width: none; }
  .main-nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tab-btn { padding: 8px 11px; font-size: .76rem; min-height: 38px; }
  .card { padding: 16px; border-radius: var(--radius-md); }
  .card-header { align-items: flex-start; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
  .card-title { font-size: 1rem; }
  .habit-main-row, .wager-form { display: grid; grid-template-columns: 1fr; width: 100%; }
  .habit-main-row > *, .wager-form > *, .focus-launch-card > *, .partner-invite-banner > * { width: 100%; min-width: 0 !important; }
  .drawer-grid { grid-template-columns: 1fr; gap: 14px; }
  .filter-bar { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .filter-chip { white-space: nowrap; }
  .habit-card { padding: 12px; gap: 10px; align-items: flex-start; }
  .habit-left { min-width: 0; }
  .habit-right { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .habit-title { font-size: .88rem; }
  .pomo-timer-module { max-width: 100%; }
  .bunny-card { align-items: center; padding: 12px; }
  .bunny-card .btn-secondary { width: 100%; }
  .bunny-carrots { margin-left: 0; }
  .analytics-section { gap: 14px; }
  /* Dashboard analytics: compact the calendar and weekly chart without horizontal scrolling. */
  .analytics-section,
  .analytics-section > .card,
  .analytics-section .ledger-grid,
  .analytics-section .trend-chart-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .analytics-section > .card { padding: 12px; overflow: hidden; }
  .analytics-section > .card .card-header { margin-bottom: 10px; }
  .analytics-section > .card .card-title { font-size: .94rem; }
  .ledger-nav-header { padding: 5px 6px; gap: 5px; margin-bottom: 8px; }
  .ledger-nav-btn { padding: 5px 7px; font-size: .68rem; }
  .ledger-month-title { font-size: .78rem; white-space: nowrap; }
  .ledger-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); min-width: 0; gap: 4px; margin-top: 6px; }
  .ledger-day-tile { min-width: 0; aspect-ratio: auto; min-height: 34px; border-radius: 6px; font-size: .7rem; }
  .ledger-day-tile .day-dot { width: 3px; height: 3px; margin-top: 1px; }
  .ledger-grid-wrap, .ledger-container { overflow-x: visible; }
  .trend-chart-container { height: 118px; gap: 6px; padding: 11px 5px 5px; margin-top: 8px; }
  .trend-bar-col { min-width: 0; gap: 4px; }
  .trend-bar-track { width: min(100%, 18px); max-width: 18px; border-radius: 5px; }
  .trend-label { font-size: .62rem; }
  .trend-tooltip { top: -22px; font-size: .6rem; padding: 2px 4px; }
  .partner-invite-banner { flex-direction: column; padding: 16px; gap: 14px; }
  .partner-invite-banner > div:last-child { width: 100%; justify-content: stretch !important; }
  .partner-invite-banner .btn-primary { width: 100%; justify-content: center; }
  .store-grid, .bunny-park-grid, .bunny-games-grid, .routine-packs-grid, .body-doubling-grid, .partner-cards-grid, .cohort-grid { grid-template-columns: 1fr; }
  .bunny-park-grid { padding: 12px; }
  .bunny-spotlight-card { grid-template-columns: 1fr; gap: 16px; padding: 16px; }
  .park-world-stage { min-height: 400px; }
  .wardrobe-items-grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); }
  .sanctuary-grid { grid-template-columns: 1fr; }
  .park-control-bar { flex-direction: column; align-items: stretch; gap: 10px; }
  .park-nav-pills { justify-content: center; }
  .park-stat-badges { justify-content: space-between; }
  .feature-section-picker { display: grid; grid-template-columns: 1fr 1fr; }
  .utilities-bar { flex-direction: column; align-items: stretch; gap: 10px; }
  .util-btn-group { display: grid; grid-template-columns: 1fr; width: 100%; }
  .util-btn-group > * { width: 100%; justify-content: center; }
  .modal-overlay { padding: 10px; align-items: flex-end; }
  .modal-card { max-height: 92dvh; padding: 24px 18px 18px; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-close-btn { top: 10px; right: 10px; }
  .focus-mode-content h2 { font-size: clamp(1.8rem, 12vw, 3rem); }
  .focus-mode-overlay { padding: 20px; }

  /* Dashboard: keep Today's Target balanced and readable on narrow phones. */
  .dashboard-grid { gap: 12px; margin-bottom: 12px !important; }
  .progress-hero-card { padding: 16px 12px; }
  .progress-hero-card .card-header { justify-content: center; text-align: center; }
  .progress-hero-card .card-title { width: 100%; }
  .ring-wrapper { width: min(52vw, 170px); height: min(52vw, 170px); margin: 2px 0 12px; }
  .ring-percentage { font-size: 1.9rem; }
  .target-readout { max-width: 260px; font-size: .88rem; line-height: 1.45; }
  .streak-badge-container { max-width: 100%; padding: 8px 14px; }
  .streak-sub { padding: 0 6px; line-height: 1.4; }

  /* Habit Workspace: make creation and controls thumb-friendly. */
  .dashboard-grid > .card:nth-child(2) { min-width: 0; }
  .dashboard-grid > .card:nth-child(2) .card-header > div { width: 100%; display: flex !important; justify-content: space-between; align-items: center; gap: 8px; }
  .btn-magic-deconstruct { flex: 1 1 auto; min-height: 42px; white-space: normal; justify-content: center; }
  .habit-creator-form { padding: 12px; margin-bottom: 14px; }
  .habit-main-row .input-field, .habit-main-row .select-field, .habit-main-row .btn-primary { min-height: 46px; }
  .btn-toggle-options { width: 100%; min-height: 42px; white-space: normal; text-align: left; line-height: 1.35; }
  .drawer-item { min-width: 0; }
  .days-chips-row, .preset-chips-row { flex-wrap: nowrap; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: thin; }
  .day-chip, .preset-chip { flex: 0 0 auto; min-height: 36px; }
  .bunny-card { flex-wrap: wrap; }
  .bunny-card > div:nth-child(2) { flex: 1 1 170px; }
  .bunny-card .btn-secondary { min-height: 42px; }
  .filter-bar { margin-inline: -2px; gap: 7px; }
  .filter-chip { min-height: 38px; }
  .habit-card { align-items: stretch; }
  .habit-left { flex-basis: 100%; }
  .habit-right { width: 100%; justify-content: flex-end; }
}

@media (max-width: 380px) {
  .brand-text h1 { font-size: 1rem; }
  .header-controls { gap: 5px; }
  .cloud-sync-badge { display: none; }
  .nav-tab-btn { padding: 8px 9px; }
  .custom-checkbox { width: 23px; height: 23px; min-width: 23px; }
  .feature-section-picker { grid-template-columns: 1fr; }
  .ledger-nav-btn { padding-inline: 5px; font-size: .64rem; }
  .ledger-month-title { font-size: .72rem; }
  .ledger-day-tile { min-height: 30px; font-size: .66rem; }
  .trend-chart-container { height: 106px; gap: 4px; }
  .trend-bar-track { max-width: 16px; }
}
