/* CHESS LAB — DỰ ÁN 02 · cùng hệ token với trang chính (portfolio.css) */

:root {
  color-scheme: dark;
  --ink: #10110f;
  --ink-raised: #171815;
  --paper: #f1f0e9;
  --muted: #9a9c93;
  --line: rgba(241, 240, 233, .16);
  --line-strong: rgba(241, 240, 233, .3);
  --acid: #d5ff39;
  --rust: #e97f56;
  --display: 'Space Grotesk', 'Arial', sans-serif;
  --mono: 'DM Mono', 'Courier New', monospace;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --sq-light: #2c2d24;
  --sq-dark: #1b1c17;
  --gutter: clamp(16px, 4vw, 60px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--ink); }
body {
  margin: 0; min-height: 100svh; background: var(--ink); color: var(--paper);
  font-family: var(--display); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; overflow-x: clip;
}
body::before {
  position: fixed; inset: 0; z-index: 4; pointer-events: none; content: ''; opacity: .1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.84' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}
a { color: inherit; text-decoration: none; }
button { color: inherit; font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
::selection { color: var(--ink); background: var(--acid); }
:focus-visible { outline: 2px solid var(--acid); outline-offset: 3px; }
.mono { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: fixed; z-index: 60; top: 10px; left: 10px; padding: 12px 16px; transform: translateY(-170%); background: var(--acid); color: var(--ink); font-size: 10px; }
.skip-link:focus { transform: translateY(0); }

.lab-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- Header ---------- */
.lab-header { border-bottom: 1px solid var(--line); }
.lab-shell { max-width: 1360px; margin: 0 auto; padding-inline: var(--gutter); }
.lab-header-grid { height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.lab-brand { display: inline-flex; align-items: center; gap: 12px; font-size: 10px; }
.lab-back { display: inline-flex; align-items: center; gap: 8px; letter-spacing: .12em; transition: color 160ms ease; }
.lab-back:hover { color: var(--acid); }
.lab-back i { font-style: normal; color: var(--acid); }
.lab-crumb { color: var(--muted); }
.lab-language { display: inline-flex; gap: 7px; align-items: center; color: var(--muted); font-size: 10px; }
.lab-language button { border: 0; padding: 6px 2px; background: transparent; color: var(--muted); font: 500 10px/1 var(--mono); letter-spacing: .1em; transition: color 160ms ease; }
.lab-language button[aria-pressed="true"], .lab-language button:hover { color: var(--acid); }

/* ---------- Layout ---------- */
.lab-main { position: relative; z-index: 6; padding-block: clamp(18px, 3vw, 34px) clamp(30px, 5vw, 64px); }
.lab-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(290px, 27%, 360px); gap: clamp(20px, 3vw, 42px); align-items: start; }
@media (max-width: 940px) {
  .lab-layout { grid-template-columns: minmax(0, 1fr); }
  .lab-stage { order: 1; }
  .lab-panel { order: 2; }
}

.lab-stage-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; color: var(--muted); font-size: 9px; flex-wrap: wrap; }
.lab-engine-badge { color: var(--acid); }
.lab-view-toggle { display: inline-flex; border: 1px solid var(--line); }
.lab-view-toggle button { border: 0; padding: 7px 13px; background: transparent; color: var(--muted); font: 500 9px/1 var(--mono); letter-spacing: .12em; transition: color 160ms ease, background 160ms ease; }
.lab-view-toggle button.is-active { background: var(--acid); color: var(--ink); }
.lab-view-toggle button:not(.is-active):hover { color: var(--paper); }

.lab-board-cell { position: relative; }

/* ---------- Bàn cờ 2D ---------- */
.lab-board {
  position: relative; max-width: min(640px, 100%); margin-inline: auto;
  aspect-ratio: 1; border: 1px solid var(--line-strong);
  box-shadow: 0 34px 90px rgba(0, 0, 0, .5), 0 0 0 1px rgba(0, 0, 0, .35);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  background: var(--sq-dark);
}
.lab-board.is-dragging { touch-action: none; }
.lab-squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }

.lab-square { position: relative; display: block; border: 0; padding: 0; background: none; }
.lab-square .lab-tint { pointer-events: none; position: absolute; inset: 0; }
.lab-square--light .lab-tint { background: var(--sq-light); }
.lab-square--dark .lab-tint { background: var(--sq-dark); }
.lab-square[data-last="true"] .lab-tint { background: color-mix(in srgb, var(--acid) 16%, var(--sq-dark)); }
.lab-square[data-last="true"].lab-square--light .lab-tint { background: color-mix(in srgb, var(--acid) 20%, var(--sq-light)); }
.lab-square[data-selected="true"] .lab-tint { box-shadow: inset 0 0 0 2px var(--acid); }
.lab-square[data-target="true"] .lab-tint::after {
  content: ''; position: absolute; inset: 0; margin: auto; border-radius: 50%;
  width: 17%; height: 17%; background: rgba(213, 255, 57, .38);
}
.lab-square[data-target="true"][data-occupied="true"] .lab-tint::after {
  width: 88%; height: 88%; border-radius: 50%; background: none;
  border: 2.5px solid rgba(213, 255, 57, .5);
}
.lab-square[data-dragover="true"] .lab-tint { box-shadow: inset 0 0 0 2.5px rgba(213, 255, 57, .65); }
.lab-square[data-playable="true"] { cursor: pointer; }
.lab-square[data-playable="true"] .lab-piece { cursor: grab; }

.lab-square[data-check="true"] .lab-tint::before {
  content: ''; position: absolute; inset: 8%; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--rust) 78%, transparent) 0%, transparent 68%);
  animation: lab-pulse 1.1s var(--ease-out) infinite alternate;
}
@keyframes lab-pulse { from { opacity: .55; } to { opacity: 1; } }

.lab-square .lab-coord { position: absolute; pointer-events: none; font: 500 9px/1 var(--mono); letter-spacing: .04em; opacity: .55; color: var(--muted); }
.lab-square[data-file="0"] .lab-coord--rank { top: 4px; left: 4px; }
.lab-square[data-rank="0"] .lab-coord--file { bottom: 4px; right: 4px; }

.lab-piece {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center;
  color: var(--piece-fill); transition: color 200ms ease;
}
.lab-piece svg { width: 82%; height: 82%; overflow: visible; fill: currentColor; stroke: var(--piece-stroke); stroke-width: 3.1; stroke-linejoin: round; stroke-linecap: round; }
.lab-piece--w { --piece-fill: #f1f0e9; --piece-stroke: #191a15; }
.lab-piece--b { --piece-fill: #131410; --piece-stroke: #8d8f84; }
.lab-piece .lab-eye { fill: var(--piece-stroke); stroke: none; }
.lab-piece .lab-slit { fill: none; stroke: var(--piece-stroke); stroke-width: 2.6; }
.lab-piece svg { filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .45)); }

.lab-square[data-check="true"] .lab-piece { color: color-mix(in srgb, var(--rust) 42%, var(--piece-fill)); }
.lab-piece.is-floating {
  position: fixed; z-index: 80; pointer-events: none; inset: auto;
  transition: none; filter: drop-shadow(0 14px 22px rgba(0, 0, 0, .55)) brightness(1.06);
}

/* Nước đi bị từ chối */
.lab-square { overflow: hidden; }
.lab-squares.is-bad { animation: lab-shake .34s ease; }
@keyframes lab-shake { 20% { transform: translateX(3px); } 45% { transform: translateX(-3px); } 70% { transform: translateX(2px); } }

/* ---------- Bàn 3D ---------- */
.lab-board3d { position: relative; max-width: min(640px, 100%); margin-inline: auto; aspect-ratio: 1; border: 1px solid var(--line-strong); overflow: hidden; background: radial-gradient(120% 120% at 50% 0%, rgba(213, 255, 57, .05), transparent 47%), var(--ink-raised); }
.lab-board3d canvas { display: block; width: 100% !important; height: 100% !important; touch-action: none; }
.lab-board3d .lab-loading3d { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font: 400 10px/1.6 var(--mono); letter-spacing: .12em; text-transform: uppercase; text-align: center; padding: 16px; }

.lab-hint { color: var(--muted); font-size: 9px; text-align: center; max-width: min(640px, 100%); margin: 12px auto 0; letter-spacing: .09em; }

.lab-live { max-width: min(640px, 100%); margin: 16px auto 0; display: flex; align-items: baseline; justify-content: center; gap: 14px; flex-wrap: wrap; }
.lab-status { margin: 0; text-align: center; font: 500 12px/1.5 var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.lab-status.has-end { color: var(--acid); }
.lab-status.has-check { color: var(--rust); }
.lab-thinking { margin: 0; display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font: 400 10px/1 var(--mono); letter-spacing: .12em; }
.lab-thinking em { font-style: normal; }
.lab-thinking span { display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--acid); animation: lab-blink 1s infinite both; }
.lab-thinking span:nth-child(2) { animation-delay: .18s; }
.lab-thinking span:nth-child(3) { animation-delay: .36s; }
@keyframes lab-blink { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

/* ---------- Panel ---------- */
.lab-panel { display: grid; gap: 0; border: 1px solid var(--line); background: color-mix(in srgb, var(--ink-raised) 82%, transparent); }
.lab-player { display: flex; align-items: center; gap: 10px; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.lab-player--bottom { border-bottom: 0; border-top: 1px solid var(--line); }
.lab-chip i { display: block; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line-strong); box-shadow: 0 0 0 2px rgba(0, 0, 0, .35); transition: all 160ms ease; }
.lab-chip[data-chip="w"] i { background: var(--paper); }
.lab-chip[data-chip="b"] i { background: #131410; }
.lab-player.is-to-move .lab-chip i { box-shadow: 0 0 0 2px rgba(0, 0, 0, .35), 0 0 12px 3px rgba(213, 255, 57, .5); border-color: var(--acid); } }
.lab-player-name { font-size: 10px; }
.lab-player-captured { flex: 1; min-width: 0; color: var(--muted); font-size: 11px; letter-spacing: .02em; text-transform: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lab-clock { font-size: 13px; letter-spacing: .05em; padding: 3px 9px; border: 1px solid transparent; transition: all 240ms ease; }
.lab-clock.is-active { border-color: var(--acid); color: var(--acid); }
.lab-clock.is-low { color: var(--rust); border-color: var(--rust); animation: lab-pulse 1s infinite alternate; }

.lab-mini-piece { display: inline-block; width: 13px; height: 13px; opacity: .75; }
.lab-mini-piece svg { display: block; width: 100%; height: 100%; fill: #9a9c93; }

.lab-history { max-height: clamp(190px, 38vh, 340px); min-height: 140px; overflow-y: auto; padding: 12px 14px; scroll-behavior: smooth; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.lab-history-inner { display: grid; grid-template-columns: auto 1fr 1fr; gap: 2px 10px; font-size: 11px; letter-spacing: .03em; line-height: 1.9; }
.lab-history .lab-move-no { color: var(--muted); }
.lab-history .lab-move { width: max-content; border-bottom: 1px solid transparent; }
.lab-history .lab-move.is-latest { color: var(--acid); border-color: rgba(213, 255, 57, .4); }
.lab-history-empty { color: var(--muted); font-size: 10px; letter-spacing: .09em; text-transform: uppercase; }

.lab-actions { display: flex; flex-wrap: wrap; gap: 7px; padding: 13px 14px; }
.lab-actions button {
  border: 1px solid var(--line); background: transparent; color: var(--paper);
  font: 500 9.5px/1 var(--mono); letter-spacing: .11em; padding: 10px 12px;
  transition: all 170ms ease;
}
.lab-actions button:hover { border-color: var(--acid); color: var(--acid); }
.lab-actions button:disabled { opacity: .32; cursor: not-allowed; }
.lab-actions button[aria-pressed="true"] { border-color: var(--acid); color: var(--acid); }
.lab-actions button:active { transform: translateY(1px); }

.lab-engine-note { padding: 0 14px 13px; margin: 0; color: var(--rust); font-size: 9.5px; line-height: 1.7; }

/* ---------- Dialog ---------- */
dialog.lab-dialog {
  color: var(--paper); background: var(--ink-raised); border: 1px solid var(--line-strong);
  padding: 26px 26px 24px; max-width: min(92vw, 430px); width: 100%;
  box-shadow: 0 40px 120px rgba(0, 0, 0, .6), 0 0 0 1px rgba(0, 0, 0, .4);
}
dialog.lab-dialog::backdrop { background: rgba(8, 9, 7, .66); backdrop-filter: blur(3px); }
dialog.lab-dialog[open] { animation: lab-rise .39s var(--ease-out); }
@keyframes lab-rise { from { opacity: 0; transform: translateY(13px); } }
.lab-dialog h2 { margin: 4px 0 18px; font: 500 13px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.lab-field { margin-bottom: 16px; }
.lab-field-label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 9px; }
.lab-choice { display: grid; gap: 7px; }
.lab-choice button {
  display: block; width: 100%; text-align: left; padding: 12px 14px;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--ink) 62%, transparent);
  color: var(--paper); transition: all 170ms ease;
}
.lab-choice button strong { display: block; font: 500 13.5px/1.2 var(--display); letter-spacing: -.01em; }
.lab-choice button small { display: block; margin-top: 3px; color: var(--muted); font: 400 10px/1.4 var(--mono); letter-spacing: .05em; }
.lab-choice button:hover { border-color: var(--line-strong); }
.lab-choice button.is-active { border-color: var(--acid); background: color-mix(in srgb, var(--acid) 9%, transparent); }
.lab-choice--small { grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); }
.lab-choice--small button { text-align: center; font: 500 10.5px/1.2 var(--mono); letter-spacing: .08em; padding: 10px 6px; }
.lab-choice--small button strong { font: inherit; }
.lab-primary {
  width: 100%; border: 0; padding: 14px; background: var(--acid); color: var(--ink);
  font: 700 11px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase;
  transition: filter 170ms ease;
}
.lab-primary:hover { filter: brightness(1.08); }
.lab-primary:active { transform: translateY(1px); }
.lab-close { position: absolute; top: 10px; right: 12px; border: 0; background: transparent; color: var(--muted); font-size: 17px; padding: 8px; line-height: 1; }
.lab-close:hover { color: var(--acid); }

.lab-promo-grid { display: grid; grid-template-columns: repeat(4, 74px); gap: 9px; }
.lab-promo-grid button { position: relative; padding: 10px 4px 12px; border: 1px solid var(--line); background: color-mix(in srgb, var(--ink) 55%, transparent); color: var(--piece-fill, var(--paper)); transition: border-color 170ms ease; }
.lab-promo-grid button:hover { border-color: var(--acid); }
.lab-promo-grid .lab-piece { position: relative; inset: auto; width: 46px; height: 46px; margin: 0 auto; }
.lab-promo-grid span { display: block; margin-top: 4px; text-align: center; font: 400 8.5px/1 var(--mono); letter-spacing: .1em; color: var(--muted); text-transform: uppercase; }
.lab-promo-grid .lab-piece--w { --piece-fill: #f1f0e9; --piece-stroke: #191a15; }
.lab-promo-grid .lab-piece--b { --piece-fill: #131410; --piece-stroke: #8d8f84; }

.lab-dialog--end { text-align: center; max-width: min(92vw, 380px); }
.lab-end-eyebrow { margin: 0 0 10px; color: var(--acid); font-size: 9px; letter-spacing: .18em; text-transform: uppercase; }
.lab-end-title { margin: 0 0 8px; font: 600 clamp(21px, 4.5vw, 27px)/1.15 var(--display); letter-spacing: -.02em; }
.lab-end-sub { margin: 0 0 20px; color: var(--muted); font-size: 10px; letter-spacing: .07em; line-height: 1.7; }
.lab-end-actions { display: flex; gap: 9px; }
.lab-end-actions button { flex: 1; border: 1px solid var(--line); background: transparent; color: var(--paper); font: 500 10px/1 var(--mono); letter-spacing: .12em; padding: 13px 6px; transition: border-color 170ms ease, color 170ms ease; }
.lab-end-actions button:hover { border-color: var(--acid); color: var(--acid); }
.lab-end-actions .lab-primary { border: 0; background: var(--acid); color: var(--ink); }
.lab-end-actions .lab-primary:hover { color: var(--ink); }

.lab-dialog--confirm { max-width: min(92vw, 340px); text-align: center; }
.lab-confirm-title { margin: 0 0 20px; font: 500 15px/1.5 var(--display); letter-spacing: -.01em; }

.lab-draw-flag { position: fixed; z-index: 50; bottom: 18px; left: 50%; transform: translateX(-50%); max-width: 90vw; padding: 11px 18px; background: var(--ink-raised); border: 1px solid var(--rust); color: var(--rust); font-size: 9.5px; letter-spacing: .12em; box-shadow: 0 18px 50px rgba(0, 0, 0, .5); animation: lab-rise .35s var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  .lab-piece, .lab-squares, .lab-clock, .lab-chip i { transition: none !important; }
  .lab-status .has-check, .lab-clock.is-low { animation: none !important; }
  .lab-thinking span { animation-duration: 2.2s; }
  dialog.lab-dialog[open] { animation: none; }
}

@media (max-width: 720px) {
  .lab-header-grid { height: auto; padding-block: 12px; flex-wrap: wrap; }
  .lab-promo-grid { grid-template-columns: repeat(2, minmax(70px, 1fr)); }
  dialog.lab-dialog { padding: 22px 18px; }
}
@media (max-width: 480px) {
  .lab-actions { gap: 6px; }
  .lab-actions button { padding: 9px 10px; font-size: 9px; }
  .lab-player { flex-wrap: wrap; padding: 11px 12px; gap: 8px; }
  .lab-clock { margin-left: auto; }
}
