/* ==========================================================================
   Đập Chuột — giao diện. Mọi màu, chữ, khoảng cách lấy từ ../design/tokens.css
   Chỉ chủ đề ban ngày (không dùng data-theme="night").
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--color-text);
  background-color: var(--color-bg-field);
  background-image:
    linear-gradient(45deg, var(--color-bg-field-dark) 25%, transparent 25%),
    linear-gradient(-45deg, var(--color-bg-field-dark) 25%, transparent 25%);
  background-size: 24px 24px;
  overflow: hidden;                 /* không cần cuộn khi chơi */
  -webkit-user-select: none;
  user-select: none;                /* không chọn chữ */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;       /* chạm nhanh không zoom */
}
body::before {                      /* làm hoa văn cỏ nhạt đi */
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: var(--color-bg-field); opacity: .55; pointer-events: none;
}

[hidden] { display: none !important; }

:root { --debug-h: 0px; }
body.is-debug { --debug-h: 8.5rem; }

.app {
  height: calc(100vh - var(--debug-h));
  height: calc(100dvh - var(--debug-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
}

.screen { width: 100%; max-width: 32rem; }

/* ---------- Khung nội dung ---------- */
.panel {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-raised);
  padding: var(--space-5) var(--space-4);
}
.panel--center { text-align: center; }
.panel--dark {
  background: var(--color-dark);
  color: var(--color-text-on-dark);
  border-color: var(--color-dark);
}
.panel p { margin: 0 0 var(--space-4); }

.game-title, .over-title {
  font-family: var(--font-display);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-display);
  text-transform: uppercase;
  line-height: var(--line-height-tight);
  margin: 0 0 var(--space-4);
}
.game-title { font-size: var(--font-size-3xl); }
.over-title { font-size: var(--font-size-2xl); }

.rules { color: var(--color-text-muted); }
.record-line { font-family: var(--font-display); font-size: var(--font-size-md); }
.over-label { color: var(--color-text-on-dark); opacity: .8; margin-bottom: 0 !important; }
.over-score {
  font-family: var(--font-display);
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  line-height: 1.1;
}
.new-record {
  font-family: var(--font-display);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-md);
  color: var(--color-status-yellow);
  text-shadow: var(--text-shadow-pixel);
}

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--touch-target-min);           /* >= 44px */
  padding: var(--space-2) var(--space-5);
  font-family: var(--font-display);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-display);
  text-transform: uppercase;
  color: var(--color-text-on-primary);
  background: var(--color-primary);
  border: var(--border-width) solid var(--color-primary-hover);
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--easing), transform var(--duration-fast) var(--easing);
}
.btn:hover { background: var(--color-primary-hover); }
.btn:active { background: var(--color-primary-active); transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn--action { min-width: 12rem; min-height: var(--control-height-lg); }

/* ---------- Thanh thông tin ---------- */
.hud {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  min-height: var(--control-height);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-overlay);
  color: var(--color-text-on-dark);
  font-family: var(--font-display);
  font-size: var(--font-size-md);
  white-space: nowrap;
}
.hud__time { transition: color var(--duration-base) var(--easing); }
.hud__time.is-warning { color: var(--color-danger); font-weight: var(--font-weight-bold); }
.hud__combo {
  display: inline-block;
  padding: 0 var(--space-2);
  background: var(--color-warning);
  color: var(--color-dark);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-sm);
}
.hud__combo.is-bump { animation: bump 220ms var(--easing); }
@keyframes bump {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---------- Lưới 3×3 ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: var(--space-2);
  aspect-ratio: 1 / 1;
  /* luôn vuông và nằm trọn màn hình: lấy cạnh nhỏ hơn giữa bề ngang và phần cao còn lại */
  width: min(100%, calc(100vh - var(--debug-h) - 6.5rem));
  width: min(100%, calc(100dvh - var(--debug-h) - 6.5rem));
  margin: 0 auto;
  padding: var(--space-2);
  background: var(--color-bg-field-dark);
  border: var(--border-width-bold) solid rgba(0, 0, 0, 0.35);
  touch-action: none;               /* chạm/kéo trên lưới không cuộn, không zoom */
  /* con trỏ hình cái búa (SVG nhúng, không tải từ Internet) */
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'><g transform='rotate(-35 16 16)'><rect x='14' y='12' width='4' height='18' fill='%238a5a2b' stroke='%23222' stroke-width='1.5'/><rect x='6' y='4' width='20' height='10' fill='%23888' stroke='%23222' stroke-width='1.5'/></g></svg>") 6 6, pointer;
}

.cell {
  position: relative;
  min-width: 0; min-height: 0;
  padding: 0;
  overflow: hidden;
  border: var(--border-width-bold) solid rgba(0, 0, 0, 0.35);
  border-radius: var(--radius-none);
  background: var(--color-bg-field);
  box-shadow: var(--shadow-inset);
  cursor: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.cell:focus { outline: none; }
.cell:focus-visible { box-shadow: var(--shadow-focus); }

/* hang tối trên nền cỏ */
.cell::before {
  content: "";
  position: absolute;
  left: 15%; right: 15%; bottom: 12%;
  height: 26%;
  background: radial-gradient(ellipse at center, #1a1209 0%, #2b1d0e 55%, #4a3418 100%);
  border-radius: var(--radius-round);
  z-index: 1;
}

/* chuột: ngoi lên khỏi hang */
.mole {
  position: absolute;
  left: 0; right: 0; bottom: 20%;
  display: flex; justify-content: center;
  font-size: min(15vw, 3.4rem);
  line-height: 1;
  transform: translateY(35%);
  opacity: 0;
  transition: transform 90ms ease-out, opacity 60ms linear;
  z-index: 2;
  pointer-events: none;
}
.cell.has-mole .mole { transform: translateY(0); opacity: 1; }
/* vừa đập trúng: chuột bẹp */
.cell.is-hit .mole {
  transform: translateY(25%) scale(1.25, 0.45);
  transition: transform 60ms ease-in;
  filter: grayscale(.4);
}
/* vừa bấm trượt: ô nháy đỏ */
.cell.is-miss { animation: missFlash 360ms var(--easing); }
@keyframes missFlash {
  0%, 100% { background: var(--color-bg-field); }
  30%      { background: rgba(240, 65, 36, 0.55); box-shadow: inset 0 0 0 4px var(--color-danger); }
}

/* chữ +1/+2/+3 hoặc −1 nổi lên */
.float {
  position: absolute;
  left: 50%; top: 30%;
  transform: translate(-50%, 0);
  font-family: var(--font-display);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xl);
  text-shadow: var(--text-shadow-pixel);
  pointer-events: none;
  z-index: 3;
  animation: floatUp 450ms ease-out forwards;
}
.float--plus  { color: var(--color-status-lime); }
.float--minus {
  color: var(--color-danger);
  text-shadow: -2px -2px 0 var(--color-surface), 2px -2px 0 var(--color-surface),
               -2px 2px 0 var(--color-surface), 2px 2px 0 var(--color-surface);
}
@keyframes floatUp {
  0%   { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -60%); }
}

@media (max-width: 400px) {
  .game-title { font-size: var(--font-size-2xl); }
  .hud { font-size: var(--font-size-sm); padding: var(--space-2); }
  .btn--action { min-width: 10rem; }
}

/* ---------- Chế độ gỡ lỗi (?debug=1) ---------- */
.debug {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--debug-h);
  display: flex; flex-direction: column;
  background: var(--color-overlay);
  color: var(--color-text-on-dark);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  z-index: var(--z-toast);
  pointer-events: none;
}
.debug__head { padding: var(--space-1) var(--space-2); background: var(--color-dark); }
.debug__log { margin: 0; padding: var(--space-1) var(--space-2) var(--space-1) var(--space-6); overflow: auto; }
.debug .cell-tag { color: var(--color-status-yellow); }
.cell.debug-active { outline: 3px dashed var(--color-status-yellow); outline-offset: -5px; }

/* ==========================================================================
   Đăng ký người chơi (03 · 4.5, 4.6) — dùng token trong design/tokens.css
   ========================================================================== */
.screen--register { max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.register { text-align: left; -webkit-user-select: text; user-select: text; }
.register .game-title { text-align: center; margin-bottom: var(--space-1); }
.register__sub { text-align: center; color: var(--color-text-muted); margin-bottom: var(--space-4) !important; }

.field { margin-bottom: var(--space-3); }
.field__label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
}
.input {
  display: block;
  width: 100%;
  min-height: var(--touch-target-min);           /* >= 44px để dễ chạm */
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: 1rem;                                /* >= 16px: Safari iPhone không tự phóng to khi gõ */
  color: var(--color-text);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-input);
  -webkit-user-select: text;
  user-select: text;
}
.input::placeholder { color: var(--color-text-muted); }
.input:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--shadow-focus); }
.field.is-invalid .input { border-color: var(--color-danger); }
.field.is-invalid .input:focus { box-shadow: 0 0 0 3px rgba(240, 65, 36, 0.3); }
.field__error {
  margin: var(--space-1) 0 0 !important;
  min-height: 0;
  font-size: var(--font-size-sm);
  color: var(--color-danger);
}
.field__error:empty { display: none; }

.check { display: flex; align-items: flex-start; gap: var(--space-2); font-size: var(--font-size-sm); cursor: pointer; }
.check input { flex: none; width: 1.25rem; height: 1.25rem; margin: 2px 0 0; accent-color: var(--color-primary); }
.field.is-invalid .check input { outline: 2px solid var(--color-danger); outline-offset: 1px; }

.link {
  display: inline;
  padding: 0;
  font: inherit;
  color: var(--color-link);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}
.link:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.form__error {
  margin: 0 0 var(--space-3) !important;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-danger);
  background: #fde6e1;
  border-left: 4px solid var(--color-danger);
}
.btn--block { display: flex; width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; transform: none; }

/* Màn hình Bắt đầu: lời chào, ghi chú, liên kết */
.greeting { font-family: var(--font-display); font-size: var(--font-size-md); margin-top: calc(var(--space-2) * -1) !important; }
.pending-note { margin: var(--space-3) 0 0 !important; font-size: var(--font-size-xs); color: var(--color-text-muted); }
.not-me { margin: var(--space-3) 0 0 !important; font-size: var(--font-size-sm); }

/* Hộp thông báo xử lý dữ liệu */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  background: var(--color-backdrop);
}
.modal__box { width: 100%; max-width: 30rem; max-height: 100%; overflow-y: auto; -webkit-user-select: text; user-select: text; }
.modal__title { font-family: var(--font-display); font-size: var(--font-size-lg); margin: 0 0 var(--space-3); }
.modal__body p { margin: 0 0 var(--space-3); }
