/*! KieuLink 桥联 — style chung 2 trò chơi (Rắn ăn trứng, Cờ caro). Mọi class tiền tố klg-. */
.klg {
  --klg-blue: var(--kl-blue, #0E3A5B);
  --klg-blue-d: var(--kl-blue-dark, #0A2C46);
  --klg-gold: var(--kl-gold, #F2A20C);
  --klg-text: var(--kl-text, #0F172A);
  --klg-muted: var(--kl-muted, #475569);
  --klg-cream: var(--kl-cream, #FEF3C7);
  --klg-line: var(--kl-line, #E2E8F0);
  box-sizing: border-box;
  display: block;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  color: var(--klg-text);
  font-family: inherit;
  line-height: 1.5;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.klg *, .klg *::before, .klg *::after { box-sizing: border-box; }
.klg:lang(km) { font-size: max(17px, 1em); line-height: 1.8; }
.klg p { margin: 0; }
.klg [hidden] { display: none !important; }

/* Nút */
.klg-btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px;
  margin: 0; padding: 8px 16px;
  border: 2px solid var(--klg-blue); border-radius: 10px;
  background: #fff; color: var(--klg-blue);
  font: inherit; font-weight: 700; line-height: 1.3;
  cursor: pointer; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  transition: background-color .15s, color .15s;
}
.klg:lang(km) .klg-btn { line-height: 1.6; padding-top: 6px; padding-bottom: 6px; }
.klg-btn:hover { background: var(--klg-cream); }
.klg-btn:focus-visible, .klg-arrow:focus-visible, .klg-cell:focus-visible { outline: 3px solid var(--klg-gold); outline-offset: 2px; }
.klg-btn:disabled { opacity: .45; cursor: not-allowed; background: #fff; }
.klg-btn-main { background: var(--klg-gold); border-color: var(--klg-gold); color: var(--klg-blue-d); }
.klg-btn-main:hover { background: #ffb933; }
.klg-btn-solid { background: var(--klg-blue); color: #fff; }
.klg-btn-solid:hover { background: var(--klg-blue-d); }
.klg-btn[aria-pressed="true"] { background: var(--klg-blue); color: #fff; }

.klg-lbl { color: var(--klg-muted); font-size: .85em; }
.klg-hint, .klg-rule, .klg-tally { color: var(--klg-muted); font-size: .9em; }

/* ===== Rắn ăn trứng ===== */
.klg-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 10px; }
.klg-stats { display: flex; gap: 20px; }
.klg-stat { display: flex; flex-direction: column; line-height: 1.25; }
.klg-num { font-size: 1.45em; font-weight: 800; color: var(--klg-blue); font-variant-numeric: tabular-nums; }
.klg-stage {
  position: relative; max-width: 100%; margin: 0 auto;
  border: 3px solid var(--klg-blue); border-radius: 14px; overflow: hidden; background: #fff;
  touch-action: none; overscroll-behavior: contain;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.klg-stage.klg-live { cursor: none; }
.klg-canvas { display: block; }
.klg-ov {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; text-align: center;
  background: rgba(10, 44, 70, .86); color: #fff;
  animation: klg-fade .2s ease-out;
}
.klg-ov-title { font-size: 1.4em; font-weight: 800; color: var(--klg-gold); line-height: 1.35; }
.klg:lang(km) .klg-ov-title { line-height: 1.7; }
.klg-ov-text { max-width: 30em; }
.klg-ov .klg-btn { min-width: 140px; margin-top: 4px; }

.klg-pad {
  display: grid; justify-content: center; gap: 8px; margin: 12px auto 0;
  grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(2, 64px);
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.klg-arrow {
  -webkit-appearance: none; appearance: none;
  display: flex; align-items: center; justify-content: center;
  width: 64px; height: 64px; margin: 0; padding: 0;
  border: 0; border-radius: 16px;
  background: var(--klg-blue); color: #fff; cursor: pointer;
  touch-action: none; transition: transform .08s, background-color .08s;
}
.klg-arrow:active { background: var(--klg-blue-d); transform: scale(.94); }
.klg-arrow svg { width: 30px; height: 30px; fill: currentColor; pointer-events: none; }
.klg-up { grid-column: 2; grid-row: 1; }
.klg-left { grid-column: 1; grid-row: 2; }
.klg-down { grid-column: 2; grid-row: 2; }
.klg-right { grid-column: 3; grid-row: 2; }
.klg-left svg { transform: rotate(-90deg); }
.klg-down svg { transform: rotate(180deg); }
.klg-right svg { transform: rotate(90deg); }
.klg-hint { margin-top: 10px; text-align: center; }
.klg-hint-keys { display: none; }
/* Máy tính có chuột, màn rộng: ẩn 4 nút, hiện hướng dẫn phím */
@media (hover: hover) and (pointer: fine) and (min-width: 700px) {
  .klg-pad, .klg-hint-touch { display: none; }
  .klg-hint-keys { display: inline; }
}

/* ===== Cờ caro ===== */
.klg-caro { max-width: 560px; }
.klg-ctrls { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 8px; }
.klg-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.klg-seg { display: inline-flex; border: 2px solid var(--klg-blue); border-radius: 10px; overflow: hidden; }
.klg-seg .klg-btn { border: 0; border-radius: 0; padding-left: 12px; padding-right: 12px; font-weight: 600; }
.klg-seg .klg-btn + .klg-btn { border-left: 2px solid var(--klg-blue); }
.klg-seg .klg-btn:focus-visible { outline-offset: -4px; }
.klg-rule { margin-bottom: 4px; }
.klg-status { min-height: 1.8em; margin: 4px 0 8px; font-weight: 700; color: var(--klg-blue); }
.klg-status.klg-busy::after { content: ""; display: inline-block; width: .6em; height: .6em; margin-left: .5em; border-radius: 50%; background: var(--klg-gold); vertical-align: middle; animation: klg-blink 1s infinite; }
.klg-board-wrap { width: 100%; position: relative; }
/* Y-030: bàn đã mở rộng quá khung thì kéo/cuộn trong khung, ô giữ cỡ cũ */
.klg-grown .klg-board-wrap { overflow: auto; max-height: 80vh; -webkit-overflow-scrolling: touch; }
.klg-grown .klg-board { max-width: none; }
.klg-board {
  display: grid; gap: 1px; width: max-content; max-width: 100%; margin: 0 auto;
  padding: 1px; border: 2px solid var(--klg-blue); border-radius: 6px;
  background: var(--klg-line);
  -webkit-user-select: none; user-select: none;
}
.klg-board[aria-busy="true"] .klg-cell { cursor: progress; }
.klg-cell {
  -webkit-appearance: none; appearance: none;
  position: relative; display: block; width: 100%; height: 100%;
  min-width: 0; min-height: 0; margin: 0; padding: 0;
  border: 0; border-radius: 0; background: #fff;
  font: inherit; cursor: pointer; touch-action: manipulation;
}
.klg-cell:hover { background: var(--klg-cream); }
.klg-cell[aria-disabled="true"] { cursor: default; }
.klg-cell:focus-visible { outline-offset: -3px; z-index: 1; }
.klg-x::before, .klg-x::after {
  content: ""; position: absolute; left: 17%; right: 17%; top: 50%;
  height: var(--klg-pw, 4px); margin-top: calc(var(--klg-pw, 4px) / -2);
  border-radius: 3px; background: var(--klg-blue);
  transform: rotate(45deg); animation: klg-pop .15s ease-out;
}
.klg-x::after { transform: rotate(-45deg); }
.klg-o::before {
  content: ""; position: absolute; left: 17%; top: 17%; right: 17%; bottom: 17%;
  border: var(--klg-pw, 4px) solid var(--klg-gold); border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(10, 44, 70, .5), inset 0 0 0 1px rgba(10, 44, 70, .5);
  animation: klg-pop .15s ease-out;
}
.klg-last { background: var(--klg-cream); box-shadow: inset 0 0 0 2px var(--klg-gold); }
.klg-win, .klg-win:hover { background: var(--klg-blue); box-shadow: none; animation: klg-glow 1.2s ease-in-out 2; }
.klg-win.klg-x::before, .klg-win.klg-x::after { background: #fff; }
.klg-win.klg-o::before { box-shadow: none; }
.klg-result {
  display: flex; align-items: center; justify-content: space-between; gap: 10px 14px; flex-wrap: wrap;
  margin-top: 12px; padding: 10px 14px; border: 2px solid var(--klg-gold); border-radius: 12px;
  background: var(--klg-cream);
}
.klg-result-text { font-size: 1.25em; font-weight: 800; color: var(--klg-blue); }
.klg-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.klg-actions .klg-btn { flex: 1 1 auto; }
.klg-tally { margin-top: 8px; font-variant-numeric: tabular-nums; }

@keyframes klg-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes klg-pop { from { opacity: 0; transform: scale(.4) rotate(var(--klg-r, 0deg)); } }
.klg-x::before { --klg-r: 45deg; }
.klg-x::after { --klg-r: -45deg; }
@keyframes klg-blink { 50% { opacity: .2; } }
@keyframes klg-glow { 50% { background: var(--klg-blue-d); } }

@media (prefers-reduced-motion: reduce) {
  .klg *, .klg *::before, .klg *::after { animation: none !important; transition: none !important; }
}
/* Giữ chỗ trước khi JS dựng trò chơi (CLS). Số đo 10/10/2026: Rắn cao ≥ 524px; Cờ caro ≥ 560px, từ khung 768px ≥ 748px */
[data-kl-game="snake"] { min-height: 520px; }
[data-kl-game="caro"] { min-height: 555px; }
@media (min-width: 768px) { [data-kl-game="caro"] { min-height: 740px; } }
