:root {
  --ink: #111111;
  --ink-soft: #6b6b6b;
  --line: #e2e2e2;
  --line-strong: #111111;
  --paper: #ffffff;
  --paper-soft: #f7f7f7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Thuộc tính hidden phải thắng mọi display khai báo bên dưới */
[hidden] { display: none !important; }

body {
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Thanh trên ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; letter-spacing: .5px;
  color: var(--paper); background: var(--ink);
  background-size: cover; background-position: center;
}
.brand-mark.has-logo { background-color: var(--paper-soft); border: 1px solid var(--line); }
.brand strong { display: block; font-size: 16px; font-weight: 600; letter-spacing: -.2px; }
.brand small { color: var(--ink-soft); font-size: 12px; }
.admin-link {
  color: var(--ink); text-decoration: none; font-size: 13px;
  border: 1px solid var(--line-strong); padding: 8px 16px; border-radius: 999px;
  transition: all .15s ease;
}
.admin-link:hover { color: var(--paper); background: var(--ink); }

/* ---------- Bố cục chính: vòng quay chiếm trọn khung nhìn ---------- */
.stage {
  display: grid; justify-items: center; align-content: center; gap: 18px;
  min-height: calc(100dvh - 68px); padding: 16px 16px 20px;
}

.tabs { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.tab {
  padding: 10px 22px; border-radius: 999px; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--ink-soft); white-space: nowrap;
  background: transparent; border: 1px solid var(--line);
  transition: all .15s ease;
}
.tab:hover { border-color: var(--ink-soft); color: var(--ink); }
.tab.is-active { color: var(--paper); background: var(--ink); border-color: var(--ink); }

/* Cạnh vòng quay lấy theo phần chiều cao còn trống, không vượt bề ngang màn hình */
.wheel-wrap {
  position: relative; aspect-ratio: 1;
  width: min(94vw, calc(100dvh - 200px), 980px);
}
#wheel { width: 100%; height: auto; display: block; cursor: pointer; }

.pointer {
  position: absolute; top: -3px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; z-index: 3;
  border-left: 17px solid transparent; border-right: 17px solid transparent;
  border-top: 34px solid var(--ink);
}

.spin-btn {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 25%; aspect-ratio: 1; border-radius: 50%; cursor: pointer;
  font-size: clamp(13px, 1.7vw, 20px); font-weight: 600; letter-spacing: 1.5px;
  color: var(--paper); background: var(--ink); border: 5px solid var(--paper);
  transition: transform .12s ease;
}
.spin-btn:active:not(:disabled) { transform: translate(-50%, -50%) scale(.94); }
.spin-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Dòng thông tin dưới vòng quay (gọn một hàng) ---------- */
.info { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; justify-content: center; }
.info-sub { color: var(--ink-soft); font-size: 14px; }
.info-sub:empty { display: none; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-soft); cursor: pointer; }
.switch:hover { color: var(--ink); }
.switch input { width: 16px; height: 16px; accent-color: var(--ink); }

/* ---------- Popup kết quả ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(255, 255, 255, .94);
}
.modal-backdrop.is-open { display: flex; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal {
  position: relative; width: 100%; max-width: 520px; max-height: 94dvh; overflow-y: auto;
  text-align: center; padding: 26px 22px 22px; border-radius: 4px;
  background: var(--paper); border: 1px solid var(--line-strong);
  animation: pop .26s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes pop { from { transform: scale(.92); opacity: 0 } to { transform: scale(1); opacity: 1 } }

.modal-close {
  position: absolute; top: 8px; right: 10px; width: 30px; height: 30px;
  border: 0; border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 1;
  color: var(--ink-soft); background: transparent;
}
.modal-close:hover { color: var(--ink); }

.modal-badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  font-size: 10px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--ink); border: 1px solid var(--line-strong); background: transparent;
}
.modal-photo {
  width: 100%; aspect-ratio: 3 / 4; max-height: 66dvh; margin: 18px 0 16px; border-radius: 2px;
  background-size: contain; background-position: center; background-repeat: no-repeat;
  background-color: var(--paper-soft);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 76px; font-weight: 300; color: var(--ink);
}
.modal-photo:not(.is-empty) { font-size: 0; }
.modal-name { font-size: 24px; font-weight: 600; letter-spacing: -.3px; margin-bottom: 8px; }
.modal-note { color: var(--ink-soft); font-size: 15px; line-height: 1.6; }
.modal-note:empty { display: none; }

.modal-actions { display: flex; gap: 10px; margin-top: 24px; }
.btn {
  flex: 1; padding: 13px 10px; border-radius: 2px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; white-space: nowrap; transition: all .15s ease;
}
.modal-actions .modal-start { flex: 1.5; }
.btn-primary { color: var(--paper); background: var(--ink); border: 1px solid var(--ink); }
.btn-primary:hover { background: #000; }
.btn-ghost { color: var(--ink); background: transparent; border: 1px solid var(--line-strong); }
.btn-ghost:hover { background: var(--paper-soft); }

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 700px) {
  .stage { gap: 14px; padding: 14px 12px 24px; }
  .wheel-wrap { width: min(96vw, calc(100dvh - 190px)); }
  .info { gap: 16px; }
}
@media (max-width: 560px) {
  .topbar { padding: 12px 14px; }
  .brand strong { font-size: 14px; }
  .brand small { font-size: 11px; }
  .brand-mark { width: 32px; height: 32px; font-size: 12px; }
  /* Chiếu TV chỉ dùng khi nối máy chiếu -> ẩn trên điện thoại cho gọn thanh trên */
  #present-btn { display: none; }
  .info { gap: 14px; font-size: 13px; }
}

/* ---------- Nút trên thanh tiêu đề ---------- */
.topbar-actions { display: flex; gap: 10px; align-items: center; }
button.admin-link { font-family: inherit; cursor: pointer; background: transparent; }
button.admin-link[aria-pressed="true"] { color: var(--paper); background: var(--ink); }

/* ---------- Chế độ chiếu TV: vòng quay chiếm trọn màn hình ---------- */
body.is-presenting { overflow: hidden; }
body.is-presenting .topbar {
  position: fixed; top: 0; right: 0; left: auto; z-index: 20;
  padding: 14px 18px; border: 0; background: transparent;
}
body.is-presenting .brand,
body.is-presenting .topbar-actions a.admin-link { display: none; }

body.is-presenting .stage {
  gap: 20px; height: 100dvh; padding: 16px; align-content: center;
}
body.is-presenting .info { display: none; }
body.is-presenting .wheel-wrap { width: min(84vh, 96vw); }
body.is-presenting .tab { font-size: 17px; padding: 12px 26px; }
body.is-presenting .spin-btn { letter-spacing: 2px; }
body.is-presenting .modal { max-width: 480px; }
body.is-presenting .modal-name { font-size: 28px; }
body.is-presenting .modal-note { font-size: 16px; }

/* Ảnh kết quả: rê chuột tới đâu thì nghiêng + phóng tới đó, kèm vệt sáng lướt */
.modal-photo {
  position: relative; overflow: hidden;
  transform-style: preserve-3d; will-change: transform;
  transition: transform .18s ease-out, background-size .2s ease, box-shadow .18s ease-out;
}
.modal-photo.is-tilting {
  box-shadow: 0 22px 50px -18px rgba(0, 0, 0, .4);
}
/* Vệt sáng chạy theo con trỏ, chỉ hiện lúc nghiêng — lúc phóng to thì tắt cho dễ nhìn */
.modal-photo::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  opacity: 0; transition: opacity .2s ease;
  background: radial-gradient(
    circle at var(--gx, 50%) var(--gy, 50%),
    rgba(255, 255, 255, .32) 0%,
    rgba(255, 255, 255, .10) 26%,
    transparent 58%
  );
}
.modal-photo.is-tilting::after { opacity: 1; }
.modal-photo.is-empty::after { display: none; }

@media (hover: hover) {
  .modal-photo:not(.is-empty) { cursor: zoom-in; }
  .modal-photo.is-zooming { cursor: zoom-out; }
}

/* Nhắc thao tác ở góc ảnh */
.modal-photo::before {
  content: 'Bấm để phóng to';
  position: absolute; left: 10px; bottom: 10px; z-index: 2;
  padding: 5px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 500; letter-spacing: .2px;
  color: var(--ink); background: rgba(255, 255, 255, .95);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  opacity: 0; transition: opacity .2s ease; pointer-events: none;
}
.modal-photo.is-tilting::before { opacity: 1; }
.modal-photo.is-zooming::before { content: 'Bấm lần nữa để thu nhỏ'; opacity: 1; }
.modal-photo.is-empty::before { display: none; }

/* ---------- Popup trên màn hình rộng: ảnh nằm trái, chữ nằm phải ----------
   Nhờ vậy ảnh cao gần hết màn hình thay vì bị phần chữ chiếm chỗ phía dưới. */
@media (min-width: 900px) and (min-height: 620px) {
  .modal-backdrop { padding: 12px; }
  .modal {
    max-width: min(960px, 94vw);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: 1fr auto auto auto auto 1fr;  /* 1fr hai đầu để dồn chữ vào giữa */
    gap: 10px 42px;
    align-content: center;
    text-align: left;
    padding: 20px;
    max-height: 96dvh;
  }
  .modal-photo {
    grid-column: 1; grid-row: 1 / -1; align-self: center;
    width: 100%; height: auto; max-height: 88dvh; margin: 0;
  }
  .modal-badge, .modal-name, .modal-note, .modal-actions { position: relative; z-index: 2; }
  .modal-badge  { grid-column: 2; grid-row: 2; justify-self: start; }
  .modal-name   { grid-column: 2; grid-row: 3; font-size: 28px; margin-bottom: 0; }
  .modal-note   { grid-column: 2; grid-row: 4; font-size: 15px; }
  .modal-actions{ grid-column: 2; grid-row: 5; width: 100%; margin-top: 18px; }
  .modal-close  { top: 12px; right: 14px; }
}

/* ---------- Đồng hồ đếm giờ thực hành ---------- */
.timer {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 24px;
  background: var(--paper);
}

.timer-inner {
  width: min(700px, 94vw); display: grid; gap: 20px; justify-items: center; text-align: center;
}
.timer-head { display: grid; gap: 10px; justify-items: center; }
.timer-badge {
  padding: 5px 14px; border-radius: 999px; border: 1px solid var(--line-strong);
  font-size: 11px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase;
}
.timer-name { font-size: clamp(20px, 3.4vw, 30px); font-weight: 600; letter-spacing: -.4px; }

.timer-clock {
  font-size: clamp(78px, 19vw, 200px); font-weight: 300; line-height: 1;
  letter-spacing: -4px; font-variant-numeric: tabular-nums;
}
.timer.is-warning .timer-clock { color: #b45309; }
.timer.is-over .timer-clock { color: #b91c1c; animation: nhapNhay 1s ease-in-out infinite; }
@keyframes nhapNhay { 50% { opacity: .35 } }

.timer-bar { width: 100%; height: 6px; background: var(--line); overflow: hidden; }
.timer-bar-fill { display: block; height: 100%; background: var(--ink); transition: width .3s linear; }
.timer.is-warning .timer-bar-fill { background: #b45309; }
.timer.is-over .timer-bar-fill { background: #b91c1c; }

.timer-presets { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.timer-preset {
  padding: 8px 16px; border-radius: 999px; cursor: pointer; font-family: inherit;
  font-size: 13px; color: var(--ink-soft); background: transparent; border: 1px solid var(--line);
}
.timer-preset:hover { border-color: var(--ink-soft); color: var(--ink); }
.timer-preset.is-active { color: var(--paper); background: var(--ink); border-color: var(--ink); }

.timer-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.timer-actions .btn { flex: 0 0 auto; padding: 12px 24px; }

/* ---------- Thanh chuyển phần luyện tập ---------- */
.site-nav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.nav-link {
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  color: var(--ink-soft); text-decoration: none; border: 1px solid transparent;
  transition: all .15s ease;
}
.nav-link:hover { color: var(--ink); border-color: var(--line); }
.nav-link.is-active { color: var(--paper); background: var(--ink); border-color: var(--ink); }
body.is-presenting .site-nav { display: none; }

/* ---------- Vòng quay tình huống ---------- */
.scenario-modal .modal { max-width: 560px; text-align: left; }
.scenario-text { font-size: 21px; font-weight: 600; line-height: 1.45; margin: 16px 0 4px; letter-spacing: -.2px; }
.scenario-tip {
  margin-top: 16px; padding: 16px; background: var(--paper-soft); border-left: 3px solid var(--ink);
}
.scenario-tip-label {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px;
}
.scenario-tip-text { font-size: 15px; line-height: 1.65; color: var(--ink); }
@media (min-width: 900px) and (min-height: 620px) {
  .scenario-modal .modal { display: block; max-width: 620px; padding: 30px; }
}

/* ---------- Thẻ ôn bài ---------- */
.stage-cards { gap: 24px; }
.card-deck { width: min(94vw, 640px); perspective: 1600px; }
.flash-card {
  position: relative; width: 100%; min-height: min(52dvh, 400px);
  cursor: pointer; transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.3, .8, .3, 1);
}
.flash-card.is-flipped { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  display: grid; align-content: center; justify-items: center; gap: 16px;
  padding: 36px 32px; text-align: center;
  border: 1px solid var(--line-strong); background: var(--paper);
}
.flash-back { transform: rotateY(180deg); background: var(--ink); color: var(--paper); border-color: var(--ink); }
.flash-label {
  font-size: 11px; font-weight: 600; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--ink-soft); padding: 4px 12px; border-radius: 999px; border: 1px solid currentColor;
}
.flash-back .flash-label { color: rgba(255, 255, 255, .7); }
.flash-text { font-size: clamp(19px, 2.6vw, 26px); font-weight: 500; line-height: 1.5; letter-spacing: -.2px; }
.flash-back .flash-text { font-weight: 400; }
.flash-hint { font-size: 12px; color: var(--ink-soft); }

.deck-actions { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.deck-count { font-size: 14px; color: var(--ink-soft); font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }
.btn-plain {
  border: 0; background: transparent; cursor: pointer; font-family: inherit;
  font-size: 13px; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px;
}
.btn-plain:hover { color: var(--ink); }

/* ---------- Chia cặp ---------- */
.stage-pairs { gap: 20px; }
.pair-setup, .pair-result { width: min(94vw, 620px); display: grid; gap: 16px; justify-items: stretch; }
.pair-title { font-size: 26px; font-weight: 600; letter-spacing: -.5px; text-align: center; }
.pair-hint { font-size: 14px; color: var(--ink-soft); text-align: center; margin-top: -8px; }
#pair-names {
  width: 100%; padding: 14px; border-radius: 2px; font-size: 15px; font-family: inherit; line-height: 1.7;
  color: var(--ink); background: var(--paper); border: 1px solid var(--line); resize: vertical;
}
#pair-names:focus { border-color: var(--ink); outline: none; }
.pair-modes { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.pair-list { display: grid; gap: 10px; }
.pair-item {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px; border: 1px solid var(--line);
}
.pair-no {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 600; color: var(--paper); background: var(--ink);
}
.pair-body { display: grid; gap: 2px; }
.pair-body strong { font-size: 17px; font-weight: 600; }
.pair-body span { font-size: 13px; color: var(--ink-soft); }
body.is-presenting .pair-body strong { font-size: 24px; }
