/* ==========================================================================
   EveHost Games — Poki-Style Instant Browser Games Portal
   Default: Vibrant Poki Blue · Toggleable: Dark Arcade Theme
   ========================================================================== */

:root {
  --bg: #009be5;
  --bg-pattern: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.14) 0 18px, transparent 19px),
                radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.1) 0 26px, transparent 27px),
                linear-gradient(155deg, #00b8ff 0%, #0095df 52%, #0077cc 100%);
  --bg-top: rgba(255, 255, 255, 0.96);
  --surface: #ffffff;
  --surface-hover: #f0f7ff;
  --border: #d7e6f5;
  --text: #111827;
  --text-muted: #4b5d78;
  --accent: #ff5a36;
  --accent-hover: #ff7152;
  --accent-ink: #ffffff;
  --poki-cyan: #009be5;
  --gold: #f59e0b;
  --danger: #ef4444;
  --tile-border: rgba(255, 255, 255, 0.92);
  --tile-shadow: 0 8px 18px rgba(0, 54, 102, 0.28), 0 3px 0 rgba(0, 54, 102, 0.22);
  --tile-hover-shadow: 0 18px 34px rgba(0, 42, 84, 0.42), 0 0 0 3px #ffffff;
  --pill-shadow: 0 3px 0 rgba(0, 66, 122, 0.16);
  --stage-bg: radial-gradient(circle at center, rgba(255, 255, 255, 0.16), rgba(0, 54, 102, 0.22) 85%);
  --footer-bg: rgba(0, 62, 114, 0.26);
  --footer-text: rgba(255, 255, 255, 0.92);
  --font-display: 'Fredoka', 'Inter', sans-serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

body.theme-dark {
  --bg: #0f1320;
  --bg-pattern: radial-gradient(circle at 18% 12%, rgba(0, 183, 255, 0.1) 0, transparent 42%),
                radial-gradient(circle at 82% 85%, rgba(255, 90, 54, 0.08) 0, transparent 42%),
                linear-gradient(180deg, #111626 0%, #0b0e18 100%);
  --bg-top: rgba(22, 27, 42, 0.96);
  --surface: #1d2336;
  --surface-hover: #262e47;
  --border: #2e3752;
  --text: #f3f6fc;
  --text-muted: #98a5c4;
  --tile-border: rgba(255, 255, 255, 0.1);
  --tile-shadow: 0 8px 20px rgba(0, 0, 0, 0.42);
  --tile-hover-shadow: 0 16px 32px rgba(0, 0, 0, 0.58), 0 0 0 3px var(--accent);
  --pill-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  --stage-bg: radial-gradient(circle at center, rgba(56, 189, 248, 0.06), transparent 72%);
  --footer-bg: rgba(15, 19, 32, 0.85);
  --footer-text: #98a5c4;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: var(--bg-pattern);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input { font-family: inherit; }

/* ==========================================================================
   Poki-Style Sticky Floating Header & Category Strip
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-top);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 6px 22px rgba(0, 48, 92, 0.14);
}

.topbar-inner {
  max-width: 1520px;
  margin: 0 auto;
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.32rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.logo-badge {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  background: linear-gradient(135deg, #ff6b35 0%, #ff3b5c 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  box-shadow: 0 4px 0 #b8223d;
  transform: rotate(-4deg);
  transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}
.logo:hover .logo-badge { transform: rotate(4deg) scale(1.08); }

.logo-text span {
  color: var(--accent);
  margin-left: 2px;
}

.search-box {
  flex: 1;
  max-width: 440px;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--surface-hover);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 0.44rem 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box:focus-within {
  border-color: var(--poki-cyan);
  box-shadow: 0 0 0 3px rgba(0, 155, 229, 0.18);
}
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 0;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.48rem 0.92rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
  box-shadow: var(--pill-shadow);
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.pill-btn:hover { background: var(--surface-hover); border-color: var(--poki-cyan); transform: translateY(-1px); }
.pill-btn:active { transform: translateY(1px); }

.pill-btn.accent {
  background: linear-gradient(135deg, #ff6b35 0%, #ff3b5c 100%);
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 3px 0 #b8223d;
}
.pill-btn.accent:hover { filter: brightness(1.06); transform: translateY(-1px); }

.pill-btn.danger {
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--danger);
}
.pill-btn.danger:hover { background: rgba(239, 68, 68, 0.12); }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--pill-shadow);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.12s;
}
.icon-btn:hover { background: var(--surface-hover); border-color: var(--poki-cyan); transform: translateY(-1px); }
.icon-btn.active {
  background: rgba(255, 90, 54, 0.16);
  border-color: var(--accent);
  color: var(--accent);
}
.icon-btn.active svg { fill: currentColor; }

/* Category Bar */
.cat-bar {
  max-width: 1520px;
  margin: 0 auto;
  padding: 0 1.25rem 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.cat-bar::-webkit-scrollbar { display: none; }

.cat-pill {
  padding: 0.38rem 0.95rem;
  border-radius: 999px;
  border: 2px solid transparent;
  background: var(--surface-hover);
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s, background 0.15s, color 0.15s, border-color 0.15s;
}
.cat-pill:hover {
  background: var(--surface);
  border-color: var(--poki-cyan);
  color: var(--text);
  transform: translateY(-1px);
}
.cat-pill.popular-pill {
  color: #e11d48;
  background: rgba(255, 59, 92, 0.11);
}
body.theme-dark .cat-pill.popular-pill { color: #fb7185; }
.cat-pill.active {
  background: linear-gradient(135deg, #00a8ff 0%, #0077cc 100%);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 3px 0 rgba(0, 68, 128, 0.35);
}
.cat-pill.popular-pill.active {
  background: linear-gradient(135deg, #ff6b35 0%, #ff3b5c 100%);
  box-shadow: 0 3px 0 rgba(184, 34, 61, 0.35);
}

/* ==========================================================================
   Poki-Style Bento Mosaic Tile Wall
   ========================================================================== */
.portal-main {
  max-width: 1520px;
  margin: 0 auto;
  padding: 1.25rem;
  min-height: calc(100vh - 155px);
}

.wall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  grid-auto-flow: dense;
  gap: 15px;
}

.game-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  overflow: hidden;
  border: 3px solid var(--tile-border);
  background: #141926;
  box-shadow: var(--tile-shadow);
  cursor: pointer;
  padding: 0;
  text-align: left;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.18s, box-shadow 0.2s;
}

/* Featured larger Poki 2x2 Spotlight Tiles */
@media (min-width: 820px) {
  .game-tile.featured {
    grid-column: span 2;
    grid-row: span 2;
    border-radius: 22px;
  }
}

.game-tile:hover {
  transform: scale(1.055) translateY(-5px);
  border-color: #ffffff;
  box-shadow: var(--tile-hover-shadow);
  z-index: 6;
}

.game-tile:focus-visible {
  outline: 3px solid #fde047;
  outline-offset: 3px;
}

.tile-art {
  width: 100%;
  height: 100%;
  display: block;
}
.tile-art svg {
  width: 100%;
  height: 100%;
  display: block;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.game-tile:hover .tile-art svg {
  transform: scale(1.06);
}

/* Poki Corner Badges (HOT / NEW / TOP) */
.tile-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #ffffff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  z-index: 2;
  pointer-events: none;
}
.game-tile.featured .tile-badge {
  top: 12px;
  left: 12px;
  padding: 4px 11px;
  font-size: 0.76rem;
}
.badge-hot { background: linear-gradient(135deg, #ff3b5c 0%, #ff7b00 100%); }
.badge-new { background: linear-gradient(135deg, #10b981 0%, #22c55e 100%); }
.badge-top { background: linear-gradient(135deg, #f59e0b 0%, #eab308 100%); color: #111827; }

.tile-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.8rem 0.65rem 0.55rem;
  background: linear-gradient(180deg, transparent 0%, rgba(9, 13, 24, 0.88) 78%);
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  transition: padding-bottom 0.16s ease;
}
.game-tile:hover .tile-overlay {
  padding-bottom: 0.7rem;
}

.tile-title {
  font-family: var(--font-display);
  font-size: 0.94rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.15;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
}
.game-tile.featured .tile-title { font-size: 1.32rem; }

.tile-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  text-transform: capitalize;
  color: #dbeafe;
}

.tile-best {
  font-family: var(--font-mono);
  color: #fde047;
  font-weight: 700;
}

.tile-fav-mark {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.82);
  color: #ff5a36;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  background: var(--bg-top);
  border-radius: 22px;
  max-width: 480px;
  margin: 2rem auto;
  box-shadow: var(--tile-shadow);
  color: var(--text-muted);
}
.empty-state p { margin: 0 0 1rem; font-size: 1.05rem; font-weight: 600; }

.portal-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--footer-bg);
  color: var(--footer-text);
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.footer-credit a {
  color: #fde047;
  font-weight: 700;
}
body.theme-dark .footer-credit a { color: var(--accent); }
.footer-credit a:hover { text-decoration: underline; }

/* ==========================================================================
   Poki-Style 3-Column Game Theater Overlay
   ========================================================================== */
.theater {
  position: fixed;
  inset: 0;
  z-index: 100;
  background-color: var(--bg);
  background-image: var(--bg-pattern);
  display: none;
  height: 100dvh;
}
.theater.open { display: flex; }

.theater-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 204px 1fr 204px;
}

.theater-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.theater-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.62rem 1rem;
  background: var(--bg-top);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.theater-title-group {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.theater-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.theater-title-group h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.1;
}
.theater-cat-chip {
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 155, 229, 0.14);
  color: var(--poki-cyan);
}
.theater-controls-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.theater-score-bar {
  display: flex;
  gap: 0.5rem;
}
.score-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.34rem 0.78rem;
  border-radius: 999px;
  background: var(--surface-hover);
  border: 2px solid var(--border);
  font-family: var(--font-mono);
}
.score-chip span { font-size: 0.66rem; font-weight: 700; color: var(--text-muted); }
.score-chip strong { font-size: 0.95rem; }
.score-chip.best strong { color: var(--gold); }

.theater-tools { display: flex; align-items: center; gap: 0.4rem; }

.stage-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: auto;
  background: var(--stage-bg);
}

.game-mount {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}

.game-canvas {
  display: block;
  border-radius: 16px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: #0d1017;
  box-shadow: 0 20px 48px rgba(0, 26, 56, 0.48);
  max-width: 100%;
  max-height: calc(100vh - 118px);
  touch-action: none;
}
body.theme-dark .game-canvas {
  border-color: var(--border);
}

/* Theater Left & Right Poki Game Rails */
.theater-rail {
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.theme-dark .theater-rail {
  background: rgba(15, 19, 32, 0.75);
}
.theater-rail-left { border-right: 1px solid rgba(255, 255, 255, 0.22); }
.theater-rail-right { border-left: 1px solid rgba(255, 255, 255, 0.22); }
body.theme-dark .theater-rail-left { border-right-color: var(--border); }
body.theme-dark .theater-rail-right { border-left-color: var(--border); }

.rail-head {
  padding: 0.78rem 0.85rem;
  font-family: var(--font-display);
  font-size: 0.94rem;
  font-weight: 700;
  color: #ffffff;
  background: rgba(0, 48, 92, 0.24);
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}
body.theme-dark .rail-head {
  background: var(--bg-top);
  border-bottom-color: var(--border);
}
.rail-grid {
  padding: 0.65rem;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rail-grid .game-tile {
  border-radius: 12px;
  border-width: 2px;
}
.rail-grid .tile-badge {
  top: 4px;
  left: 4px;
  padding: 1px 5px;
  font-size: 0.52rem;
}
.rail-grid .tile-title { font-size: 0.7rem; }
.rail-grid .tile-meta { display: none; }
.rail-grid .tile-overlay { padding: 1rem 0.35rem 0.3rem; }

/* ==========================================================================
   Interactive DOM Games (2048, Minesweeper, Memory, Simon, Whack, Reaction,
   Tic-Tac-Toe, Lights Out, Color Rush, Quick Math, Speed Typer, Word Clash)
   ========================================================================== */
.board-shell {
  background: #171c2b;
  color: #f8fafc;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 18px;
  padding: 1.15rem;
  box-shadow: 0 20px 46px rgba(0, 26, 56, 0.45);
  user-select: none;
}
body.theme-dark .board-shell {
  border-color: var(--border);
}

.board-status {
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  color: #cbd5e1;
  margin-bottom: 0.85rem;
  font-family: var(--font-mono);
}

/* 2048 */
.g2048-grid {
  display: grid;
  grid-template-columns: repeat(4, 82px);
  grid-template-rows: repeat(4, 82px);
  gap: 10px;
  background: #111521;
  padding: 10px;
  border-radius: 12px;
}
.g2048-cell {
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 700;
  background: #22283a;
  color: #fff;
}

/* Minesweeper */
.mine-grid {
  display: grid;
  grid-template-columns: repeat(10, 36px);
  gap: 4px;
}
.mine-cell {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #2b3248;
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mine-cell.open { background: #111521; border-color: #1f2937; cursor: default; }
.mine-cell.flagged { background: #4a2323; color: #ff6b6b; }
.mine-cell.bomb { background: #dc2626; color: #fff; }
.mine-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

/* Memory Flip */
.mem-grid {
  display: grid;
  grid-template-columns: repeat(4, 78px);
  gap: 10px;
}
.mem-card {
  height: 78px;
  border-radius: 10px;
  border: 2px solid #334155;
  background: #252b3f;
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
}
.mem-card.open, .mem-card.matched { background: #111521; border-color: var(--accent); }
.mem-card.matched { opacity: 0.65; border-color: #22c55e; }

/* Simon Pulse */
.simon-grid {
  display: grid;
  grid-template-columns: 145px 145px;
  gap: 14px;
}
.simon-pad {
  height: 145px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 0.1s, transform 0.1s;
}
.simon-pad.lit { opacity: 1; transform: scale(1.04); box-shadow: 0 0 28px currentColor; }

/* Whack-a-Bot */
.whack-grid {
  display: grid;
  grid-template-columns: repeat(3, 104px);
  gap: 12px;
}
.whack-hole {
  height: 104px;
  border-radius: 14px;
  border: 2px solid #334155;
  background: #111521;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  color: transparent;
  transition: background 0.08s, transform 0.08s;
}
.whack-hole.active {
  background: var(--accent);
  color: #fff;
  border-color: #fff;
  transform: scale(1.04);
}

/* Reaction Timer */
.react-pad {
  width: min(500px, 86vw);
  height: 300px;
  border-radius: 18px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  padding: 1.5rem;
  transition: background 0.12s;
  box-shadow: 0 20px 44px rgba(0, 26, 56, 0.4);
}
.react-pad h3 { font-family: var(--font-display); font-size: 2rem; margin: 0 0 0.5rem; color: #fff; }
.react-pad p { margin: 0; color: rgba(255, 255, 255, 0.88); }

/* Tic-Tac-Toe, Lights Out, Color Rush, Quick Math, Speed Typer */
.tic-grid {
  display: grid;
  grid-template-columns: repeat(3, min(104px, 26vw));
  gap: 10px;
}
.tic-cell {
  height: min(104px, 26vw);
  border-radius: 12px;
  border: 2px solid #334155;
  background: #111521;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 7vw, 2.8rem);
  font-weight: 700;
  cursor: pointer;
  color: #fff;
}
.tic-cell.tx { color: #ff5a36; }
.tic-cell.to { color: #38bdf8; }

.lights-grid {
  display: grid;
  grid-template-columns: repeat(5, min(64px, 15.5vw));
  gap: 8px;
}
.light-cell {
  height: min(64px, 15.5vw);
  border-radius: 10px;
  border: 2px solid #334155;
  background: #1a1f30;
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
}
.light-cell.on {
  background: #facc15;
  border-color: #fef08a;
  box-shadow: 0 0 18px rgba(250, 204, 21, 0.45);
}

.color-shell, .math-shell, .typing-shell {
  width: min(440px, 92vw);
  text-align: center;
}
.color-word {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 10vw, 3.6rem);
  font-weight: 700;
  margin: 1rem 0 1.4rem;
  letter-spacing: 0.04em;
}
.color-opts, .math-opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.color-btn {
  height: 58px;
  border-radius: 10px;
  border: none;
  color: #0b0e14;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}
.math-q {
  font-family: var(--font-mono);
  font-size: clamp(2rem, 8vw, 2.9rem);
  font-weight: 700;
  margin: 1rem 0 1.4rem;
}
.math-btn {
  height: 60px;
  border-radius: 10px;
  border: 2px solid #334155;
  background: #1e2438;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
}
.math-btn:hover { border-color: var(--accent); }

.type-word {
  font-family: var(--font-mono);
  font-size: clamp(1.9rem, 8vw, 2.8rem);
  font-weight: 700;
  color: var(--accent);
  margin: 1rem 0 1.25rem;
  letter-spacing: 0.06em;
}
.type-input {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 2px solid #334155;
  background: #111521;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 1.2rem;
  text-align: center;
  outline: none;
}
.type-input:focus { border-color: var(--accent); }

/* Word Clash (Wordle-Style Puzzle) */
.wordle-shell {
  width: min(460px, 94vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}
.wordle-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.wordle-grid {
  display: grid;
  grid-template-columns: repeat(5, min(54px, 14vw));
  gap: 7px;
}
.wd-cell {
  width: min(54px, 14vw);
  height: min(54px, 14vw);
  border-radius: 9px;
  border: 2px solid #334155;
  background: #111521;
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, background 0.18s, border-color 0.18s;
}
.wd-cell.filled { border-color: #64748b; transform: scale(1.03); }
.wd-cell.correct { background: #22c55e; border-color: #22c55e; }
.wd-cell.present { background: #eab308; border-color: #eab308; color: #111827; }
.wd-cell.absent { background: #3f3f46; border-color: #3f3f46; }

.wordle-kb {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wd-kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.wd-key {
  min-width: 32px;
  height: 42px;
  padding: 0 6px;
  border-radius: 8px;
  border: none;
  background: #334155;
  color: #ffffff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  flex: 1;
  max-width: 40px;
}
.wd-key.wide { max-width: 64px; font-size: 0.76rem; }
.wd-key:hover { filter: brightness(1.15); }
.wd-key.correct { background: #22c55e; }
.wd-key.present { background: #eab308; color: #111827; }
.wd-key.absent { background: #1e293b; color: #64748b; }

/* ==========================================================================
   Modals (Scores & User Account)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(9, 14, 28, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }

.modal-card {
  width: min(540px, 100%);
  max-height: 85vh;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-family: var(--font-display); font-size: 1.2rem; }
.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.modal-body {
  padding: 1.15rem 1.25rem;
  overflow-y: auto;
}
.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.stat-box {
  background: var(--surface-hover);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  text-align: center;
}
.stat-box strong { display: block; font-family: var(--font-mono); font-size: 1.3rem; color: var(--accent); }
.stat-box span { font-size: 0.75rem; color: var(--text-muted); }

.scores-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 1rem;
}
.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.85rem;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.88rem;
}
.score-row strong { font-family: var(--font-mono); color: var(--gold); }
.modal-foot { display: flex; justify-content: flex-end; }

/* Account & Profile */
.avatar-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #0284c7;
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface-hover);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}
.auth-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem;
  border-radius: 9px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}
.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.account-form { display: flex; flex-direction: column; gap: 0.85rem; }
.acc-field { display: flex; flex-direction: column; gap: 0.35rem; }
.acc-field label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.acc-field input, .profile-edit-row input {
  padding: 0.62rem 0.85rem;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface-hover);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.acc-field input:focus, .profile-edit-row input:focus { border-color: var(--poki-cyan); }

.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
}
.swatch.active { border-color: var(--text); transform: scale(1.12); }

.acc-error {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #dc2626;
  font-size: 0.82rem;
}
body.theme-dark .acc-error { color: #fca5a5; }
.full-btn { width: 100%; justify-content: center; padding: 0.65rem; }
.acc-note { margin: 0.85rem 0 0; font-size: 0.78rem; color: var(--text-muted); text-align: center; }

.profile-header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.profile-avatar {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.profile-info { flex: 1; min-width: 160px; }
.profile-info h4 { margin: 0; font-family: var(--font-display); font-size: 1.1rem; }
.profile-email { font-size: 0.78rem; color: var(--text-muted); }

.xp-wrap { margin-top: 0.45rem; }
.xp-label { display: block; font-family: var(--font-mono); font-size: 0.72rem; color: var(--gold); margin-bottom: 4px; }
.xp-track { height: 7px; border-radius: 999px; background: var(--surface-hover); overflow: hidden; border: 1px solid var(--border); }
.xp-fill { height: 100%; background: var(--accent); transition: width 0.25s; }

.profile-edit-row { display: flex; gap: 0.5rem; margin-bottom: 1.1rem; }
.profile-edit-row input { flex: 1; min-width: 0; }

.profile-section-title { font-family: var(--font-display); font-size: 0.94rem; font-weight: 700; margin-bottom: 0.6rem; }
.badges-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.badge-card {
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  opacity: 0.5;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.badge-card.unlocked {
  opacity: 1;
  border-color: var(--gold);
  background: rgba(245, 183, 0, 0.12);
}
.badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  flex-shrink: 0;
}
.badge-card.unlocked .badge-icon { color: var(--gold); }
.badge-card strong { display: block; font-size: 0.84rem; }
.badge-card span { font-size: 0.72rem; color: var(--text-muted); }

/* ==========================================================================
   Mobile / Touch On-Screen Gamepad & Responsiveness
   ========================================================================== */
.touch-controls {
  display: none;
  padding: 0.65rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: var(--bg-top);
  border-top: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
@media (max-width: 900px), (pointer: coarse) {
  .touch-controls.active { display: block; }
}

.tc-dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 50px);
  gap: 8px;
  justify-content: center;
}
.tc-up { grid-column: 2; grid-row: 1; }
.tc-left { grid-column: 1; grid-row: 2; }
.tc-down { grid-column: 2; grid-row: 2; }
.tc-right { grid-column: 3; grid-row: 2; }

.tc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 440px;
  margin: 0 auto;
}
.tc-group { display: flex; gap: 10px; }

.tc-btn {
  min-width: 56px;
  height: 52px;
  padding: 0 1rem;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--pill-shadow);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.tc-btn.tc-action {
  background: linear-gradient(135deg, #ff6b35 0%, #ff3b5c 100%);
  border-color: transparent;
  color: #fff;
  min-width: 92px;
}
.tc-btn.pressed {
  transform: scale(0.95);
  filter: brightness(1.14);
  border-color: var(--accent);
}

.theater, .stage-viewport { overscroll-behavior: none; }

@media (max-width: 1220px) {
  .theater-shell { grid-template-columns: 1fr 216px; }
  .theater-rail-left { display: none; }
}

@media (max-width: 900px) {
  .theater-shell { grid-template-columns: 1fr; }
  .theater-rail { display: none; }
  .stage-viewport { overflow: hidden; }
  .game-mount { width: 100%; height: 100%; }
  .game-canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
  }
}

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; padding: 0.6rem 0.85rem; gap: 0.55rem; }
  .cat-bar { padding: 0 0.85rem 0.55rem; }
  .portal-main { padding: 0.85rem; }
  .search-box { order: 3; max-width: 100%; width: 100%; }
  .wall-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .game-tile { border-radius: 14px; border-width: 2.5px; }
  .tile-overlay { padding: 1.1rem 0.45rem 0.4rem; }
  .tile-title { font-size: 0.78rem; }
  .tile-meta { font-size: 0.64rem; }
  .theater-bar { padding: 0.5rem 0.7rem; gap: 0.45rem; }
  .theater-title-group { gap: 0.5rem; }
  .theater-title-group h2 { font-size: 0.98rem; }
  .theater-controls-hint, .theater-cat-chip { display: none; }
  .score-chip { padding: 0.25rem 0.55rem; gap: 0.3rem; }
  .score-chip span { font-size: 0.6rem; }
  .score-chip strong { font-size: 0.82rem; }
  .stage-viewport { padding: 0.5rem; }
  .board-shell { padding: 0.75rem; max-width: 100%; }

  .g2048-grid { grid-template-columns: repeat(4, min(72px, 19vw)); grid-template-rows: repeat(4, min(72px, 19vw)); gap: 7px; padding: 7px; }
  .g2048-cell { font-size: 1.25rem; }
  .mine-grid { grid-template-columns: repeat(10, min(30px, 8.2vw)); gap: 3px; }
  .mine-cell { width: min(30px, 8.2vw); height: min(30px, 8.2vw); font-size: 0.72rem; }
  .mem-grid { grid-template-columns: repeat(4, min(72px, 19vw)); gap: 7px; }
  .mem-card { height: min(72px, 19vw); font-size: 1.2rem; }
  .simon-grid { grid-template-columns: repeat(2, min(135px, 39vw)); gap: 10px; }
  .simon-pad { height: min(135px, 39vw); }
  .whack-grid { grid-template-columns: repeat(3, min(92px, 26vw)); gap: 8px; }
  .whack-hole { height: min(92px, 26vw); font-size: 0.95rem; }
  .react-pad { width: min(460px, 92vw); height: 240px; }
  .react-pad h3 { font-size: 1.55rem; }
  .stats-summary { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
  .badges-grid { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .logo { font-size: 1.05rem; }
  .logo-badge { width: 32px; height: 32px; font-size: 1.1rem; }
  .topbar-actions .pill-btn span { display: none; }
  .topbar-actions .pill-btn { padding: 0.45rem 0.6rem; }
  .wall-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .theater-bar { padding: 0.3rem 0.6rem; }
  .theater-controls-hint { display: none; }
  .stage-viewport { padding: 0.35rem; }
  .game-canvas { max-height: calc(100dvh - 115px); }
  .touch-controls { padding: 0.35rem 0.75rem; }
  .tc-btn { height: 42px; min-width: 48px; }
}

@media (max-width: 380px) {
  .theater-bar { gap: 0.35rem; padding: 0.45rem 0.55rem; }
  .theater-bar .pill-btn span { display: none; }
  .icon-btn { width: 32px; height: 32px; }
  .tc-dpad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(2, 46px); }
  .tc-btn { min-width: 48px; height: 46px; padding: 0 0.75rem; font-size: 0.85rem; }
}
