/* Base styling — Libyan-themed, RTL-aware. */

html, body {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  background:
    radial-gradient(ellipse at top, rgba(201, 169, 97, 0.08), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(139, 38, 53, 0.06), transparent 70%),
    #1A1A2E;
  font-family: 'Cairo', 'Reem Kufi', sans-serif;
  color: #FFF8E7;
  min-height: 100vh;
  /* Kill the translucent gray rectangle Android Chrome paints on every
     tap of an element with cursor:pointer. The site has hand-built
     selection / pressed states (`.selected`, `.capture-selected`) so the
     OS hint adds nothing but visual noise on phones (the primary
     target). Inheritance covers descendants — no need to repeat. */
  -webkit-tap-highlight-color: transparent;
}

.app-footer {
  text-align: center;
  color: rgba(232, 220, 196, 0.7);
  font-size: 0.75rem;
  line-height: 1rem;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
  border-top: 1px solid rgba(201, 169, 97, 0.1);
}

/* Mobile-touch baseline (audit P0-4). Without `touch-action: manipulation`,
   iOS Safari delays click handlers by 250–350 ms while it waits to see if
   the user wanted a double-tap-zoom — at 100 ms typical RTT that's 3.5×
   the wire round-trip, wasted purely on a gesture the app doesn't use.
   Apply to every tap target the game / lobby / setup screens render so
   we don't have to chase missed selectors later. */
.card,
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost,
.shibani-pill,
.swatch,
.feature-card,
.nav-tab,
.nav-toggle,
.card-cta,
button, [role="button"], a[href] {
  touch-action: manipulation;
}

/* Subtle Libyan-tile pattern overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    repeating-linear-gradient(45deg,
      rgba(201, 169, 97, 0.02) 0px, rgba(201, 169, 97, 0.02) 2px,
      transparent 2px, transparent 30px),
    repeating-linear-gradient(-45deg,
      rgba(201, 169, 97, 0.02) 0px, rgba(201, 169, 97, 0.02) 2px,
      transparent 2px, transparent 30px);
  pointer-events: none;
  z-index: -1;
}

.card-cta {
  display: block;
  background: rgba(22, 59, 44, 0.55);
  border: 1px solid rgba(201, 169, 97, 0.30);
  border-radius: 14px;
  padding: 1.2rem 1rem;
  text-align: center;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  text-decoration: none;
  color: inherit;
}
.card-cta:hover {
  transform: translateY(-3px);
  border-color: rgba(201, 169, 97, 0.7);
  background: rgba(31, 77, 58, 0.7);
  box-shadow: 0 12px 30px -10px rgba(201, 169, 97, 0.4);
}

/* Felt table */
.felt-table {
  background:
    radial-gradient(ellipse at center, #1F4D3A 0%, #163B2C 65%, #0F2A20 100%);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.04) 0%, transparent 30%),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,0.03) 0%, transparent 30%);
}

.opponent-area {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  min-height: 130px;
}
.table-area {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  min-height: 200px;
  width: 80%;
}
.hand-area {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  min-height: 140px;
  perspective: 800px;
}

/* Toast notifications.
   Layout: container is bottom-centered above active-match-banner +
   safe-area-inset; each .toast is a flex row of optional icon, body,
   optional action, optional close. Entry/exit are JS-driven via
   `.toast--enter` (initial) and `.toast--leave` (dismissal) so the
   exit timing isn't baked into the rule (the previous CSS hard-coded
   a 2.6s out delay that quietly broke any timeout > 3s). */
#toast-container {
  position: fixed;
  bottom: max(env(safe-area-inset-bottom, 0px), 1rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  /* Above the active-match-banner (z-index: 600) and below the modal
     dialog tier (z-index: 1100+) — toasts are transient feedback that
     must remain readable even when a takeover banner is on screen. */
  z-index: 700;
  pointer-events: none;
  width: max-content;
  max-width: min(92vw, 460px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 40px;
  max-width: 100%;
  padding: 8px 14px;
  background: rgba(22, 22, 46, 0.94);
  border: 1px solid rgba(201, 169, 97, 0.42);
  border-radius: 14px;
  color: #FFF8E7;
  font-family: 'Reem Kufi', sans-serif;
  font-size: 0.92rem;
  pointer-events: auto;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 280ms ease-out, transform 280ms ease-out;
}
.toast--enter {
  opacity: 0;
  transform: translateY(8px);
}
.toast--leave {
  opacity: 0;
  transform: translateY(-8px);
}
.toast-icon {
  flex: 0 0 auto;
  font-size: 1.05rem;
  line-height: 1;
  display: inline-grid;
  place-items: center;
}
.toast-body {
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
}
.toast-action,
.toast-close {
  flex: 0 0 auto;
  /* 44px tap-target floor — toasts are touched mostly on mobile and the
     dismiss / action buttons are the primary actionable surface. */
  min-width: 44px;
  min-height: 44px;
  display: inline-grid;
  place-items: center;
  border: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
}
.toast-action {
  padding: 0 0.85rem;
  border-radius: 999px;
  background: rgba(255, 215, 0, 0.16);
  color: #FFD700;
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  transition: background-color 0.18s ease;
}
.toast-action:hover,
.toast-action:focus-visible {
  background: rgba(255, 215, 0, 0.28);
  outline: none;
}
.toast-close {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  font-size: 1.4rem;
  line-height: 1;
  opacity: 0.7;
  transition: background-color 0.18s ease, opacity 0.18s ease;
}
.toast-close:hover,
.toast-close:focus-visible {
  opacity: 1;
  background: rgba(255, 248, 231, 0.08);
  outline: none;
}

/* Kind variants — only border + a faint accent shadow change so the
   pill stays readable across the dim hayya background. */
.toast--success {
  border-color: rgba(255, 215, 0, 0.55);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 215, 0, 0.08);
}
.toast--error {
  border-color: rgba(220, 53, 69, 0.7);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(220, 53, 69, 0.12);
}
.toast--warning {
  border-color: rgba(255, 168, 64, 0.65);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 168, 64, 0.12);
}
.toast--info {
  border-color: rgba(125, 175, 255, 0.45);
}
.toast--invite {
  border-color: rgba(255, 215, 0, 0.65);
  background: linear-gradient(135deg, rgba(40, 26, 12, 0.96), rgba(22, 22, 46, 0.94));
}
.toast--message {
  border-color: rgba(125, 175, 255, 0.55);
}
.toast--achievement {
  border-color: rgba(255, 215, 0, 0.75);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5), 0 0 22px rgba(255, 215, 0, 0.18);
}

@media (max-width: 767px) {
  #toast-container {
    bottom: max(env(safe-area-inset-bottom, 0px), 0.75rem);
    left: max(env(safe-area-inset-left, 0px), 0.75rem);
    right: max(env(safe-area-inset-right, 0px), 0.75rem);
    transform: none;
    width: auto;
    max-width: none;
    align-items: stretch;
  }
  .toast {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .toast--enter,
  .toast--leave {
    transition: none;
    transform: none;
  }
}

/* Notification bell preview — desktop dropdown, mobile bottom sheet.
   Markup lives in base.html (authenticated users only); behavior in
   notifications-dropdown.js. Z-index sits at the modal-dialog tier
   (1100 panel / 1099 backdrop) per the documented modal palette so
   the panel covers the active-match-banner (z 600) and toasts (z 700)
   when open — toasts shouldn't visually compete with a dialog. */
.notif-panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, 0.55);
  z-index: 1099;
  /* Backdrop only on mobile; desktop dropdown reads as a popover and
     doesn't need a screen dimmer. Keep declared here so JS can flip
     `hidden` uniformly. */
  display: none;
  animation: notif-backdrop-in 180ms ease-out;
}
.notif-panel-backdrop[hidden] {
  display: none !important;
}
.notif-panel {
  position: fixed;
  top: 64px;
  inset-inline-end: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: min(72vh, 520px);
  background: rgba(7, 10, 18, 0.96);
  border: 1px solid rgba(255, 215, 0, 0.32);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  color: #FFF8E7;
  display: flex;
  flex-direction: column;
  z-index: 1100;
  overflow: hidden;
  animation: notif-panel-in 200ms cubic-bezier(0.34, 1.4, 0.64, 1);
}
.notif-panel[hidden] {
  display: none !important;
}
.notif-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 215, 0, 0.16);
  font-family: 'Reem Kufi', sans-serif;
  font-size: 1rem;
}
.notif-panel-close {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.75;
  transition: background-color 0.18s ease, opacity 0.18s ease;
}
.notif-panel-close:hover,
.notif-panel-close:focus-visible {
  opacity: 1;
  background: rgba(255, 248, 231, 0.08);
  outline: none;
}
.notif-panel-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 0;
}
.notif-panel-loading,
.notif-panel-empty {
  padding: 20px 16px;
  text-align: center;
  color: rgba(255, 248, 231, 0.65);
  font-family: 'Cairo', sans-serif;
  font-size: 0.92rem;
}
.notif-panel-row {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 0.75rem;
  align-items: center;
  min-height: 56px;
  padding: 10px 16px;
  text-decoration: none;
  color: inherit;
  border-inline-start: 3px solid transparent;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}
.notif-panel-row:hover,
.notif-panel-row:focus-visible {
  background: rgba(255, 215, 0, 0.06);
  outline: none;
}
.notif-panel-row.is-unread {
  background: rgba(255, 215, 0, 0.04);
  border-inline-start-color: var(--gold-bright, #FFD700);
}
.notif-panel-row.is-unread:hover,
.notif-panel-row.is-unread:focus-visible {
  background: rgba(255, 215, 0, 0.10);
}
.notif-panel-img {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
  display: block;
}
.notif-panel-fallback {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 215, 0, 0.18);
  color: var(--gold-bright, #FFD700);
  font-weight: 700;
  font-size: 0.8rem;
  font-family: 'Reem Kufi', sans-serif;
}
.notif-panel-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.notif-panel-msg {
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  line-height: 1.35;
  color: #FFF8E7;
  word-break: break-word;
}
.notif-panel-msg strong {
  font-weight: 700;
  color: var(--gold-bright, #FFD700);
}
.notif-panel-time {
  font-size: 0.78rem;
  color: rgba(255, 248, 231, 0.55);
  /* Stable digit width + LTR for mixed-content dates inside RTL body. */
  direction: ltr;
  font-feature-settings: 'tnum';
  align-self: flex-end;
}
.notif-panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 10px 16px;
  border-top: 1px solid rgba(255, 215, 0, 0.16);
}
.notif-panel-readall,
.notif-panel-link {
  min-height: 44px;
  display: inline-grid;
  place-items: center;
  padding: 0 0.85rem;
  border-radius: 999px;
  font-family: 'Reem Kufi', sans-serif;
  font-size: 0.88rem;
  text-decoration: none;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(255, 248, 231, 0.18);
  color: rgba(255, 248, 231, 0.85);
  transition: background-color 0.16s ease, border-color 0.16s ease;
}
.notif-panel-readall {
  font-family: inherit;
}
.notif-panel-readall:hover,
.notif-panel-readall:focus-visible,
.notif-panel-link:hover,
.notif-panel-link:focus-visible {
  background: rgba(255, 215, 0, 0.10);
  border-color: rgba(255, 215, 0, 0.45);
  color: var(--gold-bright, #FFD700);
  outline: none;
}

@keyframes notif-panel-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes notif-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (max-width: 767px) {
  /* Mobile: bottom sheet with backdrop. Sheet rises from the bottom
     and stretches with safe-area-inset; close button doubles as a
     "drag handle" affordance via its position above the content. */
  .notif-panel-backdrop:not([hidden]) {
    display: block;
  }
  .notif-panel {
    top: auto;
    inset-inline: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 78vh;
    border-radius: 24px 24px 0 0;
    border-inline: none;
    border-bottom: none;
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 0px);
    animation: notif-sheet-in 240ms cubic-bezier(0.22, 0.95, 0.36, 1);
  }
  .notif-panel-head {
    /* Slightly taller on mobile to host a thumb-friendly close. */
    padding: 14px 16px;
  }
  .notif-panel-row {
    /* Bigger tap area on phones where rows are the primary touch surface. */
    min-height: 64px;
  }
}
@keyframes notif-sheet-in {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .notif-panel,
  .notif-panel-backdrop {
    animation: none;
  }
}
