/*
 * StudyTogether v3.14 — interface polish layer.
 * Plain CSS loaded after the compiled app styles (app/shell.html). It only adjusts layout details the compiled
 * screens can't be rebuilt for: phone layouts, safe areas (notches / gesture bar / Android app), scrolling tab rows,
 * touch behaviour, readable line breaks and motion preferences. Remove the <link> in shell.html to switch it off.
 * Rules are unlayered on purpose, so they win over the app's Tailwind utilities without !important.
 */

/* ── Base: crisper text, nicer selection, no grey tap flash, no double-tap zoom delay ───────────────────── */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
::selection { background: color-mix(in oklab, var(--primary) 24%, transparent); }
a, button, [role="button"], [role="tab"], label, summary, input[type="checkbox"], input[type="radio"] {
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
h1, h2, h3 { text-wrap: balance; }
p, li, dd, blockquote { text-wrap: pretty; }
:where(main, [role="dialog"]) img { max-width: 100%; }

/* Keyboard users always see where they are; mouse/touch users don't get stray rings. */
:where(a, button, [role="button"], [role="tab"], [role="menuitem"], summary, [tabindex]):focus-visible {
  outline: 2px solid color-mix(in oklab, var(--primary) 70%, transparent); outline-offset: 2px;
}

/* Thin, theme-coloured scrollbars on desktop. */
@media (hover: hover) and (pointer: fine) {
  * { scrollbar-width: thin; scrollbar-color: color-mix(in oklab, var(--foreground) 22%, transparent) transparent; }
}

/* ── Scrolling tab rows (Settings, Pet World, Courses…): no scrollbar, snap, soft fade at the edges ───── */
[role="tablist"].overflow-x-auto, .pw-tabs, .pw-tabs [role="tablist"] {
  scrollbar-width: none; scroll-snap-type: x proximity; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
}
[role="tablist"].overflow-x-auto::-webkit-scrollbar, .pw-tabs::-webkit-scrollbar, .pw-tabs [role="tablist"]::-webkit-scrollbar { display: none; }
[role="tablist"].overflow-x-auto > *, .pw-tabs [role="tab"] { scroll-snap-align: start; flex-shrink: 0; }
@media (max-width: 767px) {
  [role="tablist"].overflow-x-auto { mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); }
}

/* ── Phones ───────────────────────────────────────────────────────────────────────────────────────────── */
@media (max-width: 639px) {
  /* Dashboard stat tiles (goal, streak, level, focus): two per row instead of four full-width cards. */
  main .grid.gap-4.sm\:grid-cols-2.xl\:grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  main .grid.gap-4.sm\:grid-cols-2.xl\:grid-cols-4 > * { min-width: 0; }
  main .grid.gap-4.sm\:grid-cols-2.xl\:grid-cols-4 > .surface-card { padding: .9rem; }
  main .grid.gap-4.sm\:grid-cols-2.xl\:grid-cols-4 > .surface-card.flex.items-center { flex-direction: column; align-items: flex-start; gap: .5rem; }
  main .grid.gap-4.sm\:grid-cols-2.xl\:grid-cols-4 > .surface-card .text-2xl { font-size: 1.35rem; line-height: 1.8rem; }
  main .grid.gap-4.sm\:grid-cols-2.xl\:grid-cols-4 > .surface-card .text-sm { font-size: .78rem; }

  /* Page headings breathe less on small screens. */
  main h1.text-3xl, main h1.text-4xl { font-size: 1.65rem; line-height: 2.05rem; }

  /* Pet World header: coins and sound button get their own row, so the pet's name isn't cut off. */
  .pw-hub { gap: .75rem; padding: .85rem; }
  .pw-hub > div:last-child { width: 100%; justify-content: flex-start; }
  .pw-hub .pw-chip { white-space: nowrap; }
  .pw-hub-pet { width: 56px; height: 56px; }

  /* Region switch on the landing page sits above the content instead of on top of the numbers. */
  .st-region-chip { transform: scale(.92); transform-origin: bottom right; opacity: .96; }

  /* Dialogs use the full width and never hide their buttons behind the keyboard. */
  [role="dialog"] { max-height: calc(100dvh - 1.5rem); overflow-y: auto; }
}

/* Inputs at 16px on touch screens: iOS Safari stops zooming the page when a field is tapped. */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea { font-size: max(16px, 1em); }
}

/* ── Safe areas: notches, rounded corners and the gesture bar (web, iOS and the Android app) ─────────── */
nav.fixed.bottom-0.grid-cols-5 { padding-bottom: env(safe-area-inset-bottom, 0px); }
main.pb-20 { padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px)); }
@supports (padding: max(0px)) {
  header.sticky.top-0 { padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); }
}
/* Toasts stay above the bottom navigation on phones. */
@media (max-width: 1023px) {
  [data-sonner-toaster][data-y-position="bottom"] { bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px)) !important; }
}

/* ── Android app (v2): the app adds .st-native to <html> ─────────────────────────────────────────────── */
html.st-native { overscroll-behavior-y: none; }
html.st-native body { user-select: none; -webkit-user-select: none; }
html.st-native :where(input, textarea, [contenteditable="true"], p, li, td, pre, code, .prose, [data-selectable]) { user-select: text; -webkit-user-select: text; }
html.st-native .st-hide-native { display: none !important; }

/* ── Respect the system "reduce motion" setting, not only the in-app switch ───────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ── Print: hide navigation chrome ─────────────────────────────────────────────────────────────────────── */
@media print {
  nav, header.sticky, [data-sonner-toaster], .st-region-chip { display: none !important; }
  main { padding: 0 !important; }
}

/* ── v3.15.1 — protected course cards keep their spacing ──────────────────────────────────────────────
   Paid content is wrapped in a watermark layer (.relative.z-[2]); that wrapper became the card's only child, so the
   card's own space-y-* no longer reached the question, the answer choices and the "Check answer" button / explanation
   (they touched each other). The same spacing is applied one level down. */
.surface-card.space-y-4 > .relative.z-\[2\] > :not([hidden]) ~ :not([hidden]) { margin-top: 1rem; }
.surface-card.space-y-5 > .relative.z-\[2\] > :not([hidden]) ~ :not([hidden]) { margin-top: 1.25rem; }
.surface-card.space-y-6 > .relative.z-\[2\] > :not([hidden]) ~ :not([hidden]) { margin-top: 1.5rem; }

/* ── v3.16 — phones & tablets ────────────────────────────────────────────────────────────────────────
   Exam player: fills the real visible screen (iOS/Android address bar and gesture bar included). */
.exam-host { height: 100vh; height: 100dvh; overscroll-behavior: none; }
.exam-host .exam-frame { display: block; width: 100%; height: 100%; border: 0; }
html:has(.exam-host) body { overflow: hidden; }

@media (max-width: 767px) {
  /* Code blocks and long links in course content wrap instead of widening the page. */
  main :where(.prose) :where(pre) { white-space: pre-wrap; word-break: break-word; }
  main :where(.prose) a { overflow-wrap: anywhere; }
  /* Media inside course content never overflows the card. */
  main :where(.prose, .surface-card) :where(img, video, iframe) { max-width: 100%; }
  main :where(.prose, .surface-card) :where(img, video) { height: auto; }
}
@media (pointer: coarse) {
  /* Bigger tap targets for small icon buttons in headers and toolbars. */
  header :where(button.size-8, button.size-9, a.size-8, a.size-9) { min-width: 40px; min-height: 40px; }
}

/* v3.34 — every dialog of the site stays inside the window: tall dialogs scroll inside instead of running off screen */
[role="dialog"].fixed[class*="top-[50%]"], [role="alertdialog"].fixed[class*="top-[50%]"] {
  max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem); overflow-y: auto; overscroll-behavior: contain;
  width: calc(100vw - 1.5rem);
}
@media (min-width: 640px) { [role="dialog"].fixed[class*="top-[50%]"] { width: 100%; } }

/* v3.38 — no slow page-entry effect. Every page of the app (and the home page hero) used to start invisible and fade/slide
   in over 0.45–0.9 s after it was already loaded, which made every click feel slow. Pages now appear the moment they are
   ready; small effects (dialogs, menus, toasts, the pet) are unchanged. */
.animate-fade-up { animation: none !important; }
.lx-hero-copy, .lx-visual, .lx-track { animation-duration: .2s !important; animation-delay: 0s !important; }
.lx-shot img { animation: none !important; }
