/* ==========================================================================
   EveHost Games — Friv-Style Instant Browser Games Portal
   ========================================================================== */

:root {
  --bg: #11131a;
  --bg-top: #171a24;
  --surface: #1e2230;
  --surface-hover: #262b3d;
  --border: #2c3246;
  --text: #f3f5fa;
  --text-muted: #98a2bc;
  --accent: #ff5a36;
  --accent-hover: #ff7152;
  --accent-ink: #ffffff;
  --gold: #f5b700;
  --danger: #ef4444;
  --tile-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  --font-display: 'Fredoka', 'Inter', sans-serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

body.theme-light {
  --bg: #e9eef6;
  --bg-top: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f3f6fb;
  --border: #d5deec;
  --text: #151926;
  --text-muted: #5c6680;
  --tile-shadow: 0 6px 16px rgba(21, 25, 38, 0.12);
}

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

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

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

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-top);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

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

.logo-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 3px 0 #b83216;
}

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

.search-box {
  flex: 1;
  max-width: 440px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 0.42rem 0.75rem;
  transition: border-color 0.15s;
}
.search-box:focus-within { border-color: var(--accent); }
.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;
  min-width: 0;
}
.search-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  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.4rem;
  padding: 0.48rem 0.85rem;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.pill-btn:hover { background: var(--surface-hover); border-color: var(--text-muted); }
.pill-btn:active { transform: translateY(1px); }

.pill-btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.pill-btn.accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.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: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-hover); border-color: var(--text-muted); }
.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: 1480px;
  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.36rem 0.85rem;
  border-radius: 8px;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.83rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.cat-pill:hover { background: var(--surface); color: var(--text); }
.cat-pill.active {
  background: var(--text);
  color: var(--bg);
}

/* Friv-Style Tile Wall */
.portal-main {
  max-width: 1480px;
  margin: 0 auto;
  padding: 1.25rem;
  min-height: calc(100vh - 150px);
}

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

.game-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  overflow: hidden;
  border: 2.5px solid transparent;
  background: var(--surface);
  box-shadow: var(--tile-shadow);
  cursor: pointer;
  padding: 0;
  text-align: left;
  transition: transform 0.16s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.16s, box-shadow 0.16s;
}

/* Featured larger Friv/Poki tiles on wide screens */
@media (min-width: 900px) {
  .game-tile.featured {
    grid-column: span 2;
    grid-row: span 2;
  }
}

.game-tile:hover {
  transform: scale(1.045) translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45);
  z-index: 4;
}

.game-tile:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.tile-art {
  width: 100%;
  height: 100%;
  display: block;
}
.tile-art svg {
  width: 100%;
  height: 100%;
  display: block;
}

.tile-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.6rem 0.65rem 0.55rem;
  background: linear-gradient(180deg, transparent 0%, rgba(10, 12, 18, 0.92) 85%);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  transition: opacity 0.15s;
}

.tile-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.15;
}
.game-tile.featured .tile-title { font-size: 1.25rem; }

.tile-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #c7d0e6;
}

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

.tile-fav-mark {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(15, 18, 28, 0.78);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}
.empty-state p { margin: 0 0 1rem; font-size: 1.05rem; }

.portal-footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* Game Theater Overlay */
.theater {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: none;
}
.theater.open { display: flex; }

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

.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: 1rem;
  padding: 0.65rem 1rem;
  background: var(--bg-top);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.theater-title-group {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.theater-title-group h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.1;
}
.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.32rem 0.7rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
}
.score-chip span { font-size: 0.68rem; 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: radial-gradient(circle at center, rgba(255, 255, 255, 0.03), transparent 70%);
}

.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: 12px;
  border: 2px solid var(--border);
  background: #0d1017;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  max-width: 100%;
  max-height: calc(100vh - 120px);
  touch-action: none;
}

/* Theater Right Rail */
.theater-rail {
  border-left: 1px solid var(--border);
  background: var(--bg-top);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rail-head {
  padding: 0.8rem 0.9rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.rail-grid {
  padding: 0.75rem;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rail-grid .game-tile {
  border-radius: 10px;
}
.rail-grid .tile-title { font-size: 0.74rem; }
.rail-grid .tile-meta { display: none; }
.rail-grid .tile-overlay { padding: 1rem 0.4rem 0.35rem; }

/* Interactive DOM Games (2048, Minesweeper, Memory, Simon, Whack, Reaction) */
.board-shell {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  user-select: none;
}

.board-status {
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  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: #141722;
  padding: 10px;
  border-radius: 10px;
}
.g2048-cell {
  border-radius: 8px;
  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 var(--border);
  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: #141824; border-color: #202638; cursor: default; }
.mine-cell.flagged { background: #4a2323; color: #ff6b6b; }
.mine-cell.bomb { background: #dc2626; color: #fff; }

/* Memory Flip */
.mem-grid {
  display: grid;
  grid-template-columns: repeat(4, 78px);
  gap: 10px;
}
.mem-card {
  height: 78px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #252b3f;
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}
.mem-card.open, .mem-card.matched { background: #161b29; 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 var(--border);
  background: #141824;
  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: 16px;
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  padding: 1.5rem;
  transition: background 0.12s;
}
.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.85); }

/* Scores Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(0, 0, 0, 0.72);
  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(--bg-top);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.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.15rem; }
.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);
  border: 1px solid var(--border);
  border-radius: 10px;
  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);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
}
.score-row strong { font-family: var(--font-mono); color: var(--gold); }
.modal-foot { display: flex; justify-content: flex-end; }

/* Responsive */
@media (max-width: 900px) {
  .theater-shell { grid-template-columns: 1fr; }
  .theater-rail { display: none; }
}

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; }
  .search-box { order: 3; max-width: 100%; width: 100%; }
  .wall-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
  .g2048-grid { grid-template-columns: repeat(4, 64px); grid-template-rows: repeat(4, 64px); }
  .mine-grid { grid-template-columns: repeat(10, 29px); }
  .mine-cell { width: 29px; height: 29px; font-size: 0.75rem; }
  .mem-grid { grid-template-columns: repeat(4, 64px); }
  .mem-card { height: 64px; }
  .whack-grid { grid-template-columns: repeat(3, 84px); }
  .whack-hole { height: 84px; }
}
