/* app/css/layout.css — Portrait 11-inch Redmi Pad 2 Layout (~800x1280 CSS px) */
*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100dvh;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  transition: background-color 280ms var(--ease-out-expo), color 280ms var(--ease-out-expo), font-size 220ms var(--ease-out-expo);
}

.topbar-badge {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--fill-butter);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  transition: background-color 240ms var(--ease-out-expo), color 240ms var(--ease-out-expo), border-color 240ms var(--ease-out-expo);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 220ms var(--ease-spring),
    background-color 220ms var(--ease-out-expo),
    border-color 220ms var(--ease-out-expo),
    color 220ms var(--ease-out-expo);
}

.icon-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Main Container: padding and max-width are owned by .b-page */
.app-main {
  width: 100%;
  margin: 0;
  padding: 0;
}

.icon-btn,
.btn-primary,
.btn-secondary,
.proof-toggle-btn,
.unit-pill {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* Horizontal Scroll Container for Wide Equations */
.math-block {
  margin: 14px 0;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle, rgba(128, 128, 128, 0.4)) transparent;
}

.math-block::-webkit-scrollbar,
.math-scroll::-webkit-scrollbar,
.katex-display::-webkit-scrollbar {
  height: 6px;
}

.math-block::-webkit-scrollbar-track,
.math-scroll::-webkit-scrollbar-track,
.katex-display::-webkit-scrollbar-track {
  background: transparent;
}

.math-block::-webkit-scrollbar-thumb,
.math-scroll::-webkit-scrollbar-thumb,
.katex-display::-webkit-scrollbar-thumb {
  background: var(--border-subtle, rgba(128, 128, 128, 0.4));
  border-radius: 3px;
}

.math-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 4px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle, rgba(128, 128, 128, 0.4)) transparent;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle, rgba(128, 128, 128, 0.4)) transparent;
}

/* Inline formula wider than its line (see js/wide-math.js): own block, scrolls sideways instead of being cut off. */
.math-inline--wide {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0 6px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.math-inline .katex {
  font-size: 1.04em;
}

.katex {
  text-transform: none !important;
  letter-spacing: normal !important;
}

.math-scroll .katex-display {
  margin: 0.35em 0;
}

/* Mobile Responsive Tier (Phones <= 600px) */
@media (max-width: 600px) {
  html,
  body {
    font-size: 15.5px;
    line-height: 1.58;
  }

  .topbar-badge {
    font-size: 0.68rem;
    padding: 2px 6px;
  }

  .icon-btn {
    height: 34px;
    padding: 0 9px;
    font-size: 0.8rem;
  }

  .math-scroll {
    padding: 4px 0;
  }

  .math-scroll .katex-display {
    font-size: 0.90em;
    margin: 0.22em 0;
  }
}

/* Phone Widths (<= 420px): scale display math */
@media (max-width: 420px) {
  .math-block,
  .math-block .katex-display,
  .katex-display {
    font-size: 0.92em;
  }
}

/* Standard Phone Widths (<= 390px) */
@media (max-width: 390px) {
  .math-scroll .katex-display {
    font-size: 0.85em;
  }
}

/* Compact Mobile Phone Tier (<= 380px) */
@media (max-width: 380px) {
  html,
  body {
    font-size: 15px;
    line-height: 1.55;
  }

  .topbar-badge {
    display: none;
  }

  .icon-btn {
    padding: 0 7px;
    font-size: 0.76rem;
  }

  .math-scroll .katex-display {
    font-size: 0.88em;
  }
}

/* ==========================================================================
   Desktop & Laptop Viewports (>= 1024px)
   ========================================================================== */
@media (min-width: 1024px) {
  :root {
    --reader-max-width: 860px;
    --dock-max-width: 620px;
  }

  .menu-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }
}

/* Wide Desktop Screens (>= 1440px) */
@media (min-width: 1440px) {
  :root {
    --reader-max-width: 920px;
  }
}
