/* ==========================================================================
   FASTMATHS — STRICT TABLET-ONLY STYLESHEET
   CRITICAL ISOLATION RULE:
   - EVERY rule in this file MUST be scoped to `html[data-tablet="true"]`.
   - Zero rules apply to MacBooks, Desktops (even resized to 800-1024px),
     iPhones, or Android phones (< 600px shortest dimension).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Global Tablet Safety, Safe Areas & Phone-Pill Suppression
   -------------------------------------------------------------------------- */
html[data-tablet="true"],
html[data-tablet="true"] body {
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Keep Phones untouched; Tablets strictly show Tablet-Adapted Top Header */
html[data-tablet="true"] #mobile-pill-navbar-root,
html[data-tablet="true"] #mobile-bottom-nav-root {
  display: none !important;
}

html[data-tablet="true"] #navbar-container > .navbar.fastmaths-navbar {
  display: block !important;
  padding-top: max(6px, env(safe-area-inset-top)) !important;
  padding-left: max(12px, env(safe-area-inset-left)) !important;
  padding-right: max(12px, env(safe-area-inset-right)) !important;
}

html[data-tablet="true"] .main-content {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

html[data-tablet="true"] button,
html[data-tablet="true"] a.btn,
html[data-tablet="true"] .ctrl-btn,
html[data-tablet="true"] .nav-item,
html[data-tablet="true"] .calc-btn-7a,
html[data-tablet="true"] .mcq-option-pill,
html[data-tablet="true"] .cbt-opt-card,
html[data-tablet="true"] .cbt-pal-num {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* --------------------------------------------------------------------------
   2. Tablet Navigation Header (`portrait` vs `landscape`)
   -------------------------------------------------------------------------- */
html[data-tablet="true"] .navbar .nav-container-inner {
  gap: 8px !important;
  min-height: 54px;
}

html[data-tablet="true"] .navbar .nav-item,
html[data-tablet="true"] .navbar .nav-icon-btn,
html[data-tablet="true"] .navbar .streak-pill,
html[data-tablet="true"] .navbar #account-menu-trigger,
html[data-tablet="true"] .navbar #nav-login-btn,
html[data-tablet="true"] .navbar #nav-signup-btn {
  min-height: 44px;
  white-space: nowrap;
}

html[data-tablet="true"] .navbar .mobile-nav-toggle {
  display: none !important;
}

html[data-tablet="true"] .fm-tablet-search-toggle {
  display: none;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .navbar .nav-search-capsule {
  width: min(220px, 21vw);
  min-width: 150px;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .navbar .nav-left {
  gap: 6px !important;
  position: relative;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .navbar .official-brand-logo {
  height: 32px !important;
  width: auto !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .fm-tablet-search-toggle {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border, #cbd5e1);
  background: var(--surface, #ffffff);
  color: var(--text, #0b193d);
  font-size: 16px;
  cursor: pointer;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .navbar .nav-search-capsule {
  display: none;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .navbar .nav-search-capsule.is-tablet-search-open {
  display: flex !important;
  position: fixed;
  top: calc(max(8px, env(safe-area-inset-top)) + 56px);
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  width: auto !important;
  max-width: 520px;
  margin-inline: auto;
  z-index: 10020;
  padding: 6px 14px;
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.25);
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .navbar .nav-center.horizontal-links {
  display: flex !important;
  gap: 2px !important;
  flex-shrink: 1;
  min-width: 0;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .navbar .nav-center .nav-item {
  padding: 0 9px !important;
  font-size: 13px !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .navbar .nav-right {
  gap: 5px !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .navbar #account-control-wrap {
  min-width: auto !important;
}

/* --------------------------------------------------------------------------
   3. Tablet-Only Dock Switchers & Split-View Practice Arena
   -------------------------------------------------------------------------- */
html[data-tablet="true"] .fm-tablet-dock-tabs,
html[data-tablet="true"] .fm-tablet-keypad-align,
html[data-tablet="true"] .fm-tablet-inline-palette {
  display: none;
}

/* Portrait Practice Ergonomics: 2-Row Crisp Toolbar + Left/Center/Right Keypad */
html[data-tablet="true"][data-tablet-orientation="portrait"] .practice-screen-container.jumbo-practice-screen {
  padding-inline: 20px !important;
  padding-bottom: 24px !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .practice-top-bar.jumbo-bar {
  display: grid !important;
  grid-template-columns: 1fr auto;
  gap: 8px 10px !important;
  padding: 10px 14px !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .practice-top-bar .bar-group-right {
  grid-column: 1 / -1;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .fm-tablet-keypad-align {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .fm-tablet-keypad-align-btn {
  padding: 5px 11px;
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border, #cbd5e1);
  background: var(--surface-2, #f8fafc);
  color: var(--text-muted, #475569);
  font-size: 11.5px;
  font-weight: 800;
  cursor: pointer;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .fm-tablet-keypad-align-btn.is-active {
  background: #0b193d;
  border-color: #0b193d;
  color: #ffc914;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .compact-calculator-wrapper[data-dock="left"] {
  margin-left: 0 !important;
  margin-right: auto !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .compact-calculator-wrapper[data-dock="center"] {
  margin-left: auto !important;
  margin-right: auto !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .compact-calculator-wrapper[data-dock="right"] {
  margin-left: auto !important;
  margin-right: 0 !important;
}

/* Touch Precision: Min 48-54px Targets on Keypad, MCQ & Bottom Nav */
html[data-tablet="true"] .calc-btn-7a {
  min-height: 52px !important;
  min-width: 52px;
  font-size: 1.28rem !important;
  border-radius: 12px !important;
  transition: transform 0.08s ease;
}

html[data-tablet="true"] .calc-btn-7a:active,
html[data-tablet="true"] .mcq-option-pill:active,
html[data-tablet="true"] .cbt-opt-card:active {
  transform: scale(0.96);
}

html[data-tablet="true"] .mcq-option-pill {
  min-height: 54px;
  padding: 12px 14px !important;
}

html[data-tablet="true"] .jumbo-navigation-bar button,
html[data-tablet="true"] .practice-top-bar .ctrl-btn {
  min-height: 44px !important;
}

/* Tablet Landscape Split-View Arena (`100dvh` Single-Screen Fit) */
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-screen-container.jumbo-practice-screen {
  min-height: calc(100dvh - 64px);
  padding: 8px 16px 12px !important;
  display: flex;
  flex-direction: column;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box.jumbo-card {
  display: grid !important;
  grid-template-columns: minmax(0, 1.44fr) minmax(305px, 1fr);
  grid-template-rows: auto auto auto 1fr auto;
  column-gap: 18px;
  row-gap: 10px;
  align-items: start;
  padding: 14px 18px !important;
  flex: 1;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .practice-card-head,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .practice-card-tools-row,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .practice-speed-tempo-bar,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .drill-stimulus-box,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .practice-question-display,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .answer-feedback-card,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .neutral-feedback-toast,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > #practice-inline-hint-box,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .drill-mcq-options-container,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .answer-input-container,
html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .jumbo-navigation-bar {
  grid-column: 1;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .practice-card-box > .jumbo-navigation-bar {
  margin-top: auto !important;
  padding-top: 8px;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-right-dock {
  grid-column: 2;
  grid-row: 1 / span 6;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--surface-2, #f8fafc);
  align-self: stretch;
  min-height: 100%;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-dock-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface, #ffffff);
  border: 1px solid var(--border, #cbd5e1);
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-dock-tab {
  min-height: 40px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted, #475569);
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-dock-tab.is-active {
  background: #0b193d;
  color: #ffc914;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-right-dock .compact-calculator-wrapper {
  margin: 0 !important;
  width: 100% !important;
  max-width: none !important;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-inline-palette {
  display: none;
  flex-direction: column;
  gap: 10px;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-right-dock[data-active-tab="palette"] .fm-tablet-inline-palette {
  display: flex !important;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-inline-palette .palette-numbers-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-inline-palette .palette-num-btn {
  min-height: 42px;
  font-weight: 800;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-right-dock .fm-scratchpad-drawer {
  position: static !important;
  width: 100% !important;
  max-width: none !important;
  box-shadow: none !important;
  border: none !important;
  padding: 0 !important;
  background: transparent !important;
  flex: 1;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .fm-tablet-right-dock .fm-scratchpad-drawer.is-expanded {
  position: fixed !important;
  inset: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)) !important;
  z-index: 10040 !important;
  padding: 16px !important;
  border-radius: 20px !important;
  background: var(--surface, #ffffff) !important;
  border: 2px solid var(--primary, #ff6b00) !important;
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.5) !important;
}

/* --------------------------------------------------------------------------
   4. Pro Stylus & Palm Rejection Toolbar & Dot Grid Canvas
   -------------------------------------------------------------------------- */
html[data-tablet="true"] .fm-pad-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 6px;
  border-radius: 10px;
  background: var(--surface, #ffffff);
  border: 1px solid var(--border, #e2e8f0);
  margin-bottom: 6px;
}

html[data-tablet="true"] .fm-pad-btn {
  min-height: 34px;
  min-width: 34px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border, #cbd5e1);
  background: var(--surface-2, #f8fafc);
  color: var(--text, #0f172a);
  font-size: 11.5px;
  font-weight: 800;
  cursor: pointer;
}

html[data-tablet="true"] .fm-pad-btn.is-active {
  background: #0b193d;
  border-color: #0b193d;
  color: #ffc914;
}

html[data-tablet="true"] .fm-pad-swatch {
  width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid var(--border, #cbd5e1);
  cursor: pointer;
}

html[data-tablet="true"] .fm-pad-swatch.is-active {
  box-shadow: 0 0 0 2px #ff6b00;
}

html[data-tablet="true"] .fm-stylus-pen-suggest {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 9px;
  background: rgba(37, 99, 235, 0.12);
  border: 1px solid rgba(37, 99, 235, 0.35);
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 6px;
}

html[data-tablet="true"] .fm-scratchpad-canvas {
  width: 100%;
  min-height: 220px;
  flex: 1;
  border-radius: 12px;
  touch-action: none !important;
  cursor: crosshair;
}

html[data-tablet="true"] .fm-scratchpad-canvas.has-math-dot-grid {
  background-image: radial-gradient(rgba(100, 116, 139, 0.34) 1px, transparent 1px);
  background-size: 16px 16px;
}

html[data-tablet="true"].dark .fm-scratchpad-canvas.has-math-dot-grid,
html[data-tablet="true"][data-theme="dark"] .fm-scratchpad-canvas.has-math-dot-grid,
html[data-tablet="true"][data-theme="golden"] .fm-scratchpad-canvas.has-math-dot-grid {
  background-image: radial-gradient(rgba(255, 201, 20, 0.25) 1px, transparent 1px);
}

/* Tablet Portrait Scratchpad Overlay Expansion */
html[data-tablet="true"][data-tablet-orientation="portrait"] .fm-scratchpad-drawer {
  width: min(92vw, 540px) !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom)) !important;
  z-index: 10030 !important;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .fm-scratchpad-drawer.is-expanded {
  inset: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)) !important;
  width: auto !important;
  transform: none !important;
}

/* --------------------------------------------------------------------------
   5. Live Test CBT Workspace Tablet Adaptation
   -------------------------------------------------------------------------- */
html[data-tablet="true"][data-tablet-orientation="landscape"] .cbt-runner-root {
  min-height: calc(100dvh - 64px);
  display: flex;
  flex-direction: column;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .cbt-workspace {
  display: grid !important;
  grid-template-columns: minmax(0, 1.48fr) minmax(290px, 1fr) !important;
  gap: 16px !important;
  flex: 1;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .cbt-palette-sidebar {
  display: flex !important;
  position: static !important;
  width: auto !important;
  transform: none !important;
}

html[data-tablet="true"] .cbt-opt-card {
  min-height: 52px !important;
  padding: 12px 14px !important;
}

html[data-tablet="true"] .cbt-pal-num {
  min-height: 44px !important;
  min-width: 44px !important;
}

/* --------------------------------------------------------------------------
   6. Home Grids, Setup Modals, Login, Progress & Admin Reflow
   -------------------------------------------------------------------------- */
html[data-tablet="true"][data-tablet-orientation="portrait"] .speed-drills-grid,
html[data-tablet="true"][data-tablet-orientation="portrait"] .arithmetical-grid,
html[data-tablet="true"][data-tablet-orientation="portrait"] .di-grid,
html[data-tablet="true"][data-tablet-orientation="portrait"] .hlt-cards-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 12px !important;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .speed-drills-grid,
html[data-tablet="true"][data-tablet-orientation="landscape"] .arithmetical-grid,
html[data-tablet="true"][data-tablet-orientation="landscape"] .di-grid,
html[data-tablet="true"][data-tablet-orientation="landscape"] .hlt-cards-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 14px !important;
}

/* Highlighted Mock Spotlight 2-zone balance */
html[data-tablet="true"] .fm-mock-spotlight .fm-spot-body {
  flex-wrap: nowrap !important;
  align-items: center !important;
}

/* Setup Modals & Login Modal: Sticky Header/Footer + Responsive Options Grid */
html[data-tablet="true"] .speed-setup-dialog,
html[data-tablet="true"] .tc-assign-modal,
html[data-tablet="true"] .pd-modal-card,
html[data-tablet="true"] .fm-auth-card {
  width: min(92vw, 760px) !important;
  max-height: 88dvh !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

html[data-tablet="true"] .speed-setup-header,
html[data-tablet="true"] .speed-setup-footer {
  flex-shrink: 0;
}

html[data-tablet="true"] .speed-setup-body {
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

html[data-tablet="true"][data-tablet-orientation="portrait"] .speed-cards-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .speed-cards-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
}

/* Progress Menu KPI Grids */
html[data-tablet="true"][data-tablet-orientation="portrait"] .pd-stat-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 12px !important;
}

html[data-tablet="true"][data-tablet-orientation="landscape"] .pd-stat-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 12px !important;
}

/* Dark / Golden Theme Polish for Tablet Dock & Toolbar */
html[data-tablet="true"].dark .fm-tablet-right-dock,
html[data-tablet="true"][data-theme="dark"] .fm-tablet-right-dock,
html[data-tablet="true"][data-theme="golden"] .fm-tablet-right-dock {
  background: #0e1421 !important;
  border-color: rgba(255, 201, 20, 0.25) !important;
}

html[data-tablet="true"].dark .fm-tablet-dock-tabs,
html[data-tablet="true"][data-theme="dark"] .fm-tablet-dock-tabs,
html[data-tablet="true"][data-theme="golden"] .fm-tablet-dock-tabs,
html[data-tablet="true"].dark .fm-pad-toolbar,
html[data-tablet="true"][data-theme="dark"] .fm-pad-toolbar,
html[data-tablet="true"][data-theme="golden"] .fm-pad-toolbar {
  background: #07090f !important;
  border-color: rgba(255, 201, 20, 0.24) !important;
}

html[data-tablet="true"].dark .fm-tablet-dock-tab.is-active,
html[data-tablet="true"][data-theme="dark"] .fm-tablet-dock-tab.is-active,
html[data-tablet="true"][data-theme="golden"] .fm-tablet-dock-tab.is-active,
html[data-tablet="true"].dark .fm-pad-btn.is-active,
html[data-tablet="true"][data-theme="dark"] .fm-pad-btn.is-active,
html[data-tablet="true"][data-theme="golden"] .fm-pad-btn.is-active {
  background: #ffc914 !important;
  color: #07090f !important;
}

html[data-tablet="true"][data-theme="blue"] .fm-tablet-right-dock {
  background: #eff6ff !important;
  border-color: #93c5fd !important;
}
