/* ====== Theme ====== */
:root {
  --bg: #0b1020;
  --surface: #131a2d;
  --surface-2: #0f1526;
  --text: #f2f5ff;
  --muted: #9aa6c4;
  --brand: #4da3ff;
  --accent: #75f7c0;
  --danger: #ff6b6b;
  --warning: #ffd166;
  --ring-bg: #273355;
  --ok: #39d98a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .25);
  --radius: 16px;
  --radius-sm: 14px;
}

:root.light {
  --bg: #f6f8ff;
  --surface: #ffffff;
  --surface-2: #eef1ff;
  --text: #111b2e;
  --muted: #5a678b;
  --brand: #2b6fff;
  --accent: #14b8a6;
  --danger: #e11d48;
  --warning: #f59e0b;
  --ring-bg: #dde3ff;
  --ok: #10b981;
  --shadow: 0 12px 28px rgba(30, 40, 90, .15);
}

/* ====== Reset + Mobile-first ====== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%
}

html {
  font-size: 16px
}

@media (max-width: 420px) {
  html {
    font-size: 16px
  }
}

@media (min-width: 900px) {
  html {
    font-size: 17px
  }
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(117, 247, 192, .08), transparent 65%),
    radial-gradient(600px 600px at 100% 0, rgba(77, 163, 255, .08), transparent 60%),
    var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ====== Layout ====== */
.app-header,
.app-footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header {
  position: sticky;
  top: 0;
  backdrop-filter: blur(8px);
  background: linear-gradient(to bottom, rgba(0, 0, 0, .25), rgba(0, 0, 0, 0));
  z-index: 10
}

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

.brand .logo {
  width: 40px;
  height: 40px
}

.brand h1 {
  font-size: 1.15rem;
  margin: 0
}

.brand .subtitle {
  margin: 0;
  margin-top: 2px;
  color: var(--muted);
  font-size: .9rem
}

.header-right {
  display: flex;
  gap: 8px
}

.app-footer {
  opacity: .85;
  font-size: .9rem;
  gap: 10px;
  flex-wrap: wrap;
}

.view {
  max-width: 900px;
  margin: 10px auto 24px auto;
  padding: 0 12px;
  display: none
}

.view.current {
  display: block
}

.view.hidden {
  display: none
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: stretch
}

@media (min-width: 900px) {
  .hero {
    grid-template-columns: 1.1fr .9fr;
    gap: 20px
  }
}

.hero-text {
  padding: 16px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(77, 163, 255, .08), rgba(117, 247, 192, .05));
  border: 1px solid rgba(148, 163, 184, .15)
}

.hero-text h2 {
  font-size: 1.4rem;
  margin-top: 0
}

.bullets {
  margin: 12px 0 0 0;
  color: var(--muted);
  padding-left: 18px
}

.bullets li {
  margin: 8px 0;
  line-height: 1.45
}

.card {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, .15);
  padding: 16px;
}

.form label {
  display: grid;
  gap: 6px;
  margin: 10px 0
}

.form input[type="text"],
.form input[type="email"] {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, .25);
  border-radius: 14px;
  padding: 14px 14px;
  font-size: 1rem;
  outline: none;
  min-height: 48px;
}

.form input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(77, 163, 255, .2)
}

.form .req {
  color: var(--danger)
}

.form .consent {
  color: var(--muted);
  font-size: .95rem;
  line-height: 1.4
}

.form .form-actions {
  margin-top: 10px
}

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, .25);
  padding: 14px 18px;
  font-weight: 700;
  cursor: pointer;
  color: var(--btn-fg);
  background: var(--btn-bg);
  min-height: 52px;
}

.btn-lg {
  min-height: 56px;
  font-size: 1.08rem
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0) scale(.99);
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed
}

.btn-primary {
  --btn-bg: linear-gradient(180deg, #3b82f6, #1d4ed8);
  border: 1px solid rgba(59, 130, 246, .5)
}

.btn-secondary {
  --btn-bg: linear-gradient(180deg, #0ea5e9, #0284c7);
  border: 1px solid rgba(14, 165, 233, .4)
}

.btn-ghost {
  --btn-bg: transparent;
  border-color: rgba(148, 163, 184, .25)
}

/* HUD */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center
}

.hud .label {
  color: var(--muted)
}

.hud .value {
  font-weight: 800;
  font-variant-numeric: tabular-nums
}

.timer .ring {
  --size: 80px;
  --thick: 10px;
  width: var(--size);
  height: var(--size);
  border-radius: 999px;
  display: grid;
  place-items: center;
  background:
    conic-gradient(var(--accent) calc(var(--pct, 1) * 360deg), var(--ring-bg) 0);
  position: relative;
}

@media (min-width: 900px) {
  .timer .ring {
    --size: 92px;
    --thick: 12px
  }
}

.timer .ring::after {
  content: "";
  position: absolute;
  inset: calc(var(--thick)/1.2);
  background: var(--surface);
  border-radius: 999px;
}

#timerInner {
  position: relative;
  z-index: 1;
}

#txtTimer {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Line progress (top of game view) */
.line-progress {
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, .18);
  overflow: hidden;
  margin: 6px 2px 4px 2px
}

.line-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width .25s ease;
}

/* Question card */
.question-card {
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.question-card.fade-out {
  opacity: 0;
  transform: translateY(10px);
}

.question-card h3 {
  margin-top: 4px;
  line-height: 1.4;
  font-size: 1.4rem;
  font-weight: 800;
  color: #ffffff;
}

.q-meta .tags {
  color: var(--muted);
  font-size: .95rem
}

.options {
  list-style: none;
  padding: 0;
  margin: 12px 0 8px 0
}

.option {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(148, 163, 184, .28);
  border-radius: var(--radius-sm);
  padding: 16px 16px;
  margin: 12px 0;
  cursor: pointer;
  user-select: none;
  background: var(--surface-2);
  min-height: 64px;
  transition: transform .05s ease-in, background-color .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.options:not(.locked) .option:hover {
  background: rgba(255, 255, 255, 0.05);
}

@media (prefers-color-scheme: light) {
  .options:not(.locked) .option:hover {
    background: rgba(0, 0, 0, 0.03);
  }
}

.option:active {
  transform: scale(.995);
}

.option .prefix {
  font-weight: 800;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(148, 163, 184, .18);
}

.option .text {
  line-height: 1.5;
  font-size: 1.03rem
}

.option[data-state="chosen"] {
  border-color: var(--brand);
  background: rgba(43, 111, 255, 0.1);
  box-shadow: 0 0 12px rgba(43, 111, 255, 0.35);
}

.option[data-state="chosen"] .prefix {
  background: var(--brand);
  color: #fff;
}

.option[data-state="correct"] {
  border-color: rgba(58, 199, 133, .7);
  background: linear-gradient(180deg, rgba(57, 217, 138, .12), var(--surface-2))
}

.option[data-state="incorrect"] {
  border-color: rgba(239, 68, 68, .7);
  background: linear-gradient(180deg, rgba(239, 68, 68, .12), var(--surface-2))
}

.option[data-state="correct"] .prefix {
  background: rgba(57, 217, 138, .25)
}

.option[data-state="incorrect"] .prefix {
  background: rgba(239, 68, 68, .25)
}

/* Feedback and explanation */
.feedback {
  margin-top: 8px;
  font-weight: 800
}

.feedback.ok {
  color: var(--ok)
}

.feedback.bad {
  color: var(--danger)
}

.explanation {
  margin-top: 10px;
  color: var(--muted);
}

/* Award block under explanation */
.award {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(57, 217, 138, .35);
  background: rgba(57, 217, 138, .12);
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.award .tag {
  font-size: .95rem;
  color: var(--muted)
}

.award strong {
  font-size: 1.1rem
}

.award .small {
  font-size: .95rem;
  color: var(--muted)
}

.award.bad {
  border-color: rgba(239, 68, 68, .35);
  background: rgba(239, 68, 68, .12);
}



/* Summary */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

@media (min-width: 900px) {
  .summary-grid {
    grid-template-columns: 1fr 1fr;
    gap: 18px
  }
}

.stat {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  margin: 8px 0;
  border: 1px solid rgba(148, 163, 184, .18)
}

.stat .value {
  font-weight: 800
}

.mono {
  font-variant-numeric: tabular-nums
}

.player-review .kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  margin: 6px 0
}

.review-list {
  display: grid;
  gap: 10px;
}

.review-item {
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: 12px;
}

.review-item summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 14px;
}

.review-item[open] {
  background: var(--surface-2)
}

.review-item .body {
  padding: 0 14px 14px 14px;
  color: var(--muted)
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, .25);
  font-size: .9rem
}

.badge.ok {
  background: rgba(57, 217, 138, .12);
  border-color: rgba(57, 217, 138, .35)
}

.badge.bad {
  background: rgba(239, 68, 68, .12);
  border-color: rgba(239, 68, 68, .35)
}

.send-status {
  margin-top: 10px;
  color: var(--muted)
}

/* Modal (edit player) */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  width: 100%;
  max-width: 460px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.modal-form input[type="text"],
.modal-form input[type="email"] {
  min-height: 50px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Responsive */
@media (max-width: 900px) {
  .hud {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

/* Utility */
.hidden {
  display: none !important
}

.accent {
  color: var(--accent)
}

.form .consent {
  display: flex;
  align-items: center;
  gap: 8px;
  /* khoảng cách giữa ô và chữ */
  color: var(--muted);
  font-size: 0.95rem;
}

.form .consent input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
  /* tô màu theo theme */
}

/* === Fix: tránh tràn chữ trên điện thoại === */
.summary-grid,
.player-review,
.stat,
.review-list {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.summary-grid .value,
.player-review strong {
  white-space: normal !important;
  overflow-wrap: break-word;
}

#sumSession {
  font-size: 0.9rem;
  line-height: 1.3;
  word-break: break-all;
}

#sumEmail {
  font-size: 0.95rem;
  word-break: break-all;
}

/* Giảm padding cho màn nhỏ */
@media (max-width: 480px) {
  .card {
    padding: 12px;
  }

  .player-review .kv {
    grid-template-columns: 100px 1fr;
  }

  .stat {
    flex-wrap: wrap;
    gap: 4px;
  }
}


/* Fix after removing email field: tighten grid and wrap long strings */
.player-review .kv {
  grid-template-columns: 120px 1fr;
}

@media (max-width: 480px) {
  .player-review .kv {
    grid-template-columns: 100px 1fr;
  }
}

.summary-grid,
.player-review,
.stat,
.review-list {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.options.locked .option {
  pointer-events: none;
}

.app-footer {
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
}

/* Sticky action for mobile – gọn, không phủ màu đáy */
.actions.sticky {
  position: sticky;
  bottom: env(safe-area-inset-bottom);
  padding-top: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 5;
  background: transparent;
  /* không còn dải màu */
}

.actions.sticky::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -48px;
  height: 48px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .10));
  /* fade rất mỏng */
}

.actions.sticky .btn {
  width: 100%;
}