.games-modal-open { overflow: hidden; }

.games-overlay {
  position: fixed;
  inset: 0;
  z-index: 930;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: clamp(10px, 2vw, 24px);
  color: #243f43;
  background: #142f3478;
  opacity: 0;
  backdrop-filter: blur(10px);
  transition: opacity .16s ease;
}

.games-overlay[hidden] { display: none; }
.games-overlay.is-open { opacity: 1; }

.games-shell {
  width: min(1080px, 100%);
  min-width: 0;
  height: min(840px, calc(100dvh - 32px));
  max-height: calc(100dvh - 20px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #d8e7e4;
  border-radius: 28px;
  background:
    radial-gradient(circle at 100% 0, #ffe4c9 0, transparent 26%),
    radial-gradient(circle at 0 100%, #d6eeea 0, transparent 29%),
    #fffdf9;
  box-shadow: 0 30px 90px #142e3445;
  transform: translateY(10px);
  transition: transform .16s ease;
}

.games-overlay.is-open .games-shell { transform: translateY(0); }
.games-shell * { box-sizing: border-box; }

.games-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 22px 28px 17px;
  border-bottom: 1px solid #deebe8;
}

.games-header > div > span,
.games-kicker {
  color: #df7d61;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .17em;
}

.games-header h2 {
  margin: 4px 0 3px;
  color: #245f66;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: clamp(27px, 3.5vw, 38px);
}

.games-header p { margin: 0; color: #748689; font-size: 13px; line-height: 1.6; }

.games-close {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  color: #537579;
  background: #e7f2ef;
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
}

.games-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 28px;
  border-bottom: 1px solid #e5efed;
  background: #f7fbfaaf;
}

.games-tabs button {
  border: 0;
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 12px;
  color: #617c7f;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.games-tabs button[aria-pressed="true"] {
  color: #fff;
  background: linear-gradient(135deg, #2b7378, #e08368);
  box-shadow: 0 7px 17px #2b697427;
}

.games-body {
  min-width: 0;
  min-height: 0;
  overflow: auto hidden;
  overscroll-behavior: contain;
  padding: 22px 28px 34px;
}

.game-stage { min-width: 0; display: grid; gap: 18px; }
.game-stage-heading h3 {
  margin: 6px 0 4px;
  color: #285e65;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: clamp(25px, 4vw, 36px);
}
.game-stage-heading p { margin: 0; color: #718487; font-size: 13px; line-height: 1.7; }

.gomoku-layout,
.tetris-layout,
.game-2048-layout {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 260px);
  align-items: start;
  gap: 22px;
}

.gomoku-board-wrap {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 14px;
  border: 1px solid #dbc18d;
  border-radius: 22px;
  background: #f6e4ba;
  box-shadow: inset 0 0 30px #8d632927, 0 14px 30px #74511c15;
}

.gomoku-board {
  width: min(100%, 600px);
  height: auto;
  border-radius: 12px;
  cursor: crosshair;
  touch-action: manipulation;
  box-shadow: 0 10px 24px #76501d28;
}

.game-side-card {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 23px;
  border: 1px solid #dbe8e5;
  border-radius: 20px;
  background: #fffdfbe0;
  box-shadow: 0 13px 30px #28575e10;
}

.game-side-card > p { margin: 0; color: #708386; font-size: 13px; line-height: 1.75; }
.game-side-card > span { color: #6d8285; font-size: 13px; }
.game-status { color: #285f66; font-size: 19px; line-height: 1.4; }
.game-status[data-tone="win"] { color: #ca684f; }
.game-status[data-tone="done"] { color: #7a6d68; }
.game-score { color: #2a6970; font-family: "Noto Serif SC", serif; font-size: 42px; line-height: 1; }

.games-primary,
.games-secondary,
.games-control {
  border: 0;
  border-radius: 11px;
  padding: 10px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.games-primary { color: #fff; background: linear-gradient(135deg, #286a70, #3f8c82); }
.games-secondary { color: #2d6c70; background: #e6f2ef; }
.games-control { color: #315f64; background: #edf4f2; font-size: 18px; }
.games-primary:disabled,
.games-secondary:disabled,
.games-control:disabled { opacity: .5; cursor: default; }

.tetris-layout { grid-template-columns: minmax(280px, 1fr) minmax(230px, 270px); }

.tetris-board {
  width: min(100%, 360px);
  height: auto;
  justify-self: center;
  border: 8px solid #294d53;
  border-radius: 16px;
  background: #173237;
  box-shadow: 0 18px 36px #15343a2e;
}

.tetris-side { align-self: stretch; }
.tetris-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 5px; }
.tetris-controls .wide { grid-column: 1 / -1; font-size: 13px; }

.game-2048-layout { grid-template-columns: minmax(280px, 1fr) minmax(220px, 260px); }

.game-2048-board {
  width: min(100%, 500px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(7px, 1.5vw, 13px);
  justify-self: center;
  padding: clamp(9px, 2vw, 15px);
  border-radius: 22px;
  background: #aa9480;
  touch-action: none;
  user-select: none;
  box-shadow: 0 18px 36px #513d2a28;
}

.game-2048-tile {
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: #3f716e;
  font-family: "Noto Serif SC", Georgia, serif;
  font-size: clamp(20px, 5vw, 44px);
  font-weight: 900;
  box-shadow: inset 0 2px 0 #ffffff2c;
}

.game-2048-tile.is-empty { background: #c8b7a6; box-shadow: none; }
.game-2048-tile.tile-2 { color: #695b4f; background: #eee4d6; }
.game-2048-tile.tile-4 { color: #695b4f; background: #ead7b8; }
.game-2048-tile.tile-8 { background: #e89b62; }
.game-2048-tile.tile-16 { background: #e57d57; }
.game-2048-tile.tile-32 { background: #d96351; }
.game-2048-tile.tile-64 { background: #c94b43; }
.game-2048-tile.tile-128 { background: #c9a94c; font-size: clamp(18px, 4.6vw, 38px); }
.game-2048-tile.tile-256 { background: #b99637; font-size: clamp(18px, 4.6vw, 38px); }
.game-2048-tile.tile-512 { background: #9f862e; font-size: clamp(18px, 4.6vw, 38px); }
.game-2048-tile.tile-1024 { background: #4c817b; font-size: clamp(15px, 4vw, 32px); }
.game-2048-tile.tile-2048,
.game-2048-tile.tile-super { background: linear-gradient(145deg, #276b70, #d96f57); font-size: clamp(15px, 4vw, 32px); }

.game-2048-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 7px; }

.games-quick-button {
  position: fixed;
  z-index: 250;
  left: 14px;
  bottom: 68px;
  display: none;
  min-width: 58px;
  height: 46px;
  border: 0;
  border-radius: 15px;
  color: #fff;
  background: linear-gradient(145deg, #d7775e, #b75d50);
  box-shadow: 0 12px 28px #7140352e;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
}

.games-quick-button[hidden] { display: none !important; }

@media (max-width: 980px) {
  .games-quick-button { display: block; }
  .games-shell { height: min(860px, calc(100dvh - 24px)); }
  .gomoku-layout,
  .tetris-layout,
  .game-2048-layout { grid-template-columns: 1fr; }
  .game-side-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    max-width: 640px;
    width: 100%;
    justify-self: center;
  }
  .game-side-card > p,
  .game-side-card .games-kicker,
  .game-side-card .game-status,
  .tetris-controls,
  .game-2048-controls { grid-column: 1 / -1; }
  .tetris-board { width: min(100%, 330px); }
  .game-2048-board { width: min(100%, 440px); }
}

@media (max-width: 640px) {
  .games-overlay { padding: 0; place-items: stretch; }
  .games-shell { width: 100%; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; }
  .games-header { padding: 18px 18px 14px; }
  .games-header h2 { font-size: 30px; }
  .games-header p { display: none; }
  .games-tabs { gap: 5px; padding: 8px 14px; }
  .games-tabs button { padding: 8px 5px; font-size: 12px; white-space: nowrap; }
  .games-body { padding: 18px 14px 28px; }
  .game-stage-heading h3 { font-size: 26px; }
  .gomoku-board-wrap { padding: 8px; border-radius: 16px; }
  .game-side-card { grid-template-columns: 1fr; padding: 17px; border-radius: 16px; }
  .game-side-card > p,
  .game-side-card .games-kicker,
  .game-side-card .game-status,
  .tetris-controls,
  .game-2048-controls { grid-column: auto; }
  .tetris-board { width: min(100%, 300px); }
  .game-2048-layout { min-width: 0; }
  .game-2048-board { min-width: 0; border-radius: 16px; }
  .game-2048-tile { border-radius: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .games-overlay,
  .games-shell { transition: none; }
}
