/* ============================================================================
 * games.css — "Oyun Merkezi" arcade for Shadow Chat.
 * Theme-aware (uses the same CSS custom properties as app.css) and fully
 * responsive: every board sizes to the available space so phones and desktops
 * get the same layout with no horizontal scroll. Self-contained — no rule here
 * touches the chat UI.
 * ========================================================================== */

/* --- Sidebar launcher (the entry point, injected by games.js) ------------- */
.games-launcher {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 12px 4px; padding: 12px 14px;
  border: none; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-contrast); font-weight: 700; font-size: 15px;
  cursor: pointer; width: calc(100% - 24px);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.games-launcher:hover { transform: translateY(-1px); filter: brightness(1.05); }
.games-launcher:active { transform: translateY(0) scale(.99); }
.games-launcher .gl-emoji { font-size: 20px; line-height: 1; }
.games-launcher .gl-sub { display: block; font-size: 11px; font-weight: 500; opacity: .85; margin-top: 1px; }

/* --- Full-screen overlay --------------------------------------------------- */
.games-overlay {
  position: fixed; inset: 0; z-index: 150;
  display: flex; flex-direction: column;
  background: var(--bg-primary);
  /* respect notches */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.games-overlay[hidden] { display: none; }

.games-topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.games-topbar .gt-btn {
  background: transparent; color: var(--text-secondary);
  border: 1px solid transparent; font-size: 20px; line-height: 1;
  padding: 6px 10px; border-radius: 10px; cursor: pointer; min-width: 40px;
}
.games-topbar .gt-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.games-title { font-weight: 800; font-size: 16px; color: var(--text-primary); flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.games-status { font-size: 13px; color: var(--text-secondary); white-space: nowrap;
  background: var(--bg-elevated); padding: 5px 11px; border-radius: 999px; }

.games-body { flex: 1; min-height: 0; min-width: 0; overflow-y: auto; }
.games-body.playing { overflow: hidden; display: flex; flex-direction: column; }

/* --- Hub grid -------------------------------------------------------------- */
.games-hub { padding: 18px 16px 28px; }
.games-hub-head { text-align: center; margin-bottom: 18px; }
.games-hub-head h1 { font-size: 22px; margin: 0 0 4px; color: var(--text-primary); }
.games-hub-head p { margin: 0; color: var(--text-muted); font-size: 13px; }
.games-grid {
  display: grid; gap: 14px; max-width: 760px; margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.game-card {
  position: relative; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-surface); padding: 16px 14px; cursor: pointer; text-align: center;
  transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease;
  overflow: hidden;
}
.game-card:hover { transform: translateY(-3px); border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(0,0,0,.25); }
.game-card:active { transform: translateY(-1px) scale(.99); }
.game-card .gc-emoji {
  width: 58px; height: 58px; margin: 0 auto 10px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  box-shadow: 0 6px 16px rgba(0,0,0,.22);
}
.game-card .gc-name { font-weight: 700; color: var(--text-primary); font-size: 14px; }
.game-card .gc-best { display: block; margin-top: 3px; font-size: 11px; color: var(--text-muted); }
.game-card .gc-best b { color: var(--accent); }

/* --- Generic game stage ---------------------------------------------------- */
.game-stage {
  flex: 1; min-height: 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 14px; text-align: center;
}
.game-stage canvas { touch-action: none; border-radius: var(--radius); background: var(--bg-secondary);
  box-shadow: 0 8px 28px rgba(0,0,0,.28); }
.game-hint { color: var(--text-muted); font-size: 12.5px; max-width: 420px; }
.game-btn {
  border: none; border-radius: 999px; padding: 11px 22px; font-weight: 700; font-size: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-contrast);
  cursor: pointer; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 32%, transparent);
}
.game-btn.ghost { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); box-shadow: none; }
.game-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Game-over / message banner over the stage */
.game-over {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center;
  background: color-mix(in srgb, var(--bg-primary) 78%, transparent);
  backdrop-filter: blur(3px); border-radius: var(--radius); z-index: 5; padding: 20px;
}
.game-over h2 { margin: 0; font-size: 26px; color: var(--text-primary); }
.game-over p { margin: 0; color: var(--text-secondary); }
.game-board-wrap { position: relative; }

/* --- 2048 ------------------------------------------------------------------ */
.g2048-grid {
  position: relative; background: var(--bg-elevated); border-radius: 12px; padding: 10px;
  display: grid; gap: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.28);
}
.g2048-cell { background: color-mix(in srgb, var(--text-muted) 16%, transparent); border-radius: 8px; }
.g2048-tile {
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; font-weight: 800; color: #fff;
  animation: g2048pop .14s ease;
}
@keyframes g2048pop { from { transform: scale(.6); } to { transform: scale(1); } }

/* --- Memory match ---------------------------------------------------------- */
.mem-grid { display: grid; gap: 8px; perspective: 800px; }
.mem-card {
  position: relative; border-radius: 12px; cursor: pointer;
  transition: transform .35s; transform-style: preserve-3d; aspect-ratio: 1;
}
.mem-card.flipped { transform: rotateY(180deg); }
.mem-card.matched { transform: rotateY(180deg); opacity: .55; cursor: default; }
.mem-face {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  border-radius: 12px; backface-visibility: hidden; font-size: clamp(20px, 7vw, 38px);
}
.mem-back { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-contrast); font-size: 24px; }
.mem-front { background: var(--bg-elevated); transform: rotateY(180deg); border: 1px solid var(--border); }

/* --- Snake / Flappy use canvas; nothing extra needed ----------------------- */

/* --- Tic-tac-toe ----------------------------------------------------------- */
.ttt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ttt-cell {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px;
  font-size: clamp(34px, 13vw, 64px); font-weight: 800; cursor: pointer; aspect-ratio: 1;
  transition: background .12s ease;
}
.ttt-cell:hover { background: color-mix(in srgb, var(--accent) 14%, var(--bg-elevated)); }
.ttt-cell.x { color: var(--accent); }
.ttt-cell.o { color: var(--danger); }
.ttt-cell.win { background: color-mix(in srgb, var(--accent) 30%, var(--bg-elevated)); }

/* --- Simon ----------------------------------------------------------------- */
.simon-pad { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-radius: 50%; }
.simon-btn { border: none; cursor: pointer; transition: filter .1s ease, transform .1s ease; opacity: .7; }
.simon-btn.lit { opacity: 1; filter: brightness(1.6); transform: scale(1.02); }
.simon-btn:nth-child(1) { border-top-left-radius: 100%; background: #36c46a; }
.simon-btn:nth-child(2) { border-top-right-radius: 100%; background: #e34b5b; }
.simon-btn:nth-child(3) { border-bottom-left-radius: 100%; background: #f4c443; }
.simon-btn:nth-child(4) { border-bottom-right-radius: 100%; background: #3a8ffe; }

/* --- Whack-a-mole ---------------------------------------------------------- */
.whack-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.whack-hole {
  position: relative; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 50% 120%, color-mix(in srgb, var(--text-muted) 30%, var(--bg-elevated)), var(--bg-secondary));
  overflow: hidden; cursor: pointer; border: 1px solid var(--border);
}
.whack-mole {
  position: absolute; left: 8%; right: 8%; bottom: -100%; top: auto; height: 84%;
  display: flex; align-items: center; justify-content: center; font-size: clamp(26px, 9vw, 48px);
  transition: bottom .12s ease; border-radius: 50% 50% 42% 42%;
}
.whack-mole.up { bottom: 6%; }

/* --- Minesweeper ----------------------------------------------------------- */
.mine-grid { display: grid; gap: 3px; background: var(--border); padding: 3px; border-radius: 10px; }
.mine-cell {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elevated); border-radius: 4px; cursor: pointer;
  font-weight: 800; user-select: none; aspect-ratio: 1; font-size: clamp(11px, 3.4vw, 18px);
}
.mine-cell.open { background: var(--bg-secondary); cursor: default; }
.mine-cell.flag { background: color-mix(in srgb, var(--accent) 22%, var(--bg-elevated)); }
.mine-cell.boom { background: var(--danger); }
.mine-cell[data-n="1"] { color: #4c9bff; } .mine-cell[data-n="2"] { color: #36c46a; }
.mine-cell[data-n="3"] { color: #e34b5b; } .mine-cell[data-n="4"] { color: #8b7bff; }
.mine-cell[data-n="5"] { color: #f4900c; } .mine-cell[data-n="6"] { color: #19d089; }
.mine-cell[data-n="7"] { color: var(--text-primary); } .mine-cell[data-n="8"] { color: var(--text-muted); }
.mine-toolbar { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.mine-flagtoggle { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text-primary); cursor: pointer; font-weight: 600; }
.mine-flagtoggle.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-contrast); border-color: transparent; }

/* --- On-screen D-pad (snake/2048 on touch) -------------------------------- */
.dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px);
  gap: 6px; justify-content: center; }
.dpad button { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text-primary); font-size: 20px; cursor: pointer; }
.dpad button:active { background: var(--accent); color: var(--accent-contrast); }
.dpad .du { grid-area: 1 / 2; } .dpad .dl { grid-area: 2 / 1; }
.dpad .dr { grid-area: 2 / 3; } .dpad .dd { grid-area: 3 / 2; }

@media (max-width: 720px) {
  .games-hub { padding: 14px 12px 24px; }
  .games-grid { gap: 11px; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
  .game-card .gc-emoji { width: 50px; height: 50px; font-size: 26px; }
}

/* ============================================================================
 * MULTIPLAYER — lobby, invites, and the two-player game boards.
 * ========================================================================== */
.games-section { font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted); margin: 22px auto 10px; max-width: 760px; }
.games-section-sub { margin: -6px auto 12px; max-width: 760px; color: var(--text-muted); font-size: 12.5px; }

/* Incoming-invite prompt (sits above the overlay, like an incoming call) */
.mp-invite { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg-primary) 70%, transparent); backdrop-filter: blur(4px); padding: 20px; }
.mp-invite-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; max-width: 340px; width: 100%; box-shadow: 0 18px 50px rgba(0,0,0,.4);
  animation: g2048pop .18s ease; }
.mp-invite-emoji { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 12px; display: flex;
  align-items: center; justify-content: center; font-size: 32px; background: var(--bg-elevated); box-shadow: 0 6px 16px rgba(0,0,0,.25); }
.mp-invite-title { font-size: 18px; color: var(--text-primary); }
.mp-invite-sub { color: var(--text-secondary); font-size: 13px; margin: 4px 0 16px; }

.mp-toast { position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 320;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-primary);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.3);
  transition: opacity .3s ease, transform .3s ease; }
.mp-toast.hide { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* Lobby (friend picker + waiting) */
.mp-lobby { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px 16px; max-width: 460px; margin: 0 auto; width: 100%; }
.mp-lobby-title { font-size: 18px; color: var(--text-primary); margin: 0; text-align: center; }
.mp-friends { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.mp-friend { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-surface); cursor: pointer; text-align: left; width: 100%; }
.mp-friend:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg-surface)); }
.mp-friend-av { width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto; display: flex; align-items: center;
  justify-content: center; font-weight: 800; color: var(--accent-contrast); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.mp-friend-name { display: flex; flex-direction: column; gap: 2px; font-weight: 600; color: var(--text-primary); }
.mp-pres { font-size: 11px; color: var(--text-muted); font-weight: 500; display: inline-flex; align-items: center; gap: 5px; }
.mp-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); display: inline-block; }
.mp-dot.on { background: #36c46a; box-shadow: 0 0 6px #36c46a; }
.mp-spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--border);
  border-top-color: var(--accent); animation: mpspin 1s linear infinite; }
@keyframes mpspin { to { transform: rotate(360deg); } }

/* Shared status strip */
.mp-status { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.mp-turn { font-size: 15px; color: var(--text-secondary); font-weight: 600; }
.mp-turn.me { color: var(--accent); }
.mp-result { font-size: 22px; font-weight: 800; color: var(--text-primary); }
.mp-score { font-size: 14px; color: var(--text-muted); font-weight: 600; }

/* Connect Four */
.c4-grid { display: grid; gap: 2.2%; background: linear-gradient(160deg, #2b5bd6, #1d3f9e); padding: 3%; border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,.3); }
.c4-cell { aspect-ratio: 1; border-radius: 50%; background: var(--bg-primary); display: flex; align-items: center;
  justify-content: center; box-shadow: inset 0 3px 6px rgba(0,0,0,.45); cursor: pointer; }
.c4-disc { width: 84%; height: 84%; border-radius: 50%; }
.c4-disc.p1 { background: radial-gradient(circle at 35% 30%, #ff8a96, #e23b4e); box-shadow: inset 0 -3px 6px rgba(0,0,0,.3); }
.c4-disc.p2 { background: radial-gradient(circle at 35% 30%, #ffe27a, #f2b01e); box-shadow: inset 0 -3px 6px rgba(0,0,0,.3); }
.c4-disc.drop { animation: c4drop .25s cubic-bezier(.3,1.4,.6,1); }
@keyframes c4drop { from { transform: translateY(-260%); } to { transform: translateY(0); } }

/* Rock-Paper-Scissors */
.rps-wrap { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.rps-picks { display: flex; gap: 14px; }
.rps-btn { font-size: clamp(36px, 12vw, 56px); width: clamp(76px, 24vw, 110px); height: clamp(76px, 24vw, 110px);
  border-radius: 20px; border: 1px solid var(--border); background: var(--bg-elevated); cursor: pointer;
  transition: transform .1s ease, border-color .1s ease; }
.rps-btn:hover { transform: translateY(-3px); border-color: var(--accent); }
.rps-big { font-size: clamp(48px, 16vw, 84px); }
.rps-reveal { display: flex; align-items: center; gap: 18px; }
.rps-vs { font-size: 28px; color: var(--text-muted); }

/* Blackjack */
.bj-table { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 540px; margin: 0 auto;
  background: linear-gradient(160deg, #157a43, #0c5230); border-radius: 16px; padding: 16px; box-shadow: 0 8px 28px rgba(0,0,0,.3); }
.bj-seat { background: rgba(0,0,0,.18); border-radius: 12px; padding: 10px 12px; }
.bj-seat.active { box-shadow: inset 0 0 0 2px #f4c443; }
.bj-label { color: #eafff1; font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.bj-hand { display: flex; gap: 6px; flex-wrap: wrap; min-height: 56px; }
.bj-card { width: 40px; height: 56px; border-radius: 7px; background: #fff; color: #15171c; display: flex;
  flex-direction: column; align-items: center; justify-content: center; font-weight: 800; font-size: 15px;
  box-shadow: 0 2px 6px rgba(0,0,0,.3); animation: g2048pop .15s ease; }
.bj-card.red { color: #e23b4e; }
.bj-card.back { background: repeating-linear-gradient(45deg, #4c6ef5, #4c6ef5 5px, #3b5bdb 5px, #3b5bdb 10px); }
.bj-chips { color: #cdebd9; font-size: 12px; margin-top: 6px; }
.bj-bet { width: min(80vw, 320px); }

/* Roulette */
.rl-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.rl-wheel { width: clamp(150px, 46vw, 220px); height: clamp(150px, 46vw, 220px); border-radius: 50%;
  background: conic-gradient(#1a1a1a 0 10deg, #b0202f 10deg 20deg, #1a1a1a 20deg 30deg, #b0202f 30deg 40deg,
    #1a1a1a 40deg 50deg, #b0202f 50deg 60deg, #1a1a1a 60deg 70deg, #b0202f 70deg 80deg, #1a1a1a 80deg 90deg,
    #b0202f 90deg 100deg, #1a1a1a 100deg 110deg, #b0202f 110deg 120deg, #1a1a1a 120deg 130deg, #b0202f 130deg 140deg,
    #1a1a1a 140deg 150deg, #b0202f 150deg 160deg, #1a1a1a 160deg 170deg, #b0202f 170deg 180deg, #1a1a1a 180deg 190deg,
    #b0202f 190deg 200deg, #1a1a1a 200deg 210deg, #b0202f 210deg 220deg, #1a1a1a 220deg 230deg, #b0202f 230deg 240deg,
    #1a1a1a 240deg 250deg, #b0202f 250deg 260deg, #1a1a1a 260deg 270deg, #b0202f 270deg 280deg, #1a1a1a 280deg 290deg,
    #b0202f 290deg 300deg, #1a1a1a 300deg 310deg, #b0202f 310deg 320deg, #1a1a1a 320deg 330deg, #b0202f 330deg 340deg,
    #1a1a1a 340deg 350deg, #16a34a 350deg 360deg);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 28px rgba(0,0,0,.4), inset 0 0 0 6px #d4af37; }
.rl-wheel.spin { animation: rlspin 2.6s cubic-bezier(.2,.7,.2,1); }
@keyframes rlspin { from { transform: rotate(0); } to { transform: rotate(1440deg); } }
.rl-center { width: 46%; height: 46%; border-radius: 50%; background: var(--bg-surface); display: flex;
  align-items: center; justify-content: center; font-size: clamp(24px, 8vw, 40px); font-weight: 800; color: var(--text-primary); }
.rl-center.red { color: #fff; background: #b0202f; } .rl-center.black { color: #fff; background: #1a1a1a; }
.rl-center.green { color: #fff; background: #16a34a; }
.rl-chips { color: var(--text-secondary); font-size: 13px; font-weight: 600; }
.rl-types { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 380px; }
.rl-type { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text-primary); cursor: pointer; font-weight: 600; font-size: 13px; }
.rl-type.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-contrast); border-color: transparent; }
.rl-num { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); align-items: center; }
.rl-num input { width: 90px; text-align: center; }

/* Chess */
.chess-board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 8px; overflow: hidden; box-shadow: 0 8px 28px rgba(0,0,0,.32); border: 3px solid #5b3d22; }
.chess-sq { display: flex; align-items: center; justify-content: center; position: relative; cursor: pointer; }
.chess-sq.light { background: #e9d4b0; } .chess-sq.dark { background: #9c6f43; }
.chess-sq.last { box-shadow: inset 0 0 0 100px rgba(244,196,67,.28); }
.chess-sq.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.chess-sq.hint::after { content: ''; position: absolute; width: 28%; height: 28%; border-radius: 50%;
  background: rgba(0,0,0,.3); }
.chess-pc { font-size: 1em; line-height: 1; user-select: none; pointer-events: none; }
.chess-pc.w { color: #fff; text-shadow: 0 0 2px #000, 0 1px 1px rgba(0,0,0,.7); }
.chess-pc.b { color: #15130f; text-shadow: 0 0 2px rgba(255,255,255,.45); }
