:root {
  --bg: #0b1020;
  --bg2: #121a35;
  --card: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --text: #eaf0ff;
  --muted: #93a0c4;
  --primary: #6c8cff;
  --accent: #37e6a0;
  --danger: #ff5d73;
  --warn: #ffc857;
  --radius: 16px;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 700px at 20% -10%, #1b2653 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ---- animated background blobs ---- */
.bg-blobs span {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  z-index: 0;
  animation: float 18s ease-in-out infinite;
}
.bg-blobs span:nth-child(1) { width: 380px; height: 380px; background: #4a6cff; top: -80px; left: -60px; }
.bg-blobs span:nth-child(2) { width: 320px; height: 320px; background: #23d5ab; bottom: -100px; right: -60px; animation-delay: -6s; }
.bg-blobs span:nth-child(3) { width: 260px; height: 260px; background: #b46cff; top: 45%; left: 55%; animation-delay: -12s; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, -30px) scale(1.12); }
}

.screen { position: relative; z-index: 1; min-height: 100vh; }

/* ================= AUTH ================= */
#auth-screen { display: flex; align-items: center; justify-content: center; padding: 24px; }

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 32px 28px;
  backdrop-filter: blur(18px);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.45);
  animation: pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop { from { transform: translateY(24px) scale(0.96); opacity: 0; } }

.logo { font-size: 2rem; font-weight: 800; text-align: center; margin-bottom: 20px; letter-spacing: -1px; }
.logo.small { font-size: 1.25rem; margin-bottom: 0; }

.tabs { display: flex; gap: 8px; background: rgba(0, 0, 0, 0.25); padding: 6px; border-radius: 12px; margin-bottom: 22px; }
.tab {
  flex: 1; padding: 10px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font-size: 1rem; font-weight: 600; cursor: pointer; transition: 0.2s;
}
.tab.active { background: var(--primary); color: #fff; box-shadow: 0 6px 18px rgba(108, 140, 255, 0.4); }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form label { display: flex; flex-direction: column; gap: 7px; font-weight: 600; font-size: 0.92rem; }
.auth-form label small { color: var(--muted); font-weight: 400; }
.auth-form input {
  padding: 13px 15px; border-radius: 12px; border: 1px solid var(--card-border);
  background: rgba(0, 0, 0, 0.3); color: var(--text); font-size: 1rem; outline: none; transition: 0.2s;
}
.auth-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 140, 255, 0.25); }
.auth-form input.shake { animation: shake 0.35s; border-color: var(--danger); }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-7px)} 75%{transform:translateX(7px)} }

.form-error { color: var(--danger); font-size: 0.88rem; min-height: 1.1em; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: transform 0.15s, box-shadow 0.2s; color: #fff;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, #6c8cff, #4a5fff); box-shadow: 0 8px 22px rgba(74, 95, 255, 0.4); }
.btn.accent { background: linear-gradient(135deg, #37e6a0, #17b97f); box-shadow: 0 8px 22px rgba(23, 185, 127, 0.35); color: #06281c; }
.btn.big { padding: 15px; font-size: 1.05rem; }
.btn:hover { filter: brightness(1.08); }

/* ================= APP SHELL ================= */
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 14px 26px;
  background: rgba(10, 14, 30, 0.75); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-border); position: sticky; top: 0; z-index: 50;
}
.nav { display: flex; gap: 8px; flex: 1; }
.nav-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 9px 16px; border-radius: 10px; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: 0.2s;
}
.nav-btn:hover { background: var(--card); color: var(--text); }
.nav-btn.active { background: rgba(108, 140, 255, 0.18); border-color: var(--primary); color: #fff; }

.account-zone { position: relative; }
.account-pill {
  display: flex; align-items: center; gap: 9px; padding: 7px 14px; cursor: pointer;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 999px; transition: 0.2s; user-select: none;
}
.account-pill:hover { border-color: var(--primary); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid; place-items: center; font-weight: 800; font-size: 0.85rem; color: #08112b;
}
.caret { color: var(--muted); font-size: 0.75rem; }

.account-menu {
  position: absolute; right: 0; top: calc(100% + 10px); width: 270px;
  background: #141b36; border: 1px solid var(--card-border); border-radius: 14px;
  padding: 10px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); animation: pop 0.25s ease; z-index: 60;
}
.menu-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 6px 8px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px; border: 0; background: transparent; color: var(--text);
  border-radius: 9px; cursor: pointer; font-size: 0.95rem; transition: 0.15s;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.08); }
.menu-item.current { background: rgba(108, 140, 255, 0.2); font-weight: 700; }
.menu-item.add { color: var(--accent); border-top: 1px solid var(--card-border); border-radius: 0 0 9px 9px; margin-top: 6px; }
.menu-item.danger { color: var(--danger); }
.menu-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }

.content { max-width: 1050px; margin: 0 auto; padding: 34px 24px 80px; position: relative; }
.page { animation: fadein 0.35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(14px); } }
h1 { font-size: 2rem; margin-bottom: 6px; letter-spacing: -0.5px; }
.sub { color: var(--muted); margin-bottom: 26px; }

/* ================= GAMES ================= */
.games-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.game-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 24px 20px; border-radius: var(--radius); border: 1px solid var(--card-border);
  cursor: pointer; text-align: left; color: var(--text); position: relative; overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.game-card::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(255,255,255,0.14), transparent 55%);
  pointer-events: none;
}
.game-card:hover { transform: translateY(-6px); box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45); }
.g1 { background: linear-gradient(150deg, #3a2f8f, #191d4d); }
.g2 { background: linear-gradient(150deg, #0f5f4d, #10233f); }
.g3 { background: linear-gradient(150deg, #7a2f4f, #1c1737); }
.g4 { background: linear-gradient(150deg, #0e4f66, #14213f); }
.g5 { background: linear-gradient(150deg, #6b4a10, #1d1a3a); }
.g6 { background: linear-gradient(150deg, #3f1c5e, #131a34); }
.game-card.g4, .game-card.g5, .game-card.g6 { color: #eaf0ff; }
.game-card.g4 .game-desc, .game-card.g5 .game-desc, .game-card.g6 .game-desc { color: rgba(255, 255, 255, 0.78); }

/* ---- canvas game shells ---- */
.game-stage { position: relative; width: 100%; display: flex; justify-content: center; }
.game-stage canvas {
  border-radius: 14px; border: 1px solid var(--card-border);
  background: #0d1330; max-width: 100%; touch-action: none;
}
.chess-wrap { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; align-items: flex-start; }
.chess-board {
  display: grid; grid-template-columns: repeat(8, 46px); grid-template-rows: repeat(8, 46px);
  border: 3px solid #2a3566; border-radius: 8px; overflow: hidden; user-select: none;
}
.chess-cell {
  width: 46px; height: 46px; display: grid; place-items: center; font-size: 30px;
  cursor: pointer; position: relative; line-height: 1;
}
.chess-cell.light { background: #f0d9b5; }
.chess-cell.dark { background: #b58863; }
.chess-cell.sel { background: #7dc85a !important; }
.chess-cell.hl { box-shadow: inset 0 0 0 4px rgba(55, 230, 160, 0.85); }
.chess-cell.hl-capture { box-shadow: inset 0 0 0 4px rgba(255, 93, 115, 0.9); }
.chess-cell.last-move::after {
  content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px rgba(108, 140, 255, 0.8);
  pointer-events: none;
}
.chess-cell.hint-move::before {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: rgba(20, 30, 60, 0.35); pointer-events: none;
}
.chess-side { min-width: 220px; display: flex; flex-direction: column; gap: 12px; }
.chess-status {
  background: var(--card); border: 1px solid var(--card-border); border-radius: 12px;
  padding: 13px 16px; font-weight: 700;
}
.chess-status.thinking::after { content: "…"; animation: dots 1s infinite; }
@keyframes dots { 0% { content: ""; } 33% { content: "."; } 66% { content: ".."; } 100% { content: "..."; } }
.diff-row { display: flex; gap: 6px; flex-wrap: wrap; }
.diff-btn {
  border: 1px solid var(--card-border); background: var(--card); color: var(--text);
  padding: 7px 11px; border-radius: 9px; cursor: pointer; font-weight: 700; font-size: 0.85rem; transition: 0.15s;
}
.diff-btn:hover { border-color: var(--primary); }
.diff-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.captured { min-height: 30px; font-size: 21px; letter-spacing: 2px; }
.pong-hint { text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.flappy-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px;
  align-items: center; justify-content: center; background: rgba(6, 10, 25, 0.68);
  border-radius: 14px; font-weight: 700; text-align: center; pointer-events: none;
}
.flappy-overlay .big { font-size: 1.5rem; }
.flappy-overlay button { pointer-events: auto; }
.game-emoji { font-size: 2.6rem; }
.game-name { font-size: 1.2rem; font-weight: 800; }
.game-desc { color: rgba(255, 255, 255, 0.72); font-size: 0.9rem; }

/* ================= HISTORY ================= */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 12px;
  animation: fadein 0.3s ease;
}
.history-icon { font-size: 1.3rem; width: 34px; text-align: center; }
.history-text { flex: 1; font-size: 0.97rem; }
.history-time { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.empty-state { text-align: center; color: var(--muted); padding: 50px 0; font-size: 1.05rem; }
.empty, .loading { text-align: center; color: var(--muted); padding: 34px 0; }

.hist-row {
  display: flex; gap: 14px; align-items: flex-start; padding: 13px 17px;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 12px;
  animation: fadein 0.3s ease;
}
.hist-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); margin-top: 6px; flex-shrink: 0; box-shadow: 0 0 10px var(--primary); }
.hist-body { flex: 1; }
.hist-text { font-size: 0.97rem; }
.hist-time { color: var(--muted); font-size: 0.8rem; margin-top: 3px; }

.mini-avatar {
  width: 24px; height: 24px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid; place-items: center; font-weight: 800; font-size: 0.78rem; color: #08112b;
}
.dot-cur { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: auto; box-shadow: 0 0 8px var(--accent); }
.menu-item.muted { color: var(--muted); cursor: default; font-size: 0.88rem; }

/* ================= ADMIN ================= */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 20px; text-align: center;
}
.stat-num { font-size: 2.2rem; font-weight: 800; color: var(--accent); }
.stat-label { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--card-border); border-radius: var(--radius); }
.users-table { width: 100%; border-collapse: collapse; background: rgba(0, 0, 0, 0.2); }
.users-table th, .users-table td { padding: 13px 16px; text-align: left; font-size: 0.93rem; }
.users-table th { background: rgba(255, 255, 255, 0.06); color: var(--muted); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 1px; }
.users-table tr { border-top: 1px solid rgba(255, 255, 255, 0.06); }
.users-table tbody tr:hover { background: rgba(255, 255, 255, 0.04); }
.users-table tr.row-blocked { background: rgba(255, 93, 115, 0.07); }
.users-table tr.row-blocked .cell-login { color: var(--danger); }
.cell-login { font-weight: 700; }
.cell-date { color: var(--muted); font-size: 0.84rem !important; }
.cell-actions { white-space: nowrap; }

.badge { padding: 4px 11px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.badge-admin { background: rgba(255, 200, 87, 0.18); color: var(--warn); border: 1px solid rgba(255, 200, 87, 0.4); }
.badge-block { background: rgba(255, 93, 115, 0.16); color: var(--danger); border: 1px solid rgba(255, 93, 115, 0.4); }
.badge-ok { background: rgba(55, 230, 160, 0.14); color: var(--accent); border: 1px solid rgba(55, 230, 160, 0.4); }
.badge.admin { background: rgba(255, 200, 87, 0.18); color: var(--warn); border: 1px solid rgba(255, 200, 87, 0.4); }
.badge.user { background: rgba(108, 140, 255, 0.15); color: var(--primary); border: 1px solid rgba(108, 140, 255, 0.4); }
.badge.blocked { background: rgba(255, 93, 115, 0.16); color: var(--danger); border: 1px solid rgba(255, 93, 115, 0.4); }
.badge.active { background: rgba(55, 230, 160, 0.14); color: var(--accent); border: 1px solid rgba(55, 230, 160, 0.4); }

.tbtn {
  border: 1px solid var(--card-border); background: var(--card); color: var(--text);
  padding: 7px 12px; border-radius: 9px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
  margin-right: 6px; transition: 0.15s;
}
.tbtn:hover { border-color: var(--primary); }
.tbtn.block { color: var(--danger); }
.tbtn.unblock { color: var(--accent); }
.tbtn.promote { color: var(--warn); }

/* ================= MODAL ================= */
.modal {
  position: fixed; inset: 0; background: rgba(4, 7, 18, 0.75); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-card {
  width: 100%; max-width: 560px; background: #131a34; border: 1px solid var(--card-border);
  border-radius: 20px; overflow: hidden; animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center; padding: 16px 20px;
  background: rgba(255, 255, 255, 0.05); font-weight: 800; font-size: 1.1rem;
}
.close-btn { border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.close-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.modal-body { padding: 22px 20px; }

/* Reaction */
.reaction-zone {
  height: 240px; border-radius: 14px; background: #0d1330; border: 1px dashed var(--card-border);
  display: grid; place-items: center; cursor: pointer; text-align: center; user-select: none; position: relative; overflow: hidden;
  transition: background 0.15s;
}
.reaction-zone.ready { background: #13402f; border-color: var(--accent); }
.reaction-zone.tooearly { background: #4a1420; border-color: var(--danger); }
.reaction-target { position: absolute; width: 74px; height: 74px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-size: 1.9rem; box-shadow: 0 0 30px rgba(55, 230, 160, 0.7); animation: pop 0.3s; }
.game-stat { text-align: center; font-size: 1.35rem; font-weight: 800; margin-top: 14px; }
.game-hint { text-align: center; color: var(--muted); margin-top: 8px; font-size: 0.9rem; }

/* Memory */
.memory-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 6px; }
.mem-card {
  aspect-ratio: 1; border-radius: 12px; background: linear-gradient(150deg, #2a3566, #1a2145);
  border: 1px solid var(--card-border); cursor: pointer; display: grid; place-items: center;
  font-size: 1.9rem; transition: transform 0.25s, background 0.25s; color: transparent;
}
.mem-card.flipped { background: linear-gradient(150deg, #6c8cff, #4a5fff); color: #fff; transform: rotateY(180deg); }
.mem-card.matched { background: linear-gradient(150deg, #37e6a0, #17b97f); color: #06281c; border-color: var(--accent); cursor: default; }

/* Minesweeper */
.mines-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; margin-top: 6px; }
.mine-cell {
  aspect-ratio: 1; border: 0; border-radius: 7px; background: #2a3566; color: transparent;
  font-weight: 800; font-size: 0.95rem; cursor: pointer; transition: 0.12s; display: grid; place-items: center;
}
.mine-cell:hover { background: #3a478a; }
.mine-cell.open { background: #131a34; color: var(--text); cursor: default; }
.mine-cell.boom { background: var(--danger); color: #fff; }
.mine-cell[data-n="1"] { color: #6c8cff; }
.mine-cell[data-n="2"] { color: #37e6a0; }
.mine-cell[data-n="3"] { color: #ff8b5d; }
.mine-cell[data-n="4"] { color: #b46cff; }
.mine-cell[data-n="5"], .mine-cell[data-n="6"], .mine-cell[data-n="7"] { color: #ffc857; }

.game-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

/* ---- 2048 board ---- */
.game-hud { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 700; }
.board {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  background: #0d1330; padding: 10px; border-radius: 14px; border: 1px solid var(--card-border);
}
.tile {
  aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center;
  font-weight: 800; font-size: 1.5rem; background: #1a2145; color: var(--muted);
  transition: background 0.15s, transform 0.15s;
}
.tile.t2 { background: #e9eefc; color: #3a4577; }
.tile.t4 { background: #dbe4ff; color: #3a4577; }
.tile.t8 { background: #ffd9a8; color: #6b4415; }
.tile.t16 { background: #ffbe7a; color: #6b3a08; }
.tile.t32 { background: #ff9f68; color: #5c2404; }
.tile.t64 { background: #ff7f54; color: #fff; }
.tile.t128 { background: #6c8cff; color: #fff; font-size: 1.3rem; }
.tile.t256 { background: #5a7bff; color: #fff; font-size: 1.3rem; }
.tile.t512 { background: #4a5fff; color: #fff; font-size: 1.3rem; }
.tile.t1024, .tile.t2048 { background: linear-gradient(150deg, #37e6a0, #17b97f); color: #05281b; font-size: 1.15rem; }
.game-over {
  margin-top: 14px; text-align: center; font-weight: 800; font-size: 1.1rem;
  color: var(--warn); display: flex; gap: 12px; justify-content: center; align-items: center;
}
.board.mem { grid-template-columns: repeat(4, 1fr); background: transparent; border: 0; padding: 0; }

/* ---- memory cards ---- */
.mem-card { position: relative; transform-style: preserve-3d; }
.mem-front, .mem-back {
  position: absolute; inset: 0; display: grid; place-items: center;
  border-radius: 12px; backface-visibility: hidden; font-size: 1.9rem;
}
.mem-back { background: linear-gradient(150deg, #2a3566, #1a2145); color: var(--primary); font-weight: 800; border: 1px solid var(--card-border); }
.mem-front { background: linear-gradient(150deg, #6c8cff, #4a5fff); color: #fff; transform: rotateY(180deg); }
.mem-card.open .mem-front, .mem-card.done .mem-front { transform: rotateY(0deg); }
.mem-card.open .mem-back, .mem-card.done .mem-back { transform: rotateY(180deg); }
.mem-card.done .mem-front { background: linear-gradient(150deg, #37e6a0, #17b97f); color: #05281b; }
.mem-card.done { cursor: default; }

/* ---- mini button ---- */
.btn-mini {
  border: 1px solid var(--card-border); background: var(--card); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 0.82rem; font-weight: 700; transition: 0.15s;
}
.btn-mini:hover { border-color: var(--primary); background: rgba(255,255,255,0.1); }
.btn-mini.red { color: var(--danger); border-color: rgba(255,93,115,0.4); }
.btn-mini.green { color: var(--accent); border-color: rgba(55,230,160,0.4); }
.btn-mini.purple { color: var(--warn); border-color: rgba(255,200,87,0.4); }
.btn-mini.gray { color: var(--muted); }

/* ================= TOAST ================= */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 90px);
  background: #1c2547; border: 1px solid var(--primary); color: var(--text);
  padding: 13px 22px; border-radius: 12px; font-weight: 600; z-index: 200;
  opacity: 0; transition: 0.3s cubic-bezier(0.2, 1.2, 0.4, 1); box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.ok { border-color: var(--accent); }
.toast.err { border-color: var(--danger); }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .memory-grid { grid-template-columns: repeat(4, 1fr); }
}
