:root {
  --font: "Be Vietnam Pro", Arial, sans-serif;
  --ink: #344861;
  --line: #bec6d4;
  --thick: #344861;
  --given: #344861;
  --user: #325aaf;
  --wrong: #e55c6c;
  --sel: #bbdefb;
  --peer: #e2ebf3;
  --same: #c3d7ea;
  --accent: #5a7bc0;
  --bg: #f3f6fa;
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  min-height: 100%;
}
body {
  min-height: 100vh;
  background: var(--bg);
  font-family: var(--font);
  color: var(--ink);
}
button {
  font-family: var(--font);
  cursor: pointer;
  color: inherit;
}

.wrap {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 14px 14px 26px;
}
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  margin-bottom: 14px;
}
.back {
  color: #6e7c8c;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}
.top h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
}
.levels {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.levels button {
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #6e7c8c;
  font-weight: 600;
  font-size: 14px;
}
.levels button.on {
  background: #dce5f1;
  color: var(--ink);
}

.layout {
  display: grid;
  grid-template-columns: auto 300px;
  gap: 28px;
  align-items: start;
  justify-content: center;
}
.game {
  width: min(540px, calc(100vw - 28px), calc(100vh - 150px));
  width: min(540px, calc(100vw - 28px), calc(100dvh - 150px));
  min-width: 270px;
}
.info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  color: #6e7c8c;
  font-size: 14px;
}
.info b {
  color: var(--ink);
  font-weight: 700;
}
.info b.bad {
  color: var(--wrong);
}
.timer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.pause {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: #dce5f1;
  font-size: 9px;
  letter-spacing: -1px;
}

/* ---------- Bảng ---------- */
.board-wrap {
  position: relative;
  container-type: inline-size;
}
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1;
  border: 2px solid var(--thick);
  background: #fff;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 6.6cqw;
  font-weight: 500;
  color: var(--user);
  cursor: pointer;
  transition: background 0.1s;
}
.cell:nth-child(9n) {
  border-right: 0;
}
.cell:nth-child(9n + 3),
.cell:nth-child(9n + 6) {
  border-right: 2px solid var(--thick);
}
.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--thick);
}
.cell:nth-child(n + 73) {
  border-bottom: 0;
}
.cell.given {
  color: var(--given);
}
.cell.peer {
  background: var(--peer);
}
.cell.same {
  background: var(--same);
}
.cell.sel {
  background: var(--sel);
}
.cell.wrong {
  color: var(--wrong);
}
.cell.conflict {
  background: #f7cfd6;
}
.cell.pop {
  animation: pop 0.25s ease;
}
@keyframes pop {
  50% {
    transform: scale(1.25);
  }
}
.cell.wave {
  animation: wave 0.6s ease;
}
@keyframes wave {
  40% {
    background: #a8c8ee;
  }
}
.notes {
  position: absolute;
  inset: 4%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: 2.15cqw;
  font-weight: 500;
  color: #6e7c8c;
  line-height: 1;
}
.notes span {
  display: grid;
  place-items: center;
}
.notes span.hl {
  color: #fff;
  background: var(--user);
  border-radius: 3px;
}

/* ---------- Lớp phủ ---------- */
.cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(243, 246, 250, 0.96);
  border: 2px solid var(--thick);
}
.play {
  width: 72px;
  height: 72px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  box-shadow: 0 8px 20px rgba(90, 123, 192, 0.4);
}
.result {
  background: rgba(243, 246, 250, 0.9);
  animation: fade 0.3s;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.card {
  width: min(84%, 330px);
  padding: 22px 20px 18px;
  border-radius: 16px;
  background: #fff;
  text-align: center;
  box-shadow: 0 16px 40px rgba(52, 72, 97, 0.2);
  animation: pop2 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}
@keyframes pop2 {
  from {
    transform: scale(0.75);
    opacity: 0;
  }
}
.card .ico {
  font-size: 44px;
  line-height: 1;
}
.card h2 {
  margin: 8px 0 4px;
  font-size: 24px;
}
.card p {
  margin: 0 0 12px;
  color: #6e7c8c;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
.stats div {
  padding: 8px 4px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 11px;
  color: #6e7c8c;
}
.stats b {
  display: block;
  font-size: 16px;
  color: var(--ink);
}
.btns {
  display: grid;
  gap: 8px;
}

/* ---------- Cột công cụ ---------- */
.side {
  display: grid;
  gap: 14px;
}
.tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.tool {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: #6e7c8c;
}
.ti {
  position: relative;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #eaeef4;
  font-size: 22px;
  color: var(--accent);
  transition: background 0.15s;
}
.tool:hover .ti {
  background: #dce5f1;
}
.tool:disabled {
  opacity: 0.45;
  cursor: default;
}
.badge {
  position: absolute;
  top: -4px;
  right: -8px;
  padding: 2px 5px;
  border: 2px solid var(--bg);
  border-radius: 10px;
  background: #adb6c3;
  color: #fff;
  font: 700 9px var(--font);
  font-style: normal;
}
.badge.on {
  background: var(--accent);
}
.badge.num {
  right: -4px;
  min-width: 20px;
  background: var(--accent);
}
.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.pad button {
  position: relative;
  height: 64px;
  border: 0;
  border-radius: 10px;
  background: #eaeef4;
  color: var(--user);
  font-size: 32px;
  font-weight: 500;
  transition:
    background 0.15s,
    transform 0.08s;
}
.pad button:hover {
  background: #dce5f1;
}
.pad button:active {
  transform: scale(0.95);
}
.pad button small {
  position: absolute;
  right: 7px;
  top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #8a96a6;
}
.pad button.done {
  visibility: hidden;
}
.pad.notes-on button {
  color: #8a96a6;
  font-size: 26px;
}
.btn {
  height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: #eaeef4;
  font-weight: 700;
  font-size: 15px;
}
.btn.primary {
  background: var(--accent);
  color: #fff;
}
.btn.primary:hover {
  background: #4a6bb0;
}
.help {
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
  color: #8a96a6;
}
kbd {
  padding: 0 4px;
  border: 1px solid #cfd6e0;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  font: 600 11px var(--font);
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 16px;
  }
  .game {
    width: min(540px, calc(100vw - 20px));
  }
  .side {
    width: min(540px, 100%);
  }
  .pad {
    grid-template-columns: repeat(9, 1fr);
    gap: 4px;
  }
  .pad button {
    height: 56px;
    font-size: 26px;
  }
  .pad button small {
    right: 3px;
    top: 2px;
    font-size: 9px;
  }
  .levels {
    margin-left: 0;
    width: 100%;
  }
  .levels button {
    flex: 1;
    padding: 6px 4px;
  }
  .help {
    display: none;
  }
}
@media (max-width: 420px) {
  .wrap {
    padding: 10px 10px 20px;
  }
  .ti {
    width: 46px;
    height: 46px;
  }
  .pad button {
    height: 50px;
    font-size: 23px;
  }
}
