/* =============================================================================
   main.css — Play3CR Shared Design Tokens & Utilities
   Style: Premium Agency-grade (Double-Bezel, Soft Depth, Fluid Motion)
   ============================================================================= */

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
input, button, textarea, select { font-family: inherit; }

:root {
  /* ── Color Palette (Light) ─────────────────────────────────────────────── */
  --c-bg:          #F9F9FB;
  --c-surface:     #FFFFFF;
  --c-surface-2:   #F3F4F6;
  --c-border:      #E5E7EB;
  --c-border-light:#F3F4F6;

  --c-ink:         #0F172A;
  --c-ink-2:       #475569;
  --c-ink-3:       #94A3B8;

  /* Brand — Sophisticated Indigo */
  --c-brand:       #4F46E5;
  --c-brand-dark:  #4338CA;
  --c-brand-light: rgba(79, 70, 229, 0.08);

  --c-accent:      #F59E0B;
  --c-accent-light:#FEF3C7;

  --c-error:       #EF4444;
  --c-error-bg:    #FEF2F2;
  --c-success:     #10B981;
  --c-success-bg:  #ECFDF5;
  --c-warning:     #F59E0B;
  --c-warning-bg:  #FFFBEB;

  --c-state-idle:    #94A3B8;
  --c-state-playing: #10B981;
  --c-state-waiting: #F59E0B;

  /* Glass / Translucent */
  --bg-glass:      rgba(255, 255, 255, 0.7);
  --bg-glass-heavy:rgba(255, 255, 255, 0.9);

  /* Board canvas (paper/caro display mode only — see board.js _readBoardTheme).
     "Stone" display mode's radial gradient + filled discs intentionally keep
     their own light backdrop regardless of theme; inverting it would collapse
     black-stone-vs-board contrast to ~2:1.
     Fix #10 "Paper Style" palette — flat #D9D9D9 gray bg, navy cross, red circle.
     Wall tones are WCAG-derived: --board-wall-dark-rgb (#616161) is the anchor
     shade solved from the 4.5:1-contrast equation against this background;
     the mortar/base/light steps are tonal offsets from that anchor.
     Fix #11 lightened the cross ink from navy to sky-blue (--board-ink-rgb).
     Fix #12 moved the light-theme bg to near-white and cross to a saturated blue.
     Fix #13 removed the cyan tint from that near-white bg — plain neutral gray now.
     Fix #14 added --board-highlight-rgb (last-move cell marker) — the old
     accentRgb-at-0.15-alpha fill measured ~1.3:1 against #F7F7F7, effectively
     invisible; this amber/gold reads clearly at 3:1+ in both themes.
     Fix #16 dropped the border, fill-only now.
     Fix #17 moved --board-highlight-rgb from amber to a green family (too
     close in hue to the red circle) — now theme-varying since fill-only
     contrast pulls in opposite directions per background lightness.
     Fix #18 tried a flat pale mint (#A3FFBC) per explicit user hex — measures
     only ~1.1:1 opaque against this background (mathematically worse than
     Fix #17's forest green), kept anyway pending visual check; see fix-log. LOCKED:
     --board-bg, --board-ink-rgb, the circle's rgb(255,29,35) stroke, every
     --board-wall-*-rgb token, and --board-accent-rgb must not change. */
  --board-bg:          #F7F7F7;
  --board-accent-rgb:  45, 60, 95;
  --board-ink-rgb:     41, 98, 255;
  --board-pending-rgb: 72, 135, 95;
  --board-highlight-rgb: 255, 234, 0;
  --board-wall-mortar-rgb: 74, 74, 74;
  --board-wall-dark-rgb:   97, 97, 97;
  --board-wall-base-rgb:   138, 138, 138;
  --board-wall-light-rgb:  176, 176, 176;

  /* ── Geometry & Depth (Double-Bezel compatible) ────────────────────────── */
  --radius:     12px;
  --radius-lg:  20px;
  --radius-xl:  32px;
  --shadow-sm:  0 2px 8px -2px rgba(15, 23, 42, 0.04), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
  --shadow:     0 12px 24px -4px rgba(15, 23, 42, 0.04), 0 4px 12px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg:  0 32px 64px -12px rgba(15, 23, 42, 0.06), 0 16px 32px -8px rgba(15, 23, 42, 0.08);
  --shadow-glass: inset 0 1px 0 rgba(255,255,255,1);
  --shadow-glass-inset: inset 0 1px 0 rgba(255,255,255,1), 0 4px 12px rgba(0,0,0,0.02);

  /* ── Typography ────────────────────────────────────────────────────────── */
  --font: 'Nunito', system-ui, -apple-system, sans-serif;
  --font-display: var(--font);   /* #307 trial: Fraunces dropped, titles use the UI face */
  --fs-scale: 1;   /* every hard-coded font-size is calc(Npx * var(--fs-scale, 1)); desktop raises it below */
  
  /* ── Animation (Fluid Dynamics) ────────────────────────────────────────── */
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 0.2s;
  --duration-normal: 0.4s;
  --duration-slow: 0.7s;
  --duration-xfast: 0.1s;

  /* ── Layers (z-index scale) ────────────────────────────────────────────── */
  --z-crop: 100;
  --z-board-toast: 900;
  --z-topnav: 1000;
  --z-banner: 1150;
  --z-toast: 1200;
  --z-modal: 2000;
  --z-settings: 2200;
  --z-chat: 2500;

  /* ── Spacing Scale ──────────────────────────────────────────────────────── */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  24px;
  --space-6:  32px;
  --space-7:  48px;
  --space-8:  64px;

  /* ── Card tokens (ticket-rows.md): one padding / radius / gap for every card or ticket ── */
  --card-pad:    var(--space-3) var(--space-4);   /* 12px 16px */
  --card-pad-lg: var(--space-4);                  /* roomy multi-line card */
  --card-radius: var(--radius-lg);                /* skins retune radius-lg */
  --card-gap:    var(--space-2);                  /* between sibling cards */
}
@media (min-width: 900px) { :root { --fs-scale: 1.15; } }   /* desktop text was too small (13px body -> 15px) */

/* ── Icons (SVG sprite, TODO.md #129 — replaces Phosphor icon font) ────────
   Sized in `em` so it inherits the font-icon convention: any selector that
   used to set `font-size` on `.ph`/`.ph-bold` keeps working unchanged on
   `.icon`, since 1em resolves against the element's own font-size either
   way. */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: -0.125em;
  flex-shrink: 0;
}

/* ── Entry Animations ────────────────────────────────────────────────────── */
@keyframes fadeUp {
  0% { opacity: 0; transform: translateY(24px); }
  100% { opacity: 1; transform: translateY(0); }
}
.animate-fade-up {
  animation: fadeUp var(--duration-slow) var(--ease-spring) backwards;
  will-change: transform, opacity, filter;
}
.delay-1 { animation-delay: 0.05s; }
.delay-2 { animation-delay: 0.1s; }
.delay-3 { animation-delay: 0.15s; }
.delay-4 { animation-delay: 0.2s; }
.delay-5 { animation-delay: 0.25s; }

@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-fast: 0s;
    --duration-normal: 0s;
    --duration-slow: 0s;
    --duration-xfast: 0s;
  }
  /* ui-audit F3: animations with literal durations ignore the tokens above */
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* ui-audit F2: keep focused elements / anchor targets clear of the sticky top bar */
html { scroll-padding-top: calc(var(--nav-h, 56px) + 8px); }

html, body {
  min-height: 100vh;
  min-height: 100svh;
  /* iOS fix for min-height */
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
  overflow-x: hidden;
  transition: background-color var(--duration-normal) var(--ease-out), color var(--duration-normal) var(--ease-out);
}

/* Typography Hierarchy */
h1, h2, h3, h4, h5, h6 {
  letter-spacing: -0.03em;
  font-weight: 700;
  line-height: 1.2;
}
p, li {
  letter-spacing: -0.01em;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 4px; border: 2px solid var(--c-bg); }
::-webkit-scrollbar-thumb:hover { background: var(--c-ink-3); }

/* ── Connection Status Banner ─────────────────────────────────────────────── */
.status-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-banner);
  padding: 10px 16px;
  background: var(--c-warning-bg);
  color: var(--c-warning);
  font-size: calc(14px * var(--fs-scale, 1));
  font-weight: 600;
  text-align: center;
  border-bottom: 1px solid var(--c-border);
  transform: translateY(-100%);
  transition: transform var(--duration-normal) var(--ease-out);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.status-banner.visible {
  transform: translateY(0);
}

/* ── Top Nav ──────────────────────────────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 64px;
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--c-border);
  border-radius: 9999px;
  position: sticky;
  top: 16px;
  margin: 0 auto 32px auto;
  max-width: 1200px;
  z-index: var(--z-topnav);
  box-shadow: var(--shadow-sm), var(--shadow-glass-inset);
  transition: var(--duration-normal) var(--ease-out);
  transition-property: background-color, color, border-color, box-shadow, transform, opacity;
}

.topnav__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  transition: opacity var(--duration-fast) var(--ease-in-out);
}
.topnav__brand:hover { opacity: 0.8; }

.topnav__logo {
  display: block;
  border-radius: 8px;
  flex-shrink: 0;
}

.topnav__title {
  font-size: calc(18px * var(--fs-scale, 1));
  font-weight: 800;
  color: var(--c-ink);
  letter-spacing: -0.02em;
}

.topnav__right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topnav__user {
  font-size: calc(14px * var(--fs-scale, 1));
  color: var(--c-ink-2);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

.topnav__room-id {
  font-weight: 800;
  letter-spacing: 0.06em;
  font-size: calc(14px * var(--fs-scale, 1));
  color: var(--c-ink);
}

#room-id-nav[role="button"]:hover { text-decoration: underline; }

/* Room QR modal (room-ui.js openQrModal) */
.room-qr { max-width: 320px; padding: 20px; align-items: center; gap: 12px; text-align: center; }
.room-qr__code { font-weight: 800; font-size: 22px; letter-spacing: 0.06em; color: var(--c-ink); }
.room-qr__img { width: 220px; max-width: 100%; background: #fff; border-radius: 8px; padding: 4px; line-height: 0; }
.room-qr__img svg { width: 100%; height: auto; display: block; }
.room-qr__hint { font-size: 14px; color: var(--c-ink-soft, var(--c-ink)); }
.room-qr__actions { display: flex; gap: 8px; }

/* Desktop shows the room name; the compact ID takes over on mobile. */
.topnav__room-code { display: none; }

.topnav__badge {
  font-size: calc(14px * var(--fs-scale, 1));
  padding: 4px 10px;
  border-radius: 9999px;
  background: var(--c-surface-2);
  color: var(--c-ink-2);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid var(--c-border);
}

.topnav__btn {
  padding: 8px 16px;
  font-size: calc(14px * var(--fs-scale, 1));
  font-weight: 700;
  color: var(--c-ink);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 9999px;
  cursor: pointer;
  transition: var(--duration-fast) var(--ease-spring);
  transition-property: background-color, color, border-color, box-shadow, transform, opacity;
  font-family: var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}
.topnav__btn:hover {
  background: var(--c-surface-2);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.topnav__btn:active {
  transform: translateY(0) scale(0.96);
}

.topnav__btn--icon {
  padding: 8px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topnav {
    margin-inline: 8px;
    margin-bottom: 16px;
    top: 8px;
    height: 48px;
    padding: 0 12px;
  }
  .topnav__title { display: none; }
  .topnav__user { max-width: 80px; }
  /* Room name would be ellipsised to ~80px here — swap in the short room ID,
     which always fits whole. Full name stays available via the title attr. */
  .topnav__room-name { display: none; }
  .topnav__room-code { display: inline; }
  .topnav__room-id { max-width: none; }
  .topnav__right { gap: 6px; }
  .hide-on-mobile { display: none !important; }
  .topnav__btn { padding: 8px; }
}

/* ── Language Switcher ────────────────────────────────────────────────────── */
.lang-switch {
  padding: 4px 10px;
  font-size: calc(14px * var(--fs-scale, 1));
  font-weight: 700;
  font-family: var(--font);
  color: var(--c-ink-2);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 9999px;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: var(--duration-fast) var(--ease-in-out);
  transition-property: background-color, color, border-color, box-shadow, transform, opacity;
  text-transform: uppercase;
}
.lang-switch:hover {
  background: var(--c-surface-2);
  color: var(--c-ink);
}

.card__logo .lang-switch {
  color: var(--c-ink-2);
  background: var(--c-surface);
  border-color: var(--c-border);
  margin-left: 8px;
}

/* ── Toast Stack ────────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed;
  top: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
  width: max-content;
  max-width: min(90vw, 420px);
}
.toast {
  pointer-events: auto;
  padding: 14px 24px;
  border-radius: 9999px;
  font-size: calc(14px * var(--fs-scale, 1));
  font-weight: 600;
  color: var(--c-on-ink);
  background: var(--c-ink);
  box-shadow: var(--shadow-lg);
  text-align: center;
  word-break: break-word;
  animation: toast-in var(--duration-normal) var(--ease-spring), toast-out var(--duration-normal) var(--ease-out) forwards;
  animation-delay: 0s, 3s;
}
.toast--error   { background: var(--c-error); }
.toast--success { background: var(--c-success); }
.toast--info    { background: var(--c-brand); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-24px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-16px) scale(0.95); }
}

/* ── Accessibility & Global UX ───────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--c-brand) !important;
  outline-offset: 2px !important;
}

/* ── Haptic Button Physics ───────────────────────────────────────────────── */
button:not(:disabled):active,
.btn:not(:disabled):active,
.topnav__btn:not(:disabled):active {
  transform: scale(0.97) !important;
  transition: transform var(--duration-fast) var(--ease-spring);
}

/* ── Double-Bezel Architecture (Global) ──────────────────────────────────── */
.ui-shell {
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-xl);
  padding: 6px;
  box-shadow:
    0 2px 2px rgba(0,0,0,0.01),
    0 8px 24px -4px rgba(0,0,0,0.03);
}

.ui-core {
  background: var(--c-surface);
  border-radius: calc(var(--radius-xl) - 6px);
  box-shadow: var(--shadow-glass-inset);
  border: 1px solid var(--c-border);
  overflow: hidden;
}
