/* =========================================================================
   style.css — Đập Sếp
   Chỉ dùng token từ design/tokens.css. Thời lượng hiệu ứng chuột (--anim-ms)
   được game.js đặt lại từ CONFIG.ANIM_MS; giá trị dưới đây là dự phòng.
   ========================================================================= */

:root {
  --anim-ms: var(--duration-fast);
  --grid-cols: 1;   /* game.js đặt lại từ CONFIG.GRID_COLS / GRID_ROWS */
  --grid-rows: 1;

  /* Màu hình vẽ: sếp + bàn làm việc */
  --art-skin: #f2c9a0;
  --art-skin-dark: #e0ad80;
  --art-hair: #8a8a8f;
  --art-suit: #2f3440;
  --art-shirt: var(--palette-white);
  --art-tie: var(--palette-red-600);
  --art-ink: var(--palette-gray-900);
  --art-desk: #8b5a35;
  --art-desk-top: #a8703f;
  --art-desk-line: #6f4426;
  --art-paper: var(--palette-white);
  --art-paper-2: #fff3b0;
  --art-mug: var(--palette-blue-500);
  --art-steam: var(--palette-red-600);
  --art-star: #ffc400;

  /* Nền văn phòng */
  --office-wall: #ece6da;
  --office-wall-shade: #e2dacb;
  --office-floor: #7d8a99;
  --office-floor-line: #74808e;
  --office-baseboard: #5d6670;
  --office-frame: #ffffff;
  --office-sky-top: #9fd2f5;
  --office-sky-bottom: #e3f3ff;
  --office-city: #a9bfd3;
  --office-card: rgba(255, 255, 255, 0.86);
  --office-cell: rgba(255, 255, 255, 0.55);
  --office-cell-flash: rgba(255, 255, 255, 0.95);
  --bubble-bg: var(--palette-white);
  --bubble-text: var(--palette-gray-900);
  --bubble-border: var(--palette-gray-900);
}

/* Văn phòng buổi tối khi máy để chế độ tối */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --office-wall: #2b2a2e; --office-wall-shade: #252428;
    --office-floor: #2f3640; --office-floor-line: #2a3039;
    --office-baseboard: #1c2026; --office-frame: #4a4a50;
    --office-sky-top: #0d1b33; --office-sky-bottom: #26385a; --office-city: #3c4d6b;
    --office-card: rgba(22, 22, 23, 0.86); --office-cell: rgba(0, 0, 0, 0.35);
    --office-cell-flash: rgba(255, 255, 255, 0.18);
  }
}
:root[data-theme="dark"] {
  --office-wall: #2b2a2e; --office-wall-shade: #252428;
  --office-floor: #2f3640; --office-floor-line: #2a3039;
  --office-baseboard: #1c2026; --office-frame: #4a4a50;
  --office-sky-top: #0d1b33; --office-sky-bottom: #26385a; --office-city: #3c4d6b;
  --office-card: rgba(22, 22, 23, 0.86); --office-cell: rgba(0, 0, 0, 0.35);
  --office-cell-flash: rgba(255, 255, 255, 0.18);
}

/* ----- Nền trang ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--office-wall);
  color: var(--color-text);
  font-family: var(--font-text);
  font-size: var(--text-body-size);
  line-height: var(--text-body-line);
  letter-spacing: var(--text-body-tracking);
  overflow-x: hidden;
}

/* ----- Nền văn phòng ------------------------------------------------- */
.office {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, transparent 0 120px, var(--office-wall-shade) 120px 122px),
    var(--office-wall);
}
.office-window {
  position: absolute;
  top: 8%;
  width: min(30vw, 340px);
  height: 34%;
  border: 10px solid var(--office-frame);
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  background:
    linear-gradient(var(--office-frame), var(--office-frame)) center / 6px 100% no-repeat,
    linear-gradient(var(--office-frame), var(--office-frame)) center / 100% 6px no-repeat,
    linear-gradient(to top, var(--office-city) 0 22%, transparent 22%) 0 0 / 100% 100% no-repeat,
    repeating-linear-gradient(90deg, var(--office-city) 0 14%, transparent 14% 20%, var(--office-city) 20% 28%, transparent 28% 33%) bottom / 100% 40% no-repeat,
    linear-gradient(var(--office-sky-top), var(--office-sky-bottom));
}
.office-window-left { left: 4%; }
.office-window-right { right: 4%; }
.office-clock {
  position: absolute;
  top: 6%;
  left: 50%;
  width: 54px;
  height: 54px;
  margin-left: -27px;
  border-radius: 50%;
  border: 4px solid var(--palette-gray-800);
  background:
    linear-gradient(var(--palette-gray-900), var(--palette-gray-900)) 50% 30% / 3px 40% no-repeat,
    linear-gradient(var(--palette-red-600), var(--palette-red-600)) 62% 50% / 34% 2px no-repeat,
    var(--palette-white);
}
.office-board {
  position: absolute;
  top: calc(6% + 70px);
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  padding: 6px 14px;
  border: 4px solid var(--palette-gray-500);
  border-radius: 4px;
  background: var(--palette-white);
  color: var(--palette-red-600);
  font: var(--font-weight-bold) 14px/1.2 var(--font-display);
  white-space: nowrap;
}
.office-floor {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 28%;
  border-top: 10px solid var(--office-baseboard);
  background:
    repeating-linear-gradient(90deg, transparent 0 60px, var(--office-floor-line) 60px 62px),
    var(--office-floor);
}
.office-plant {
  position: absolute;
  left: 3%;
  bottom: 6%;
  width: 60px;
  height: 110px;
  background:
    radial-gradient(ellipse 14px 30px at 30% 35%, #3f8f4a 98%, transparent) ,
    radial-gradient(ellipse 14px 30px at 70% 35%, #3f8f4a 98%, transparent),
    radial-gradient(ellipse 12px 34px at 50% 28%, #4fa65b 98%, transparent),
    linear-gradient(#c0643a, #a4522d) bottom / 70% 38% no-repeat;
}
@media (max-width: 600px) {
  .office-window { width: 38vw; height: 22%; }
  .office-board, .office-plant { display: none; }
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

.app {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-10) var(--page-gutter);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen {
  width: auto;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  --card-pad: clamp(var(--space-2), 3vw, var(--space-10));
  padding: var(--space-6) var(--card-pad) var(--space-8);
  border-radius: var(--radius-lg);
  background: var(--office-card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.screen[hidden] { display: none; }

/* Vùng game: chạm không chọn chữ, không hiện menu lưu ảnh */
.app, .game-area {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.num { font-variant-numeric: tabular-nums; }

/* ----- Chữ ------------------------------------------------------------- */
.title {
  margin: var(--space-6) 0 var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-h1-size);
  line-height: var(--text-h1-line);
  letter-spacing: var(--text-h1-tracking);
  font-weight: var(--font-weight-semibold);
}
.lead {
  margin: 0 0 var(--space-6);
  font-family: var(--font-display);
  font-size: var(--text-lead-size);
  line-height: var(--text-lead-line);
  letter-spacing: var(--text-lead-tracking);
  color: var(--color-text-secondary);
}
.body-text { margin: 0 0 var(--space-4); font-size: var(--text-body-size); }
.label {
  margin: var(--space-2) 0 0;
  font-size: var(--text-lead-size);
  line-height: var(--text-lead-line);
  color: var(--color-text-secondary);
}
.big-num {
  margin: var(--space-2) 0 var(--space-4);
  font-family: var(--font-display);
  font-size: var(--text-h1-size);
  line-height: var(--text-h1-line);
  font-weight: var(--font-weight-semibold);
}
.badge-new {
  margin: 0 0 var(--space-4);
  color: var(--color-accent);
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-h4-size);
  line-height: var(--text-h4-line);
}
.badge-new[hidden] { display: none; }

.start-art { width: 120px; height: 120px; }

/* ----- Nút (theo design-system) --------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  margin-top: var(--space-4);
  padding: var(--button-padding-y) var(--button-padding-x);
  border: 1px solid transparent; border-radius: var(--radius-pill);
  font-family: var(--font-text); font-size: var(--text-small-size);
  line-height: var(--text-small-line); letter-spacing: var(--text-small-tracking);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard),
              opacity var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
}
.btn:active { transform: scale(0.97); }
.btn:focus { outline: none; }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn-primary { background: var(--color-accent); color: var(--color-accent-text); }
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-lg {
  padding: var(--button-lg-padding-y) var(--button-lg-padding-x);
  font-size: var(--text-body-size); letter-spacing: var(--text-body-tracking);
}
.btn[aria-disabled="true"] { opacity: 0.42; cursor: default; transform: none; }
.btn[aria-disabled="true"]:hover { background: var(--color-accent); }

/* ----- MH-02 · Đang chơi ---------------------------------------------- */
.screen-play {
  /* Kích thước ô theo tài liệu: clamp(80px, 28vw, 140px), và không vượt quá
     bề rộng còn lại sau lề trang để 320px không bị cuộn ngang. */
  --gap: clamp(var(--space-2), 2vw, var(--space-3));
  --cell: clamp(80px,
                min(28vw, (100vw - 2 * var(--page-gutter) - 2 * var(--card-pad) - (var(--grid-cols) - 1) * var(--gap)) / var(--grid-cols)),
                140px);
  --grid-width: calc(var(--grid-cols) * var(--cell) + (var(--grid-cols) - 1) * var(--gap));
}

.hud {
  width: var(--grid-width);
  max-width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  font-family: var(--font-display);
  font-size: var(--text-h4-size);     /* 21px ≥ 20px */
  line-height: var(--text-h4-line);
  font-weight: var(--font-weight-semibold);
  font-variant-numeric: tabular-nums;
}
.hud-time { display: inline-block; transform-origin: right center; }
.hud-time.is-warning { color: var(--color-danger); }
.hud-time.is-pulse { animation: pulse var(--duration-slow) var(--ease-standard); }

@keyframes pulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), var(--cell));
  grid-template-rows: repeat(var(--grid-rows), var(--cell));
  gap: var(--gap);
  justify-content: center;
  touch-action: manipulation;
  padding-top: var(--space-6);   /* chỗ cho bong bóng thoại ở hàng trên cùng */
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--office-cell);
  color: inherit;
  cursor: pointer;
  overflow: visible;
  display: grid;
  place-items: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.cell:focus { outline: none; }
.cell.is-up { z-index: 1; }
.cell-art { width: 84%; height: 84%; display: block; overflow: hidden; pointer-events: none; }

/* Hình vẽ */
.svg-skin      { fill: var(--art-skin); }
.svg-skin-dark { fill: var(--art-skin-dark); }
.svg-bump      { fill: #f0a58a; }
.svg-hair      { fill: var(--art-hair); }
.svg-suit      { fill: var(--art-suit); }
.svg-shirt     { fill: var(--art-shirt); }
.svg-tie       { fill: var(--art-tie); }
.svg-eye       { fill: var(--art-ink); }
.svg-mustache  { fill: var(--art-ink); }
.svg-mouth     { fill: var(--art-ink); }
.svg-brow, .svg-frown, .svg-glasses, .svg-eye-x, .svg-shine, .svg-steam {
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.svg-brow    { stroke: var(--art-ink); stroke-width: 3; }
.svg-frown   { stroke: var(--art-ink); stroke-width: 1.8; }
.svg-glasses { stroke: var(--art-ink); stroke-width: 1.4; }
.svg-eye-x   { stroke: var(--art-ink); stroke-width: 2.4; }
.svg-shine   { stroke: rgba(255, 255, 255, 0.7); stroke-width: 2; }
.svg-steam   { stroke: var(--art-steam); stroke-width: 2.2; opacity: 0.75; }
.svg-star    { fill: var(--art-star); }
.svg-desk     { fill: var(--art-desk); }
.svg-desk-top { fill: var(--art-desk-top); }
.svg-desk-line { fill: var(--art-desk-line); }
.svg-paper    { fill: var(--art-paper); stroke: var(--palette-gray-300); stroke-width: 0.8; }
.svg-paper-2  { fill: var(--art-paper-2); }
.svg-mug      { fill: var(--art-mug); }
.svg-mug-handle { fill: none; stroke: var(--art-mug); stroke-width: 2; }

/* Sếp: ẩn sau bàn, trượt lên khi .is-up */
.mole {
  transform: translateY(64px);
  transition: transform var(--anim-ms) var(--ease-standard);
}
.cell.is-up .mole { transform: translateY(0); }
.mole-hit { display: none; }
.cell.is-hit .mole-normal { display: none; }
.cell.is-hit .mole-hit { display: inline; }

/* Bong bóng thoại “Xong chưa???” trên đầu sếp */
.bubble {
  position: absolute;
  left: 50%;
  bottom: 76%;
  z-index: 2;
  padding: 3px 9px;
  border: 2px solid var(--bubble-border);
  border-radius: 12px;
  background: var(--bubble-bg);
  color: var(--bubble-text);
  font-family: var(--font-display);
  font-size: clamp(11px, 3.2vw, 15px);
  line-height: 1.25;
  font-weight: var(--font-weight-bold);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 6px) scale(0.6);
  transform-origin: 50% 100%;
  transition: opacity var(--anim-ms) var(--ease-standard),
              transform var(--anim-ms) var(--ease-standard);
}
.bubble::before, .bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  border-style: solid;
  border-color: transparent;
}
.bubble::before {     /* viền đuôi */
  top: 100%;
  margin-left: -7px;
  border-width: 8px 7px 0;
  border-top-color: var(--bubble-border);
}
.bubble::after {      /* lõi đuôi */
  top: 100%;
  margin-left: -4.5px;
  margin-top: -1px;
  border-width: 5.5px 4.5px 0;
  border-top-color: var(--bubble-bg);
}
.cell.is-up:not(.is-hit) .bubble {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

/* Ô nháy sáng khi đập trúng */
.cell.is-flash { animation: flash var(--duration-slow) var(--ease-standard); }
@keyframes flash {
  0%   { background: var(--office-cell-flash); box-shadow: inset 0 0 0 2px var(--color-success); }
  100% { background: var(--office-cell); box-shadow: inset 0 0 0 2px transparent; }
}

/* “+1” bay lên và mờ dần */
.plus {
  position: absolute;
  top: var(--space-2);
  right: var(--space-3);
  font-weight: var(--font-weight-bold);
  font-size: var(--text-h4-size);
  color: var(--color-success);
  opacity: 0;
  pointer-events: none;
}
.plus.is-showing { animation: plus-fly var(--duration-slow) var(--ease-standard) forwards; }
@keyframes plus-fly {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-24px); }
}
@keyframes plus-static {
  0%, 99% { opacity: 1; }
  100%    { opacity: 0; }
}

/* ----- CN-12 · Con trỏ búa (chỉ thiết bị có chuột) -------------------- */
@media (pointer: fine) {
  .grid, .cell {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cg transform='rotate(-45 16 16)'%3E%3Crect x='14.5' y='12' width='3' height='18' rx='1.5' fill='%2386868b' stroke='%23ffffff' stroke-width='1'/%3E%3Crect x='7' y='4' width='18' height='9' rx='2' fill='%23424245' stroke='%23ffffff' stroke-width='1.2'/%3E%3C/g%3E%3C/svg%3E") 10 10, pointer;
  }
}

/* ----- Giảm chuyển động ----------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .mole, .bubble { transition: none; }
  .btn { transition: none; }
  .btn:active { transform: none; }
  .hud-time.is-pulse { animation: none; }
  .cell.is-flash { animation: none; }
  .plus.is-showing { animation: plus-static var(--duration-slow) linear forwards; }
}
