/* ============================================================================
   2WapWorld theme layer — design tokens over Bootstrap 5.3
   Phase 1 of docs/modern-ui-plan.md.
   Load order: bootstrap.min.css -> theme.css -> custom-style.css
   (custom-style keeps the last word for its fixes).
   Pure tokens + surface polish; no layout changes.
   ============================================================================ */

/* ---- Typography: self-hosted Inter variable ---- */
@font-face {
  font-family: 'Inter';
  src: url('../fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto,
                         'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  --bs-body-line-height: 1.6;
  font-optical-sizing: auto;

  /* Shape: softer, current-gen radii (flow into .btn/.badge/.form-control/.card) */
  --bs-border-radius-sm: .375rem;
  --bs-border-radius: .5rem;
  --bs-border-radius-lg: .75rem;
  --bs-border-radius-xl: 1rem;

  /* Elevation: two-layer ambient+key shadows (picked up by .shadow-sm/.shadow) */
  --bs-box-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --bs-box-shadow:    0 2px 4px rgba(16, 24, 40, .05), 0 6px 16px rgba(16, 24, 40, .08);
  --bs-box-shadow-lg: 0 4px 8px rgba(16, 24, 40, .05), 0 16px 40px rgba(16, 24, 40, .12);

  /* Softer focus ring */
  --bs-focus-ring-width: .2rem;
  --bs-focus-ring-color: rgba(13, 110, 253, .18);
}

/* ---- Light theme: white surfaces lifted off a cool-gray canvas ---- */
:root,
[data-bs-theme=light] {
  --tw-surface: #ffffff;                       /* elevated surface (cards, menus) */
  --bs-body-bg: #f5f6f8;
  --bs-body-color: #212733;
  --bs-secondary-bg: #eef0f3;
  --bs-tertiary-bg: #f3f5f7;
  --bs-border-color: #e5e8ee;
  --bs-border-color-translucent: rgba(15, 23, 42, .08);
  --bs-secondary-color: rgba(33, 39, 51, .62);
}

/* ---- Dark theme: elevation-tinted grays, not flat #212529 ---- */
[data-bs-theme=dark] {
  color-scheme: dark;
  --tw-surface: #171b21;
  --bs-body-bg: #0f1216;
  --bs-body-color: #d6dbe3;
  --bs-secondary-bg: #171b21;
  --bs-tertiary-bg: #1f252d;
  --bs-border-color: #2a313b;
  --bs-border-color-translucent: rgba(255, 255, 255, .08);
  --bs-secondary-color: rgba(214, 219, 227, .58);
  --bs-box-shadow-sm: 0 1px 2px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .35);
  --bs-box-shadow:    0 2px 4px rgba(0, 0, 0, .4),  0 6px 16px rgba(0, 0, 0, .45);
  --bs-box-shadow-lg: 0 4px 8px rgba(0, 0, 0, .4),  0 16px 40px rgba(0, 0, 0, .55);
  --bs-focus-ring-color: rgba(110, 168, 254, .22);
}

/* ---- Headings: tighter tracking, medium-bold via the variable font ---- */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
  letter-spacing: -.015em;
  font-weight: 650;
}

/* ---- Elevated surfaces: cards, dropdowns, modals, toasts, offcanvas ----
   Bootstrap paints these with body-bg; put them on the surface token instead
   so they lift off the new canvas in both themes. */
.card           { --bs-card-bg: var(--tw-surface);
                  --bs-card-border-color: var(--bs-border-color-translucent);
                  --bs-card-cap-bg: transparent; }
.dropdown-menu  { --bs-dropdown-bg: var(--tw-surface);
                  --bs-dropdown-border-color: var(--bs-border-color-translucent);
                  box-shadow: var(--bs-box-shadow); }
.modal          { --bs-modal-bg: var(--tw-surface); }
.toast          { --bs-toast-bg: var(--tw-surface); }
.offcanvas      { --bs-offcanvas-bg: var(--tw-surface); }

/* Flush lists and tables inside cards stay on the card surface, not body-bg */
.card .list-group { --bs-list-group-bg: transparent; }
.card .table      { --bs-table-bg: transparent; }

/* Card headers: hairline divider instead of a filled cap */
.card > .card-header { border-bottom-color: var(--bs-border-color-translucent); }

/* ============================================================================
   Phase 2 — Chrome: sticky translucent top nav, mobile bottom nav, page hero
   ============================================================================ */

/* Top nav: floating glass bar. The WRAPPER is sticky (the nav's own container
   is only as tall as the nav, so sticking the nav itself would do nothing). */
.tw-topnav-wrap {
  position: sticky;
  top: .5rem;
  z-index: 1030;
}
.tw-topnav {
  border-radius: var(--bs-border-radius-lg);
  background: color-mix(in srgb, var(--tw-surface) 84%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  backdrop-filter: blur(14px) saturate(160%);
  border: 1px solid var(--bs-border-color-translucent);
  box-shadow: var(--bs-box-shadow-sm);
  padding-top: .3rem;
  padding-bottom: .3rem;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tw-topnav { background: var(--tw-surface); }
}

/* Nav links as quiet pills; active route gets a tonal fill */
.tw-topnav .navbar-nav .nav-link {
  border-radius: var(--bs-border-radius-pill, 50rem);
  padding: .35rem .8rem;
  font-weight: 500;
  color: var(--bs-body-color);
  transition: background-color .15s ease, color .15s ease;
}
.tw-topnav .navbar-nav .nav-link:hover { background: var(--bs-tertiary-bg); }
.tw-topnav .navbar-nav .nav-link.active {
  background: rgba(13, 110, 253, .12);
  color: var(--bs-link-color);
}
[data-bs-theme=dark] .tw-topnav .navbar-nav .nav-link.active {
  background: rgba(110, 168, 254, .15);
}
.tw-topnav .navbar-brand { font-weight: 650; letter-spacing: -.01em; }

/* When the collapse opens on mobile, keep it on the glass surface */
.tw-topnav .navbar-collapse.show,
.tw-topnav .navbar-collapse.collapsing { padding-bottom: .5rem; }

/* Bottom mobile nav: surface bar with hairline top edge + iOS safe area */
.tw-bottomnav {
  background: color-mix(in srgb, var(--tw-surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  backdrop-filter: blur(14px) saturate(160%);
  border-top: 1px solid var(--bs-border-color-translucent);
  padding-bottom: calc(.5rem + env(safe-area-inset-bottom, 0px));
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tw-bottomnav { background: var(--tw-surface); }
}
.tw-bottomnav .nav-link {
  color: var(--bs-secondary-color);
  transition: color .15s ease, transform .15s ease;
}
.tw-bottomnav .nav-link.active {
  color: var(--bs-link-color);
}
.tw-bottomnav .nav-link.active i { transform: translateY(-1px); }

/* Page hero: refine the shared tinted header (52 templates) — soft gradient
   into the surface + hairline edge. Utility-var override, so the block's
   rounded-top fusion with cards below keeps working. */
.bg-primary-subtle.rounded-top {
  background: linear-gradient(
      135deg,
      var(--bs-primary-bg-subtle),
      color-mix(in srgb, var(--bs-primary-bg-subtle) 35%, var(--tw-surface))
    ) !important;
  border: 1px solid var(--bs-border-color-translucent);
  border-bottom: 0;
}

/* ============================================================================
   Phase 3 — Core surfaces: forums list, topic rows, posts conversation
   ============================================================================ */

/* Interactive list cards — the clickable stretched-link card idiom used on
   forums, topics, chat lobby, blogs, polls, events: gentle hover raise */
@media (prefers-reduced-motion: no-preference) {
  .card.position-relative {
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  }
}
.card.position-relative:hover {
  transform: translateY(-1px);
  box-shadow: var(--bs-box-shadow);
  border-color: color-mix(in srgb, var(--bs-primary) 25%, var(--bs-border-color));
}

/* Forum icon: tonal rounded-square tile instead of a bare glyph */
.forum-tile {
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; flex-shrink: 0;
  font-size: 1.35rem;
  border-radius: var(--bs-border-radius-lg);
  background: rgba(13, 110, 253, .10);
}
[data-bs-theme=dark] .forum-tile { background: rgba(110, 168, 254, .12); }

/* Meta badges on list cards -> quiet tonal chips (site-wide) */
.card .badge.bg-secondary {
  background-color: var(--bs-tertiary-bg) !important;
  color: var(--bs-secondary-color) !important;
  border: 1px solid var(--bs-border-color-translucent);
  font-weight: 500;
}

/* Sort bar -> segmented pills */
.topics-page .btn-sm { border-radius: 50rem; }

/* Topic title: a touch more presence */
.topics-page .card-title a { font-weight: 600; color: var(--bs-body-color); }
.topics-page .card-title a:hover { color: var(--bs-link-color); }

/* ---- Posts page ---- */

/* Heavy solid-blue card caps -> tonal caps (topic header, reply form, create) */
.forum-topic .card-header.bg-primary,
.topics-page .card-header.bg-primary {
  background: linear-gradient(
      135deg,
      var(--bs-primary-bg-subtle),
      color-mix(in srgb, var(--bs-primary-bg-subtle) 35%, var(--tw-surface))
    ) !important;
  color: var(--bs-primary-text-emphasis) !important;
  border-bottom: 1px solid var(--bs-border-color-translucent);
}
.forum-topic .card-header.bg-primary .badge.bg-light,
.topics-page .card-header.bg-primary .badge.bg-light {
  background-color: var(--tw-surface) !important;
  color: var(--bs-body-color) !important;
  border: 1px solid var(--bs-border-color-translucent);
}

/* Accepted solution: tinted surface, softer border */
.forum-topic .card.border-success {
  --bs-card-bg: color-mix(in srgb, var(--bs-success-bg-subtle) 40%, var(--tw-surface));
  border-width: 1px !important;
  border-color: color-mix(in srgb, var(--bs-success) 45%, var(--bs-border-color)) !important;
}

/* Post body rhythm */
.forum-topic .card-text,
.forum-topic [id^="post-text-"] { font-size: .95rem; line-height: 1.65; }

/* BBCode quotes: left accent bar on a tonal surface */
.quote {
  border: 0 !important;
  border-left: 3px solid color-mix(in srgb, var(--bs-primary) 55%, transparent) !important;
  background: var(--bs-tertiary-bg) !important;
  border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0 !important;
}

/* Reaction chips: pill shape + count pop on change */
.reaction-bar .btn-reaction { border-radius: 50rem; }
@media (prefers-reduced-motion: no-preference) {
  .reaction-bar .btn-reaction .rcount.bump { animation: tw-pop .25s ease; display: inline-block; }
  @keyframes tw-pop { 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
}

/* ============================================================================
   Phase 4 — Forms & auth
   ============================================================================ */

/* Auth pages (login / register / lost-password): narrow centered column */
.auth-page { max-width: 460px; }

/* Comfortable touch targets + consistent field chrome, site-wide */
.form-control, .form-select {
  min-height: 44px;
  border-color: var(--bs-border-color);
}
textarea.form-control { min-height: 0; }
.form-control::placeholder { color: var(--bs-secondary-color); opacity: .8; }
.form-label { font-weight: 550; font-size: .875rem; }
.form-text { color: var(--bs-secondary-color); }

/* Floating labels: keep the label quiet until focus */
.form-floating > label { color: var(--bs-secondary-color); }

/* Inputs on elevated surfaces read better slightly inset in dark mode */
[data-bs-theme=dark] .card .form-control,
[data-bs-theme=dark] .card .form-select {
  background-color: var(--bs-body-bg);
}

/* Button hierarchy: secondary-outline reads as a quiet tonal button */
.btn-outline-secondary {
  --bs-btn-color: var(--bs-body-color);
  --bs-btn-border-color: var(--bs-border-color);
  --bs-btn-hover-bg: var(--bs-tertiary-bg);
  --bs-btn-hover-color: var(--bs-body-color);
  --bs-btn-hover-border-color: var(--bs-border-color);
  --bs-btn-active-bg: var(--bs-secondary-bg);
  --bs-btn-active-color: var(--bs-body-color);
  --bs-btn-active-border-color: var(--bs-border-color);
}

/* Checkbox/switch accent follows the theme */
.form-check-input:checked { background-color: #0d6efd; border-color: #0d6efd; }

/* Small field variants keep their compact size */
.form-control-sm, .form-select-sm { min-height: 0; }

/* ============================================================================
   Phase 5 — Feedback & micro-interactions
   ============================================================================ */

/* Toasts: bottom-right on desktop, bottom-center above the tab bar on mobile */
#tw-toasts { bottom: 1rem; right: 1rem; z-index: 1080; }
@media (max-width: 575.98px) {
  #tw-toasts {
    right: auto; left: 50%; transform: translateX(-50%);
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    width: max-content; max-width: 92vw;
  }
}
.toast { box-shadow: var(--bs-box-shadow); border-left: 3px solid var(--bs-primary); }
.tw-toast-success { border-left-color: var(--bs-success); }
.tw-toast-danger  { border-left-color: var(--bs-danger); }

/* Skeleton shimmer lines (bell dropdown while loading) */
.tw-skel {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg,
      var(--bs-tertiary-bg) 25%, var(--bs-secondary-bg) 40%, var(--bs-tertiary-bg) 60%);
  background-size: 400% 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .tw-skel { animation: tw-shimmer 1.1s linear infinite; }
  @keyframes tw-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

  /* Dropdowns ease in instead of popping */
  .dropdown-menu.show { animation: tw-fade-up .16s ease; }
  @keyframes tw-fade-up { from { opacity: 0; transform: translateY(4px); } }
}

/* ============================================================================
   Phase 6 — Accessibility hardening
   ============================================================================ */

/* Visible keyboard focus everywhere (mouse clicks stay clean) */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: 2px;
  border-radius: var(--bs-border-radius-sm);
}
[data-bs-theme=dark] a:focus-visible,
[data-bs-theme=dark] button:focus-visible,
[data-bs-theme=dark] .btn:focus-visible { outline-color: #6ea8fe; }

/* Blanket reduced-motion fallback: kill residual animation for users who ask */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- ChatZone / dialog polish ---- */

/* Bubbles (chat room + inbox dialog share .chat-bubble): rounder, hairline on
   received bubbles so they read on the new canvas */
.chat-bubble.rounded-3 { border-radius: 1.125rem !important; }
.chat-bubble.bg-body-tertiary { border: 1px solid var(--bs-border-color-translucent); }

/* Message panes sit on the surface, not the canvas */
#chat-messages, .dialog-messages { background: var(--tw-surface); }

/* ============================================================================
   Phase 7 — Delight: ambient aurora, view transitions, reveal, depth
   ============================================================================ */

/* Cross-document View Transitions: smooth fade between page loads
   (Chromium 126+; everyone else just gets normal navigation) */
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .22s; }

/* Ambient aurora: soft brand glow drifting behind the page.
   body::before with z-index:-1 sits behind the body — so the page background
   moves to <html> and body goes transparent to let the glow show through. */
html { background-color: var(--bs-body-bg); }
body { background-color: transparent; }
body::before {
  content: '';
  position: fixed;
  top: -12rem; left: -8rem; right: -8rem; height: 34rem;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(42% 60% at 16% 30%, rgba(13, 110, 253, .10), transparent 70%),
    radial-gradient(34% 52% at 78% 18%, rgba(124, 58, 237, .07), transparent 70%),
    radial-gradient(30% 46% at 52% 8%,  rgba(34, 211, 238, .07), transparent 70%);
}
[data-bs-theme=dark] body::before {
  background:
    radial-gradient(42% 60% at 16% 30%, rgba(59, 130, 246, .16), transparent 70%),
    radial-gradient(34% 52% at 78% 18%, rgba(139, 92, 246, .12), transparent 70%),
    radial-gradient(30% 46% at 52% 8%,  rgba(34, 211, 238, .09), transparent 70%);
}
@media (min-width: 992px) and (prefers-reduced-motion: no-preference) {
  body::before { animation: tw-aurora 36s ease-in-out infinite alternate; will-change: transform; }
  @keyframes tw-aurora {
    from { transform: translate3d(-3%, 0, 0) scale(1); }
    to   { transform: translate3d(3%, 2rem, 0) scale(1.08); }
  }
}

/* Brand wordmark: gradient ink */
.tw-topnav .navbar-brand span {
  background: linear-gradient(92deg, #0d6efd, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
[data-bs-theme=dark] .tw-topnav .navbar-brand span {
  background: linear-gradient(92deg, #6ea8fe, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
}

/* Top nav condenses + gains depth once you scroll */
.tw-topnav-wrap.is-scrolled .tw-topnav {
  background: color-mix(in srgb, var(--tw-surface) 93%, transparent);
  box-shadow: var(--bs-box-shadow);
}

/* Scroll-reveal: cards rise in as they enter the viewport (JS adds .tw-reveal
   only when IO + motion allowed, so no-JS/reduced-motion users see everything) */
.tw-reveal { opacity: 0; }
.tw-reveal.tw-in { animation: tw-rise .45s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes tw-rise {
  from { opacity: 0; transform: translateY(12px) scale(.99); }
  to   { opacity: 1; transform: none; }
}

/* Primary buttons: glass sheen + hover glow */
.btn-primary {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, 0));
  border: 0;
  transition: box-shadow .2s ease, transform .15s ease;
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(13, 110, 253, .35); transform: translateY(-1px); }
.btn-primary:active { transform: none; }

/* Dark cards get a glass top-edge highlight (rides the shadow-sm utility var) */
[data-bs-theme=dark] {
  --bs-box-shadow-sm: inset 0 1px 0 rgba(255, 255, 255, .04),
                      0 1px 2px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .35);
}

/* Unread bell badge: soft pulse */
@media (prefers-reduced-motion: no-preference) {
  .notif-badge { animation: tw-pulse 2.2s ease-in-out infinite; }
  @keyframes tw-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
}

/* Finishing touches: branded selection, thin standard scrollbars */
::selection { background: rgba(13, 110, 253, .22); }
html { scrollbar-width: thin; scrollbar-color: var(--bs-border-color) transparent; }

/* ============================================================================
   Phase 8 — Content design: reading typography + restructured surfaces
   ============================================================================ */

/* User-generated content: comfortable reading rhythm everywhere */
.tw-content {
  font-size: .95rem;
  line-height: 1.65;
}
.tw-content a { text-decoration: none; }
.tw-content a:hover { text-decoration: underline; }
.tw-content img { border-radius: var(--bs-border-radius); }
.tw-content iframe { border-radius: var(--bs-border-radius-lg); max-width: 100%; }
.tw-content pre {
  border-radius: var(--bs-border-radius);
  padding: .75rem 1rem;
}
.tw-content hr { opacity: .12; }

/* Topic title block */
.tw-topic-head h4 { font-weight: 700; letter-spacing: -.02em; }

/* OP badge: quiet tonal pill */
.tw-op-badge {
  background: rgba(13, 110, 253, .12);
  color: var(--bs-link-color);
  font-weight: 600;
  font-size: .66rem;
  vertical-align: 2px;
}
[data-bs-theme=dark] .tw-op-badge { background: rgba(110, 168, 254, .16); }

/* Opening post: subtle brand accent edge */
.tw-post-op { border-left: 3px solid color-mix(in srgb, var(--bs-primary) 55%, transparent); }

/* Replies divider */
.tw-replies-divider hr { opacity: .15; }

/* Topic rows: pinned band + status glyph + 2-line excerpt clamp */
.tw-topic-row .tw-topic-ico { font-size: 1.05rem; width: 1.35rem; text-align: center; }
.tw-topic-row.tw-pinned {
  border-color: color-mix(in srgb, var(--bs-warning) 45%, var(--bs-border-color));
  background: linear-gradient(90deg, color-mix(in srgb, var(--bs-warning) 7%, var(--tw-surface)), var(--tw-surface) 40%);
}
.tw-topic-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Breadcrumbs: quiet, small, tonal divider */
.breadcrumb { --bs-breadcrumb-divider-color: var(--bs-secondary-color); }
.breadcrumb .breadcrumb-item.active { color: var(--bs-secondary-color); }

/* Composer: focus lifts the card */
.tw-composer:focus-within {
  box-shadow: var(--bs-box-shadow) !important;
  border-color: color-mix(in srgb, var(--bs-primary) 35%, var(--bs-border-color));
}

/* ---- Profile hero ---- */
.tw-profile-cover {
  height: 96px;
  background:
    radial-gradient(60% 120% at 20% 0%, rgba(13, 110, 253, .28), transparent 70%),
    radial-gradient(50% 110% at 80% 0%, rgba(34, 211, 238, .20), transparent 70%),
    linear-gradient(135deg, var(--bs-primary-bg-subtle), var(--tw-surface));
}
.tw-profile-idrow { margin-top: -44px; }
.tw-profile-avatar {
  width: 112px; height: 112px;
  object-fit: cover;
  border-radius: var(--bs-border-radius-xl);
  border: 4px solid var(--tw-surface);
  box-shadow: var(--bs-box-shadow-sm);
  background: var(--tw-surface);
}
.tw-profile-stats > div { min-width: 3.5rem; }
@media (max-width: 575.98px) {
  .tw-profile-idrow { margin-top: -56px; }
  .tw-profile-stats { margin-top: .25rem; }
}

/* ---- Inbox: unread conversations ---- */
.tw-unread {
  border-left: 3px solid var(--bs-primary);
  background: color-mix(in srgb, var(--bs-primary) 4%, var(--tw-surface));
}
.tw-unread-dot {
  width: 10px; height: 10px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--bs-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, .18);
}
