/* ==========================================================================
   MathClash — Games tab styles (v1)
   --------------------------------------------------------------------------
   Loaded AFTER polish.css (see index.html). Adds:
     · the Games tab button itself (already styled by .mode-tab in the
       app's own CSS — we just override the indicator width so the
       sliding underline still aligns once a 6th tab exists).
     · the Games panel layout (6-card grid).
     · the fullscreen game overlay (topbar + canvas stage).
     · canvas wrapper (centers + scales the canvas to fit the stage).
     · action buttons (reset etc.).
     · body-scroll lock when a game is open.

   Pure additive — never overrides the app's own layout dimensions
   except for the indicator width (which we MUST override because React
   computes it from its own internal tab count, and we've added a 6th).
   ========================================================================== */

/* ----------------------------------------------------------------------
   1. Sliding indicator — force 1/6 width
   ----------------------------------------------------------------------
   React sets inline `width: 20%` (100 / ll.length where ll.length === 5).
   We've appended a 6th tab (Games) at the end, so the strip now holds 6
   equal-flex tabs. !important is necessary because React's inline style
   would otherwise win. translateX is left to React (it animates to
   idx * 100% of the element's own width — and 100% of 1/6 is exactly
   one tab slot, so the math still lines up). When GAMES is active we set
   translateX(500%) from JS to point at the 6th slot.
   ---------------------------------------------------------------------- */
.mode-selector-indicator {
  width: calc(100% / 6) !important;
}

/* ----------------------------------------------------------------------
   1b. Tab labels — allow wrapping so 6 tabs don't clip "Daily Challenge"
   ----------------------------------------------------------------------
   The React bundle sets `white-space: nowrap` on .mode-tab at ALL widths,
   only switching to `white-space: normal` inside `@media (max-width: 600px)`.
   With the original 5 tabs that was fine — each tab was ~105px even in
   the 881-1160px two-column band. Adding the 6th Games tab shrinks each
   to ~88px, and "Daily Challenge" (the longest label, ~110px+ with
   padding) gets `overflow: hidden`-clipped at 601-1160px.

   Fix: allow text to wrap at ALL widths now. Tabs have `min-height: 42px`
   which comfortably fits 2 lines of 0.78rem text. "Daily Challenge"
   wraps to "Daily" / "Challenge" on 2 lines — no clipping, no layout
   shift, no horizontal scroll needed. Same specificity as the bundle's
   rule (.mode-tab), loaded AFTER it, so we win the cascade without
   needing !important.
   ---------------------------------------------------------------------- */
.mode-tab {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.15;
}

/* At the narrow band where the 2-column layout squeezes the tab strip,
   tighten the padding slightly so all 6 tabs still fit comfortably. */
@media (min-width: 601px) and (max-width: 1160px) {
  .mode-tab {
    padding: 8px 5px;
    font-size: 0.72rem;
  }
}

/* ----------------------------------------------------------------------
   2. Games panel — heading + 6-card grid
   ----------------------------------------------------------------------
   NOTE: Do NOT add a `display: block !important` rule here! The previous
   version had one, which overrode the MathClash CSS rule `.mode-panel.hidden
   { display: none }` — so the Games panel was ALWAYS visible, leaking into
   every other tab section (Daily, Duels, Party, Leaderboard, Streaks).
   Now we only force `display: flex` when the panel is `.active`; when it's
   `.hidden`, the app's own `.mode-panel.hidden { display: none }` takes
   effect and properly hides the Games panel.
   ---------------------------------------------------------------------- */
.mc-games-panel.active {
  display: flex !important;
  flex-direction: column;
  gap: 18px;
  padding: 14px 4px 28px;
  animation: mc-games-in 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes mc-games-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.mc-games-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mc-games-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text, #f3f6fb);
}
.mc-games-sub {
  margin: 0;
  font-size: 13px;
  color: var(--muted, #8792aa);
  line-height: 1.5;
}

.mc-games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  width: 100%;
}

.mc-game-card {
  --card-accent: #ffc83d;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 16px 16px;
  text-align: left;
  cursor: pointer;
  background: linear-gradient(160deg,
    rgba(17, 26, 48, 0.92),
    rgba(13, 21, 38, 0.92));
  border: 1px solid rgba(28, 42, 74, 0.9);
  border-radius: 12px;
  color: inherit;
  font: inherit;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
              border-color 0.22s ease,
              box-shadow 0.22s ease;
  overflow: hidden;
  isolation: isolate;
}
.mc-game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 90% at 100% 0%,
    color-mix(in srgb, var(--card-accent) 22%, transparent),
    transparent 60%);
  opacity: 0.6;
  z-index: -1;
  pointer-events: none;
}
.mc-game-card::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--card-accent);
  opacity: 0.85;
  border-radius: 12px 0 0 12px;
}
.mc-game-card:hover,
.mc-game-card:focus-visible {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--card-accent) 70%, #232c47);
  box-shadow:
    0 12px 32px -16px color-mix(in srgb, var(--card-accent) 60%, transparent),
    0 0 0 1px color-mix(in srgb, var(--card-accent) 40%, transparent) inset;
  outline: none;
}
.mc-game-card:active {
  transform: translateY(-1px) scale(0.992);
}

.mc-game-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--card-accent) 14%, transparent);
  color: var(--card-accent);
  margin-bottom: 4px;
}
.mc-game-icon svg {
  width: 22px;
  height: 22px;
}

.mc-game-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text, #f3f6fb);
  letter-spacing: -0.005em;
}
.mc-game-blurb {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted, #8792aa);
  flex: 1;
}
.mc-game-cta {
  font-size: 12px;
  font-weight: 700;
  color: var(--card-accent);
  letter-spacing: 0.02em;
  margin-top: 4px;
}

/* ----------------------------------------------------------------------
   3. Fullscreen game overlay
   ---------------------------------------------------------------------- */
html.mc-game-locked,
html.mc-game-locked body {
  overflow: hidden !important;
  height: 100% !important;
}

.mc-game-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #070b18;
  color: var(--text, #f3f6fb);
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.mc-game-overlay.open {
  opacity: 1;
}
/* Real browser fullscreen sets the element to the screen; we still
   need the stage to fill it. */
.mc-game-overlay:fullscreen,
.mc-game-overlay:-webkit-full-screen,
.mc-game-overlay:-moz-full-screen,
.mc-game-overlay:-ms-fullscreen {
  width: 100vw;
  height: 100vh;
  background: #070b18;
}

/* ----------------------------------------------------------------------
   Topbar — floating pill, CONSTANT ON TOP of the canvas (takes zero
   vertical space). The stage fills the entire overlay; the topbar
   floats over the top edge with a semi-transparent backdrop + blur so
   the game content underneath stays visible at the edges. This is the
   "constant on top" pattern: the bar never scrolls, never pushes
   content down, never takes a row.
   ---------------------------------------------------------------------- */
.mc-game-topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px 6px 6px;
  background: rgba(13, 21, 38, 0.78);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border: 1px solid rgba(44, 65, 112, 0.6);
  border-radius: 12px;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.6),
              0 0 0 1px rgba(126, 230, 224, 0.06) inset;
  pointer-events: auto;
}
.mc-game-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: #f3f6fb;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.85;
}
.mc-game-exit,
.mc-game-fs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(28, 42, 74, 0.8);
  background: rgba(17, 26, 48, 0.9);
  color: #f3f6fb;
  cursor: pointer;
  font: 600 12px "Geist", sans-serif;
  transition: background 0.18s ease, border-color 0.18s ease,
              transform 0.18s ease;
  padding: 0;
  flex-shrink: 0;
}
.mc-game-exit {
  width: auto;
  padding: 0 10px 0 8px;
  gap: 5px;
}
.mc-game-exit:hover,
.mc-game-fs:hover {
  background: rgba(22, 34, 62, 0.95);
  border-color: rgba(44, 65, 112, 1);
}
.mc-game-exit:active,
.mc-game-fs:active {
  transform: scale(0.94);
}
.mc-game-exit svg,
.mc-game-fs svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.mc-game-stage {
  position: absolute;
  top: 60px;          /* below the floating topbar (~56px) + 4px gap */
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;   /* the canvas, then (on phones) the number keys */
  background: #100f0f;
  overflow: hidden;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  outline: none;
  /* swipes, drags and quick taps belong to the game, not to the page */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.mc-canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
}
.mc-canvas-wrap canvas {
  background: #070b18;
  border-radius: 10px;
  box-shadow: 0 24px 60px -30px #000000aa,
              0 0 0 1px #232c47 inset;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;        /* pointermove drives game state */
}

.mc-game-action {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #232c47;
  background: #141b30;
  color: #f3f6fb;
  cursor: pointer;
  font: 700 12px "Geist", sans-serif;
  transition: background 0.18s ease, border-color 0.18s ease,
              transform 0.18s ease;
  z-index: 5;
}
.mc-game-action:hover {
  background: #1d2640;
  border-color: #37425f;
}
.mc-game-action:active {
  transform: scale(0.97);
}
.mc-game-action-secondary {
  top: 12px;
  right: 12px;
}

/* read to screen readers, not shown */
.mc-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* On-screen number keys (phones and tablets): games-tab.js keypad() */
.mc-keypad {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 440px;
  margin: 10px auto 0;
  touch-action: manipulation;
}
.mc-keypad button {
  display: grid;
  place-items: center;
  height: 54px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--ui-2, #343331);
  background: var(--bg-2, #1c1b1a);
  color: var(--tx-hi, #fffcf0);
  font: 600 24px/1 "Geist", -apple-system, BlinkMacSystemFont, sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.08s ease, transform 0.08s ease;
}
.mc-keypad button.is-down { background: var(--ui, #282726); transform: scale(0.96); }
.mc-keypad .mc-key-fn { font-size: 16px; color: var(--tx-2, #878580); }
@media (max-height: 700px) {
  .mc-keypad { gap: 6px; margin-top: 8px; }
  .mc-keypad button { height: 46px; }
}
/* a phone held sideways: a slimmer top bar, and the keys beside the game, not under it */
@media (max-height: 500px) and (orientation: landscape) {
  .mc-game-topbar { top: 6px; padding-top: 3px; padding-bottom: 3px; }
  .mc-game-stage { top: 50px; padding-top: 6px; }
  .mc-game-stage.has-keypad { flex-direction: row; align-items: center; }
  .mc-game-stage.has-keypad .mc-keypad { width: 240px; max-width: 40%; margin: 0 0 0 10px; gap: 6px; }
  .mc-game-stage.has-keypad .mc-keypad button { height: 40px; font-size: 20px; }
  .mc-game-stage.has-keypad .mc-canvas-wrap { height: 100%; }
}

.mc-game-error {
  color: #ff5c7a;
  font: 700 16px "Geist", sans-serif;
  text-align: center;
  padding: 24px;
}

/* ----------------------------------------------------------------------
   4. Mobile tweaks
   ---------------------------------------------------------------------- */
@media (max-width: 560px) {
  .mc-games-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .mc-game-card {
    padding: 14px 14px 12px;
  }
  .mc-game-name { font-size: 15px; }
  .mc-game-blurb { font-size: 12px; }
  .mc-game-title { font-size: 12px; }
  /* On phones, hide the "Exit" text label and keep just the icon */
  .mc-game-exit { width: 32px; padding: 0; }
  .mc-game-exit span { display: none; }
}

/* ----------------------------------------------------------------------
   5. Reduced motion — kill the panel slide-in only (game canvases keep
      their own internal animations because they're interactive).
   ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .mc-games-panel.active { animation: none; }
  .mc-game-card { transition: border-color 0.18s ease, box-shadow 0.18s ease; }
  .mc-game-overlay { transition: none; }
}
