/* ══════════════════════════════════════════════════════
   BREAKPOINTS (mobile-first, min-width only)
   ══════════════════════════════════════════════════════ */

/* ── 480px: mid-size phones ── */
@media (min-width: 480px) {
  .timeline { grid-template-columns: repeat(2, 1fr); }
}

/* ── 640px: larger phones / small tablets ── */
@media (min-width: 640px) {
  :root { --gutter: 20px; }
  .hero { grid-template-columns: auto 1fr; }
  .hero-kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
  .kpi-value { font-size: 1.4rem; }
  .chart-wrap { height: 320px; }
  .skeleton-chart { height: 320px; }
  .compare-chart-wrap { height: 340px; }
  .mini-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mini-grid-featured { grid-template-columns: 1fr; }
  .mini-grid-rest { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .timeline { grid-template-columns: repeat(4, 1fr); }
  .fav-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .email-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .email-meta { grid-template-columns: 1fr 1fr; }
  .chart-title { font-size: 1rem; }
  .delta-value { font-size: 1.6rem; }
  .mini-card-number { font-size: 1.6rem; }
}

/* ── 768px: tablet portrait ── */
@media (min-width: 768px) {
  .hero {
    grid-template-columns: auto 1fr auto;
    gap: var(--s-5); padding: var(--s-6) 0 var(--s-4);
    align-items: center;
  }
  .puzzle-layout { grid-template-columns: 1fr 1fr; }
  .compare-selectors { grid-template-columns: repeat(3, 1fr); }
  .mini-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* ── 768px: tablets (iPad portrait, large phones landscape) ──
   Bridges mobile (<640px) and laptop (>=1024px) which previously
   inherited mobile defaults at this range and wasted horizontal
   real estate. */
@media (min-width: 768px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .progress-row { grid-template-columns: 1fr 1fr; }
  .chart-wrap { height: 360px; }
  .skeleton-chart { height: 360px; }
}

/* ── 1024px: small laptops ── */
@media (min-width: 1024px) {
  .progress-row { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .chart-wrap { height: 380px; }
  .skeleton-chart { height: 380px; }
  .compare-chart-wrap { height: 360px; }
  .fav-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .email-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .email-split { grid-template-columns: 1fr 1fr; }
  .email-split .email-output, .email-split .email-preview { min-height: 420px; }
  .chart-title { font-size: 1.05rem; }
  .kpi-value { font-size: var(--fs-6); }
  .delta-value { font-size: 1.8rem; }
  .hero-ci { font-size: var(--fs-4); }
  .mini-card-number { font-size: 1.7rem; }
  .puzzle-rating { font-size: 1.8rem; }
  .chart-card { padding: var(--s-5); }
  .panel { padding: var(--s-5) var(--s-6); }
}

/* ══════════════════════════════════════════════════════
   LANDSCAPE PHONE
   ══════════════════════════════════════════════════════ */
@media (orientation: landscape) and (max-height: 500px) {
  .drop-menu, .tab-search-results, .drop-menu-search .tab-search-results {
    max-height: 40vh;
  }
}

/* ══════════════════════════════════════════════════════
   MOBILE BOTTOM-SHEET DROPDOWNS (< 640px)
   ══════════════════════════════════════════════════════ */
@media (max-width: 639px) {
  .drop-menu {
    position: fixed;
    left: 0; right: 0; top: auto; bottom: 0;
    width: 100%; max-width: 100%;
    max-height: 82vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -8px 24px rgba(0,0,0,.4);
    padding-bottom: env(safe-area-inset-bottom);
    animation: dropSlideUp .2s ease;
    z-index: 300;
  }
  .drop-menu::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 6px;
  }
  .drop-menu-search .tab-search-results { max-height: 60vh; }
  .tab-search-panel {
    position: fixed;
    left: 0; right: 0; top: auto; bottom: 0;
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -8px 24px rgba(0,0,0,.4);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 300;
  }
  .tab-search-results { max-height: 60vh; }
}
@keyframes dropSlideUp {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Mobile drawer backdrop scrim (< 640px) ── */
@media (max-width: 639px) {
  body.drawer-open::before {
    content: '';
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 250;
    animation: scrimFadeIn .2s ease;
    pointer-events: none;
  }
}
@keyframes scrimFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ══════════════════════════════════════════════════════
   MOBILE PERF — REDUCE EXPENSIVE EFFECTS
   ══════════════════════════════════════════════════════ */
@media (max-width: 639px) {
  /* Hero number gradient text already costs; trim the 20px shadow blur */
  .hero-number { filter: drop-shadow(0 0 10px rgba(240,192,64,.18)); }
  /* Live-glow on chart-card uses two large box-shadows; tone down */
  .chart-card.live-glow { box-shadow: 0 0 20px rgba(56,139,253,.05); }
}

/* ══════════════════════════════════════════════════════
   TOUCH FEEDBACK
   ══════════════════════════════════════════════════════ */
/* Suppress the iOS gray tap-highlight flash; custom :active states below provide feedback. */
* { -webkit-tap-highlight-color: transparent; }

/* Subtle press feedback on interactive elements that mostly relied on :hover */
.mini-card, .fav-card, .puzzle-btn, .de-save-btn,
.email-generate-btn, .email-copy-btn, .email-link-btn,
.email-split-tab, .compare-add-btn, .fav-btn {
  transition: transform .12s ease, opacity .12s ease,
    color .15s, border-color .15s, background .15s, box-shadow .2s;
}
.mini-card:active, .fav-card:active { transform: scale(.985); }
.puzzle-btn:active, .de-save-btn:active, .email-generate-btn:active,
.email-copy-btn:active, .email-link-btn:active, .email-split-tab:active,
.compare-add-btn:active, .fav-btn:active { transform: scale(.96); opacity: .85; }

/* Prevent iOS auto-zoom on focused inputs (fires when computed font-size < 16px) */
@media (max-width: 639px) {
  .tab-search-input,
  .email-meta-input,
  .de-table input[type="text"],
  .de-table input[type="number"],
  .de-table input[type="date"] {
    font-size: 16px;
  }
}

/* ── Puzzles tab mobile polish (< 640px) — Round 32 ──
   - Button row: 2-col grid; primary "Next" spans full width as the prominent CTA.
   - Rating prominence: bump font-size, add letter-spacing.
   - Info card: tighten padding, larger status text. */
@media (max-width: 639px) {
  .puzzle-layout { gap: var(--s-3); }
  .puzzle-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--s-2);
    margin-top: var(--s-3);
  }
  .puzzle-nav .puzzle-btn {
    width: 100%;
    padding: 12px 12px;
    font-size: var(--fs-3);
    margin: 0;
  }
  .puzzle-nav .puzzle-btn.primary { grid-column: 1 / -1; }
  .puzzle-rating { font-size: 2.1rem; letter-spacing: -.5px; }
  .puzzle-info { padding: var(--s-3); }
  .puzzle-status { font-size: var(--fs-4); min-height: 24px; margin: var(--s-2) 0; }
  .puzzle-themes { gap: 4px; margin-top: 6px; }
  .puzzle-theme-tag { font-size: var(--fs-1); padding: 2px 8px; }
  .puzzle-progress { gap: 4px; margin: var(--s-2) 0; }
  .puzzle-dot { width: 9px; height: 9px; }
  .puzzle-score { font-size: var(--fs-2); }
  .chess-board-wrap { max-width: 100%; }
}

/* ══════════════════════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

