/* ===== 基礎與主題 ===== */
:root {
  --bg-1: #0b1020;
  --bg-2: #141a32;
  --bg-card: #1a2142;
  --bg-card-2: #232c54;
  --text: #f4f6ff;
  --text-dim: #a4abc8;
  --text-muted: #6b7299;
  --accent: #ffb547;
  --accent-2: #ff8a3d;
  --primary: #5b8cff;
  --primary-2: #7aa0ff;
  --green: #38d39f;
  --red: #ff5f6d;
  --gold: #f7c948;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-1);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
    "PingFang TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior-y: contain;
}

body {
  background: radial-gradient(1200px 800px at 0% 0%, #1a234a 0%, transparent 50%),
              radial-gradient(900px 700px at 100% 100%, #1f1a3a 0%, transparent 55%),
              var(--bg-1);
}

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

/* ===== 畫面切換 ===== */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  animation: fadeIn 0.18s ease-out;
}
.screen.active { display: flex; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== 按鈕 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}
.btn:active { transform: scale(0.98); }
.btn.big { padding: 16px 22px; font-size: 18px; border-radius: 16px; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: transparent;
  color: white;
  box-shadow: 0 6px 18px rgba(91, 140, 255, 0.35);
}
.btn-primary:hover { filter: brightness(1.05); }

.iconbtn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.iconbtn:active { transform: scale(0.95); }

/* ===== 主選單 ===== */
#screen-home {
  justify-content: space-between;
  text-align: center;
  padding: 32px 20px;
}
.hero {
  margin-top: 8vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.hero-badge {
  padding: 6px 12px;
  background: rgba(255, 181, 71, 0.16);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 12px;
}
.hero-title {
  font-size: 48px;
  margin: 8px 0 4px;
  line-height: 1.1;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #ffd479, #ff8a3d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-title span { display: block; font-size: 32px; }
.hero-sub { color: var(--text-dim); margin: 0; }
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 8px 24px;
}
.home-footer { color: var(--text-muted); font-size: 12px; margin: 0; }

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.topbar h2 {
  font-size: 18px;
  margin: 0;
  flex: 1;
}
.topbar-center { flex: 1; }
.topbar-right { margin-left: auto; }

#search-input {
  width: 160px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  -webkit-appearance: none;
}
#search-input::placeholder { color: var(--text-muted); }
#search-input:focus { outline: 2px solid var(--primary); outline-offset: 0; }

/* ===== 題庫列表 ===== */
.category-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.category-item {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.15s;
}
.category-item:active { background: var(--bg-card-2); }
.category-item .ci-name {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.35;
}
.category-item .ci-count {
  color: var(--text-dim);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.06);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.category-item .ci-tag {
  font-size: 11px;
  color: var(--accent);
  background: rgba(255, 181, 71, 0.12);
  padding: 3px 8px;
  border-radius: 6px;
}

/* ===== Setup ===== */
.setup-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 8px;
}
.setup-meta {
  color: var(--text-dim);
  margin: 0;
  line-height: 1.6;
}
.setup-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.setup-row > label {
  color: var(--text-dim);
  font-size: 14px;
  width: 60px;
}
.seg {
  display: inline-flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  flex-wrap: wrap;
}
.seg button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.seg button.active {
  background: var(--primary);
  color: white;
}
#setup-start { margin-top: 12px; }

/* ===== Quiz ===== */
.qprogress {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 6px;
}
.qbar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.qbar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.25s ease;
}
.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
}
.score-correct { color: var(--green); }
.score-wrong { color: var(--red); }
.score-sep { color: var(--text-muted); }

.quiz-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 8px 0;
  overflow-y: auto;
}
.qcard {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.qcard-text {
  font-size: 19px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.qcard-image-wrap {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}
.qcard-image-wrap img {
  max-width: 100%;
  max-height: 40vh;
  border-radius: 10px;
  background: white;
  padding: 4px;
}
.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 17px;
  text-align: left;
  color: var(--text);
  width: 100%;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
  font-weight: 500;
}
.opt:active { transform: scale(0.99); }
.opt-letter {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.opt-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  word-break: break-word;
}
.opt-body img {
  max-width: 240px;
  max-height: 160px;
  border-radius: 6px;
  background: white;
  padding: 3px;
  align-self: flex-start;
}
.opt.correct {
  background: rgba(56, 211, 159, 0.15);
  border-color: var(--green);
}
.opt.correct .opt-letter { background: var(--green); color: white; }
.opt.wrong {
  background: rgba(255, 95, 109, 0.15);
  border-color: var(--red);
}
.opt.wrong .opt-letter { background: var(--red); color: white; }
.opt.disabled { pointer-events: none; opacity: 0.85; }

.quiz-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
}
.feedback {
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  min-height: 24px;
}
.feedback.right { color: var(--green); }
.feedback.wrong-text { color: var(--red); }

/* ===== 注音 ruby ===== */
ruby { ruby-align: center; }
rt {
  font-size: 0.6em;
  color: var(--text-dim);
  letter-spacing: -0.05em;
}

/* ===== Result ===== */
.result-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  gap: 16px;
}
.result-medal { font-size: 64px; }
.result-name { color: var(--text-dim); margin: 0; }
.result-stats {
  display: flex;
  gap: 12px;
  margin: 16px 0;
  width: 100%;
  max-width: 380px;
}
.result-stats > div {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 8px;
}
.stat-num { font-size: 28px; font-weight: 800; color: var(--accent); }
.stat-label { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.result-actions {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== About ===== */
.about-body {
  padding: 8px 12px 24px;
  line-height: 1.7;
  overflow-y: auto;
  user-select: text;
  -webkit-user-select: text;
}
.about-body h3 {
  margin: 16px 0 4px;
  color: var(--accent);
  font-size: 16px;
}
.about-body p, .about-body ol { color: var(--text-dim); margin: 8px 0; }
.about-body ol { padding-left: 22px; }

/* ============================================
   ⚔️ 二人對戰模式（快打旋風風格）
============================================ */

/* setup 模式提示 */
.battle-hint {
  background: linear-gradient(135deg, rgba(255, 95, 109, 0.12), rgba(91, 140, 255, 0.12));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}
.bh-title { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.bh-row { color: var(--text-dim); line-height: 1.7; }
.bh-row.tiny { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.bh-tag {
  display: inline-block;
  width: 28px;
  padding: 2px 0;
  text-align: center;
  border-radius: 4px;
  font-weight: 700;
  font-size: 11px;
  margin-right: 6px;
}
.bh-tag.p1 { background: linear-gradient(135deg, #ff5f6d, #ff8a3d); color: white; }
.bh-tag.p2 { background: linear-gradient(135deg, #5b8cff, #38d39f); color: white; }

kbd {
  display: inline-block;
  padding: 2px 7px;
  margin: 0 2px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-bottom-width: 2px;
  border-radius: 4px;
  min-width: 18px;
  text-align: center;
}

/* ===== 對戰畫面 — 橫式滿版雙人速度賽 ===== */
.battle-screen {
  max-width: none;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
  inset: 0;
  z-index: 100;
  gap: 0;
}
.battle-screen.active { display: flex; flex-direction: column; }

/* === 頂部 HUD === */
.bhud-top {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #1e40af 0%, #0f1f6b 100%);
  border-bottom: 3px solid #000;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.5);
  position: relative;
  z-index: 2;
  padding-top: max(8px, env(safe-area-inset-top));
}
.bhud-side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bhud-side.p2-side { justify-content: flex-end; }

.bhud-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 3px solid;
  overflow: hidden;
  background: #fff;
  flex: 0 0 56px;
}
.bhud-avatar.p1 { border-color: #ffd60a; box-shadow: 0 0 12px rgba(255, 214, 10, 0.6); }
.bhud-avatar.p2 { border-color: #2ecc71; box-shadow: 0 0 12px rgba(46, 204, 113, 0.6); }
.bhud-avatar img {
  width: 100%; height: 100%;
  object-fit: cover; object-position: top;
}
.bhud-info {
  flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.bhud-info.right { align-items: flex-end; }
.bhud-name {
  font-weight: 900; font-size: 14px; letter-spacing: 0.1em;
  color: #fff; text-shadow: 2px 2px 0 #000;
}
.bhud-name.p1 { color: #ffd60a; }
.bhud-name.p2 { color: #2ecc71; }

.bhp {
  position: relative;
  width: 100%; max-width: 260px; height: 14px;
  background: #4b0d12;
  border: 2px solid #000;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.5);
}
.bhp-fill {
  height: 100%;
  transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}
.p1-hp .bhp-fill {
  background: repeating-linear-gradient(90deg, #ff4444 0, #ff4444 6px, #ff8800 6px, #ff8800 12px);
  margin-left: auto;
}
.p1-hp { transform: scaleX(-1); }
.p2-hp .bhp-fill {
  background: repeating-linear-gradient(90deg, #ffcc00 0, #ffcc00 6px, #ff8800 6px, #ff8800 12px);
}
.bhp.hurt { animation: hp-shake 0.4s; }
@keyframes hp-shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
.p1-hp.hurt { animation-name: hp-shake-mirror; }
@keyframes hp-shake-mirror {
  0%,100% { transform: scaleX(-1) translateX(0); }
  20% { transform: scaleX(-1) translateX(-5px); }
  40% { transform: scaleX(-1) translateX(5px); }
  60% { transform: scaleX(-1) translateX(-3px); }
  80% { transform: scaleX(-1) translateX(3px); }
}

.bhud-stats {
  display: flex; gap: 8px; font-size: 12px;
  font-weight: 700; color: #fff;
  text-shadow: 1px 1px 0 #000;
}
.bhud-stats .streak.p1 { color: #ffd60a; }
.bhud-stats .streak.p2 { color: #2ecc71; }
.bhud-stats .miss { color: #ff8a8a; }

/* 中央 HUD */
.bhud-center {
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  padding: 0 8px;
}
.bquit-btn {
  width: 28px; height: 28px;
  border: 2px solid #000;
  background: #e63946;
  color: #fff;
  font-weight: 900; font-size: 13px;
  border-radius: 4px;
  cursor: pointer; padding: 0;
  box-shadow: 0 2px 0 #000;
}
.bquit-btn:active { transform: translateY(2px); box-shadow: 0 0 0 #000; }
.bschedule {
  background: #e63946; color: #fff;
  padding: 2px 10px;
  font-weight: 900; font-size: 11px; letter-spacing: 0.15em;
  border: 2px solid #000;
  border-radius: 4px;
}
.bvs-anim {
  font-size: 24px; font-weight: 900;
  background: linear-gradient(135deg, #ffd479, #ff5f6d, #5b8cff);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  letter-spacing: 0.05em;
  filter: drop-shadow(0 0 8px rgba(255, 213, 121, 0.5));
  animation: vs-pulse 1.4s ease-in-out infinite;
}
@keyframes vs-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* === 中央格鬥場景 === */
.bstage {
  flex: 0 0 auto;
  position: relative;
  height: 28vh;
  min-height: 180px;
  max-height: 280px;
  background: #1e40af;
  border-bottom: 3px solid #000;
  overflow: hidden;
}
.bstage-bg-img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: 0;
}
.fighter {
  position: absolute;
  bottom: 6px;
  height: 90%;
  aspect-ratio: 893 / 1600;
  z-index: 2;
  transition: transform 0.35s ease, filter 0.2s ease;
  transform-origin: 50% 100%;
}
.fighter.p1 { left: 8%; }
.fighter.p2 { right: 8%; transform: scaleX(-1); }
.fighter img {
  width: 100%; height: 100%;
  display: block;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(3px 4px 0 rgba(0, 0, 0, 0.45));
}

/* 角色動畫 */
@keyframes f-hurt {
  0%,100% { transform: translateX(0); filter: brightness(1); }
  20% { transform: translateX(-12px); filter: brightness(2); }
  40% { transform: translateX(10px); filter: brightness(1.5); }
  60% { transform: translateX(-8px); filter: brightness(2); }
  80% { transform: translateX(6px); filter: brightness(1.3); }
}
@keyframes f-hurt-mirror {
  0%,100% { transform: scaleX(-1) translateX(0); filter: brightness(1); }
  20% { transform: scaleX(-1) translateX(-12px); filter: brightness(2); }
  40% { transform: scaleX(-1) translateX(10px); filter: brightness(1.5); }
  60% { transform: scaleX(-1) translateX(-8px); filter: brightness(2); }
  80% { transform: scaleX(-1) translateX(6px); filter: brightness(1.3); }
}
.fighter.p1.hurt { animation: f-hurt 0.55s ease; }
.fighter.p2.hurt { animation: f-hurt-mirror 0.55s ease; }
@keyframes f-victory {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
@keyframes f-victory-mirror {
  0%,100% { transform: scaleX(-1) translateY(0); }
  50% { transform: scaleX(-1) translateY(-12px); }
}
.fighter.p1.victory { animation: f-victory 0.55s ease-in-out infinite; }
.fighter.p2.victory { animation: f-victory-mirror 0.55s ease-in-out infinite; }
.fighter.p1.ko {
  transform: rotate(-85deg) translate(-30px, 10px);
  filter: grayscale(0.3) brightness(0.85);
}
.fighter.p2.ko {
  transform: scaleX(-1) rotate(-85deg) translate(-30px, 10px);
  filter: grayscale(0.3) brightness(0.85);
}

/* POW! / BAM! 攻擊特效 */
.bhit {
  position: absolute;
  top: 30%;
  font-family: -apple-system, "Impact", "Arial Black", sans-serif;
  font-size: clamp(28px, 5vw, 48px);
  font-weight: 900;
  font-style: italic;
  color: #ffd60a;
  -webkit-text-stroke: 3px #000;
  text-shadow: 4px 4px 0 #c1272d, -2px -2px 0 #fff;
  letter-spacing: -2px;
  z-index: 3;
  animation: hit-pop 0.6s ease;
  pointer-events: none;
}
#b-hit-p1 { left: 22%; }
#b-hit-p2 { right: 22%; }
@keyframes hit-pop {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  40% { transform: scale(1.3) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(-5deg); opacity: 1; }
}

/* 對白框 (KO 時) */
.bbubble {
  position: absolute;
  top: 12%;
  background: #fff;
  border: 3px solid #000;
  border-radius: 12px;
  padding: 8px 14px;
  font-weight: 900;
  font-size: clamp(12px, 1.3vw, 16px);
  color: #000;
  z-index: 3;
  max-width: 220px;
  text-align: center;
  box-shadow: 4px 4px 0 #000;
  animation: bubble-in 0.3s ease;
}
.bbubble-p1 { left: 16%; }
.bbubble-p2 { right: 16%; }
.bbubble-p1::after, .bbubble-p2::after {
  content: '';
  position: absolute;
  bottom: -14px;
  border: 7px solid transparent;
  border-top-color: #fff;
  filter: drop-shadow(0 3px 0 #000);
}
.bbubble-p1::after { left: 30px; }
.bbubble-p2::after { right: 30px; }
@keyframes bubble-in {
  0% { transform: scale(0); }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* === 雙人作答區（下半） === */
.dual-arena {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  background: #1e40af;
  position: relative;
}
.parena {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.parena-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.parena.p1 .parena-bg {
  background: linear-gradient(180deg, rgba(255, 235, 200, 0.88), rgba(255, 200, 150, 0.88));
}
.parena.p2 .parena-bg {
  background: linear-gradient(180deg, rgba(200, 255, 220, 0.88), rgba(150, 230, 180, 0.88));
}
.parena-content {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  min-height: 0;
}
.parena-qcard {
  flex: 0 0 auto;
  background: #fff;
  border: 3px solid #000;
  border-radius: 6px;
  padding: 10px 14px;
  box-shadow: 0 3px 0 #000;
  max-height: 40%;
  overflow-y: auto;
}
.parena-qtext {
  font-size: clamp(14px, 1.6vw, 19px);
  font-weight: 900;
  line-height: 1.45;
  word-break: break-word;
  color: #1a1a2e;
  white-space: pre-wrap;
}
.parena-qimg-wrap { margin-top: 8px; display: flex; justify-content: center; }
.parena-qimg-wrap img {
  max-width: 100%;
  max-height: 14vh;
  border: 2px solid #000;
}

.parena-options {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  min-height: 0;
}
.popt {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #fff;
  border: 3px solid #000;
  border-radius: 6px;
  font-size: clamp(14px, 1.4vw, 18px);
  font-weight: 900;
  color: #1a1a2e;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 0 #000;
  transition: transform 0.06s, box-shadow 0.06s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  word-break: break-word;
  line-height: 1.3;
  min-height: 50px;
}
.popt:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 #000;
}
.popt-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 2px solid #000;
  border-radius: 3px;
  font-weight: 900; font-size: 14px;
  flex: 0 0 28px;
}
.parena.p1 .popt-num { background: #ffd60a; color: #000; }
.parena.p2 .popt-num { background: #2ecc71; color: #000; }
.popt-body { flex: 1; min-width: 0; }
.popt.correct {
  background: #66bb6a !important;
  color: #fff !important;
  border-color: #2e7d32 !important;
  animation: opt-bounce 0.3s;
}
.popt.wrong {
  background: #ef5350 !important;
  color: #fff !important;
  border-color: #c62828 !important;
  animation: opt-shake 0.4s;
}
@keyframes opt-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px) scale(1.04); }
}
@keyframes opt-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* 答對 / 答錯時整片區域閃光 */
.parena-flash {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
}
.parena-flash.right { background: rgba(56, 211, 159, 0.4); animation: flash-fade 0.5s; }
.parena-flash.wrong { background: rgba(255, 95, 109, 0.4); animation: flash-fade 0.5s; }
@keyframes flash-fade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* 中間分隔線 */
.parena-divider {
  flex: 0 0 6px;
  background: repeating-linear-gradient(45deg,
    #000 0, #000 6px, #ffd60a 6px, #ffd60a 12px);
  border-left: 2px solid #000;
  border-right: 2px solid #000;
  z-index: 2;
}

/* === 底部鍵盤提示 === */
.bkeys-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 6px 10px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: #0b1020;
  border-top: 2px solid #000;
  font-size: 11px;
  color: #ccc;
  font-weight: 700;
}
.bkeys-footer .p1-key { color: #ffd60a; }
.bkeys-footer .p2-key { color: #2ecc71; }
.bkeys-footer .vs-mini { font-size: 14px; }

/* 觸控裝置：放大按鈕、隱藏鍵盤提示 */
@media (hover: none) and (pointer: coarse) {
  .bkeys-footer { display: none; }
  .popt { padding: 14px; font-size: clamp(15px, 2vw, 22px); min-height: 60px; }
  .popt-num { width: 34px; height: 34px; flex: 0 0 34px; font-size: 16px; }
}

/* 直立提示 (portrait 模式) */
.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(135deg, #1e40af, #0f1f6b);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-align: center;
  gap: 24px;
  padding: 20px;
}
.rotate-icon {
  font-size: 96px;
  animation: rotate-spin 2s ease-in-out infinite;
}
@keyframes rotate-spin {
  0%, 100% { transform: rotate(-15deg); }
  50% { transform: rotate(75deg); }
}
.rotate-text {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.6;
}
/* 在 portrait + 窄螢幕（手機/iPad 直立）時，覆蓋對戰畫面 */
@media (orientation: portrait) and (max-width: 900px) {
  .battle-screen.active .rotate-hint { display: flex; }
}

/* 結算畫面 — 對戰模式的紅白機四色按鈕 */
#screen-result.is-battle {
  background:
    repeating-linear-gradient(0deg, transparent 0, transparent 14px, rgba(0,0,0,0.06) 14px, rgba(0,0,0,0.06) 15px),
    linear-gradient(180deg, #4fc3f7 0%, #1976d2 100%);
}
#screen-result.is-battle .result-wrap {
  background: #fff;
  border: 4px solid #000;
  border-radius: 8px;
  margin: 20px;
  padding: 18px;
  box-shadow: 0 6px 0 #000;
}
#screen-result.is-battle .result-medal { font-size: 56px; }
#screen-result.is-battle #result-title {
  font-family: -apple-system, "Impact", sans-serif;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #c1272d;
  text-shadow: 3px 3px 0 #ffd60a;
  margin: 8px 0;
}
#screen-result.is-battle .result-name { color: #000; font-weight: 700; }
#screen-result.is-battle .result-stats > div {
  background: #ffd60a;
  border: 3px solid #000;
  box-shadow: 0 3px 0 #000;
  color: #000;
}
#screen-result.is-battle .stat-num { color: #c1272d; }
#screen-result.is-battle .stat-label { color: #000; font-weight: 700; }
#screen-result.is-battle .result-actions { gap: 8px; }
#screen-result.is-battle .result-actions .btn {
  background: #e63946 !important;
  color: #fff !important;
  border: 3px solid #000 !important;
  border-radius: 4px !important;
  font-weight: 900 !important;
  letter-spacing: 0.05em !important;
  box-shadow: 0 4px 0 #000 !important;
  text-shadow: none !important;
}
#screen-result.is-battle .result-actions .btn:active {
  transform: translateY(4px) !important;
  box-shadow: 0 0 0 #000 !important;
}
#screen-result.is-battle #result-retry {
  background: #ffd60a !important;  /* 黃色 = 重新再玩 */
  color: #000 !important;
}
#screen-result.is-battle .result-actions .btn .en {
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
  opacity: 0.75;
  margin-top: 1px;
  font-weight: 700;
}

/* K.O. 全螢幕特效 */
.ko-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(0,0,0,0.85), rgba(0,0,0,0.55));
  z-index: 50;
  animation: ko-fadein 0.3s ease;
}
@keyframes ko-fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}
.ko-text {
  font-size: clamp(80px, 22vw, 240px);
  font-weight: 900;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, #ffd479, #ff5f6d, #5b8cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 2px rgba(255,255,255,0.15);
  filter: drop-shadow(0 0 30px rgba(255, 138, 61, 0.8));
  animation: ko-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes ko-pop {
  0% { transform: scale(0.3) rotate(-12deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* 響應式 (窄螢幕) */
/* ===== 大螢幕 ===== */
@media (min-width: 720px) {
  .hero-title { font-size: 64px; }
  .hero-title span { font-size: 40px; }
  .opt { font-size: 18px; }
  .qcard-text { font-size: 22px; }
}
