/* ============================================================
   Launcher Shell — Phase 1 (+ Phase 10 action-bar integration)
   Phase 10: nav + back-button moved into #main-action-bar
   (the persistent top bar). No floating elements anymore.
   Default-on launcher, opt-out via ?launcher=0.
   Responsive: 3-col mobile / 4-col tablet+ / iPhone notch safe
   ============================================================ */

/* Default: launcher hidden unless launcher-active */
#launcher-shell { display: none; }

/* ---------- When launcher is active ---------- */
body.launcher-active #launcher-shell { display: block; }

/* Hide legacy dashboard chrome while launcher Home grid is shown.
   Phase 10: #main-action-bar is NOT hidden anymore — it persists across
   Home + every bucket view (it carries the launcher's nav buttons). */
body.launcher-active #setup-screen,
body.launcher-active #master-hub-banner,
body.launcher-active .dashboard-section,
body.launcher-active .dashboard-divider,
body.launcher-active .dashboard-divider-faded,
body.launcher-active .setup-hero,
body.launcher-active .setup-hero-stack {
  display: none !important;
}

/* Belt-and-braces: hide any top nav/footer that lives outside #setup-screen
   but should not appear behind the launcher grid.
   Phase 10: explicit exception for #main-action-bar so it stays visible. */
body.launcher-active > nav:not(#main-action-bar),
body.launcher-active > header,
body.launcher-active > footer {
  display: none !important;
}

/* ============================================================
   Phase 8 — Per-bucket section isolation
   ------------------------------------------------------------
   When a bucket is "open" (body[data-active-bucket=X]) we hide
   every tagged section that does NOT match X. Untagged elements
   stay visible (login overlay, modals, the launcher itself).
   The body class .launcher-active still hides everything when
   the user is on the launcher home grid.
   ============================================================ */
body[data-active-bucket] [data-bucket-section] {
  display: none !important;
}

/* Hide legacy chrome that shouldn't appear inside a bucket view either.
   Mirrors the .launcher-active rules above. */
body[data-active-bucket] .setup-hero,
body[data-active-bucket] .setup-hero-stack,
body[data-active-bucket] .dashboard-divider,
body[data-active-bucket] .dashboard-divider-faded {
  display: none !important;
}

/* attribute selector with ~= matches one token in a space-separated list,
   so #dashboard-exam-flow can declare data-bucket-section="main-quest exam-list" */
body[data-active-bucket="main-quest"]   [data-bucket-section~="main-quest"],
body[data-active-bucket="exam-list"]    [data-bucket-section~="exam-list"],
body[data-active-bucket="overview"]     [data-bucket-section~="overview"],
body[data-active-bucket="history"]      [data-bucket-section~="history"],
body[data-active-bucket="suspended"]    [data-bucket-section~="suspended"],
body[data-active-bucket="daily-quest"]  [data-bucket-section~="daily-quest"],
body[data-active-bucket="character"]    [data-bucket-section~="character"],
body[data-active-bucket="achievements"] [data-bucket-section~="achievements"],
body[data-active-bucket="skills"]       [data-bucket-section~="skills"],
body[data-active-bucket="system-log"]   [data-bucket-section~="system-log"],
body[data-active-bucket="master-hub"]   [data-bucket-section~="master-hub"] {
  display: revert !important;
}

/* Reset the bottom-nav padding when a bucket is active (launcher home only) */
body[data-active-bucket]:not(.launcher-active) {
  padding-bottom: calc(var(--launcher-bottom-nav-h) + var(--launcher-bottom-nav-safe));
}

/* The progression section parent stays in the flow even when empty;
   collapse its padding when all children are hidden so we don't get
   a giant blank gap. */
body[data-active-bucket]:not([data-active-bucket="skills"]):not([data-active-bucket="character"]):not([data-active-bucket="achievements"]):not([data-active-bucket="daily-quest"]) #dashboard-progression {
  padding: 0 !important;
  margin: 0 !important;
  min-height: 0 !important;
}

/* ============================================================
   Launcher Shell Container
   ============================================================ */
#launcher-shell {
  max-width: 960px;
  margin: 18px auto 24px;
  padding: 0 14px;
  box-sizing: border-box;
}

.launcher-shell__header {
  text-align: center;
  margin: 8px 0 18px;
}
.launcher-shell__title {
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  font-weight: 900;
  letter-spacing: .02em;
  margin: 0 0 4px;
  color: #1f1b3a;
}
[data-theme="dark"] .launcher-shell__title { color: #e9e6ff; }
.launcher-shell__subtitle {
  font-size: .85rem;
  opacity: .72;
  margin: 0;
}

/* ============================================================
   Icon Grid — 3-col mobile / 4-col tablet+
   ============================================================ */
.launcher-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
@media (min-width: 720px) {
  .launcher-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
}
@media (min-width: 1024px) {
  .launcher-grid { gap: 22px; }
}

/* ---------- Icon Tile ---------- */
.launcher-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  aspect-ratio: 1 / 1;
  padding: 10px 8px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255,255,255,.96), rgba(245,244,255,.92));
  border: 1px solid rgba(124, 77, 255, .18);
  box-shadow: 0 6px 18px rgba(80, 60, 160, .08), inset 0 1px 0 rgba(255,255,255,.5);
  cursor: pointer;
  transition: transform .14s ease, box-shadow .18s ease, border-color .18s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  color: inherit;
  font: inherit;
}
[data-theme="dark"] .launcher-tile {
  background: linear-gradient(135deg, rgba(40,34,70,.94), rgba(28,22,52,.92));
  border-color: rgba(160, 130, 255, .22);
  box-shadow: 0 6px 18px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.05);
}
.launcher-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(80, 60, 160, .14);
  border-color: rgba(124, 77, 255, .42);
}
.launcher-tile:active { transform: translateY(0); }
.launcher-tile:focus-visible {
  outline: 2px solid #7c4dff;
  outline-offset: 3px;
}

.launcher-tile__icon {
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(124,77,255,.18));
}
.launcher-tile__label {
  font-size: .82rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: .01em;
  color: #2a2454;
}
[data-theme="dark"] .launcher-tile__label { color: #e6e2ff; }

/* Master-only tile accent */
.launcher-tile--master {
  background: linear-gradient(135deg, rgba(255,248,225,.96), rgba(248,232,255,.94));
  border-color: rgba(255, 193, 7, .48);
}
[data-theme="dark"] .launcher-tile--master {
  background: linear-gradient(135deg, rgba(54,42,18,.94), rgba(40,26,58,.92));
  border-color: rgba(255, 213, 79, .42);
}
.launcher-tile--master .launcher-tile__label { color: #8a6700; }
[data-theme="dark"] .launcher-tile--master .launcher-tile__label { color: #ffd54f; }

/* Loading badge (used by Phase 2 loader; safe placeholder now) */
.launcher-tile__badge {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: .62rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(124, 77, 255, .14);
  color: #5a3ec8;
  display: none;
}
.launcher-tile.is-loading .launcher-tile__badge { display: inline-block; }
.launcher-tile.is-loading { opacity: .7; cursor: progress; }

/* ============================================================
   Phase 10 — Quick-nav inside #main-action-bar (replaces bottom-nav + FAB)
   Injected by launcher-shell.js as #launcher-action-nav next to the
   brand text. Includes a back-Home button (visible only inside bucket)
   followed by 4 quick-nav icons (🏠📝📊👤).
   ============================================================ */
.launcher-action-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  flex-wrap: wrap;
}

/* Back-to-Home button: only visible when a bucket is open */
.launcher-action-nav__back {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 10px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #7c4dff 0%, #5a3ec8 100%);
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: .82rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(80, 60, 160, .28);
  -webkit-tap-highlight-color: transparent;
  transition: transform .14s ease, box-shadow .18s ease;
}
body.launcher-bucket-open .launcher-action-nav__back { display: inline-flex; }
.launcher-action-nav__back:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(80, 60, 160, .42);
}
.launcher-action-nav__back:active { transform: translateY(0); }
.launcher-action-nav__back:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.launcher-action-nav__back-icon { font-size: 1rem; line-height: 1; }

/* Quick-nav buttons (Home / Exam / Stats / Profile) */
.launcher-action-nav__item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid rgba(124, 77, 255, .25);
  border-radius: 999px;
  background: rgba(255, 255, 255, .82);
  color: #2a2454;
  font: inherit;
  font-weight: 700;
  font-size: .8rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .14s ease, border-color .14s ease, transform .14s ease;
  position: relative;
}
/* ขยาย tap area ให้ได้ 44px min (WCAG 2.5.5) */
.launcher-action-nav__item::after {
  content: '';
  position: absolute;
  inset: -6px;
}
[data-theme="dark"] .launcher-action-nav__item {
  background: rgba(40, 34, 70, .78);
  border-color: rgba(160, 130, 255, .32);
  color: #e6e2ff;
}
.launcher-action-nav__item:hover {
  background: rgba(124, 77, 255, .12);
  border-color: rgba(124, 77, 255, .55);
  transform: translateY(-1px);
}
[data-theme="dark"] .launcher-action-nav__item:hover {
  background: rgba(160, 130, 255, .18);
  border-color: rgba(160, 130, 255, .55);
}
.launcher-action-nav__item:active { transform: translateY(0); }
.launcher-action-nav__item:focus-visible {
  outline: 2px solid #7c4dff;
  outline-offset: 2px;
}
.launcher-action-nav__item[aria-current="page"] {
  background: linear-gradient(135deg, #7c4dff 0%, #5a3ec8 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 10px rgba(80, 60, 160, .25);
}
.launcher-action-nav__icon { font-size: 1rem; line-height: 1; }
.launcher-action-nav__label { letter-spacing: .01em; }

/* Logout pill — แดงเด่นชัด แตะออกระบบได้ทันที */
.launcher-action-nav__item--logout {
  margin-left: 6px;
  background: rgba(244, 67, 54, .10);
  border-color: rgba(244, 67, 54, .45);
  color: #c62828;
}
[data-theme="dark"] .launcher-action-nav__item--logout {
  background: rgba(244, 67, 54, .18);
  border-color: rgba(244, 67, 54, .55);
  color: #ff8a80;
}
.launcher-action-nav__item--logout:hover {
  background: rgba(244, 67, 54, .22);
  border-color: rgba(244, 67, 54, .7);
}

/* Mobile: icon-only nav (hide text labels to save horizontal space) */
@media (max-width: 720px) {
  .launcher-action-nav { gap: 4px; margin-left: 4px; }
  .launcher-action-nav__item { padding: 6px 8px; }
  .launcher-action-nav__label { display: none; }
  .launcher-action-nav__back { padding: 6px 10px 6px 8px; font-size: .76rem; }
  .launcher-action-nav__back-label { display: none; }
}

/* During quiz/exam: hide logout (and back) to prevent accidental exit mid-exam */
body.quiz-running #launcher-logout-btn,
body.quiz-running #launcher-back-btn { display: none !important; }

/* Print: hide entirely */
@media print {
  .launcher-action-nav { display: none !important; }
}
