/* Giấy kẻ ô vở học trò: nền kem, quân X đỏ, O xanh. */
:root {
  --bg: #f3e3c3;
  --paper: #fffaf0;
  --grid: #c9d7e8;
  --panel: #fff;
  --line: #e2d3b3;
  --text: #3a2a1a;
  --muted: #8a7458;
  --accent: #e0312f;
  --x: #e0312f;
  --o: #1f6fd6;
  --good: #2e9e5b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); overflow: hidden;
  font: 15px/1.4 "Be Vietnam Pro", "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.ic { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; }
button, input { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; justify-content: center;
}
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
button.on { border-color: var(--accent); color: var(--accent); font-weight: 700; }
input { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  width: min(380px, calc(100vw - 32px)); display: grid; gap: 12px; text-align: center; box-shadow: 0 12px 40px #6b4a2033;
}
.card h1, .card h2 { margin: 0; }
.card h1 { display: flex; align-items: center; justify-content: center; gap: 8px; }
.card h1 .logo { width: 40px; height: 40px; }
.card h1 .back { color: var(--muted); display: inline-flex; }
.card h2 { display: flex; align-items: center; justify-content: center; gap: 8px; }
.card label { display: grid; gap: 4px; text-align: left; color: var(--muted); }
.card label.check { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--text); }
/* Công tắc kiểu chia-keo (h-6 w-11, núm trắng trượt) làm từ checkbox gốc: vẫn dùng bàn phím / trình đọc màn hình. */
input.switch {
  --off: #d6d3d1;
  appearance: none; flex: none; width: 44px; height: 24px; margin: 0; padding: 0; border: 0; border-radius: 999px; cursor: pointer;
  /* Núm = lớp gradient tròn trắng, trượt bằng background-position (pseudo-element không chạy trên input). */
  background: radial-gradient(circle, #fff 9px, #0000 10px) left 2px center / 20px 20px no-repeat, var(--off);
  box-shadow: inset 0 1px 2px #0002; transition: background-position .2s, background-color .2s;
}
input.switch:checked { --off: var(--accent); background-position: right 2px center, 0 0; }
input.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input.switch:disabled { opacity: .5; cursor: default; }
.sub, .muted { margin: 0; color: var(--muted); }
.muted { font-size: 12px; }
.join { display: flex; gap: 8px; }
#code { text-transform: uppercase; letter-spacing: 3px; text-align: center; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#home { height: 100%; display: grid; place-items: center; padding: 16px; }

#room { height: 100%; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 6px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
header .grow { flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--x); flex: none; }
.dot.on { background: var(--good); }
@media (max-width: 480px) { header .lbl { display: none; } }

/* Thanh đối đầu: X bên trái, O bên phải, đồng hồ ở giữa. */
#vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 0 12px; }
.side { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 6px 10px; border-radius: 12px; border: 2px solid transparent; background: #fff8; }
.side[data-seat="2"] { justify-content: flex-end; }
.side b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .sc { font-weight: 800; font-variant-numeric: tabular-nums; }
.side.turn { border-color: currentColor; background: #fff; }
.side[data-seat="1"].turn { color: var(--x); } .side[data-seat="2"].turn { color: var(--o); }
.side.me b::after { content: ' (bạn)'; font-weight: 400; color: var(--muted); }
html[lang="en"] .side.me b::after { content: ' (you)'; }
.pc { display: inline-grid; place-items: center; width: 24px; height: 24px; flex: none; }
.pc.x { color: var(--x); } .pc.o { color: var(--o); }
.pc .ic { width: 100%; height: 100%; stroke-width: 3; }
#clock { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; }
#clock.low { color: var(--x); animation: blink .5s infinite alternate; }
@keyframes blink { to { opacity: .4; } }

/* Bàn to hơn màn (điện thoại, 19×19) thì ô giữ cỡ tối thiểu, vuốt 1 ngón để kéo bàn. */
#wrap { flex: 1; min-height: 0; margin: 8px; display: grid; overflow: auto; overscroll-behavior: contain; scrollbar-width: none; }
#wrap::-webkit-scrollbar { display: none; }
#board {
  margin: auto; display: grid; background: var(--paper);
  border: 2px solid #9fb4cf; box-shadow: 0 8px 24px #6b4a2033; border-radius: 4px;
}
.c { border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); display: grid; place-items: center; cursor: pointer; }
.c.x { color: var(--x); } .c.o { color: var(--o); }
.c .ic { width: 78%; height: 78%; stroke-width: 3; }
.c.last { background: #fff1a8; }
.c.win { background: #ffd23f; animation: pop .4s ease-out both; }
@keyframes pop { from { transform: scale(.6); } }
/* Ô trống lúc tới lượt mình: hiện mờ quân của mình khi rê chuột. */
#board.mine .c:empty:hover::after { content: ''; width: 50%; height: 50%; border-radius: 50%; background: currentColor; opacity: .25; }
#board.mine.as-x .c:empty:hover { color: var(--x); } #board.mine.as-o .c:empty:hover { color: var(--o); }

#overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #f3e3c366; z-index: 5; }
#btnResult { position: absolute; left: 50%; bottom: 8px; translate: -50% 0; z-index: 6; box-shadow: 0 6px 20px #6b4a2044; }

#emoBar { display: flex; justify-content: center; gap: 6px; padding: 6px 12px max(8px, env(safe-area-inset-bottom)); }
#emoBar button { padding: 4px 12px; font-size: 20px; }
.emo-fly { position: fixed; translate: -50% -100%; font-size: 34px; pointer-events: none; z-index: 20; animation: emo 1.6s ease-out forwards; }
.emo-fly .ic { filter: drop-shadow(0 2px 3px #0005); }
@keyframes emo { to { transform: translateY(-80px) scale(1.4); opacity: 0; } }

/* Kiểu "đá": nền xám nhạt, lưới mảnh, quân tròn đen / xanh ngọc, nước vừa đi có chấm trắng (tham khảo bố cục papergames). */
body.skin-stone { --bg: #f4f6f9; --paper: #fbfcfd; --grid: #e2e7ee; --x: #2c3e50; --o: #1abc9c; --accent: #1abc9c; }
body.skin-stone #board { border-color: #d5dce5; box-shadow: 0 8px 24px #2c3e5018; }
body.skin-stone .c .ic, body.skin-stone .pc .ic { display: none; }
body.skin-stone .c.x::after, body.skin-stone .c.o::after, body.skin-stone .pc::after {
  content: ''; width: 76%; height: 76%; border-radius: 50%; background: currentColor; box-shadow: inset 0 -2px #0002;
}
body.skin-stone .c.last { background: none; }
body.skin-stone .c.last::after { background: radial-gradient(circle, #fff 0 14%, currentColor 16%); }
body.skin-stone .c.win { background: #d9f5ee; }
body.skin-stone .side.turn { background: #fff; }
