/* ============================================================
   CaribFlow — css/responsive.css
   Comprehensive Viewport Media Queries
   Mobile-first (360px+) → Tablet (768px+) → Desktop (1280px+)
   ============================================================ */

@import url("./variables.css");

/* ── VIEWPORT-RELATIVE BASE ────────────────────────────────── */
html {
  font-size: clamp(14px, 2vw, 16px);
}

/* ═══════════════════════════════════════════════════════════
   MOBILE FIRST: 360px — 767px
   ═══════════════════════════════════════════════════════════ */

/* Container full-width on mobile */
.container {
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

/* Grids collapse to single column */
.grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
.grid-auto { grid-template-columns: 1fr; }

/* Dynamic Island shrinks */
#dynamic-island {
  max-width: calc(100vw - 80px);
  font-size: var(--text-xs);
  padding: 8px 14px;
}

/* Hero text scales */
h1 { font-size: clamp(1.6rem, 5vw, 2.5rem); }
h2 { font-size: clamp(1.3rem, 4vw, 2rem); }
.pomodoro-display { font-size: clamp(3rem, 12vw, 3.5rem); }

/* Modal full-width on mobile */
.modal-box {
  max-width: 100%;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-6) var(--space-4);
  margin: 0;
  animation: slideUp 0.3s var(--ease-spring);
}
.modal-overlay { align-items: flex-end; padding: 0; }
/* Keep centered modals on mobile when explicitly set */
.modal-overlay.centered { align-items: center; padding: var(--space-4); }
.modal-overlay.centered .modal-box {
  position: static;
  border-radius: var(--radius-xl);
  animation: scaleIn 0.25s var(--ease-bounce);
}

/* Nav bar safe area */
.page-content {
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

/* Tab bar scrolls horizontally */
.tab-bar {
  overflow-x: auto;
  width: 100%;
  border-radius: var(--radius-apple);
}

/* Dashboard grid collapses */
.dashboard-grid { grid-template-columns: 1fr; }
.dashboard-grid .col-span-2 { grid-column: span 1; }
.dashboard-grid .col-span-3 { grid-column: span 1; }

/* Profile grid single col */
.profile-grid {
  grid-template-columns: 1fr;
  padding: var(--space-3);
}

/* Spin wheel scales down */
.spin-wheel-wrapper { width: 260px; height: 260px; }
#spin-wheel-canvas { width: 260px !important; height: 260px !important; }

/* Periodic table scrolls */
.periodic-table-wrapper { overflow-x: auto; }
.element-card { width: 40px; height: 40px; }
.element-symbol { font-size: 0.85rem; }

/* Leaderboard tabs stack */
.leaderboard-tabs { flex-direction: column; gap: var(--space-2); }

/* Flash card smaller */
.flashcard-scene { height: 240px; }

/* Currency chips compact */
.currency-chip { padding: 4px 8px; font-size: 11px; }

/* Settings modal */
.settings-modal { padding: var(--space-6) var(--space-4); }

/* Ad modal */
.ad-modal-box { padding: var(--space-6) var(--space-5); }

/* Pomodoro ring */
.pomodoro-ring { width: 180px; height: 180px; }
.pomodoro-ring svg { width: 180px; height: 180px; }

/* Whiteboard full-width */
#whiteboard-canvas { height: 280px; }

/* Subject rank stacks */
.subject-rank-card .subject-rank-progress { display: none; }

/* Hide labels on smallest screens */
.nav-item .nav-label { display: none; }

/* Hero section condensed on mobile */
.profile-hero { padding: var(--space-4) var(--space-3) var(--space-3); }
.profile-banner { height: 100px; }
.profile-avatar-wrap { margin-top: 60px; }
.profile-avatar { width: 80px; height: 80px; }
.profile-username { font-size: var(--text-xl); }
.profile-stats-row { gap: var(--space-4); }
.profile-stat-value { font-size: var(--text-lg); }

/* Auth card padding */
.auth-card { padding: var(--space-6) var(--space-5); }

/* Mascot smaller */
.mascot-image { width: 90px; height: 90px; }

/* SRS buttons wrap */
.srs-rating-row { gap: var(--space-1); }
.srs-btn { padding: 6px 10px; font-size: var(--text-xs); }

/* ═══════════════════════════════════════════════════════════
   SMALL MOBILE: < 360px
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 359px) {
  html { font-size: 13px; }
  .spin-wheel-wrapper { width: 220px; height: 220px; }
  #spin-wheel-canvas { width: 220px !important; height: 220px !important; }
  .profile-avatar { width: 70px; height: 70px; }
  .element-card { width: 34px; height: 34px; }
}

/* ═══════════════════════════════════════════════════════════
   TABLET: 768px — 1279px
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  html { font-size: 15px; }

  /* Container */
  .container { padding-left: var(--space-6); padding-right: var(--space-6); }

  /* Nav labels visible */
  .nav-item .nav-label { display: block; }

  /* Grids */
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

  /* Dashboard partial grid */
  .dashboard-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--space-4);
  }
  .dashboard-grid .col-span-2 { grid-column: span 2; }
  .dashboard-grid .col-span-3 { grid-column: span 3; }
  .dashboard-grid .col-span-6 { grid-column: span 6; }

  /* Profile grid two columns */
  .profile-grid { grid-template-columns: repeat(2, 1fr); }

  /* Modal centered */
  .modal-box {
    position: static;
    border-radius: var(--radius-xl);
    max-width: 520px;
    padding: var(--space-8);
    animation: scaleIn 0.25s var(--ease-bounce);
  }
  .modal-overlay { align-items: center; padding: var(--space-6); }

  /* Spin wheel full size */
  .spin-wheel-wrapper { width: 300px; height: 300px; }
  #spin-wheel-canvas { width: 300px !important; height: 300px !important; }

  /* Flash card */
  .flashcard-scene { height: 280px; }

  /* Pomodoro ring */
  .pomodoro-ring { width: 200px; height: 200px; }
  .pomodoro-ring svg { width: 200px; height: 200px; }

  /* Profile hero */
  .profile-hero { padding: var(--space-8) var(--space-6) var(--space-4); }
  .profile-banner { height: 140px; }
  .profile-avatar-wrap { margin-top: 80px; }
  .profile-avatar { width: 96px; height: 96px; }

  /* Whiteboard */
  #whiteboard-canvas { height: 400px; }

  /* Element cards */
  .element-card { width: 48px; height: 48px; }
  .element-symbol { font-size: 1rem; }

  /* Auth card */
  .auth-card { padding: var(--space-8); max-width: 440px; margin: 0 auto; }

  /* Nav is now fixed at bottom with full labels */
  .nav-item { min-width: 80px; }

  /* Subject rank progress visible */
  .subject-rank-card .subject-rank-progress { display: block; }

  /* Cosmetics grid wider */
  .cosmetics-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }

  /* Mascot */
  .mascot-image { width: 110px; height: 110px; }
}

/* ═══════════════════════════════════════════════════════════
   DESKTOP: 1280px+
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 1280px) {
  html { font-size: 16px; }

  /* Container */
  .container { padding-left: var(--space-8); padding-right: var(--space-8); }

  /* Full grids */
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-auto { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

  /* Full 12-col dashboard */
  .dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--space-5);
  }
  .dashboard-grid .col-span-2  { grid-column: span 2; }
  .dashboard-grid .col-span-3  { grid-column: span 3; }
  .dashboard-grid .col-span-4  { grid-column: span 4; }
  .dashboard-grid .col-span-6  { grid-column: span 6; }
  .dashboard-grid .col-span-8  { grid-column: span 8; }
  .dashboard-grid .col-span-12 { grid-column: span 12; }

  /* Profile grid three columns */
  .profile-grid { grid-template-columns: repeat(3, 1fr); padding: var(--space-6); }

  /* Nav: side rail on desktop */
  .nav-bar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    right: auto;
    width: 80px;
    flex-direction: column;
    justify-content: flex-start;
    padding: 80px 0 var(--space-6);
    border-top: none;
    border-right: 1px solid var(--glass-border);
    border-bottom: none;
  }
  .nav-item {
    width: 100%;
    border-radius: 0;
    padding: var(--space-3) 0;
    flex-direction: column;
    min-width: 80px;
  }
  .nav-item.active { background: var(--accent-subtle); }

  /* Offset page for side nav */
  .page-content { padding-left: 80px; padding-top: calc(64px + var(--space-4)); }

  /* Modal stays centered, larger */
  .modal-box { max-width: 560px; }
  .modal-box.modal-lg { max-width: 800px; }

  /* Dashboard two-sidebar layout */
  .dashboard-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: var(--space-6);
    align-items: start;
  }
  .dashboard-sidebar {
    position: sticky;
    top: calc(64px + var(--space-4));
  }

  /* Spin wheel larger */
  .spin-wheel-wrapper { width: 340px; height: 340px; }
  #spin-wheel-canvas { width: 340px !important; height: 340px !important; }

  /* Flash card */
  .flashcard-scene { max-width: 560px; height: 320px; }

  /* Profile hero */
  .profile-hero { padding: var(--space-10) var(--space-8) var(--space-6); }
  .profile-banner { height: 180px; }
  .profile-avatar-wrap { margin-top: 100px; }
  .profile-avatar { width: 112px; height: 112px; }

  /* Whiteboard larger */
  #whiteboard-canvas { height: 500px; }

  /* Mascot full size */
  .mascot-image { width: 130px; height: 130px; }

  /* Toast larger */
  #toast-container { max-width: 360px; }

  /* Cosmetics grid */
  .cosmetics-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }

  /* Pomodoro ring */
  .pomodoro-ring { width: 240px; height: 240px; }
  .pomodoro-ring svg { width: 240px; height: 240px; }

  /* Element cards full size */
  .element-card { width: 56px; height: 56px; }
}

/* ═══════════════════════════════════════════════════════════
   LARGE DESKTOP: 1600px+
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 1600px) {
  .container { max-width: 1440px; }
  .dashboard-layout { grid-template-columns: 1fr 360px; }
}

/* ═══════════════════════════════════════════════════════════
   LANDSCAPE MOBILE: short/wide viewport
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 767px) and (orientation: landscape) {
  .profile-banner { height: 80px; }
  .profile-avatar-wrap { margin-top: 40px; }
  .spin-wheel-wrapper { width: 220px; height: 220px; }
  #spin-wheel-canvas { width: 220px !important; height: 220px !important; }
  .pomodoro-ring { width: 160px; height: 160px; }
  .pomodoro-ring svg { width: 160px; height: 160px; }
  .modal-box {
    max-height: 80vh;
    overflow-y: auto;
  }
}

/* ═══════════════════════════════════════════════════════════
   PRINT
   ═══════════════════════════════════════════════════════════ */
@media print {
  #dynamic-island,
  .nav-bar,
  .profile-settings-btn,
  .btn-primary,
  #toast-container,
  .modal-overlay { display: none !important; }
  body { padding: 0; }
  .page-content { padding: 0; }
  .glass-card {
    border: 1px solid #ccc;
    box-shadow: none;
    backdrop-filter: none;
  }
}

/* ═══════════════════════════════════════════════════════════
   HOVER DETECTION (touch devices)
   ═══════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  /* Disable hover effects that feel wrong on touch */
  .glass-card:hover { transform: none; }
  .subject-card:hover { transform: none; }
  .cosmetic-item:hover { transform: none; }
  .profile-badge-item:hover { transform: none; }

  /* Tap targets minimum 44px */
  .btn, .nav-item, .toggle-wrap, .tab-btn { min-height: 44px; }

  /* Larger hit targets for interactive items */
  .color-swatch, .brush-size-btn { width: 36px; height: 36px; }
}

/* ═══════════════════════════════════════════════════════════
   DARK MODE SYSTEM PREFERENCE (fallback before JS loads)
   ═══════════════════════════════════════════════════════════ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg-primary:       #000000;
    --bg-secondary:     rgba(28, 28, 30, 0.65);
    --glass-bg:         rgba(30, 30, 30, 0.4);
    --glass-border:     rgba(255, 255, 255, 0.12);
    --panel-overlay:    rgba(0, 0, 0, 0.85);
    --text-main:        #f5f5f7;
    --text-secondary:   #d1d1d6;
    --text-muted:       #86868b;
    --text-placeholder: #636366;
    --divider:          rgba(255, 255, 255, 0.08);
    --input-bg:         rgba(44, 44, 46, 0.7);
    --input-border:     rgba(255, 255, 255, 0.12);
    --card-bg:          rgba(30, 30, 30, 0.6);
    --nav-bg:           rgba(0, 0, 0, 0.85);
    --island-bg:        rgba(30, 30, 30, 0.95);
    --island-text:      #f5f5f7;
    --scrollbar-thumb:  rgba(255, 255, 255, 0.2);
    --scrollbar-track:  rgba(255, 255, 255, 0.03);
    --skeleton-base:    rgba(255, 255, 255, 0.06);
    --skeleton-shine:   rgba(255, 255, 255, 0.02);
  }
}
