/* Cờ Caro — màu trang đổi theo kiểu bàn: giấy ô li (sáng), gỗ (ấm), neon (tối) */
:root,
body[data-theme="paper"] {
  --bg: #f4f1e6;
  --bg2: #ebe6d4;
  --panel: #fffdf6;
  --panel2: #f1ecdc;
  --line: rgba(40, 50, 90, 0.14);
  --text: #23283a;
  --muted: #6b7088;
  --accent: #2457c5;
  --x: #e0393e;
  --o: #2457c5;
  --gold: #c98a00;
  --shadow: 0 10px 30px rgba(60, 50, 20, 0.15);
}
body[data-theme="wood"] {
  --bg: #3a2717;
  --bg2: #2c1d10;
  --panel: #4a3220;
  --panel2: #5a3e28;
  --line: rgba(255, 230, 190, 0.14);
  --text: #fbefdc;
  --muted: #d1b48f;
  --accent: #ffb547;
  --x: #fbefdc;
  --o: #ff8a6a;
  --gold: #ffcf5a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
body[data-theme="neon"] {
  --bg: #0b0d1f;
  --bg2: #070815;
  --panel: #151935;
  --panel2: #1e2347;
  --line: rgba(140, 160, 255, 0.16);
  --text: #eef1ff;
  --muted: #959cc8;
  --accent: #3ef0ff;
  --x: #3ef0ff;
  --o: #ff4fa3;
  --gold: #ffd84d;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.25s;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.grow {
  flex: 1;
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- nút ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel2);
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 800;
  font-size: 15px;
  transition: transform 0.08s;
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
body[data-theme="neon"] .btn.primary,
body[data-theme="wood"] .btn.primary {
  color: #1a1206;
}
.btn.big {
  width: 100%;
  padding: 14px;
  font-size: 17px;
}
.btn.small {
  padding: 8px 12px;
  font-size: 13.5px;
}
.btn.danger {
  background: transparent;
  color: #e0393e;
  border-color: rgba(224, 57, 62, 0.4);
}
.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 17px;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.back {
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 14px;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  flex: none;
}
.bar h2 {
  margin: 0;
  font-size: 20px;
}
.pill {
  font-weight: 900;
  color: var(--gold);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--line);
  flex-wrap: wrap;
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}
.seg button.on {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 0 0 1.5px var(--accent);
}

/* ---------- sảnh ---------- */
.home {
  overflow: auto;
  background:
    radial-gradient(ellipse 50% 35% at 20% 10%, color-mix(in srgb, var(--x) 14%, transparent), transparent 70%),
    radial-gradient(ellipse 50% 35% at 85% 20%, color-mix(in srgb, var(--o) 14%, transparent), transparent 70%),
    var(--bg);
}
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 0 16px 28px;
  text-align: center;
}
.hero-marks {
  display: flex;
  justify-content: center;
  gap: 14px;
  font-size: 30px;
  font-weight: 900;
  font-family: "Patrick Hand", "Be Vietnam Pro", sans-serif;
}
.hx {
  color: var(--x);
  transform: rotate(-8deg);
}
.ho {
  font-size: 1.25em;
  color: var(--o);
}
.logo {
  margin: 2px 0 0;
  font-size: clamp(44px, 9vw, 72px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -1px;
}
.logo span {
  color: var(--x);
}
.tag {
  margin: 8px auto 0;
  max-width: 440px;
  color: var(--muted);
  font-size: 15px;
}
.modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(640px, 100%);
}
.mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 18px 10px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.mode:hover {
  transform: translateY(-3px);
}
.mode .mi {
  font-size: 34px;
}
.mode b {
  font-size: 17px;
}
.mode small {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 700;
}
.settings {
  width: min(640px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 12px 16px;
  display: grid;
  gap: 10px;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  text-align: left;
}
.row > span {
  font-weight: 800;
  font-size: 14px;
  color: var(--muted);
}
.rule-note {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: left;
}

/* ---------- leo thang ---------- */
.ladder {
  background: var(--bg);
  overflow: auto;
}
.lad-note {
  margin: 0 16px 10px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
.lad-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 0 14px 24px;
}
.opp {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  text-align: left;
  transition: transform 0.12s;
}
.opp:hover:not(.locked) {
  transform: translateY(-2px);
}
.opp .av {
  font-size: 34px;
  width: 52px;
  height: 52px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--panel2);
}
.opp .ot {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
}
.opp small {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.opp b {
  font-size: 17px;
}
.opp i {
  font-size: 12.5px;
  color: var(--text);
  opacity: 0.8;
}
.opp em {
  font-style: normal;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}
.opp .os {
  flex: none;
  font-weight: 900;
  font-size: 14px;
  color: var(--gold);
}
.opp.done {
  border-color: color-mix(in srgb, #2fbf71 55%, transparent);
}
.opp.done .os {
  color: #2fbf71;
}
.opp.next {
  box-shadow: 0 0 0 2px var(--accent), var(--shadow);
}
.opp.boss .av {
  background: linear-gradient(135deg, #ffcf33, #ff6b2d);
}
.opp.locked {
  opacity: 0.5;
}

/* ---------- trong ván ---------- */
.play {
  background: var(--bg);
}
.pbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
}
.player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
  transition: box-shadow 0.2s;
}
.player.right {
  flex-direction: row-reverse;
  padding: 5px 6px 5px 12px;
  text-align: right;
}
.player canvas {
  flex: none;
}
.player span {
  display: grid;
  min-width: 0;
  line-height: 1.15;
}
.player b {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}
.player.turn {
  box-shadow: 0 0 0 2px var(--accent);
}
.status {
  flex: 1;
  text-align: center;
  font-weight: 800;
  font-size: 14px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.think {
  color: var(--muted);
  animation: blink 1s infinite;
}
@keyframes blink {
  50% {
    opacity: 0.45;
  }
}
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}
#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.pfoot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 10px;
}
.info {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}

/* ---------- lớp phủ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 12, 24, 0.45);
  backdrop-filter: blur(3px);
}
.sheet {
  position: relative;
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  animation: pop 0.2s ease-out;
}
@keyframes pop {
  from {
    transform: scale(0.94);
    opacity: 0;
  }
}
.sheet h2 {
  margin: 0;
  text-align: center;
  font-size: 22px;
}
.sheet ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  font-size: 14px;
  line-height: 1.5;
}
.sub {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: var(--panel2);
  font-size: 20px;
  line-height: 1;
}
.res {
  text-align: center;
}
.res-ico {
  font-size: 58px;
  line-height: 1;
  animation: pop 0.4s ease-out;
}
.btns {
  display: grid;
  gap: 8px;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th,
.table td {
  padding: 7px 6px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.table th {
  color: var(--muted);
  font-size: 12px;
}
.table td:first-child {
  text-align: left;
  font-weight: 800;
}
.toast {
  position: absolute;
  left: 50%;
  top: 70px;
  translate: -50% 0;
  z-index: 40;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 9px 16px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- điện thoại ---------- */
@media (max-width: 640px) {
  .modes {
    gap: 8px;
  }
  .mode {
    padding: 14px 6px;
  }
  .mode .mi {
    font-size: 28px;
  }
  .mode b {
    font-size: 15px;
  }
  .row {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
  .lad-list {
    grid-template-columns: 1fr;
  }
  .player small {
    display: none;
  }
  .player b {
    font-size: 13px;
    max-width: 92px;
  }
  .pbar {
    flex-wrap: wrap;
  }
  .status {
    order: 5;
    flex-basis: 100%;
  }
  .player {
    flex: 1;
  }
}
@media (max-height: 500px) {
  .play {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .pbar {
    flex-direction: column;
    align-items: stretch;
    width: 200px;
    order: 1;
  }
  .stage {
    order: 2;
    height: 100%;
  }
  .pfoot {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 200px;
    flex-direction: column;
    align-items: stretch;
  }
  .player.right {
    flex-direction: row;
    text-align: left;
    padding: 5px 12px 5px 6px;
  }
  .status {
    order: 0;
    flex: none;
    white-space: normal;
    padding: 4px 0;
  }
  .home-body {
    gap: 10px;
  }
  .tag {
    display: none;
  }
}
