:root {
  --radius: 16px;
  --radius-sm: 8px;
  --radius-lg: 24px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, Menlo, Consolas, monospace;
  --transition: 200ms cubic-bezier(0.2, 0, 0, 1);}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding: 16px;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  padding: 28px 36px 36px;
  border: 1px solid var(--border);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
  gap: 12px;
}

.page-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.page-title .title-icon {
  flex-shrink: 0;
  color: var(--accent);
  -webkit-text-fill-color: initial;
}
.header h1 {
  font-size: 2.1rem;
  font-weight: 750;
  letter-spacing: -0.6px;
  margin: 0;
  text-align: center;
  background: linear-gradient(135deg, #43a047, #2e7d32);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

body.dark .header h1 {
  background: linear-gradient(135deg, #81c784, #a5d6a7);
  -webkit-background-clip: text;
  background-clip: text;
}

.lang-block { display: none; }
.lang-block.active { display: block; }

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 8px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.game-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-elevated);
  transform: translateY(-2px);
  text-decoration: none;
}

.game-card .icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
}

.game-card .icon-wrap svg {
  width: 36px;
  height: 36px;
}

.game-card h3 {
  font-size: 1.05rem;
  font-weight: 650;
  text-align: center;
}

.game-card p {
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.view { display: none; }
.view.active { display: block; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.game-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #43a047, #2e7d32);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

body.dark .game-header h2 {
  background: linear-gradient(135deg, #81c784, #a5d6a7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  background: var(--accent);
  color: var(--on-primary);
  border: none;
  padding: 8px 18px;
  border-radius: 30px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: var(--font);
  transition: transform 0.12s, filter 0.15s;
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.96); }

.score-panel {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--muted);
}

.score-panel span b {
  color: var(--accent);
  font-weight: 700;
}

.game-area {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  margin: 12px 0;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.game-area canvas {
  border-radius: 12px;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface-variant);
  max-width: 100%;
}

@media (pointer: coarse), (max-width: 700px) {
  .container { padding: 16px 12px 24px; }

  .game-card { padding: 16px 12px; }
  .game-card .icon-wrap { width: 56px; height: 56px; }
  .game-card .icon-wrap svg { width: 32px; height: 32px; }

  .chk-board { width: 100%; max-width: 100%; }
  .chk-piece { width: 78%; height: 78%; }

  .ttt-board { max-width: min(100%, 280px); }
  .ttt-cell { font-size: 2.2rem; min-height: 72px; }

  .score-panel { font-size: 0.85rem; gap: 10px; }
  .btn { padding: 10px 16px; font-size: 0.95rem; min-height: 44px; }
}

.swipe-area { -webkit-user-select: none; user-select: none; }
.swipe-area canvas { touch-action: none; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 12px;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  z-index: 10;
}

.overlay.hidden { display: none; }

.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 300px;
  margin: 0 auto;
}

.ttt-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface-variant);
  font-size: 2.4rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  color: var(--text);
}

.ttt-cell:hover:not(.taken) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ttt-cell.x { color: #e53935; }
.ttt-cell.o { color: #1e88e5; }

.ms-board {
  display: grid;
  gap: 2px;
  margin: 0 auto;
  background: var(--border);
  border-radius: 8px;
  padding: 2px;
}

.ms-cell {
  width: var(--ms-cell, 28px);
  height: var(--ms-cell, 28px);
  border-radius: 4px;
  background: var(--surface-variant);
  border: 1px solid var(--outline);
  font-size: calc(var(--ms-cell, 28px) * 0.5);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  font-family: var(--font-mono);
}

.ms-cell.revealed {
  background: var(--card);
  border-color: transparent;
  cursor: default;
}

.ms-cell.flagged { background: #fff8e1; }
.ms-cell.mine { background: #fce8e6; }
.ms-cell.n1 { color: #1976d2; }
.ms-cell.n2 { color: #388e3c; }
.ms-cell.n3 { color: #d32f2f; }
.ms-cell.n4 { color: #7b1fa2; }
.ms-cell.n5 { color: #c62828; }
.ms-cell.n6 { color: #00838f; }
.ms-cell.n7 { color: #212121; }
.ms-cell.n8 { color: #616161; }

.chk-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0;
  width: min(100%, 520px);
  max-width: 520px;
  margin: 0 auto;
  border: 3px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.chk-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chk-cell.light { background: #e8f5e9; }
.chk-cell.dark { background: #2e7d32; }
body.dark .chk-cell.light { background: #1e3324; }
body.dark .chk-cell.dark { background: #1b5e20; }

.chk-piece {
  width: 72%;
  height: 72%;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  transition: transform 0.15s;
}

.chk-piece.white {
  background: radial-gradient(circle at 35% 30%, #fff, #e0e0e0);
  border: 2px solid #bdbdbd;
}

.chk-piece.black {
  background: radial-gradient(circle at 35% 30%, #555, #212121);
  border: 2px solid #111;
}

.chk-piece.king::after {
  content: "♔";
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 1.1rem;
  color: #ffc107;
}

.chk-piece.selected {
  outline: 3px solid #ffeb3b;
  outline-offset: 2px;
  transform: scale(1.08);
}

.chk-cell.highlight {
  box-shadow: inset 0 0 0 3px #ffeb3b;
}

.ctrl-select {
  appearance: auto;
  -webkit-appearance: menulist;
  background: var(--accent-soft);
  color: var(--text);
  border: 1.5px solid var(--border);
  padding: 8px 12px;
  border-radius: 30px;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: var(--font);
  cursor: pointer;
  min-height: 40px;
}
.ctrl-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.bb-grid {
  display: grid;
  gap: var(--bb-gap, 3px);
  width: fit-content;
  margin: 0 auto;
  padding: var(--bb-pad, 4px);
  background: var(--border);
  border-radius: 10px;
}
.bb-cell { width: var(--bb-cell); height: var(--bb-cell); border-radius: 4px; background: var(--surface-variant); }
.bb-cell.bb-ok { opacity: .6; }
.bb-cell.bb-bad { background: rgba(239, 83, 80, .45) !important; }
.bb-cell.bb-clear { box-shadow: inset 0 0 0 2px var(--accent); opacity: 1; }
.bb-pieces { display: flex; gap: 12px; justify-content: center; align-items: center; margin-top: 16px; }
.bb-slot {
  --tray-size: calc(var(--bb-mini) * var(--bb-tray, 4) + var(--bb-gap, 3px) * (var(--bb-tray, 4) - 1));
  display: flex; align-items: center; justify-content: center;
  width: var(--tray-size); height: var(--tray-size);
}
.bb-piece, .bb-ghost {
  display: grid; gap: var(--bb-gap, 3px);
  user-select: none; -webkit-user-select: none;
  touch-action: none; -webkit-touch-callout: none;
}
.bb-piece { cursor: grab; }
.bb-piece.dragging { opacity: .25; }
.bb-piece.stuck:not(.dragging) { opacity: .4; }
.bb-ghost {
  position: fixed; left: 0; top: 0; z-index: 1000;
  pointer-events: none; will-change: transform; opacity: .92;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .3));
}
.bb-piece-cell { width: var(--s); height: var(--s); border-radius: 4px; }
.bb-piece-cell:not(.on) { background: transparent; }

.hint, .status-line { text-align: center; color: var(--muted); }
.hint { margin-top: 10px; font-size: 0.85rem; }
.status-line { margin-top: 12px; min-height: 1.6em; }

@media (max-width:480px){
  .games-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
  .game-card{padding:14px 10px}
}

.score-panel .ms-ico {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
}
