/* ============================================================================
   _global-ui.css — locked fixes for the 20 recurring bugs (RECURRING-BUGS.md).
   Import this at the TOP of every frontend build's <style> block, THEN layer
   the project theme tokens (from _neutral.md / a brand theme) on top.

   Theme tokens expected (define in :root and [data-theme="dark"]):
     --bg --card --ink --muted --line --primary --primary-soft --danger
   If a project already defines these, this file just consumes them.
   ============================================================================ */

/* --- 0. Base reset that kills the common gotchas ------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); }                 /* bug #7: no white strip on dark toggle */
body { margin: 0; color: var(--ink); background: var(--bg); }

/* bug #8: form controls must inherit font + color (UA default is black) */
button, input, textarea, select {
  font: inherit;
  color: inherit;
}

/* bug #16: 16px inputs stop iOS auto-zoom; 44px = WCAG touch target */
input, select, textarea, button {
  font-size: 16px;
  min-height: 44px;
}

/* --- 1. Z-index ladder (bug #9,#10). NEVER hardcode z-index elsewhere. --- */
:root {
  --z-base: 1;
  --z-nav: 50;
  --z-panel: 51;
  --z-dropdown: 70;
  --z-tooltip: 80;
  --z-toast: 90;
  --z-modal: 100000;
}
.navbar, .sidebar, .nav { z-index: var(--z-nav); }   /* keep sidebars < 1000 */
.dropdown { z-index: var(--z-dropdown); }
.tooltip { z-index: var(--z-tooltip); }
.toast-host { z-index: var(--z-toast); }
.modal, .modal-overlay, .lightbox { z-index: var(--z-modal); }

/* --- 2. Tags / pills (bug #1,#2) ---------------------------------------- */
.tag, .pill {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  min-height: 0;             /* tags are not form controls; opt out of 44px */
}
.tag-row { display: flex; flex-wrap: wrap; gap: 4px; }
.kv { display: flex; flex-wrap: wrap; gap: 8px; }
.kv > .k { flex-shrink: 0; }
.kv > .v { min-width: 0; max-width: 100%; word-break: break-word; }

/* --- 3. Text clamp (bug #5) --------------------------------------------- */
.clamp-1, .clamp-2, .clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.clamp-1 { -webkit-line-clamp: 1; }
.clamp-2 { -webkit-line-clamp: 2; }
.clamp-3 { -webkit-line-clamp: 3; }

/* --- 4. Card that keeps its footer pinned (bug #3,#4) -------------------- */
.card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.card > .card-foot { margin-top: auto; }
/* when reusing a container that had an old grid, add class="reset-grid" */
.reset-grid { display: block !important; }

/* --- 5. Modal + gallery arrows (bug #9,#10) ----------------------------- */
.modal-overlay, .lightbox {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex; align-items: center; justify-content: center;
}
.arrow-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);            /* solid, not #ffffff22 ghost */
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff; font-size: 30px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: calc(var(--z-modal) + 1);
}
.arrow-btn:hover { background: rgba(0, 0, 0, 0.75); }
.arrow-btn.prev { left: 16px; }
.arrow-btn.next { right: 16px; }

/* --- 6. Long scrolling panels (chat/logs) (bug — Werewolf chat) ---------- */
.scroll-panel { max-height: 78vh; overflow-y: auto; flex-shrink: 0; }

/* --- 7. Toast + tooltip visuals (logic lives in ui-helpers.js) (bug #12) - */
.toast-host {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.tooltip {
  position: absolute; background: var(--ink); color: var(--bg);
  padding: 6px 10px; border-radius: 8px; font-size: 12px;
  pointer-events: none; white-space: nowrap;
  opacity: 0; transition: opacity .15s;
}
.tooltip.show { opacity: 1; }

/* --- 8. Language-aware fonts (bug #19) ---------------------------------- */
:root { --font-ui: "Poppins", system-ui, sans-serif; }
body { font-family: var(--font-ui); }
[lang="vi"] .pixel, [lang="vi"] .decorative {
  font-family: "Be Vietnam Pro", var(--font-ui);   /* pixel fonts lack VN glyphs */
  font-weight: 800;
}

/* --- 9. Accessibility: respect reduced motion --------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- 10. Responsive breakpoints (bug #17,#18) --------------------------- */
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }
  .scroll-panel { max-height: 60vh; }
}
@media (max-width: 640px) {
  html { font-size: 14px; }
  .card { padding: 12px; }
  .arrow-btn { width: 44px; height: 44px; font-size: 24px; }
}

/* --- 11. Full-viewport slides (bug #18) --------------------------------- */
.slide {
  height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
}
.slide h1 { font-size: clamp(28px, 6vw, 52px); }
.slide p  { font-size: clamp(14px, 2.5vw, 22px); }
