/* football-site — CSS thuần.
   Bố cục bằng flex: sân và danh sách là hai flex item, sân tự co theo cả hai chiều bằng
   aspect-ratio + container query. Chỉ MỘT media query (< 600px) cho khay dưới cùng thanh kéo. */

:root {
  /* Nền tối là mặc định. Sân xanh và thẻ vàng là hai chỗ sáng nhất — cố ý. */
  --bg: #101309;
  --surf: #191d12;
  --surf2: #22271b;
  --line: #2f3527;
  --ink: #e8eadd;
  --ink2: #99a38c;
  --accent: #22c55e;
  --accent-ink: #06210f;
  /* Chữ "Chấn thương": #f87171 đạt 6,19:1 trên nền tối (#c0392b chỉ 3,15:1). */
  --danger: #f87171;
  --blue: #1c5fd0;
  --red: #cf3a26;
  /* Thẻ vàng FIFA: giữ nguyên mã, không pha tối. */
  --gold-1: #fdf3c8;
  --gold-2: #eccb63;
  --gold-3: #c9a03a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  --tap: 44px;
  accent-color: var(--accent);
  color-scheme: dark;
}

* { box-sizing: border-box; }

*,
*::before,
*::after { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); }

/* Thuộc tính hidden phải thắng các lớp có display riêng (.btn, .btn-block...) */
[hidden] { display: none !important; }

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select { font-family: inherit; }

button { color: inherit; }

/* Ô nhập >= 16px để Safari không tự phóng to khi chạm vào. */
input,
select,
textarea { font-size: 16px; }

.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--ink2);
}

/* ---------- Khung ứng dụng: một màn ---------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--surf);
  border-bottom: 1px solid var(--line);
}

.lineup-open {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  min-height: var(--tap);
  max-width: 40vw;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  min-width: 0;
}

.lineup-open .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Nhóm trái của thanh trên: Lưu (nút chính) rồi tới + Sơ đồ, trước tên sơ đồ. */
.lineup-save,
.lineup-add {
  flex: none;
  padding: 6px 12px;
  font-weight: 700;
  white-space: nowrap;
}

.lineup-open .sub {
  font-weight: 400;
  color: var(--ink2);
  font-size: 12px;
  white-space: nowrap;
}

.lineup-open[disabled] { cursor: default; }

.mode-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surf2);
}

.mode-switch button {
  min-height: var(--tap);
  padding: 4px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  color: var(--ink2);
  font-weight: 700;
  font-size: 13.5px;
}

.mode-switch button[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.btn {
  min-height: var(--tap);
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surf2);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.btn-solid { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { display: block; width: 100%; }
.btn-danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.45); }

.linklike {
  border: 0;
  background: none;
  padding: 6px 2px;
  color: var(--ink2);
  text-decoration: underline;
  cursor: pointer;
  font-size: 13px;
}

a.linklike { text-decoration: underline; }

/* ---------- Menu tài khoản ---------- */

.account { position: relative; }

.account-name {
  display: inline-block;
  max-width: 32vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
}

.menu-item {
  min-height: var(--tap);
  padding: 8px 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  text-align: left;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}

.menu-item:hover { background: var(--surf2); }

/* Nhãn "Chỉ xem" / "Quản trị" */
.view-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surf2);
  color: var(--ink2);
  white-space: nowrap;
}

.view-badge.admin { background: rgba(34, 197, 94, 0.16); color: var(--accent); }

/* ---------- Hai cột: flex, không breakpoint ---------- */

.board-area {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}

.board {
  flex: 1 1 0;
  min-width: 240px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 4px;
}

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  container-type: size;
}

/* Sân: khung ngoài SVG có viewBox -2 -2.6 24 45.2 (chừa lề cho khung thành và vạch thay người),
   bên trong khung đó phần sân thật đúng 20 × 40. Sân co theo chiều nào chật hơn, không bao giờ tràn. */
.stage {
  position: relative;
  flex: none;
  aspect-ratio: 24 / 45.2;
  height: min(100%, calc(100cqw * 45.2 / 24));
  width: auto;
  max-width: 100%;
}

.stage > img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Phần sân thật 20 × 40 m nằm trong khung SVG ở các tỉ lệ này; chấm cầu thủ đặt theo % ở đây. */
.pitch-area {
  position: absolute;
  left: 8.3333%;
  top: 5.7522%;
  width: 83.3333%;
  height: 88.4956%;
  container-type: size;
  /* Chỉ nơi này đặt bề rộng thẻ; --ch suy ra từ đây. */
  --cw: clamp(34px, calc(100cqw / 7.6), 58px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Thẻ cầu thủ trên sân: thẻ vàng FIFA thu nhỏ, viền 3 màu theo vùng. */
.dot {
  --ch: calc(var(--cw) * 1.36);
  position: absolute;
  width: var(--cw);
  height: var(--ch);
  transform: translate(-50%, -50%);
  border-radius: 7px;
  border: 3px solid #9aa08e;
  overflow: visible; /* huy hiệu chấn thương nằm ở góc ngoài, không bị cắt */
  color: #fff;
  background: radial-gradient(
    120% 80% at 22% 0%,
    #fff8d0 0%,
    #eedd9c 24%,
    #c8a63c 54%,
    #87690f 80%,
    #4d3a08 100%
  );
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.44);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  z-index: 2;
  transition: border-color 0.1s ease, transform 0.08s ease;
}

/* Số áo: góc trên-trái */
.dot .pno {
  position: absolute;
  left: 4%;
  top: 0;
  font-size: calc(var(--cw) * 0.4);
  font-weight: 900;
  line-height: 1.02;
  color: #3a2c05;
  font-family: "Trebuchet MS", sans-serif;
  letter-spacing: -0.03em;
}

/* Hình bóng người ở giữa */
.dot .pfig {
  position: absolute;
  left: 50%;
  bottom: calc(var(--ch) * 0.19);
  transform: translateX(-50%);
  height: calc(var(--ch) * 0.5);
  width: auto;
  opacity: 0.32;
}

/* Tên ngắn ở đáy */
.dot .pnm {
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: 1px;
  text-align: center;
  font-size: calc(var(--cw) * 0.165);
  font-weight: 900;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
}

.dot[data-fit="ok"] {
  border-color: #16a34a;
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.4), 0 2px 6px rgba(0, 0, 0, 0.44);
}

.dot[data-fit="sec"] {
  border-color: #eab308;
  box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.4), 0 2px 6px rgba(0, 0, 0, 0.44);
}

.dot[data-fit="bad"] {
  border-color: #dc2626;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.4), 0 2px 6px rgba(0, 0, 0, 0.44);
}

/* Huy hiệu chấn thương: góc ngoài trên-trái */
.dot > .inj {
  position: absolute;
  left: -9px;
  top: -9px;
  width: 21px;
  height: 16px;
  z-index: 4;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

/* Nhãn cảnh báo nổi phía trên thẻ khi viền đỏ */
.dot .warn {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 13px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: none;
  z-index: 7;
}

/* Thẻ sát mép trên sân: lật nhãn xuống dưới thẻ */
.dot .warn.below {
  bottom: auto;
  top: calc(100% + 13px);
}

.dot .warn .pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px 2px 3px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.dot .warn .pill svg {
  display: block;
  flex: none;
  width: 11px;
  height: 10px;
}

/* Chấm đội ở góc trên-phải: bấm để đổi đội (chỉ chế độ đấu tập) */
.dot .team-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  z-index: 5;
}

.dot .team-badge::after {
  /* vùng chạm rộng hơn hình vẽ */
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
}

.dot[data-team="B"] .team-badge { background: var(--red); }

.dot.dragging {
  z-index: 6;
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.45);
}

/* Thẻ sắp bị đè: vòng sáng trắng để thấy trước khi thả (đổi chỗ) */
.dot.swap-target {
  box-shadow: 0 0 0 3px #fff, 0 0 0 7px #fff5;
  transform: translate(-50%, -50%) scale(1.06);
  z-index: 4;
}


.dot.outside { opacity: 0.55; outline: 2px dashed rgba(22, 32, 43, 0.55); outline-offset: 3px; }

.dot.ghost {
  position: fixed;
  z-index: 300;
  pointer-events: none;
  opacity: 0.95;
  --cw: 46px;
}

/* Khách chỉ xem: thẻ không kéo được */
.pitch-area.read-only .dot { cursor: default; }

.hint {
  flex: none;
  margin: 2px 0 0;
  text-align: center;
  color: var(--ink2);
  font-size: 12px;
  line-height: 1.25;
}

/* ---------- Danh sách ---------- */

.squad {
  flex: 0 1 300px;
  min-width: 260px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surf);
  border-left: 1px solid var(--line);
}

.sheet-handle { display: none; }

.squad-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  min-height: 0;
  flex: 1;
}

/* ---------- Bộ lọc theo vị trí ở đầu danh sách ---------- */

.pos-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 1px 0;
  flex: none;
}

.fchip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surf);
  color: var(--ink2);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  flex: none;
  cursor: pointer;
}

.fchip .fnum { font-size: 11px; font-weight: 700; opacity: 0.7; }
.fchip:not(:disabled):hover { color: var(--ink); border-color: #46503a; }
.fchip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.fchip.on .fnum { opacity: 0.75; }
.fchip:disabled { opacity: 0.35; cursor: default; }
.fchip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.prow {
  display: grid;
  grid-template-columns: 44px 34px 1fr auto;
  gap: 6px;
  align-items: center;
  min-height: 48px;
  padding: 4px 6px;
  border-radius: 10px;
  cursor: pointer;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.prow.on-pitch { opacity: 0.45; }
.prow.drag-src { opacity: 0.25; }

/* Vùng cầm để kéo vào sân: chạm vào đây thì kéo luôn, không bị Safari cuộn danh sách. */
.prow .grip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  touch-action: none;
  cursor: grab;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surf2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--ink2);
  font-size: 13px;
  flex: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.shirt {
  min-width: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
  background: var(--surf2);
  border-radius: 7px;
  padding: 2px 4px;
  font-size: 13px;
}

.pcol { min-width: 0; }

.pname {
  display: block;
  font-weight: 600;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ppos {
  display: block;
  font-size: 12px;
  color: var(--ink2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty {
  color: var(--ink2);
  font-size: 13.5px;
  padding: 14px 8px;
  text-align: center;
}

.squad-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
  font-size: 12.5px;
  color: var(--ink2);
}

.squad-foot .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Chấn thương ---------- */

.inj {
  display: inline-block;
  vertical-align: -1px;
  flex: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}

.prow .inj { width: 14px; height: 10.5px; }

.r-inj { color: var(--danger); font-weight: 800; }

/* Vị trí phụ giải thích vì sao cầu thủ này lọt bộ lọc đang chọn. */
.r-hit {
  display: inline-block;
  padding: 0 4px;
  border-radius: 5px;
  background: rgba(34, 197, 94, 0.18);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  vertical-align: 1px;
}

/* thẻ FIFA: góc trên-phải */
.card-inj {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  line-height: 0;
}

.card-inj .inj { width: 24px; height: 18px; }

/* ---------- Nút sửa cầu thủ trong danh sách ---------- */

.edit-btn {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surf2);
  color: var(--ink2);
  cursor: pointer;
}

.edit-btn svg { width: 18px; height: 18px; }

/* ---------- Công tắc trong form ---------- */

.switch-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 6px 2px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.switch-line input { width: 22px; height: 22px; margin: 0; }

/* ---------- Hộp thoại ---------- */

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 100vw;
  max-height: 100dvh;
  margin: auto;
}

dialog::backdrop {
  background: #0b0d08cc;
  backdrop-filter: blur(3px);
}

.sheet {
  width: min(440px, calc(100vw - 20px));
  background: var(--surf);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet h2 { margin: 0; font-size: 18px; }

.field { display: flex; flex-direction: column; gap: 5px; }

.field > label,
.field > .label { font-size: 13px; font-weight: 700; color: var(--ink2); }

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}

/* Ô chọn tệp của trình duyệt: nút mặc định là màu sáng, phải đổi cho hợp nền tối */
input[type="file"] { color: var(--ink2); font-size: 13px; max-width: 100%; }

input[type="file"]::file-selector-button {
  margin-right: 8px;
  padding: 8px 12px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surf2);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.checks { display: flex; flex-wrap: wrap; gap: 6px; }

.checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  background: var(--surf2);
  color: var(--ink);
}

.checks label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}
.checks input { margin: 0; width: 16px; height: 16px; }

.foot-row { display: flex; gap: 10px; }

/* Hai nút giày: bật thì sáng, tắt thì mờ */
.boot-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  min-height: var(--tap);
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surf2);
  cursor: pointer;
}

.boot-btn[aria-pressed="true"] { border-color: var(--accent); background: rgba(34, 197, 94, 0.14); }

/* Đôi giày chân thuận: chân thuận sáng, chân kia mờ */
.boots {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  vertical-align: -2px;
}

.boots .boot { color: var(--ink2); opacity: 0.45; }
.boots .boot.on { color: var(--accent); opacity: 1; }
.boots .boot.flip { transform: scaleX(-1); }

/* Trên thẻ vàng FIFA: nâu đậm cho chân sáng, nâu nhạt mờ cho chân kia */
.boots.gold .boot.on { color: #2f2403; opacity: 1; }
.boots.gold .boot.off { color: #7a6320; opacity: 0.3; }

.boot-btn .boot { color: var(--ink2); opacity: 0.45; }
.boot-btn[aria-pressed="true"] .boot { color: var(--accent); opacity: 1; }

/* Mã vị trí trong vòng tròn đầu dòng khi cầu thủ chưa có ảnh */
.avatar:has(.pos-code) {
  width: 36px;
  height: 36px;
  background: transparent;
  box-shadow: none;
}

.pos-code {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: var(--surf2);
  color: var(--ink2);
}

.pos-code[data-pos="gk"] { background: #3a2f10; color: #f0c04a; }
.pos-code[data-pos="fixo"] { background: #1c2a44; color: #8fb2f0; }
.pos-code[data-pos="ala_l"] { background: #12302b; color: #4fd1b8; }
.pos-code[data-pos="ala_r"] { background: #251f3d; color: #b9a6f5; }
.pos-code[data-pos="pivo"] { background: #3a1f1c; color: #f09080; }

.photo-row { display: flex; align-items: center; gap: 12px; }

.photo-prev {
  width: 66px;
  height: 66px;
  border-radius: 12px;
  background: var(--surf2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
  color: var(--ink2);
  font-size: 11px;
  text-align: center;
}

.photo-prev img { width: 100%; height: 100%; object-fit: cover; display: block; }

.file-line { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.file-line input[type="file"] { font-size: 14px; max-width: 100%; }

.small { font-size: 12px; color: var(--ink2); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.sheet-actions .grow { margin-right: auto; }

/* Danh sách sơ đồ */
/* Ô tạo sơ đồ mới: dòng đầu của hộp thoại, chỉ quản trị viên thấy */
.lineup-new {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 10px;
}

.lineup-new input {
  flex: 1;
  min-width: 0;
}

.lineup-new[hidden] { display: none; }

/* Sơ đồ đang mở: viền xanh, nền sáng hơn một chút */
.lineup-list li.active {
  background: rgba(34, 197, 94, 0.12);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.lineup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.lineup-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surf2);
  min-height: 52px;
}

.lineup-list .lcol {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.lineup-list .lname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lineup-list .lmeta { font-size: 12px; color: var(--ink2); }

.badge {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surf2);
  color: var(--ink2);
  white-space: nowrap;
}

/* ---------- Thẻ cầu thủ (FIFA UT, thẻ vàng) ---------- */

.card-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.card-gold {
  position: relative;
  width: 262px;
  aspect-ratio: 262 / 368;
  border-radius: 16px;
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  color: #40320c;
  background:
    radial-gradient(120% 80% at 20% 0%, #fff9dd 0%, rgba(255, 249, 221, 0) 62%),
    linear-gradient(158deg, var(--gold-1) 0%, var(--gold-2) 46%, var(--gold-3) 100%);
  box-shadow: 0 14px 30px rgba(80, 60, 10, 0.3), inset 0 0 0 1px rgba(255, 255, 255, 0.55);
  overflow: hidden;
}

.card-gold::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 11px;
  pointer-events: none;
}

.card-head { display: flex; align-items: flex-start; gap: 8px; position: relative; z-index: 1; }

.card-num {
  font-size: 44px;
  line-height: 0.92;
  font-weight: 800;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  color: #3a2c08;
}

.card-sub {
  display: flex;
  flex-direction: column;
  padding-top: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #5a4712;
}

.card-photo {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin: 4px -4px 0;
}

.card-photo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(80, 60, 10, 0.25));
}

.card-photo svg { width: 72%; max-height: 100%; fill: #8d7a45; opacity: 0.85; }

.card-name {
  position: relative;
  z-index: 1;
  margin: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-chips {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.chip {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.45);
  color: #5a4712;
  white-space: nowrap;
}

.chip.primary { background: #3a2c08; color: var(--gold-1); }

.card-tools { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- Ghi chú của HLV (dưới thẻ cầu thủ) ---------- */

.note-block {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.note-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink2);
}

.note-block textarea {
  width: 100%;
  min-height: 76px; /* ~3 dòng, giãn được */
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px; /* để Safari không tự phóng to */
  line-height: 1.4;
  resize: vertical;
}

.note-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.note-status { font-size: 13px; font-weight: 700; color: var(--accent); }

/* ---------- Thông báo ---------- */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 500;
  pointer-events: none;
  width: max-content;
  max-width: 92vw;
}

.toast {
  background: rgba(34, 39, 27, 0.97);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px 15px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
}

/* ---------- Khay dưới: media query DUY NHẤT ---------- */

@media (max-width: 599px) {
  /* màn hẹp: sân trên, danh sách thành khay dưới — vẫn là flex, chỉ đổi hướng */
  .board-area {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  .board {
    flex: 1 1 auto;
    min-height: 0;
    padding: 4px 6px 0;
  }

  .squad {
    flex: 0 0 auto;
    min-width: 0;
    max-width: none;
    max-height: 45%;
    border-left: 0;
    border-top: 1px solid var(--line);
    transition: max-height 0.2s ease;
    overflow: hidden;
  }

  .squad.collapsed { max-height: 56px; }

  .sheet-handle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: var(--tap);
    padding: 16px 12px 8px;
    border: 0;
    background: transparent;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    position: relative;
  }

  .sheet-handle .grip-bar {
    position: absolute;
    left: 50%;
    top: 6px;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
  }

  .sheet-handle .count { margin-left: auto; color: var(--ink2); font-weight: 400; }

  .lineup-open { max-width: 46vw; font-size: 14px; }
  .lineup-open .sub { display: none; }

  .mode-switch button { padding: 4px 10px; }
  .btn { padding: 6px 10px; font-size: 13.5px; }

  .hint { display: none; }

  dialog { margin: auto 0 0; width: 100%; max-width: 100%; }

  .sheet {
    width: 100%;
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    max-height: 88dvh;
  }

  dialog[open] .sheet { animation: sheet-up 0.2s ease; }

  .toast-stack { bottom: calc(64px + env(safe-area-inset-bottom)); }
}

@keyframes sheet-up {
  from { transform: translateY(20px); opacity: 0.7; }
  to { transform: translateY(0); opacity: 1; }
}

/* Tiêu đề cấp 1 chỉ dành cho trình đọc màn hình: trang chỉ có một h1, các hộp thoại dùng h2. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Người dùng yêu cầu giảm chuyển động: bỏ hết chuyển tiếp và hiệu ứng vào hình. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
