/* Battle Mode styles — mobile-first, readable in light and dark mode. */
/* Full-screen immersive battle view: the arena takes the whole viewport. */
#battle-screen {
  position: fixed;
  inset: 0;
  z-index: 9000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #f3ede0;
  color: #1c2534;
}
/* Follow the portal's own theme toggle (data-theme on <html>), not the OS
   setting — otherwise battle and portal can end up in different themes. */
[data-theme="dark"] #battle-screen { background: #0f1722; color: #EAE3D0; }
#battle-screen .bt-wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px 32px;
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
/* Vertical centering that never clips tall content. */
#battle-screen .bt-wrap > .bt-card {
  margin-top: auto;
  margin-bottom: auto;
  width: 100%;
  box-sizing: border-box;
}
@media (min-width: 800px) {
  #battle-screen .bt-wrap { max-width: 820px; }
  #battle-screen .bt-card { padding: 40px 44px; }
  #battle-screen .bt-title { font-size: 34px; }
  #battle-screen .bt-sub { font-size: 16px; }
  #battle-screen .bt-papers { grid-template-columns: repeat(7, 1fr); }
  #battle-screen .bt-paper { padding: 14px 4px; font-size: 16px; }
  #battle-screen .bt-btn { font-size: 16px; padding: 14px 26px; }
  #battle-screen .bt-code { font-size: 52px; }
}
/* (desktop arena rules live further down, after the base .bt-arena styles) */
.bt-card {
  background: #fffdf8;
  border: 1px solid #e8dcc8;
  border-radius: 16px;
  padding: 22px 18px;
  box-shadow: 0 8px 22px rgba(24, 50, 72, .10);
}
[data-theme="dark"] .bt-card { background: #1d2733; border-color: #334155; color: #f1f5f9; }
.bt-center { text-align: center; }
.bt-title { font-size: 24px; font-weight: 800; margin: 0 0 8px; }
.bt-sub { font-size: 14px; opacity: .78; line-height: 1.5; margin: 0 0 14px; }
.bt-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; opacity: .6; margin: 14px 0 8px; }
.bt-papers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.bt-paper {
  border: 2px solid #e8dcc8; background: transparent; border-radius: 12px;
  padding: 10px 4px; font-weight: 800; font-size: 14px; cursor: pointer; color: inherit;
}
.bt-paper.on { border-color: #c62828; background: rgba(198, 40, 40, .08); }
.bt-btn {
  display: inline-block; border: 2px solid #e8dcc8; background: transparent;
  border-radius: 999px; padding: 11px 20px; font-weight: 700; font-size: 14px;
  cursor: pointer; color: inherit; margin: 4px 2px;
}
.bt-btn.bt-primary { background: #c62828; border-color: #c62828; color: #fff; }
.bt-btn:active { transform: scale(.97); }
.bt-row2 { margin-top: 6px; }
.bt-joinrow { display: flex; gap: 8px; margin-top: 10px; }
.bt-joinrow input {
  flex: 1; border: 2px solid #e8dcc8; border-radius: 12px; padding: 10px 12px;
  font-size: 16px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase;
  text-align: center; background: transparent; color: inherit; min-width: 0;
}
.bt-note { font-size: 12px; opacity: .6; margin: 12px 0 0; line-height: 1.5; }
.bt-code {
  font-size: 40px; font-weight: 800; letter-spacing: .25em; text-align: center;
  background: rgba(198, 40, 40, .08); border: 2px dashed #c62828; border-radius: 14px;
  padding: 14px 8px 14px 16px; margin: 6px 0 14px;
}
.bt-spinner {
  width: 42px; height: 42px; margin: 18px auto;
  border: 4px solid rgba(198, 40, 40, .2); border-top-color: #c62828;
  border-radius: 50%; animation: bt-spin 0.9s linear infinite;
}
@keyframes bt-spin { to { transform: rotate(360deg); } }

/* Arena */
.bt-arena {
  max-width: 640px; margin: 0 auto; padding: 24px 14px 24px;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; box-sizing: border-box;
  overflow: hidden;
  --bt-fit: 1;
}
/* Mirror the mock exam's fixed full-screen card: it never changes size.
   Like the mock, text shrinks to fit (via --bt-fit) instead of scrolling. */
.bt-arena > .bt-qcard {
  flex: 1 1 auto; min-height: 0; max-height: 100%;
  overflow-y: auto;
  margin-top: 0; margin-bottom: 0;
  display: flex; flex-direction: column;
}
/* Arena goes full-width on desktop, like the mock exam screen. */
@media (min-width: 800px) {
  .bt-arena { max-width: none; width: 100%; padding: 40px clamp(20px, 4vw, 64px) 24px; }
  .bt-qcard { padding: 40px 44px; }
  .bt-qtext { font-size: calc(22px * var(--bt-fit)); }
  .bt-opt { font-size: calc(17px * var(--bt-fit)); padding: calc(16px * var(--bt-fit)); }
}
.bt-scorebar {
  display: flex; align-items: stretch; gap: 8px; margin-bottom: 6px;
}
.bt-timer {
  text-align: center; font-size: 13px; font-weight: 700; opacity: .6;
  margin: 0 0 12px; font-variant-numeric: tabular-nums;
}
.bt-p {
  flex: 1; background: #fffdf8; border: 1px solid #e8dcc8; border-radius: 14px;
  padding: 10px 12px; text-align: center;
}
[data-theme="dark"] .bt-p { background: #1d2733; border-color: #334155; color: #f1f5f9; }
.bt-me { border-left: 5px solid #2e7d32; }
.bt-opp { border-right: 5px solid #c62828; }
.bt-pname { font-size: 12px; font-weight: 700; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt-pscore { font-size: 30px; font-weight: 800; line-height: 1.1; }
.bt-pprog { font-size: 12px; opacity: .6; font-weight: 700; }
.bt-vs { align-self: center; font-weight: 800; font-size: 14px; opacity: .5; }
.bt-qcard {
  background: #fffdf8; border: 1px solid #e8dcc8; border-radius: 16px;
  padding: 18px 16px; box-shadow: 0 8px 22px rgba(24, 50, 72, .10);
}
[data-theme="dark"] .bt-qcard { background: #1d2733; border-color: #334155; color: #f1f5f9; }
.bt-qmeta { font-size: calc(12px * var(--bt-fit)); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; opacity: .55; margin-bottom: 8px; }
.bt-qtext { font-size: calc(17px * var(--bt-fit)); font-weight: 600; line-height: 1.45; margin-bottom: 14px; }
.bt-opts { display: grid; gap: calc(10px * var(--bt-fit)); }
.bt-opt {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  border: 2px solid #e8dcc8; background: transparent; border-radius: 12px;
  padding: calc(12px * var(--bt-fit)); font-size: calc(15px * var(--bt-fit)); cursor: pointer; color: inherit; line-height: 1.4;
}
.bt-opt:active { transform: scale(.98); }
.bt-olet {
  flex: 0 0 26px; height: 26px; border-radius: 50%; background: rgba(198, 40, 40, .1);
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
}
.bt-opt.bt-right { border-color: #2e7d32; background: rgba(46, 125, 50, .12); }
.bt-opt.bt-wrong { border-color: #c62828; background: rgba(198, 40, 40, .10); }
.bt-opt:disabled { cursor: default; opacity: .85; }
.bt-opt.bt-right:disabled, .bt-opt.bt-wrong:disabled { opacity: 1; }
.bt-feedback { margin-top: 12px; font-weight: 700; font-size: calc(15px * var(--bt-fit)); }
.bt-feedback.bt-ok { color: #2e7d32; }
.bt-feedback.bt-no { color: #c62828; }
/* Typed-question UI (fillblank / matching / multiselect / grid) */
.bt-fillwrap { display: flex; }
.bt-fill {
  width: 100%; box-sizing: border-box; padding: calc(12px * var(--bt-fit));
  font-size: calc(15px * var(--bt-fit)); border-radius: 12px;
  border: 2px solid #e8dcc8; font-family: inherit; background: transparent; color: inherit;
}
.bt-fill:focus { outline: none; border-color: #c62828; }
.bt-matchrow {
  display: flex; align-items: center; gap: 8px; padding: calc(8px * var(--bt-fit));
  border: 1.5px solid #e8dcc8; border-radius: 10px; flex-wrap: wrap;
}
.bt-matchleft { flex: 1 1 120px; font-weight: 700; font-size: calc(14px * var(--bt-fit)); }
.bt-matchsel {
  flex: 1 1 120px; padding: 8px 10px; border-radius: 8px; font-size: calc(14px * var(--bt-fit));
  border: 1.5px solid #e8dcc8; font-family: inherit; background: transparent; color: inherit; max-width: 100%;
}
.bt-mbox {
  flex: 0 0 20px; height: 20px; border-radius: 6px; border: 2px solid #b9c2d4; margin-top: 2px;
}
.bt-opt.bt-multi.on .bt-mbox { background: #c62828; border-color: #c62828; }
.bt-opt.bt-multi.on { border-color: #c62828; }
.bt-grid { border-collapse: collapse; width: 100%; font-size: calc(13px * var(--bt-fit)); }
.bt-grid th, .bt-grid td { border: 1.5px solid #e8dcc8; padding: calc(8px * var(--bt-fit)); text-align: center; }
.bt-grid th { background: rgba(198, 40, 40, .06); font-weight: 800; font-size: calc(12px * var(--bt-fit)); }
.bt-gridrow { text-align: left !important; font-weight: 700; }
.bt-gridcell input[type=radio] { width: 18px; height: 18px; accent-color: #c62828; cursor: pointer; }
.bt-gridcell.bt-ok { background: rgba(46, 125, 50, .15); }
.bt-gridcell.bt-no { background: rgba(198, 40, 40, .12); }
.bt-gridcell.bt-missed { background: rgba(255, 152, 0, .15); }
.bt-tnote { font-size: calc(13px * var(--bt-fit)); margin-top: 6px; line-height: 1.45; }
.bt-tnote.bt-ok { color: #2e7d32; font-weight: 700; }
.bt-tnote.bt-no { color: #c62828; font-weight: 700; }
.bt-submit { margin-top: 4px; }
[data-theme="dark"] .bt-tnote.bt-ok { color: #7bc47f; }
[data-theme="dark"] .bt-tnote.bt-no { color: #ef5350; }
[data-theme="dark"] .bt-fill, [data-theme="dark"] .bt-matchsel { border-color: #334155; background: #16202c; }
[data-theme="dark"] .bt-matchrow { border-color: #334155; }
[data-theme="dark"] .bt-grid th, [data-theme="dark"] .bt-grid td { border-color: #334155; }
/* Dark mode needs lighter greens/reds to stay readable on the dark card. */
[data-theme="dark"] .bt-feedback.bt-ok { color: #7bc47f; }
[data-theme="dark"] .bt-feedback.bt-no { color: #ef5350; }
.bt-qcard .bt-btn { width: 100%; margin-top: 12px; font-size: calc(14px * var(--bt-fit)); }
.bt-qfoot { margin-top: 14px; text-align: center; }
.bt-link { background: none; border: none; color: inherit; opacity: .55; font-size: 13px; text-decoration: underline; cursor: pointer; }

/* Results */
.bt-final { display: flex; gap: 10px; margin: 16px 0; }
.bt-final > div {
  flex: 1; border-radius: 14px; padding: 14px 8px;
  background: rgba(0, 0, 0, .04); border: 1px solid #e8dcc8;
}
[data-theme="dark"] .bt-final > div { background: rgba(255, 255, 255, .05); border-color: #334155; }
.bt-final span { display: block; font-size: 12px; font-weight: 700; opacity: .7; margin-bottom: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt-final b { font-size: 34px; font-weight: 800; }
.bt-win .bt-title { color: #2e7d32; }
.bt-lose .bt-title { color: #c62828; }
[data-theme="dark"] .bt-win .bt-title { color: #7bc47f; }
[data-theme="dark"] .bt-lose .bt-title { color: #ef5350; }

/* Hide the floating channel popups while battling — full focus arena. */
.kkd-battle-active .kkd-whatsapp-channel,
.kkd-battle-active .kkd-telegram-channel { display: none; }

/* ── Live online popup (battle mode, bottom-left corner) ──────────────────── */
.bt-online-pop {
  position: fixed; left: 16px; bottom: 16px; z-index: 60;
  display: flex; align-items: center; gap: 8px;
  background: rgba(26, 38, 52, .92); color: #e8eef5;
  border: 1px solid #33475e; border-radius: 30px;
  padding: 9px 16px; font-size: 13px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  pointer-events: none; white-space: nowrap;
}
.bt-online-pop .bt-sp-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #4ade80; flex: 0 0 auto;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, .6);
  animation: bt-pulse 2s infinite;
}
@keyframes bt-pulse {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, .55); }
  70% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}
