/* My Smart Stake — mobile-first refinement V144
   Layered after zach.css so the existing desktop design and app logic remain intact. */
:root {
  --mss-mobile-safe-top: env(safe-area-inset-top, 0px);
  --mss-mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mss-mobile-gutter: clamp(10px, 3vw, 18px);
  --mss-mobile-tap: 44px;
}

html { scroll-padding-top: 76px; }
body { min-width: 320px; overflow-x: clip; }
main, .page, .panel, .auth-card, .setup-card, .restricted-card,
.table-card, .progress-card, .proposal, .match-card, .unp-card,
.sim-box, .modal-box, .dashboard-top { min-width: 0; }
button, a, [role="button"] { -webkit-tap-highlight-color: transparent; }

@media (max-width: 760px) {
  html { width: 100%; overflow-x: clip; scroll-padding-top: 68px; }
  body {
    width: 100%; max-width: 100%; min-width: 320px;
    font-size: 15px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
    overflow-x: clip;
  }
  main {
    width: 100%; max-width: none; min-width: 0;
    padding: 14px var(--mss-mobile-gutter) calc(36px + var(--mss-mobile-safe-bottom));
  }
  .topbar {
    min-height: 60px; height: auto; gap: 8px;
    padding: calc(7px + var(--mss-mobile-safe-top)) 12px 7px;
    flex-wrap: wrap;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .brand { flex: 1 1 150px; min-width: 0; gap: 8px; }
  .brand img { flex: 0 0 auto; width: 36px; height: 36px; max-width: 74px; }
  .brand-copy { min-width: 0; }
  .brand-copy b { max-width: 42vw; font-size: clamp(13px, 3.8vw, 16px); overflow: hidden; text-overflow: ellipsis; }
  .brand-copy small { display: none; }
  .top-actions { flex: 0 1 auto; min-width: 0; max-width: 100%; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .top-actions select { min-width: 70px; max-width: 112px; min-height: var(--mss-mobile-tap); padding: 8px 22px 8px 8px; }
  .top-actions button { min-height: var(--mss-mobile-tap); }
  #logoutBtn { max-width: 105px; padding: 8px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Prevent iOS zoom-on-focus and keep every control comfortably tappable. */
  input:not([type="checkbox"]), select, textarea { font-size: 16px !important; max-width: 100%; }
  button { touch-action: manipulation; }
  .primary, .secondary, .ghost, .danger-btn, .odds-btn,
  .hub-tab, .tab, .social-btn, .recover-btn, .pay-method,
  .mc-stats-btn, .usl-open, #uslPublishBtn {
    min-height: 42px;
  }
  .wide { width: 100%; }

  /* Main account dashboard and stake plan */
  .dashboard-top { width: 100%; padding: 14px; border-radius: 16px; gap: 12px; }
  .dashboard-top h1 { font-size: clamp(22px, 6vw, 28px); line-height: 1.16; overflow-wrap: anywhere; }
  .dashboard-actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .dashboard-actions button { min-width: 0; min-height: 44px; padding: 9px 8px; line-height: 1.25; white-space: normal; overflow-wrap: anywhere; }
  .panel { padding: 13px; margin: 10px 0; border-radius: 15px; }
  .plan-box { width: 100%; max-width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-cell { min-width: 0; padding: 10px 8px; }
  .plan-cell span { font-size: clamp(10px, 2.9vw, 12px); line-height: 1.3; overflow-wrap: anywhere; }
  .plan-cell strong { font-size: clamp(15px, 4.2vw, 18px); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
  .final-fixed { grid-column: 1 / -1; display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
  .final-fixed span { min-width: 0; }
  .final-fixed strong { max-width: 62%; text-align: right; overflow-wrap: anywhere; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { min-width: 0; padding: 11px; border-radius: 13px; }
  .stat span { display: block; font-size: 11px; line-height: 1.3; overflow-wrap: anywhere; }
  .stat b { font-size: clamp(15px, 4.4vw, 19px); line-height: 1.2; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
  .progress-card { padding: 12px; border-radius: 14px; }

  /* Keep the complete stake table visible on mobile; pinch-zoom remains enabled. */
  .table-card { width: 100%; min-width: 0; max-width: 100%; overflow: visible; border-radius: 14px; }
  .table-title { align-items: flex-start; gap: 8px; padding: 12px; }
  .table-title h2 { font-size: 17px; line-height: 1.25; }
  .table-title p { font-size: 12px; line-height: 1.4; }
  .stake-table { display: block; width: 100%; min-width: 0 !important; max-width: 100%; overflow: visible; touch-action: pan-y pinch-zoom; }
  .stake-table .tr { width: 100%; min-width: 0 !important; grid-template-columns: minmax(0,.78fr) minmax(0,1fr) minmax(0,1.02fr) minmax(0,.98fr) minmax(0,1.25fr); }
  .stake-table .tr > div { min-width: 0; overflow-wrap: anywhere; }

  /* Compact, readable sections; avoid cards forcing the viewport wider. */
  .proposals, .hub, .hub-pane, .fich-pane, .proposal-list,
  .hub-tools, .hub-sub, .odds-categories { min-width: 0; max-width: 100%; }
  .proposal-list { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .proposal, .match-card, .unp-card, .sim-box { width: 100%; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
  .hub-tabs { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .hub-tabs::-webkit-scrollbar { display: none; }
  .hub-tab { min-height: 42px; flex: 0 0 auto; }
  .hub-sub, .odds-categories { gap: 7px; }
  .hub-sub > *, .odds-categories > * { max-width: 100%; }
  .odds-btn { padding: 9px 11px; }

  /* Profile, settings and payment panels */
  .profile-grid { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .profile-fields, .setup-grid { grid-template-columns: minmax(0, 1fr); }
  .setup-grid .wide { grid-column: auto; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .setting-card { min-width: 0; padding: 12px; }
  .subscription-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .sub-card { min-width: 0; padding: 12px 5px; border-width: 1px; border-radius: 12px; overflow-wrap: anywhere; }
  .sub-card b { font-size: 24px; }
  .sub-card span { font-size: 11px; }
  .sub-card strong { display: block; font-size: clamp(10px, 2.8vw, 13px); overflow-wrap: anywhere; }
  .method-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .pay-method-cell { min-width: 0; }
  .pay-method { min-width: 0; width: 100%; padding: 10px 7px; line-height: 1.25; overflow-wrap: anywhere; }
  .pay-mini-agent { min-height: 40px; min-width: 40px; }
  .recover-methods { grid-template-columns: minmax(0, 1fr); }
  .profile-photo { width: 100px; height: 100px; }

  /* Modals respect safe areas and use the phone viewport, including browser bars. */
  .modal-overlay { padding: max(10px, var(--mss-mobile-safe-top)) 10px max(10px, var(--mss-mobile-safe-bottom)); }
  .modal-box, .modal-box[role="dialog"] {
    width: 100%; max-width: 560px; max-height: calc(100dvh - var(--mss-mobile-safe-top) - var(--mss-mobile-safe-bottom) - 16px);
    padding: 18px 13px; border-radius: 18px; overflow-y: auto;
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  }
  #matchStatsModal { align-items: flex-end; padding: max(6px, var(--mss-mobile-safe-top)) 6px max(6px, var(--mss-mobile-safe-bottom)); backdrop-filter: none; -webkit-backdrop-filter: none; }
  #matchStatsModal .match-stats-box {
    width: 100%; max-width: none; max-height: calc(100dvh - var(--mss-mobile-safe-top) - var(--mss-mobile-safe-bottom) - 12px);
    border-radius: 20px 20px 14px 14px; padding: 0; overflow: hidden;
  }
  #matchStatsModal .ms-modal-head { padding: 17px 48px 13px 15px; }
  #matchStatsModal .ms-stats-content { min-height: 0; padding: 12px 10px calc(18px + var(--mss-mobile-safe-bottom)); overflow-y: auto; }
  #matchStatsModal .close-panel, #matchStatsModal .modal-close { min-width: 42px; min-height: 42px; }
  #refInfoModal .referee-modal-box { width: 100%; max-width: 560px; max-height: calc(100dvh - var(--mss-mobile-safe-top) - var(--mss-mobile-safe-bottom) - 16px); padding: 18px 14px; border-radius: 18px; }
  .toast { bottom: calc(14px + var(--mss-mobile-safe-bottom)); max-width: calc(100vw - 24px); text-align: center; }

  /* Reduce expensive hover, blur and large shadow work on touch devices. */
  .topbar::after { opacity: .35; }
  .table-card:hover, .progress-card:hover, .stat:hover, .proposal:hover,
  .match-card:hover, .unp-card:hover, .setting-card:hover { transform: none; }
}

@media (max-width: 520px) {
  .auth-screen, .restricted-screen { min-height: calc(100svh - 58px); align-items: start; padding-top: 8px; }
  .auth-card { padding: 20px 14px; border-radius: 18px; }
  .auth-card h1 { font-size: clamp(22px, 6vw, 27px); }
  .auth-trust { gap: 6px; flex-wrap: wrap; justify-content: center; }
  .auth-trust span { font-size: 10px; }
  .dashboard-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .ms-stat-row, .ms-stat-team-head { min-width: 0; }
  .ss-sync-actions { width: 100%; }
  .ss-sync-actions button { flex: 1 1 auto; min-height: 40px; }
  .share-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 380px) {
  :root { --mss-mobile-gutter: 9px; }
  .topbar { padding-left: 9px; padding-right: 9px; gap: 5px; }
  .brand { flex-basis: 128px; gap: 6px; }
  .brand img { width: 32px; height: 32px; }
  .brand-copy b { max-width: 30vw; font-size: 12px; }
  .top-actions { gap: 4px; }
  .top-actions select { max-width: 76px; min-width: 60px; padding-left: 5px; padding-right: 15px; font-size: 12px !important; }
  #logoutBtn { max-width: 78px; padding: 7px 6px; font-size: 11px; }
  .final-fixed { align-items: flex-start; flex-direction: column; gap: 3px; }
  .final-fixed strong { max-width: 100%; text-align: left; }
  .subscription-grid { grid-template-columns: minmax(0, 1fr); }
  .sub-card { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 8px; text-align: left; padding: 10px 12px; }
  .sub-card b { font-size: 20px; }
  .sub-card span { text-align: left; }
  .sub-card strong { text-align: right; font-size: 12px; }
  .stake-table .tr > div { padding-left: 1px !important; padding-right: 1px !important; }
  .stake-table .tr.th > div { font-size: 8px !important; }
  .stake-table .result-select { padding-left: 2px !important; padding-right: 10px !important; }
  .stake-table .result-arrow { right: 2px; }
  #matchStatsModal .ms-stat-team-head, #matchStatsModal .ms-stat-row { grid-template-columns: minmax(82px, 1fr) minmax(0, .85fr) minmax(0, .85fr); gap: 4px; }
}

@media (hover: none) and (pointer: coarse) and (max-width: 760px) {
  .auth-card, .setup-card, .panel, .table-card, .progress-card, .stat,
  .proposal, .match-card, .unp-card, .sim-box, .dashboard-top {
    box-shadow: 0 4px 14px rgba(7, 48, 31, .055);
  }
  body.dark-mode .auth-card, body.dark-mode .setup-card, body.dark-mode .panel,
  body.dark-mode .table-card, body.dark-mode .progress-card, body.dark-mode .stat,
  body.dark-mode .proposal, body.dark-mode .match-card, body.dark-mode .unp-card,
  body.dark-mode .sim-box, body.dark-mode .dashboard-top {
    box-shadow: 0 5px 16px rgba(0, 0, 0, .18);
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .modal-overlay { align-items: flex-start; }
  .modal-box, .modal-box[role="dialog"] { max-height: calc(100dvh - 12px); }
  #matchStatsModal .match-stats-box { max-height: calc(100dvh - 12px); }
  .auth-screen { min-height: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .table-card, .progress-card, .stat, .proposal, .match-card, .unp-card,
  .sim-box, .setting-card { transition: none !important; }
}
