/* ═══════════════════════════════════════════════
   2048 ARENA — Neon Arcade Aesthetic
   ═══════════════════════════════════════════════ */

:root {
  color-scheme: dark;

  /* ── Palette ── */
  --void: #06080f;
  --abyss: #0a0e1a;
  --surface: rgba(12, 16, 28, 0.88);
  --surface-hot: rgba(18, 24, 42, 0.92);
  --border: rgba(0, 255, 255, 0.08);
  --border-hot: rgba(0, 255, 255, 0.22);
  --border-pink: rgba(255, 0, 128, 0.22);

  --neon: #00fff2;
  --neon-dim: rgba(0, 255, 242, 0.5);
  --neon-glow: rgba(0, 255, 242, 0.12);
  --pink: #ff2d78;
  --pink-glow: rgba(255, 45, 120, 0.12);
  --amber: #ffb800;
  --amber-glow: rgba(255, 184, 0, 0.12);
  --lime: #39ff14;
  --lime-glow: rgba(57, 255, 20, 0.1);

  --text: #e8ecf4;
  --text-sub: #7b8bad;
  --text-dim: #4a5578;

  /* ── Shape ── */
  --radius: 6px;
  --radius-lg: 10px;
  --cut: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px));
  --shadow: 0 0 40px rgba(0, 255, 242, 0.06), 0 8px 30px rgba(0, 0, 0, 0.4);
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);

  /* ── Type ── */
  --font-display: "Orbitron", monospace;
  --font-body: "Chakra Petch", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "Share Tech Mono", ui-monospace, Menlo, Consolas, monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --board-gap: 5px;
  --board-pad: 7px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.55;
  color: var(--text);
  background: var(--void);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  outline: none;
  border: none;
  background: none;
}

/* ═══════════════════════════════════════════════
   Background Atmosphere
   ═══════════════════════════════════════════════ */

.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.35;
  will-change: transform;
}

.blob-1 {
  width: 500px;
  height: 500px;
  top: -15%;
  left: -10%;
  background: radial-gradient(circle, rgba(0, 255, 242, 0.3), transparent 70%);
  animation: blobDrift1 18s ease-in-out infinite;
}

.blob-2 {
  width: 400px;
  height: 400px;
  bottom: -10%;
  right: -8%;
  background: radial-gradient(circle, rgba(255, 45, 120, 0.25), transparent 70%);
  animation: blobDrift2 22s ease-in-out infinite;
}

.blob-3 {
  width: 300px;
  height: 300px;
  top: 40%;
  left: 50%;
  background: radial-gradient(circle, rgba(255, 184, 0, 0.15), transparent 70%);
  animation: blobDrift3 15s ease-in-out infinite;
}

@keyframes blobDrift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(60px, 40px) scale(1.15); }
  66% { transform: translate(-30px, 70px) scale(0.9); }
}

@keyframes blobDrift2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-50px, -60px) scale(1.2); }
}

@keyframes blobDrift3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, -30px) scale(1.1); }
}

/* CRT Scanlines */
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  mix-blend-mode: multiply;
}

/* ═══════════════════════════════════════════════
   App Shell
   ═══════════════════════════════════════════════ */

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-hot);
  background: rgba(6, 8, 15, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 10;
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.brand-glyph {
  color: var(--pink);
  opacity: 0.6;
}

.brand-neon {
  color: var(--neon);
  text-shadow: 0 0 12px rgba(0, 255, 242, 0.5), 0 0 30px rgba(0, 255, 242, 0.2);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.topbar-action {
  min-width: auto;
  padding: 0 12px;
  font-size: 10px;
  height: 32px;
}

/* ═══════════════════════════════════════════════
   Form Controls
   ═══════════════════════════════════════════════ */

input[type="text"],
input[type="password"],
input[type="number"],
select {
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(10, 14, 26, 0.9);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input::placeholder {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
}

input:focus, select:focus {
  border-color: var(--neon-dim);
  box-shadow: 0 0 0 2px var(--neon-glow), 0 0 16px rgba(0, 255, 242, 0.08);
}

button {
  height: 38px;
  padding: 0 18px;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255, 255, 255, 0.06));
  pointer-events: none;
}

button:active:not(:disabled) {
  transform: scale(0.96) translateY(1px);
}

button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  filter: saturate(0.3);
}

.btn-primary, #connectButton {
  background: linear-gradient(135deg, var(--neon), #0088aa);
  color: var(--void);
  box-shadow: 0 0 14px rgba(0, 255, 242, 0.2);
}

.btn-primary:hover:not(:disabled), #connectButton:hover:not(:disabled) {
  box-shadow: 0 0 22px rgba(0, 255, 242, 0.35), 0 0 60px rgba(0, 255, 242, 0.1);
}

.btn-secondary {
  background: rgba(10, 14, 26, 0.8);
  border: 1px solid var(--border);
  color: var(--text-sub);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-hot);
  color: var(--neon);
  box-shadow: 0 0 10px rgba(0, 255, 242, 0.08);
}

.btn-success {
  background: linear-gradient(135deg, var(--lime), #1a9e00);
  color: var(--void);
  box-shadow: 0 0 14px var(--lime-glow);
}

.btn-warn {
  background: linear-gradient(135deg, var(--amber), #cc8800);
  color: var(--void);
  box-shadow: 0 0 14px var(--amber-glow);
}

.btn-danger {
  background: linear-gradient(135deg, var(--pink), #aa0040);
  color: #fff;
  box-shadow: 0 0 14px var(--pink-glow);
}

/* ═══════════════════════════════════════════════
   Status Strip
   ═══════════════════════════════════════════════ */

.status-strip {
  display: flex;
  align-items: center;
  padding: 0 20px 0 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.status-strip:empty { display: none; }

.status-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-info strong {
  color: var(--neon);
  font-weight: 600;
}

.status-sep {
  color: var(--text-dim);
  margin: 0 4px;
}

.alert-stack {
  position: absolute;
  left: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  pointer-events: none;
  z-index: 24;
}

.alert-stack:empty {
  display: none;
}

.alert-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(10, 14, 26, 0.82);
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: alertReveal 220ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.alert-banner.error {
  border-color: rgba(255, 45, 120, 0.28);
  box-shadow: 0 0 24px rgba(255, 45, 120, 0.12), 0 10px 24px rgba(0, 0, 0, 0.28);
}

.alert-banner.warning {
  border-color: rgba(255, 184, 0, 0.26);
  box-shadow: 0 0 24px rgba(255, 184, 0, 0.1), 0 10px 24px rgba(0, 0, 0, 0.28);
}

.alert-copy {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.alert-copy strong {
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.alert-close {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: rgba(8, 12, 22, 0.72);
  color: var(--text-sub);
  box-shadow: none;
}

.alert-close:hover:not(:disabled) {
  border-color: var(--border-hot);
  color: var(--neon);
  box-shadow: 0 0 12px rgba(0, 255, 242, 0.08);
}

@keyframes alertReveal {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 2px;
  background: rgba(10, 14, 26, 0.7);
  border: 1px solid var(--border);
  color: var(--text-sub);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
}

.chip strong {
  color: var(--neon);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════
   Layout
   ═══════════════════════════════════════════════ */

.layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  gap: 12px;
  padding: 12px 20px;
  overflow: hidden;
}

.pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  flex: 1;
}

.pane-info {
  overflow-y: auto;
  scrollbar-width: thin;
  overscroll-behavior: contain;
  flex: 1;
}

.pane-info .card {
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   Card
   ═══════════════════════════════════════════════ */

.card {
  display: flex;
  flex-direction: column;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  animation: cardReveal 300ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Neon top-edge accent */
.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 20px;
  right: 20px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--neon-dim), transparent);
  opacity: 0.6;
}

@keyframes cardReveal {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.card:empty { display: none; }

.chat-card {
  flex: 1 1 auto;
  min-height: 200px;
}

/* ── Card Content ── */
.card-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  height: 100%;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-header h2 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--neon);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-scroll {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.meta {
  color: var(--text-sub);
  font-size: 12px;
  font-family: var(--font-mono);
}

.hint {
  color: var(--text-dim);
  font-size: 12px;
}

.empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* ═══════════════════════════════════════════════
   Badge
   ═══════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 2px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid rgba(0, 255, 242, 0.25);
  background: var(--neon-glow);
  color: var(--neon);
}

.badge.subtle {
  color: var(--text-sub);
  border-color: var(--border);
  background: rgba(10, 14, 26, 0.6);
}

.badge.success {
  color: var(--lime);
  border-color: rgba(57, 255, 20, 0.25);
  background: var(--lime-glow);
}

.badge.warning {
  color: var(--amber);
  border-color: rgba(255, 184, 0, 0.2);
  background: var(--amber-glow);
}

.badge.error {
  color: var(--pink);
  border-color: rgba(255, 45, 120, 0.25);
  background: var(--pink-glow);
}

.badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════
   Stack Row
   ═══════════════════════════════════════════════ */

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stack-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(8, 12, 22, 0.7);
  border: 1px solid var(--border);
  border-left: 2px solid var(--neon);
}

.stack-label {
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 2px;
}

/* ── Actions ── */
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Forms ── */
.form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.form-row input,
.form-row select {
  flex: 1 1 120px;
  min-width: 0;
}

.auth-landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  padding: 40px 32px 36px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-hot);
  background: linear-gradient(170deg, rgba(14, 20, 36, 0.96), rgba(8, 12, 22, 0.98));
  box-shadow:
    0 0 60px rgba(0, 255, 242, 0.06),
    0 0 120px rgba(0, 255, 242, 0.03),
    0 12px 40px rgba(0, 0, 0, 0.5);
}

.auth-card::before {
  content: "";
  position: absolute;
  top: -1px; left: -1px; right: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--neon), transparent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.auth-brand {
  text-align: center;
  margin-bottom: 4px;
}

.auth-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 0 20px rgba(0, 255, 242, 0.3);
}

.auth-title .auth-neon {
  color: var(--neon);
}

.auth-subtitle {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.auth-toggle {
  display: flex;
  gap: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  background: rgba(6, 8, 15, 0.6);
}

.auth-tab {
  flex: 1;
  padding: 10px 0;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text-dim);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: color var(--transition), background var(--transition), box-shadow var(--transition);
}

.auth-tab:hover {
  color: var(--text);
  background: rgba(0, 255, 242, 0.03);
}

.auth-tab.active {
  color: var(--neon);
  background: rgba(0, 255, 242, 0.1);
  box-shadow: inset 0 -2px 0 var(--neon);
}

.auth-card .form-row input {
  height: 44px;
  font-size: 14px;
  background: rgba(6, 8, 15, 0.7);
  border-color: rgba(0, 255, 242, 0.1);
}

.auth-card .form-row input:focus {
  border-color: var(--neon-dim);
  box-shadow: 0 0 0 2px var(--neon-glow), 0 0 20px rgba(0, 255, 242, 0.1);
}

.auth-submit {
  width: 100%;
  height: 44px;
  font-size: 13px;
  letter-spacing: 0.14em;
  margin-top: 4px;
}

/* ═══════════════════════════════════════════════
   Room List
   ═══════════════════════════════════════════════ */

.room-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.room-item {
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(8, 12, 22, 0.6);
  border: 1px solid var(--border);
  border-left: 3px solid var(--pink);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.room-item:hover {
  background: rgba(12, 18, 30, 0.8);
  border-color: var(--border-pink);
  box-shadow: 0 0 20px rgba(255, 45, 120, 0.06);
}

.room-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.room-item .meta { margin-bottom: 8px; }

/* ═══════════════════════════════════════════════
   Member Grid
   ═══════════════════════════════════════════════ */

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  align-content: start;
}

.member-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: linear-gradient(170deg, rgba(14, 20, 36, 0.95), rgba(8, 12, 22, 0.98));
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}

/* Diagonal accent stripe */
.member-card::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, transparent 48%, rgba(0, 255, 242, 0.06) 49%, rgba(0, 255, 242, 0.03) 100%);
  pointer-events: none;
}

.member-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-hot);
  box-shadow: 0 0 30px rgba(0, 255, 242, 0.08), 0 12px 30px rgba(0, 0, 0, 0.3);
}

.member-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.member-title { display: flex; flex-direction: column; gap: 2px; }

.member-name {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.member-subtitle {
  color: var(--text-sub);
  font-family: var(--font-mono);
  font-size: 11px;
}

.member-badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.member-art-wrap {
  display: grid;
  place-items: center;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid rgba(0, 255, 242, 0.08);
  background: rgba(6, 8, 15, 0.8);
  min-height: 78px;
}

.member-art {
  color: var(--neon);
  text-align: center;
  font: 700 12px/1.25 var(--font-mono);
  white-space: pre;
  text-shadow: 0 0 8px rgba(0, 255, 242, 0.3);
}

.member-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.stat-box {
  padding: 7px 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(6, 8, 15, 0.6);
  text-align: center;
}

.stat-box .stat-label {
  display: block;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 3px;
}

.stat-box .stat-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--neon);
}

.member-foot {
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-mono);
  margin-top: auto;
}

/* ═══════════════════════════════════════════════
   Score Items
   ═══════════════════════════════════════════════ */

.score-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.score-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 2px solid var(--amber);
  background: rgba(8, 12, 22, 0.6);
}

.score-item strong {
  display: block;
  margin-bottom: 2px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.04em;
}

/* ═══════════════════════════════════════════════
   Board (2048)
   ═══════════════════════════════════════════════ */

.board-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 0;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.board-meta {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: min(100%, 420px);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--board-gap);
  width: min(100%, clamp(240px, 55vmin, 420px));
  padding: var(--board-pad);
  border-radius: var(--radius-lg);
  background: rgba(6, 8, 15, 0.85);
  border: 1px solid var(--border-hot);
  box-shadow:
    0 0 40px rgba(0, 255, 242, 0.04),
    inset 0 0 30px rgba(0, 0, 0, 0.3);
  position: relative;
  contain: layout paint style;
}

.tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: rgba(16, 22, 38, 0.9);
  font-family: var(--font-display);
  font-size: clamp(14px, 2.6vmin, 26px);
  font-weight: 900;
  letter-spacing: 0.02em;
  transition: background 120ms ease, transform 80ms ease, opacity 120ms ease, box-shadow 120ms ease;
  will-change: transform, opacity;
  backface-visibility: hidden;
  transform: translateZ(0);
}

/* Tile color ramp — from cool to hot neon */
.tile[data-value="0"]    { color: rgba(255,255,255,0.05); border: 1px solid rgba(0, 255, 242, 0.03); }
.tile[data-value="2"]    { background: #0d1a2e; color: #4a8fcc; border: 1px solid rgba(0, 255, 242, 0.08); }
.tile[data-value="4"]    { background: #0f2040; color: #5ea8e6; border: 1px solid rgba(0, 255, 242, 0.12); }
.tile[data-value="8"]    { background: #0a2a5c; color: #00fff2; border: 1px solid rgba(0, 255, 242, 0.2); box-shadow: 0 0 8px rgba(0, 255, 242, 0.08); }
.tile[data-value="16"]   { background: #14306e; color: #00fff2; border: 1px solid rgba(0, 255, 242, 0.25); box-shadow: 0 0 12px rgba(0, 255, 242, 0.1); }
.tile[data-value="32"]   { background: #2a1a6e; color: #b48eff; border: 1px solid rgba(180, 142, 255, 0.25); box-shadow: 0 0 14px rgba(180, 142, 255, 0.1); }
.tile[data-value="64"]   { background: #4a0e6e; color: #e066ff; border: 1px solid rgba(224, 102, 255, 0.25); box-shadow: 0 0 16px rgba(224, 102, 255, 0.12); }
.tile[data-value="128"]  { background: #6e0a4a; color: #ff2d78; border: 1px solid rgba(255, 45, 120, 0.3); box-shadow: 0 0 18px rgba(255, 45, 120, 0.12); }
.tile[data-value="256"]  { background: #7a1030; color: #ff5a9e; border: 1px solid rgba(255, 90, 158, 0.3); box-shadow: 0 0 20px rgba(255, 45, 120, 0.15); }
.tile[data-value="512"]  { background: #6e3a00; color: var(--amber); border: 1px solid rgba(255, 184, 0, 0.3); box-shadow: 0 0 22px rgba(255, 184, 0, 0.15); }
.tile[data-value="1024"] { background: #5e4400; color: #ffe066; border: 1px solid rgba(255, 224, 102, 0.3); box-shadow: 0 0 24px rgba(255, 184, 0, 0.18); }
.tile[data-value="2048"] {
  background: linear-gradient(135deg, #39ff14, #00fff2);
  color: var(--void);
  border: 1px solid rgba(57, 255, 20, 0.5);
  box-shadow: 0 0 30px rgba(57, 255, 20, 0.25), 0 0 60px rgba(0, 255, 242, 0.12);
  animation: tileGlow 1.5s ease-in-out infinite alternate;
}

@keyframes tileGlow {
  from { box-shadow: 0 0 30px rgba(57, 255, 20, 0.25), 0 0 60px rgba(0, 255, 242, 0.12); }
  to { box-shadow: 0 0 40px rgba(57, 255, 20, 0.4), 0 0 80px rgba(0, 255, 242, 0.2); }
}

.tile-pop {
  animation: tilePop 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tilePop {
  0% { transform: scale(0.75); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.tile-hidden { opacity: 0; }

.board-fx-layer {
  position: absolute;
  inset: var(--board-pad);
  pointer-events: none;
  z-index: 3;
  contain: layout paint;
}

.fx-tile {
  position: absolute;
  z-index: 4;
  transform: var(--fx-transform-from, translate3d(0, 0, 0) scale(1));
  transition:
    transform 150ms cubic-bezier(0.22, 0.88, 0.24, 1),
    opacity 150ms ease;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.fx-tile.fx-run {
  transform: var(--fx-transform-to, translate3d(0, 0, 0) scale(1));
}

.fx-tile.fx-spawn {
  opacity: 0;
  transform: var(--fx-transform-from, translate3d(0, 0, 0) scale(0.72));
}

.fx-tile.fx-spawn.fx-run {
  opacity: 1;
  transform: var(--fx-transform-to, translate3d(0, 0, 0) scale(1));
}

.board-caption {
  width: min(100%, 420px);
  text-align: center;
}

/* ═══════════════════════════════════════════════
   Chat
   ═══════════════════════════════════════════════ */

.chat-shell {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  height: 100%;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.chat-line {
  padding: 7px 12px;
  border-radius: var(--radius);
  background: rgba(6, 8, 15, 0.6);
  border: 1px solid var(--border);
  border-left: 2px solid var(--neon);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
  color: var(--lime);
  animation: chatPulse 200ms ease both;
}

@keyframes chatPulse {
  from { opacity: 0; border-left-color: var(--pink); }
  to { opacity: 1; border-left-color: var(--neon); }
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(10, 14, 26, 0.9);
  color: var(--lime);
  font-family: var(--font-mono);
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input:focus {
  border-color: var(--neon-dim);
  box-shadow: 0 0 0 2px var(--neon-glow);
}

/* ═══════════════════════════════════════════════
   Mobile Tab Bar
   ═══════════════════════════════════════════════ */

.mobile-tabs {
  display: none;
  padding: 6px 16px calc(6px + var(--safe-bottom));
  background: rgba(6, 8, 15, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-hot);
  gap: 4px;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  transition: color var(--transition), background var(--transition), box-shadow var(--transition);
  position: relative;
}

.tab.active {
  color: var(--neon);
  background: var(--neon-glow);
  box-shadow: 0 0 12px rgba(0, 255, 242, 0.08);
}

.tab.has-unread::after {
  content: "";
  position: absolute;
  top: 5px;
  right: calc(50% - 18px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pink);
  box-shadow: 0 0 8px rgba(255, 45, 120, 0.5);
  animation: unreadPulse 1.2s ease-in-out infinite;
}

@keyframes unreadPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}

/* ═══════════════════════════════════════════════
   Stage (main game area)
   ═══════════════════════════════════════════════ */

.stage-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  height: 100%;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.stage-header h2 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--neon);
}

.stage-scroll {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  overscroll-behavior: contain;
  flex: 1 1 auto;
}

/* ═══════════════════════════════════════════════
   Responsive — Desktop (≥960px)
   ═══════════════════════════════════════════════ */

@media (min-width: 960px) {
  .mobile-tabs { display: none !important; }
  .app { grid-template-rows: auto 1fr; }

  .layout {
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 340px);
  }

  .pane { display: flex !important; }
  .pane-chat { display: none !important; }
  .pane-main .card { flex: 1; min-height: 0; }
  .pane-info { overflow-y: auto; }

  body[data-view="room"] .layout,
  body[data-view="game"] .layout {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 300px) minmax(280px, 340px);
  }

  body[data-view="room"] .pane-chat,
  body[data-view="game"] .pane-chat {
    display: flex !important;
  }
}

/* ── Tablet (640–959px) ── */
@media (min-width: 640px) and (max-width: 959px) {
  .mobile-tabs { display: none !important; }
  .app { grid-template-rows: auto 1fr; }

  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  }

  .pane-main .card { flex: 1; min-height: 0; }
  .pane-chat { display: none !important; }

  body[data-view="room"] .pane-chat,
  body[data-view="game"] .pane-chat {
    display: none !important;
  }

}

/* ── Mobile (<640px) ── */
@media (max-width: 639px) {
  :root {
    --board-gap: 4px;
    --board-pad: 5px;
  }

  .mobile-tabs { display: flex; }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .brand h1 { font-size: 15px; }

  .status-strip { display: none; }
  .alert-stack {
    left: 12px;
    right: 12px;
  }
  .layout { padding: 8px 12px; }

  .alert-banner {
    align-items: flex-start;
    flex-direction: column;
  }

  .alert-copy {
    width: 100%;
  }

  .alert-close {
    align-self: flex-end;
  }

  .pane { display: none !important; }
  .pane.pane-active { display: flex !important; }
  .pane-main .card { flex: 1; min-height: 0; }

  .card {
    padding: 12px;
    border-radius: 8px;
  }

  .auth-card {
    padding: 28px 20px 24px;
    max-width: 100%;
    margin: 0 12px;
  }

  .auth-title {
    font-size: 22px;
  }

  .member-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }

  .member-card { padding: 12px; }

  .member-stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }

  .stat-box { padding: 5px; }
  .stat-box .stat-label { font-size: 7px; }
  .stat-box .stat-value { font-size: 12px; }

  .board-grid {
    width: min(100%, min(88vw, 360px));
  }

  .tile {
    border-radius: 4px;
    font-size: clamp(12px, 5vw, 20px);
  }

  /* Reduce blob sizes on mobile */
  .blob-1 { width: 250px; height: 250px; }
  .blob-2 { width: 200px; height: 200px; }
  .blob-3 { width: 150px; height: 150px; }
}

/* ═══════════════════════════════════════════════
   View-Based Visibility
   ═══════════════════════════════════════════════ */

body[data-view="offline"] .pane-info { display: none !important; }
body[data-view="offline"] .pane-chat { display: none !important; }
body[data-view="offline"] .pane-main { display: flex !important; }
body[data-view="offline"] .mobile-tabs { display: none !important; }
body[data-view="offline"] .layout { grid-template-columns: 1fr !important; }

body[data-view="lobby"] #rulesCard { display: none; }
body[data-view="lobby"] #chatCard { display: none; }

body[data-view="room"] #roomsCard { display: none; }

body[data-view="game"] #rulesCard { display: none; }
body[data-view="game"] #roomsCard { display: none; }

/* ── Swipe Hint ── */
@keyframes swipeHint {
  0%, 100% { opacity: 0.3; transform: translateX(0); }
  25% { opacity: 1; transform: translateX(4px); }
  75% { opacity: 1; transform: translateX(-4px); }
}

.swipe-hint {
  display: inline-block;
  animation: swipeHint 2.5s ease-in-out infinite;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--neon-dim);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 255, 242, 0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 255, 242, 0.3); }
