/* === M4D Base (mobile-first) === */
:root {
  --bg: #0b1022;
  --bg2: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --card: #0d1224;
  --card2: #0a1020;
  --accent: #60a5fa;
  --accent-2: #34d399;
  --ring: rgba(96, 165, 250, .45);
  --border: rgba(255, 255, 255, .08);
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 18px;
  --safeTop: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box
}

html {
  background: var(--bg);           /* iOS overscroll rubber-band always dark */
  overflow-x: hidden;              /* stronger than clip — fixed children can't escape */
}

html,
body {
  height: auto;
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  background-attachment: scroll;
  overflow-x: hidden;
  overscroll-behavior-x: none;     /* no horizontal rubber-band on iOS */
  -webkit-text-size-adjust: 100%;
}

img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
  height: auto
}

/* Prevent any rogue element from forcing page-wide horizontal scroll */
:where(.page, main, section) {
  max-width: 100%
}

/* Containers */
.container {
  max-width: min(1100px, calc(100% - 24px));
  margin-inline: auto;
  padding: 16px 12px
}

/* Fluid grids */
.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr))
}

@media (max-width:420px) {
  .grid {
    grid-template-columns: 1fr
  }
}

/* Cards */
.card {
  display: block;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 18px;
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  min-height: clamp(100px, 20vw, 140px);
}

.card h3 {
  margin: 0 0 6px;
  font-size: 18px;
  letter-spacing: .2px
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px
}

/* Tables: keep page from scrolling horizontally, but allow table itself to scroll when needed */
table {
  width: 100%;
  border-collapse: collapse
}

@media (max-width: 768px) {
  /* Only add scroll to bare tables — skip tables already inside a scroll wrapper */
  table:not(.tablewrap table):not(.boardwrap table):not(.listwrap table):not(.tbl-wrap table):not(.mini-table-wrap table):not(.roster-wrap table):not(.prob-table-wrap table) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch
  }
}

/* ── Toast ───────────────────────────────────────────────────── */
#m4d-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0b1220;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  color: #e5e7eb;
  z-index: 9999;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
#m4d-toast.show { opacity: 1; }

/* ── Error state ─────────────────────────────────────────────── */
.error-state {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #7f1d1d;
  background: #1a0505;
  color: #fecaca;
  margin-top: 8px;
}
.error-state button {
  border: 1px solid #7f1d1d;
  background: rgba(239,68,68,.15);
  color: #fca5a5;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}

/* ── Skeleton shimmer rows ───────────────────────────────────── */
@keyframes m4d-shimmer {
  0%   { background-position: 200% 0 }
  100% { background-position: -200% 0 }
}
.skel td {
  background: linear-gradient(90deg, #0d1424 25%, #1a2540 50%, #0d1424 75%) !important;
  background-size: 200% 100% !important;
  animation: m4d-shimmer 1.4s ease-in-out infinite;
  color: transparent !important;
  border-color: transparent !important;
}
.skel td::after {
  content: '';
  display: block;
  height: 14px;
  border-radius: 4px;
  width: 80%;
}

/* ── Thin custom scrollbar ───────────────────────────────────── */
html { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.12) transparent; }
::-webkit-scrollbar        { width: 5px; height: 5px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: rgba(255,255,255,.14); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(96,165,250,.45); }

/* ── Table row hover (inner pages) ──────────────────────────── */
tbody tr { transition: background .12s ease; }
tbody tr:hover td { background: rgba(96,165,250,.055) !important; }

/* ── Gradient text utility ───────────────────────────────────── */
.gradient-text {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── Consistent focus ring ───────────────────────────────────── */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; }

/* ═══════════════════════════════════════════════════════════════
   Mobile polish — tighter text, better scroll UX, cohesive feel
   ═══════════════════════════════════════════════════════════════ */

/* ── Scroll-wrapper improvements ──────────────────────────────── */
.tablewrap,
.boardwrap,
.listwrap,
.tbl-wrap,
.prob-table-wrap,
.b-scroll {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;    /* don't let horizontal drag bounce page */
}

@media (max-width: 768px) {
  /* Compact table cells on mobile */
  .tablewrap td,
  .tablewrap th,
  .tbl-wrap td,
  .tbl-wrap th {
    padding: 8px 8px;
    font-size: 12.5px;
  }

  /* Compact headings */
  h1 { font-size: clamp(20px, 5vw, 28px); }
  h2 { font-size: clamp(18px, 4.5vw, 26px); }
  .lead, p.lead { font-size: 13px; }

  /* Panels breathe a bit less on small screens */
  .panel { padding: 14px; }
  .container { padding: 12px 10px; }

  /* Filter/control buttons compact */
  .controls { gap: 8px; }
  select, .filter-btn, .chip {
    font-size: 13px;
    padding: 7px 10px;
  }

  /* Week bar charts — more compact */
  .week-bar-wrap { min-width: 40px; }
  .week-bar-outer { width: 38px; }

  /* Toast repositioned for thumb reach */
  #m4d-toast {
    bottom: env(safe-area-inset-bottom, 16px);
    right: 16px;
    left: 16px;
    text-align: center;
  }
}