/* ================================================================
   MOBILE RESPONSIVE — max-width: 768px
   !! 完全不改動電腦版樣式 !! 只在手機螢幕套用
   ================================================================ */

/* ── Hide mobile elements on desktop ── */
.hm-mobile-nav { display: none; }

/* ================================================================
   @media mobile: all pages
   ================================================================ */
@media (max-width: 768px) {

  /* ── Global ── */
  html {
    overflow: hidden !important; /* prevent bounce scroll on iOS */
  }
  body {
    overflow: hidden !important;
  }
  .hm-body, .hm-header {
    zoom: 1 !important;
  }

  /* ── Fixed overlays: MUST never be clipped ── */
  #quest5-reminder-modal,
  #notification-dropdown,
  #hm-side-menu,
  #hm-side-overlay {
    position: fixed !important;
    z-index: 99999 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Reminder modal: full-screen overlay on mobile */
  #quest5-reminder-modal {
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }
  #quest5-reminder-modal-content {
    padding: 28px 18px !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    border-radius: 20px !important;
    border-width: 3px !important;
  }
  /* Scale down text inside reminder modal */
  #quest5-reminder-modal h2 {
    font-size: 18px !important;
    margin-bottom: 18px !important;
  }
  #quest5-reminder-modal span[style*="font-size: 22px"] {
    font-size: 15px !important;
  }
  #quest5-reminder-modal button[style*="padding: 18px 80px"] {
    padding: 14px 40px !important;
    font-size: 17px !important;
  }
  #quest5-reminder-modal > div > div[style*="display: flex; flex-direction: column"] {
    padding: 0 !important;
    gap: 12px !important;
  }
  #quest5-reminder-modal > div > div > div {
    padding: 14px 16px !important;
    border-radius: 14px !important;
  }

  /* All .page elements: allow vertical scroll on mobile */
  .page {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ================================================================
     HOME PAGE
     ================================================================ */
  #page-home {
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }
  .hm-header        { padding: 0 14px; height: 54px; flex-shrink: 0; }
  .hm-level-badge   { display: none !important; }
  .hm-body          { flex: 1; overflow: hidden !important; position: relative; }
  .hm-left          { display: none !important; }
  .hm-right         { display: none !important; }
  .hm-center        { display: none !important; }
  .hm-shop-card     { display: none !important; }
  .hm-ai-card       { display: none !important; }
  .hm-quest-map     { display: none !important; }
  .hm-bg            { opacity: 0.55; }
  .hm-footer        { display: none !important; }

  /* Mobile nav: shown only on mobile */
  .hm-mobile-nav {
    display: flex !important;
    flex-direction: column;
    position: absolute;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 14px 80px;
    gap: 12px;
    z-index: 10;
  }
  .hm-mn-char {
    display: flex; align-items: center; gap: 12px;
    background: rgba(253,246,236,0.95);
    border: 1.5px solid #d2bca8; border-radius: 16px;
    padding: 14px 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18); flex-shrink: 0;
  }
  .hm-mn-badge { width: 52px; height: 52px; object-fit: contain; flex-shrink: 0; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.15)); }
  .hm-mn-char-info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
  .hm-mn-role { font-size: 14px; font-weight: 800; color: #6e1414; display: flex; align-items: center; gap: 8px; }
  .hm-mn-lv { font-size: 10px; font-weight: 800; color: #f4ece4; background: #6e1414; border-radius: 8px; padding: 1px 8px; }
  .hm-mn-xp-wrap { height: 6px; background: #d2bca8; border-radius: 3px; overflow: hidden; }
  .hm-mn-xp-fill { height: 100%; background: #6e1414; border-radius: 3px; }
  .hm-mn-xp-text { font-size: 11px; font-weight: 700; color: #4a2323; }
  .hm-mn-progress-ring { position: relative; width: 48px; height: 48px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
  .hm-mn-progress-ring svg { width: 48px; height: 48px; }
  .hm-mn-progress-ring span { position: absolute; font-size: 10px; font-weight: 800; color: #6e1414; }
  .hm-mn-section-title { font-size: 13px; font-weight: 800; color: #fdf6ec; letter-spacing: 2px; padding: 0 4px; text-shadow: 0 1px 4px rgba(0,0,0,0.5); flex-shrink: 0; }
  .hm-mn-cards { display: flex; flex-direction: column; gap: 10px; }
  .hm-mn-card {
    display: flex; align-items: center; gap: 12px;
    background: rgba(253,246,236,0.95);
    border: 1.5px solid #d2bca8; border-radius: 14px;
    padding: 12px 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    transition: transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .hm-mn-card:active { transform: scale(0.97); }
  .hm-mn-card-icon { width: 48px; height: 48px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: linear-gradient(135deg,#ffe599,#d4af37); overflow: hidden; }
  .hm-mn-card-icon img { width: 40px; height: 40px; object-fit: contain; mix-blend-mode: multiply; }
  .hm-mn-icon-locked { filter: grayscale(1) opacity(0.5); }
  .hm-mn-card-body { flex: 1; min-width: 0; }
  .hm-mn-card-num { font-size: 10px; font-weight: 700; color: #a07850; letter-spacing: 1px; margin-bottom: 1px; }
  .hm-mn-card-title { font-size: 15px; font-weight: 800; color: #1a1a1a; }
  .hm-mn-card-sub { font-size: 11px; color: #666; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hm-mn-card-badge { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px; white-space: nowrap; flex-shrink: 0; }
  .hm-mn-badge-done   { background: #dcfce7; color: #166534; }
  .hm-mn-badge-active { background: #6e1414; color: white; }
  .hm-mn-badge-locked { background: #f4f4f5; color: #999; }
  .hm-mn-active { border-left: 4px solid #6e1414; }
  .hm-mn-done   { border-left: 4px solid #22c55e; opacity: 0.85; }
  .hm-mn-locked { opacity: 0.7; }
  .hm-mn-shop   { border-left: 4px solid #f59e0b; background: rgba(254,243,199,0.95); }

  /* ================================================================
     COVER PAGE (宿舍申請 + 健康檢查封面)
     ================================================================ */
  .cover-page {
    overflow-y: auto !important;
    align-items: flex-start;
    justify-content: flex-start;
  }
  .cover-center {
    padding: 24px 18px 80px;
    gap: 12px;
    max-width: 100%;
  }
  .cover-headline h1 { font-size: clamp(22px, 8vw, 34px); }
  .cover-desc        { font-size: 13px; }
  .float-stage       { height: 140px; }
  .ncku-emblem-circle { width: 76px; height: 76px; }
  .ncku-emblem-img    { width: 56px; height: 56px; }
  .float-card { padding: 8px 10px; min-width: 62px; }
  .fc-value   { font-size: 13px; }
  .fc-label   { font-size: 9px; }
  .fc-tooltip { display: none !important; }
  .fc-1 { left: 0%; }
  .fc-2 { right: 0%; top: 4%; }
  .fc-3 { right: 0%; }
  .cta-bar { height: 60px; padding: 0 16px; }
  .cta-label { font-size: 14px; }
  .cta-arrow-btn { width: 40px; height: 40px; }

  /* ================================================================
     OVERVIEW PAGE (任務清單總覽)
     ================================================================ */
  .overview-page { overflow-y: auto !important; }
  .ov-header      { padding: 12px 14px; }
  .ov-title       { font-size: 15px; }
  .steps-list     { padding: 12px 12px 10px; gap: 8px; }
  .step-row       { padding: 12px 10px; gap: 10px; }
  .step-row-title    { font-size: 13px; }
  .step-row-subtitle { font-size: 11px; }
  .step-num-badge    { width: 34px; height: 34px; font-size: 14px; }
  .ov-footer         { padding: 12px 16px 20px; }

  /* ================================================================
     STEP DETAIL PAGE (步驟詳情)
     ================================================================ */
  .step-page   { overflow-y: auto !important; }
  .step-hero   { padding: 44px 18px 24px; }
  .step-hero-title { font-size: 18px; }
  .step-emoji-large { font-size: 46px; }
  .step-body   { padding: 16px 14px; gap: 12px; }

  /* ================================================================
     QUIZ PAGE (宿舍測驗)
     ================================================================ */
  .quiz-page   { overflow-y: auto !important; }
  .quiz-header { padding: 12px 16px; }
  .quiz-body   {
    flex-direction: column !important;
    overflow-y: auto !important;
    height: auto !important;
  }
  .quiz-left-panel  { width: 100% !important; min-width: 0 !important; padding: 16px 14px !important; }
  .quiz-right-panel { display: none !important; }   /* hide map on mobile – not interactive anyway */
  .quiz-q-title     { font-size: 18px !important; }
  .quiz-q-desc      { font-size: 13px !important; }
  .quiz-options     { gap: 10px !important; }
  .quiz-option      { padding: 12px !important; }
  .quiz-opt-icon    { font-size: 28px !important; }
  .quiz-pref-grid   { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .quiz-pref-card   { padding: 14px 10px !important; }
  .quiz-footer      { padding: 14px !important; }

  /* ================================================================
     RESULTS PAGE (宿舍結果)
     ================================================================ */
  .results-page      { overflow-y: auto !important; }
  .results-header    {
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 12px 14px !important;
    gap: 8px;
    zoom: 1 !important;
  }
  .results-header-center { display: none !important; }
  .results-header-search { font-size: 12px !important; }
  .results-container {
    flex-direction: column !important;
    padding: 12px 12px 40px !important;
    gap: 12px !important;
    zoom: 1 !important;
    overflow-y: auto !important;
    height: auto !important;
  }
  .results-sidebar {
    width: 100% !important;
    min-width: 0 !important;
    max-height: none !important;
    padding: 0 !important;
  }
  .results-map-container { height: 180px !important; }
  .results-list {
    overflow-y: visible !important;
    max-height: none !important;
  }

  /* ================================================================
     DETAILS PAGE (宿舍詳情)
     ================================================================ */
  #page-details {
    overflow-y: auto !important;
  }
  #page-details .dt-split,
  #page-details > div[style*="display: flex"] {
    flex-direction: column !important;
  }
  .dt-gallery-panel {
    width: 100% !important;
    min-height: 220px !important;
    max-height: 260px;
  }
  .dt-info-panel {
    width: 100% !important;
    padding: 18px 14px !important;
  }

  /* ================================================================
     SUCCESS PAGE (宿舍申請說明)
     ================================================================ */
  #page-success {
    flex-direction: column !important;
    overflow-y: auto !important;
    padding: 14px !important;
    gap: 14px !important;
    height: auto !important;
    min-height: 100vh;
    align-items: stretch !important;
  }
  .op-sidebar {
    width: 100% !important;
    border-radius: 24px !important;
    padding: 24px 18px !important;
    zoom: 1 !important;
  }
  #mock-screen-success {
    zoom: 1 !important;
    min-height: 300px;
    border-radius: 16px !important;
  }

  /* ================================================================
     SHOP PAGE (新生商城)
     ================================================================ */
  #page-shop {
    overflow-y: auto !important;
    zoom: 1 !important;
  }
  .shop-layout {
    flex-direction: column !important;
    overflow: visible !important;
    height: auto !important;
  }
  .shop-sidebar-left {
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .shop-sidebar-box { padding: 14px !important; }
  .shop-cat-list { display: flex; flex-wrap: wrap; gap: 8px; }
  .shop-cat-item { flex: 0 0 auto; }
  .shop-main-bg  { width: 100% !important; overflow: visible !important; }
  .shop-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  .shop-product-card { padding: 12px !important; }
  .shop-product-img  { height: 130px !important; }
  .shop-product-title { font-size: 13px !important; }
  .shop-banner { height: 140px !important; }
  .shop-banner-content h2 { font-size: 18px !important; }
  .shop-header-area { padding: 10px 14px !important; flex-wrap: wrap; gap: 8px; }
  .shop-top-controls { gap: 8px !important; }
  .shop-checkout-layout {
    flex-direction: column !important;
  }
  .shop-checkout-left, .shop-checkout-right {
    width: 100% !important;
  }

  /* ================================================================
     MATTRESS / BED CUSTOMIZER PAGES
     ================================================================ */
  #page-mattress, #page-mattress-ads {
    flex-direction: column !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100vh;
  }
  #page-mattress > div,
  #page-mattress-ads > div {
    width: 100% !important;
  }

  /* ================================================================
     CHECKOUT PAGE
     ================================================================ */
  #page-checkout {
    overflow-y: auto !important;
  }
  #page-checkout > div[style*="display: flex"] {
    flex-direction: column !important;
  }

  /* ================================================================
     FINAL PAGE
     ================================================================ */
  #page-final {
    overflow-y: auto !important;
    padding: 20px 16px !important;
  }

  /* ================================================================
     ADMIN PAGE
     ================================================================ */
  #page-admin {
    overflow-y: auto !important;
  }
  #page-admin table {
    font-size: 12px !important;
  }
  #page-admin th, #page-admin td {
    padding: 6px 8px !important;
    white-space: nowrap;
  }
  #page-admin > div {
    overflow-x: auto;
  }

  /* ================================================================
     HEALTH CHECK PAGES — quest5 step2, 3, 4, 5
     ================================================================ */
  #page-task-quest5-step1,
  #page-task-quest5-step2,
  #page-task-quest5-step3,
  #page-task-quest5-step4,
  #page-task-quest5-step5 {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    min-height: 100vh;
  }

  /* Sub-page headers */
  #page-task-quest5-step1 header,
  #page-task-quest5-step2 header,
  #page-task-quest5-step3 header,
  #page-task-quest5-step4 header,
  #page-task-quest5-step5 header {
    padding: 10px 12px !important;
    flex-wrap: wrap !important;
    height: auto !important;
  }
  /* Hide breadcrumb path on mobile */
  #page-task-quest5-step1 header > div:first-child > div:last-child,
  #page-task-quest5-step2 header > div:first-child > div:last-child,
  #page-task-quest5-step3 header > div:first-child > div:last-child,
  #page-task-quest5-step4 header > div:first-child > div:last-child,
  #page-task-quest5-step5 header > div:first-child > div:last-child {
    display: none !important;
  }
  /* System title */
  #page-task-quest5-step1 header span[style*="font-size: 20px"],
  #page-task-quest5-step2 header span[style*="font-size: 20px"],
  #page-task-quest5-step3 header span[style*="font-size: 20px"],
  #page-task-quest5-step4 header span[style*="font-size: 20px"],
  #page-task-quest5-step5 header span[style*="font-size: 20px"] {
    font-size: 15px !important;
  }
  /* User info row: hide XP on mobile */
  #page-task-quest5-step1 header > div:last-child > div:nth-child(2),
  #page-task-quest5-step2 header > div:last-child > div:nth-child(2),
  #page-task-quest5-step3 header > div:last-child > div:nth-child(2),
  #page-task-quest5-step4 header > div:last-child > div:nth-child(2),
  #page-task-quest5-step5 header > div:last-child > div:nth-child(2) {
    display: none !important;
  }

  /* Step 2 hospital cards: stack vertically */
  #page-task-quest5-step2 > div:last-child {
    flex-direction: column !important;
    gap: 16px !important;
    padding: 14px 12px !important;
    margin: 0 !important;
  }
  #page-task-quest5-step2 > div:last-child > div {
    width: 100% !important;
    max-width: 100% !important;
  }
  /* Hospital card images */
  #page-task-quest5-step2 > div:last-child > div > div:first-child {
    width: 100% !important;
    height: 160px !important;
  }

  /* Steps 1, 3, 4, 5: sidebar + iframe/content → stack */
  #page-task-quest5-step1 > div[style*="display: flex"],
  #page-task-quest5-step3 > div[style*="display: flex"],
  #page-task-quest5-step4 > div[style*="display: flex"],
  #page-task-quest5-step5 > div[style*="display: flex"] {
    flex-direction: column !important;
    gap: 14px !important;
    margin: 14px auto !important;
    padding: 0 12px !important;
    max-width: 100% !important;
  }
  #page-task-quest5-step1 aside,
  #page-task-quest5-step3 aside,
  #page-task-quest5-step4 aside,
  #page-task-quest5-step5 aside {
    width: 100% !important;
    padding: 18px 14px !important;
  }
  #page-task-quest5-step1 main,
  #page-task-quest5-step3 main,
  #page-task-quest5-step4 main,
  #page-task-quest5-step5 main {
    min-width: 0 !important;
    height: 340px !important;
    min-height: 0 !important;
  }
  /* iframe inside quest5 mains */
  #page-task-quest5-step1 iframe,
  #page-task-quest5-step3 iframe,
  #page-task-quest5-step4 iframe,
  #page-task-quest5-step5 iframe {
    height: 100% !important;
    min-height: 300px !important;
  }
  /* Step checklist: show add-todo buttons */
  .q5s3-step {
    flex-wrap: wrap !important;
  }
  .td-step-content {
    flex-wrap: wrap !important;
  }

  /* ================================================================
     SIDE MENU
     ================================================================ */
  #hm-side-menu {
    width: 88vw !important;
    max-width: 320px;
  }

  /* ================================================================
     NOTIFICATION DROPDOWN
     ================================================================ */
  #notification-dropdown {
    right: 10px !important;
    width: calc(100vw - 20px) !important;
    max-width: 340px !important;
    top: 56px !important;
  }

  /* ================================================================
     LOADING PAGE
     ================================================================ */
  .loading-page { zoom: 1 !important; }
  .loading-center-box { width: 90vw !important; max-width: 360px !important; }
  .loading-emblem { width: 60px !important; height: 60px !important; }
  .loading-progress-label { font-size: 14px !important; letter-spacing: 2px !important; }
  .loading-progress-pct   { font-size: 18px !important; }
  .loading-bottom-hint    { font-size: 16px !important; letter-spacing: 2px !important; bottom: 24px !important; }

  /* ================================================================
     GENERAL UX
     ================================================================ */
  button, [role="button"] {
    min-height: 40px;
  }
  .hm-mn-card, .hm-bell, .hm-menu-icon, .hm-user-badge {
    -webkit-user-select: none;
    user-select: none;
  }
  /* Back buttons: ensure always touchable */
  .back-btn, .shop-back-btn {
    padding: 8px 14px;
    font-size: 13px;
  }
  /* Bigger tap targets for quest5 checkboxes */
  .q5s3-step-check {
    min-width: 28px !important;
    min-height: 28px !important;
  }

} /* end @media (max-width: 768px) */


/* ================================================================
   VERY SMALL PHONES — max-width: 400px
   ================================================================ */
@media (max-width: 400px) {
  .hm-header { padding: 0 10px; height: 50px; }
  .hm-user-name { display: none; }
  .hm-avatar { width: 26px; height: 26px; }
  .hm-mn-card-sub { display: none; }
  .cover-headline h1 { font-size: 20px; }
  .shop-grid {
    grid-template-columns: 1fr !important;
  }
  .quiz-pref-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}
