@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@600;700&family=Plus+Jakarta+Sans:wght@600;700;800&display=swap');

:root {
  --bg-main: #0c0e14;
  --bg-panel: #151923;
  --bg-card: #1c2230;
  --helldiver-yellow: #facc15;
  --helldiver-amber: #f59e0b;
  --tactical-cyan: #38bdf8;
  --danger-red: #ef4444;
  --success-green: #22c55e;
  --border-subtle: rgba(255, 255, 255, 0.14);
}

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

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background-color: var(--bg-main);
  background-image:
    radial-gradient(circle at 15% 20%, rgba(250, 204, 21, 0.08), transparent 40%),
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 100% 100%, 32px 32px, 32px 32px;
  color: #f8fafc;
  height: 100vh;
  overflow: hidden;
}

/* --- HAZARD STRIPES --- */
.hazard-stripe {
  position: fixed;
  left: 0;
  right: 0;
  height: 8px;
  background: repeating-linear-gradient(
    -45deg,
    var(--helldiver-yellow),
    var(--helldiver-yellow) 14px,
    #111827 14px,
    #111827 28px
  );
  opacity: 0.85;
  z-index: 30;
}
.hazard-stripe.top { top: 0; }
.hazard-stripe.bottom { bottom: 0; }

/* --- TOP UTILITY --- */
.top-utility {
  position: fixed;
  top: 20px;
  right: 24px;
  display: flex;
  gap: 10px;
  z-index: 50;
}

.tac-icon-btn {
  background: rgba(21, 25, 35, 0.9);
  border: 1px solid var(--helldiver-yellow);
  color: var(--helldiver-yellow);
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 14px;
  cursor: pointer;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  transition: 0.15s;
}

.tac-icon-btn:hover {
  background: var(--helldiver-yellow);
  color: #0f172a;
}

/* --- SCREENS --- */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  padding: 28px 36px;
  flex-direction: column;
  justify-content: center;
  animation: slideUp 0.25s ease-out;
}

.screen.active {
  display: flex;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- SCREEN 1: START MENU (ASYMMETRIC BRIEFING) --- */
.start-container {
  max-width: 1060px;
  width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 36px;
  align-items: center;
}

.mission-tag {
  display: inline-block;
  background: rgba(250, 204, 21, 0.14);
  border-left: 4px solid var(--helldiver-yellow);
  color: var(--helldiver-yellow);
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 14px;
  letter-spacing: 1.5px;
  margin-bottom: 14px;
}

.hero-title {
  margin: 0 0 16px;
  line-height: 0;
}

.hero-title img {
  display: block;
  width: min(100%, 560px);
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.55));
}

/* Tombol MULAI OPERASI (gambar dari assets/ui/btn-start.png) */
.btn-start-img {
  display: block;
  width: min(100%, 460px);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.btn-start-img img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  pointer-events: none;
}

.btn-start-img:hover,
.btn-start-img:focus-visible {
  outline: none;
  transform: scale(1.04);
  filter: brightness(1.1) drop-shadow(0 0 16px rgba(250, 204, 21, 0.7));
}

.btn-start-img:active {
  transform: scale(0.97);
  filter: brightness(0.92);
}

.hero-desc {
  color: #cbd5e1;
  font-size: 1.02rem;
  line-height: 1.6;
  max-width: 500px;
  margin-bottom: 28px;
}

.btn-deploy {
  background: var(--helldiver-yellow);
  color: #090d16;
  border: none;
  padding: 16px 36px;
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  box-shadow: 0 8px 25px rgba(250, 204, 21, 0.25);
  transition: transform 0.12s, background 0.15s;
}

.btn-deploy span {
  font-size: 1.45rem;
  letter-spacing: 1px;
}

.btn-deploy small {
  font-size: 0.75rem;
  opacity: 0.8;
  letter-spacing: 1.2px;
}

.btn-deploy.small {
  padding: 12px 26px;
  align-items: center;
  font-size: 1rem;
}

.btn-deploy:hover {
  background: #fde047;
  transform: translateY(-2px);
}

/* --- KARTU PREVIEW MENU START ---
   Bingkai: assets/ui/card_preview.png (bezel baja tipis; header & footer teks sudah menjadi bagian gambar,
   sudut luar dan jendela tengah transparan). Ukuran asli gambar 1122 x 1402 (rasio 0,8003); lubang transparan di x 48..1074, y 99..1220 (sudut miring).
   Susunan lapisan:
     z-index 1 = #preview-stage (kanvas live + background ngarai), di BELAKANG bingkai
     z-index 2 = bingkai card_preview.png (::after), di ATAS, tidak menangkap klik
   #preview-stage sengaja dibuat lebih besar 10px-gambar ke semua sisi dari lubang transparan bingkai, sehingga
   tepinya masuk ke bawah bibir bezel (sudah diverifikasi: cincin 10px itu 100% buram): jendela terisi penuh tanpa
   celah gelap di atas / bawah di semua ukuran layar. Persentase dihitung terhadap kartu, jadi ikut skala kartu. */
.radar-card {
  --card-ar: 0.80029;       /* lebar / tinggi gambar = 1122 / 1402 (renderer.js ikut mengoreksi dari ukuran gambar asli) */
  --card-max: 410px;        /* lebar maksimum di desktop; dinaikkan oleh media query monitor besar di bawah */
  position: relative;
  /* Lebar proporsional (31vw, dibatasi 300px..--card-max), tetap tidak melebihi kolom dan tinggi layar */
  width: min(100%, clamp(300px, 31vw, var(--card-max)), calc((100vh - 7rem) * var(--card-ar)));
  width: min(100%, clamp(300px, 31vw, var(--card-max)), calc((100dvh - 7rem) * var(--card-ar)));
  min-width: 13rem;
  aspect-ratio: var(--card-ar);
  margin-inline: auto;
}

/* Lapisan atas: bingkai baja */
.radar-card::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: url('assets/ui/card_preview.png') center / 100% 100% no-repeat;
  image-rendering: pixelated;
  filter: drop-shadow(0 10px 22px rgba(0, 0, 0, 0.55));
}

/* Lapisan bawah: panggung animasi, menyelinap sedikit di bawah bibir bingkai */
.radar-card .preview-stage,
#preview-stage {
  position: absolute;
  top: 6.35%;
  left: 3.39%;
  width: 93.22%;
  height: 81.38%;
  z-index: 1;
  overflow: hidden;
  background: #090d16;
  image-rendering: pixelated;
}

#preview-canvas {
  width: 100%;
  height: 100%;
  background: transparent;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* --- SHARED SUB-SCREEN HEADER --- */
.header-bar {
  max-width: 960px;
  width: 100%;
  margin: 0 auto 28px auto;
  display: flex;
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 16px;
}

.btn-back {
  border: solid transparent;
  border-width: 9px 10px 9px 34px;
  border-image: url('assets/ui/frame-back.png') 26 30 26 90 fill stretch;
  background: none;
  color: #fde68a;
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 1px;
  min-height: 46px;
  padding: 4px 14px 4px 8px;
  cursor: pointer;
  image-rendering: pixelated;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.btn-back:hover,
.btn-back:focus-visible {
  outline: none;
  filter: brightness(1.2) drop-shadow(0 0 8px rgba(250, 204, 21, 0.55));
}

.btn-back:active {
  transform: translateX(-2px) scale(0.97);
}

.step-badge {
  display: inline-block;
  margin-bottom: 6px;
  border: solid transparent;
  border-width: 8px 12px;
  border-image: url('assets/ui/frame-badge.png') 28 40 fill stretch;
  padding: 1px 10px;
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.78rem;
  color: var(--tactical-cyan);
  letter-spacing: 1.5px;
  image-rendering: pixelated;
}

.header-titles h2 {
  font-family: 'Chakra Petch', sans-serif;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  color: #ffffff;
  letter-spacing: 0.5px;
}

/* --- SCREEN 2: SQUAD SELECTION --- */
.squad-grid {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

/* Layar pilih mata pelajaran: 3 kartu sejajar (PPKn, Matematika, Bahasa Inggris) */
#screen-subjects .squad-grid {
  max-width: 1060px;
  grid-template-columns: repeat(3, 1fr);
}

/* Layar pilih pemain: tetap 2 kolom */
#screen-players .squad-grid {
  grid-template-columns: repeat(2, 1fr);
}

.squad-card {
  --bw: clamp(18px, 2.2vw, 28px);
  border: var(--bw) solid transparent;
  border-image: url('assets/ui/frame-card.png') 56 fill stretch;
  background: none;
  padding: clamp(6px, 1vw, 16px);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  image-rendering: pixelated;
  transition: transform 0.15s, filter 0.15s;
}

.squad-card:hover,
.squad-card:focus-visible {
  outline: none;
  transform: translateY(-4px);
  filter: brightness(1.15) drop-shadow(0 0 14px rgba(250, 204, 21, 0.4));
}

.squad-card:active {
  transform: translateY(0) scale(0.985);
}

.squad-code {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.78rem;
  color: var(--helldiver-yellow);
  letter-spacing: 1.5px;
}

.squad-avatar {
  font-size: 2.8rem;
  margin: 4px 0;
}

.squad-card h3 {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1.65rem;
}

.squad-card p {
  color: #94a3b8;
  font-size: 0.9rem;
  line-height: 1.5;
  flex: 1;
}

.squad-footer {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.8rem;
  color: var(--tactical-cyan);
}

/* --- SCREEN 3: SECTOR / TOPIC GRID --- */
.sector-grid {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.sector-card {
  --bw: clamp(16px, 1.8vw, 24px);
  border: var(--bw) solid transparent;
  border-image: url('assets/ui/frame-card.png') 56 fill stretch;
  background: none;
  padding: 6px 8px;
  cursor: pointer;
  image-rendering: pixelated;
  transition: transform 0.15s, filter 0.15s;
}

/* Kartu unggulan & tile Matematika: bingkai kotak kuning menyala */
.sector-card.featured,
.sector-card.math-tile {
  --bw: clamp(14px, 1.6vw, 20px);
  border-image-source: url('assets/ui/frame-tile.png');
  border-image-slice: 44 fill;
}

.sector-card:hover,
.sector-card:focus-visible {
  outline: none;
  transform: translateY(-3px);
  filter: brightness(1.15) drop-shadow(0 0 12px rgba(250, 204, 21, 0.4));
}

.sector-card:active {
  transform: translateY(0) scale(0.985);
}

.sector-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sector-id {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--helldiver-yellow);
  padding: 3px 8px;
}

.sector-icon {
  font-size: 1.5rem;
}

.sector-card h3 {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1.15rem;
  margin-bottom: 6px;
  color: #ffffff;
}

.sector-card p {
  font-size: 0.82rem;
  color: #94a3b8;
  line-height: 1.4;
}

/* --- SCREEN 4: IN-GAME ARENA (NEW TACTICAL LAYOUT) --- */
#screen-game {
  padding: 0;
}

.arena-wrapper {
  display: flex;
  width: 100%;
  height: 100%;
}

.player-lane {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-right: 3px solid var(--helldiver-yellow);
  position: relative;
}

.player-lane:last-child {
  border-right: none;
}

/* Top Tactical HUD Bar (Di luar canvas agar lebih bersih) */
.lane-topbar {
  height: 44px;
  background: #0b0e17;
  border-bottom: 2px solid #262f42;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hearts-box {
  font-size: 1.2rem;
  letter-spacing: 3px;
}

.squad-tag {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.8rem;
  color: var(--tactical-cyan);
  letter-spacing: 1px;
}

.score-tag {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1.05rem;
  color: var(--helldiver-yellow);
  font-weight: 700;
}

/* Battlefield Area */
.battle-stage {
  position: relative;
  height: 50%;
  width: 100%;
  background: #090d16;
  overflow: hidden;
}

.battle-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* Bottom Command Deck (Tampilan soal & opsi berbeda dari kalkulator referensi) */
.command-deck {
  flex: 1;
  background: #111520;
  border-top: 2px solid #2c354a;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.question-terminal {
  flex: 1 1 0;
  min-height: 84px;
  border: solid transparent;
  border-width: 14px 13px 14px 22px;
  border-image: url('assets/ui/terminal-question.png') 38 34 38 56 fill stretch;
  padding: 2px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  image-rendering: pixelated;
}

.question-text {
  font-size: clamp(0.86rem, 1.15vw, 1rem);
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.4;
}

.status-pill {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.72rem;
  padding: 4px 8px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--tactical-cyan);
  white-space: nowrap;
  flex-shrink: 0;
}

.status-pill.swapped {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.options-matrix {
  /* Tinggi tombol: mengikuti lebar kolom (rasio bingkai 3,7 : 1), dibatasi sisa tinggi dek */
  --opt-cols: 2;
  --opt-rows: 2;
  --opt-gap: 10px;
  --term-min: 84px;
  --opt-h: clamp(
    34px,
    min(
      calc((100cqw - 44px) / var(--opt-cols) * 0.27),
      calc((100cqh - var(--term-min) - var(--opt-gap) * var(--opt-rows)) / var(--opt-rows))
    ),
    128px
  );
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--opt-cols), minmax(0, 1fr));
  grid-auto-rows: minmax(0, var(--opt-h));
  align-content: center;
  gap: var(--opt-gap) 14px;
  min-height: 0;
}

/* Tombol jawaban: bingkai 3 bagian (tutup kiri berisi slot emas, tengah melar, tutup kanan) */
.tac-opt-btn {
  position: relative;
  container-type: size;
  display: flex;
  align-items: stretch;
  padding: 0;
  border: 0;
  background:
    url('assets/ui/answer-cap-r.png') right center / auto 100% no-repeat,
    url('assets/ui/answer-cap-l.png') left center / auto 100% no-repeat,
    url('assets/ui/answer-mid.png') center / 100% 100% no-repeat;
  color: #f1f5f9;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  image-rendering: pixelated;
  transition: transform 0.08s ease, filter 0.12s ease;
}

/* Tombol jawaban: kotak lencana A/B/C/D menimpa ujung kiri batang jawaban agar menyatu */
.tac-opt-btn {
  --badge-overlap: 42cqh; /* jarak ujung kiri batang jawaban yang masuk ke bawah answer-badge */
  position: relative;
  container-type: size;
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  border: 0;
  background: none;
  color: #f1f5f9;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  image-rendering: pixelated;
  transition: transform 0.08s ease, filter 0.12s ease;
}

.tac-opt-btn:hover:not(:disabled),
.tac-opt-btn:focus-visible {
  outline: none;
  filter: brightness(1.18) drop-shadow(0 0 8px rgba(250, 204, 21, 0.5));
}

.tac-opt-btn:active:not(:disabled) {
  transform: translateY(2px) scale(0.99);
}

/* Lapisan atas (z-index: 2): kotak lencana menimpa ujung kiri batang jawaban */
.opt-cap {
  position: relative;
  z-index: 2;
  flex: none;
  height: 100%;
  aspect-ratio: 140 / 120;
  margin-right: calc(-1 * var(--badge-overlap));
  background: url('assets/ui/answer-badge.png') center / 100% 100% no-repeat;
}

/* Huruf A/B/C/D tepat di titik tengah bingkai emas */
.opt-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 0.04em;
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  font-size: clamp(0.85rem, 26cqh, 1.85rem);
  line-height: 1;
  color: #facc15;
  text-shadow: 0 0 8px rgba(250, 204, 21, 0.5);
}

/* Lapisan bawah (z-index: 1): batang jawaban menyambung keluar dari balik answer-badge */
.opt-text {
  position: relative;
  z-index: 1;
  isolation: isolate;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 0 44cqh 0 calc(var(--badge-overlap) + 12cqh);
  background:
    url('assets/ui/answer-cap-r.png') right center / auto 100% no-repeat,
    url('assets/ui/answer-mid.png') center / 100% 100% no-repeat;
  font-size: 0.85rem;
  font-size: clamp(0.72rem, 17cqh, 1.4rem);
  line-height: 1.2;
}

.opt-text::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: url('assets/ui/answer-cap-r.png') right center / auto 100% no-repeat;
  transform: scaleX(-1);
  pointer-events: none;
}

.tac-opt-btn.wrong-flash {
  animation: shake 0.3s;
  filter: hue-rotate(-38deg) saturate(1.5) drop-shadow(0 0 10px rgba(239, 68, 68, 0.9));
}

.tac-opt-btn.correct-flash {
  filter: hue-rotate(78deg) saturate(1.3) drop-shadow(0 0 10px rgba(34, 197, 94, 0.9));
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* --- MODALS --- */
.overlay-modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 16, 0.88);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  text-align: center;
}

.overlay-modal.active {
  display: flex;
}

.cd-label {
  font-family: 'Chakra Petch', sans-serif;
  color: var(--tactical-cyan);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.countdown-number {
  font-family: 'Chakra Petch', sans-serif;
  font-size: clamp(5rem, 14vw, 8.5rem);
  color: var(--helldiver-yellow);
  text-shadow: 0 0 35px rgba(250, 204, 21, 0.45);
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--helldiver-yellow);
  padding: 28px 32px;
  max-width: 520px;
  width: 100%;
  clip-path: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
}

.modal-badge {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.75rem;
  color: var(--tactical-cyan);
  letter-spacing: 1.5px;
  margin-bottom: 6px;
}

.modal-card h2 {
  font-family: 'Chakra Petch', sans-serif;
  color: var(--helldiver-yellow);
  font-size: 1.9rem;
  margin-bottom: 14px;
}

.modal-card ul {
  text-align: left;
  padding-left: 18px;
  margin-bottom: 20px;
  color: #cbd5e1;
  font-size: 0.92rem;
  line-height: 1.55;
}

.modal-card li {
  margin-bottom: 8px;
}

.result-stats {
  display: flex;
  gap: 14px;
  margin: 18px 0;
}

.stat-pill {
  flex: 1;
  background: #0c0f17;
  border: 1px solid #2c354a;
  padding: 14px;
}

.stat-pill h3 {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.82rem;
  color: #94a3b8;
  margin-bottom: 4px;
}

.stat-pill .big-score {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 2rem;
  color: var(--helldiver-yellow);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.eliminated-banner {
  position: absolute;
  inset: 0;
  background: rgba(9, 12, 18, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.eliminated-banner h3 {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1.8rem;
  color: var(--danger-red);
}

@media (max-width: 820px) {
  .start-container { grid-template-columns: 1fr; }
  .start-right { display: none; }
  .sector-grid { grid-template-columns: repeat(2, 1fr); }
  .options-matrix { --opt-cols: 1; --opt-rows: 4; --opt-gap: 8px; }
}


/* =========================================================
   PANEL & TOMBOL AKSI (tanpa aset gambar)
   ========================================================= */

:root {
  --steel-panel: #0f172a;
  --steel-panel-raised: #1e293b;
  --steel-edge-light: #334155;
  --steel-edge-dark: #020617;
  --tactical-yellow: #facc15;
}

.modal-card {
  background-color: var(--steel-panel);
  border-top: 2px solid var(--steel-edge-light);
  border-right: 1px solid #1e293b;
  border-bottom: 3px solid var(--steel-edge-dark);
  border-left: 1px solid #334155;
  clip-path: polygon(
    0 0,
    calc(100% - 14px) 0,
    100% 14px,
    100% 100%,
    14px 100%,
    0 calc(100% - 14px)
  );
}

.btn-deploy,
.btn-deploy.small,
.tac-icon-btn {
  clip-path: polygon(
    0 0,
    calc(100% - 14px) 0,
    100% 14px,
    100% 100%,
    14px 100%,
    0 calc(100% - 14px)
  );
}

.btn-deploy {
  border-top: 2px solid #fde68a;
  border-bottom: 3px solid #92400e;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 7px 18px rgba(250, 204, 21, 0.18);
}

.btn-deploy:active,
.tac-icon-btn:active {
  transform: translateY(2px);
}

/* Ikon sprite: rendering tajam untuk aset pixel art */
.pixel-sprite {
  display: inline-block;
  flex: 0 0 auto;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Hormati preferensi pengguna yang mengurangi animasi */
@media (prefers-reduced-motion: reduce) {
  .btn-back,
  .btn-start-img,
  .squad-card,
  .sector-card,
  .tac-opt-btn,
  .retro-calc-btn,
  .btn-deploy,
  .tac-icon-btn {
    transition: none;
  }
}


/* =========================================================
   IKON PIKSEL (assets/icons)
   ========================================================= */
.ico {
  display: inline-block;
  height: 1.1em;
  width: auto;
  vertical-align: middle;
}
.ico-inline { height: 1.15em; }

.tac-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tac-icon-btn .ico { height: 20px; }

.hearts-box {
  display: flex;
  align-items: center;
  gap: 4px;
  letter-spacing: normal;
}
.hearts-box .ico { height: 24px; }

.stat-pill .ico { height: 16px; margin: 0 1px; }

.squad-avatar {
  display: flex;
  align-items: center;
  min-height: 64px;
}
.squad-avatar .ico { height: 60px; }

.sector-icon {
  display: flex;
  align-items: center;
}
.sector-icon .ico { height: 32px; }


/* =========================================================
   RESPONSIVE (HP, tablet, laptop, monitor besar)
   ========================================================= */

html { -webkit-text-size-adjust: 100%; }

body {
  height: 100vh;
  height: 100dvh; /* tinggi layar yang benar di browser HP (address bar naik turun) */
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Dek input (keypad Matematika & pilihan ganda): matikan gestur browser sepenuhnya.
   Dua siswa menyentuh layar bersamaan tidak boleh dibaca sebagai pinch-zoom, pan, atau double-tap zoom. */
.retro-calc-keypad,
.retro-calc-btn,
.options-matrix,
.tac-opt-btn {
  touch-action: none;
}

/* Menu bisa di-scroll di layar pendek, tetap rata tengah di layar tinggi */
.screen {
  overflow-y: auto;
  justify-content: flex-start;
  padding: clamp(16px, 3vw, 36px);
}
.start-container { margin: auto; }
.header-bar { margin-top: auto; }
.squad-grid,
.sector-grid { margin-bottom: auto; }

#screen-game {
  padding: 0;
  overflow: hidden;
}

/* Modal bisa di-scroll di layar pendek */
.overlay-modal {
  overflow-y: auto;
  justify-content: flex-start;
}
.overlay-modal > :first-child { margin-top: auto; }
.overlay-modal > :last-child { margin-bottom: auto; }

/* Arena 1 pemain: lebar menyesuaikan layar */
.arena-wrapper.solo {
  max-width: var(--solo-w);
  width: 100%;
  margin: 0 auto;
}

.command-deck {
  min-height: 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}
.options-matrix { min-height: 0; }

/* ---------- Layar kecil: tablet & HP tegak (<= 1000px) ---------- */
@media (max-width: 1000px) {
  .start-container { grid-template-columns: 1fr; }
  .start-right { display: none; }
}

/* ---------- Tablet & HP (<= 820px) ---------- */
@media (max-width: 820px) {
  .screen { padding-top: 64px; }
  .start-container { gap: 20px; }
  .hero-desc { font-size: 0.95rem; margin-bottom: 20px; }
  .squad-grid,
  #screen-subjects .squad-grid,
  #screen-players .squad-grid { grid-template-columns: 1fr; gap: 14px; }
  .header-bar { gap: 12px; margin-bottom: 18px; }
  .lane-topbar { padding: 0 12px; }

  /* Mode 2 pemain: layar ditumpuk atas dan bawah */
  .arena-wrapper.duo { flex-direction: column; }
  .arena-wrapper.duo .player-lane {
    flex: 1 1 0;
    height: auto;
    min-height: 0;
    border-right: none;
    border-bottom: 3px solid var(--helldiver-yellow);
  }
  .arena-wrapper.duo .player-lane:last-child { border-bottom: none; }
  .arena-wrapper.duo .lane-topbar { height: 32px; }
  .arena-wrapper.duo .hearts-box .ico { height: 18px; }
  .arena-wrapper.duo .battle-stage { height: 40%; }
  .arena-wrapper.duo .command-deck { padding: 6px 10px; gap: 6px; }
  .arena-wrapper.duo .question-terminal { min-height: 0; padding: 6px 10px; }
  .arena-wrapper.duo .question-text { font-size: 0.78rem; line-height: 1.25; }
  .arena-wrapper.duo .status-pill { display: none; }
  .arena-wrapper.duo .options-matrix { --opt-cols: 2; --opt-rows: 2; --opt-gap: 6px; --term-min: 50px; }

}

/* ---------- HP tegak (<= 560px) ---------- */
@media (max-width: 560px) {
  .top-utility { top: 10px; right: 10px; gap: 6px; }
  .tac-icon-btn { padding: 6px 10px; font-size: 0.72rem; }
  .tac-icon-btn .ico { height: 16px; }
  .btn-deploy { width: 100%; padding: 14px 22px; }
  .btn-deploy span { font-size: 1.25rem; }
  .squad-card { padding: 20px 18px; }
  .squad-card h3 { font-size: 1.35rem; }
  .squad-avatar .ico { height: 48px; }
  .sector-card { padding: 14px; }
  .modal-card { padding: 20px 18px; }
  .modal-card h2 { font-size: 1.5rem; }
  .result-stats { flex-direction: column; }
  .modal-actions { flex-direction: column; }
  .modal-actions > * { width: 100%; }
  .squad-tag { font-size: 0.7rem; }
  .score-tag { font-size: 0.9rem; }
  .hearts-box .ico { height: 20px; }
}

@media (max-width: 480px) {
  .sector-grid { grid-template-columns: 1fr; gap: 10px; }
}

/* ---------- Layar pendek: HP mendatar (landscape) ---------- */
@media (max-height: 560px) {
  .lane-topbar { height: 32px; padding: 0 10px; }
  .hearts-box .ico { height: 18px; }
  .battle-stage { height: 46%; }
  .command-deck { padding: 6px 10px; gap: 6px; }
  .question-terminal { min-height: 0; padding: 6px 10px; }
  .question-text { font-size: 0.78rem; line-height: 1.25; }
  .status-pill { display: none; }
  .options-matrix { --opt-cols: 2; --opt-rows: 2; --opt-gap: 6px; --term-min: 44px; }

  .screen { padding-top: 56px; }

}

/* ---------- Monitor besar ---------- */
@media (min-width: 2200px) and (min-height: 1100px) {
  html { font-size: 20px; }
  .start-container { max-width: 1320px; }
  .radar-card { --card-max: 580px; }
  .header-bar,
  .sector-grid { max-width: 1200px; }
  .squad-grid { max-width: 1020px; }
  #screen-subjects .squad-grid { max-width: 1340px; }
  #screen-game { --solo-w: 1280px; }
}

@media (min-width: 3000px) and (min-height: 1700px) {
  html { font-size: 26px; }
  .start-container { max-width: 1700px; }
  .radar-card { --card-max: 760px; }
  .header-bar,
  .sector-grid { max-width: 1560px; }
  .squad-grid { max-width: 1320px; }
  #screen-subjects .squad-grid { max-width: 1720px; }
  #screen-game { --solo-w: 1840px; }
}

/* =========================================================
   BILAH TIMER OPERASI (02:00) & KETAJAMAN IKON
   ========================================================= */
.ico {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#screen-game.active {
  display: flex;
  flex-direction: column;
}

.arena-wrapper {
  flex: 1;
  min-height: 0;
}

.match-timer-bar {
  height: 36px;
  width: 100%;
  background: #070a11;
  border-bottom: 2px solid #262f42;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
  z-index: 15;
}

.match-timer-bar .timer-label {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.78rem;
  color: #94a3b8;
  letter-spacing: 1.5px;
}

.match-timer-bar .timer-value {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--helldiver-yellow);
  background: #111827;
  border: 1px solid rgba(250, 204, 21, 0.45);
  padding: 2px 12px;
  letter-spacing: 2px;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}

.match-timer-bar.urgent .timer-value {
  color: #fca5a5;
  background: #450a0a;
  border-color: var(--danger-red);
  animation: timerPulse 0.6s infinite alternate;
}

@keyframes timerPulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

/* =========================================================
   TOMBOL AUDIO & PANEL DROPDOWN SLIDER VOLUME
   ========================================================= */
.audio-menu-wrap {
  position: relative;
  display: inline-block;
}

.audio-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background: var(--steel-panel, #0f172a);
  border-top: 2px solid var(--steel-edge-light, #334155);
  border-right: 1px solid #1e293b;
  border-bottom: 3px solid var(--steel-edge-dark, #020617);
  border-left: 3px solid var(--helldiver-yellow);
  padding: 12px 14px;
  clip-path: polygon(
    0 0,
    calc(100% - 12px) 0,
    100% 12px,
    100% 100%,
    12px 100%,
    0 calc(100% - 12px)
  );
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.65);
  display: none;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
}

.audio-popover.open {
  display: flex;
  animation: slideUp 0.15s ease-out;
}

.audio-popover-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: #94a3b8;
}

#volume-pct {
  color: var(--helldiver-yellow);
  font-size: 0.85rem;
}

.audio-popover-body {
  display: flex;
  align-items: center;
  gap: 10px;
}

.popover-mute-btn {
  background: #1e293b;
  border: 1px solid rgba(250, 204, 21, 0.45);
  padding: 5px 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: 0.12s;
}

.popover-mute-btn:hover {
  background: #27364d;
  border-color: var(--helldiver-yellow);
}

.popover-mute-btn .ico {
  height: 18px;
}

#volume-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  width: 100%;
  height: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  accent-color: var(--helldiver-yellow);
  outline: none;
  cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 18px;
  background: var(--helldiver-yellow);
  border: 1px solid #090d16;
  cursor: pointer;
}

#volume-slider::-moz-range-thumb {
  width: 12px;
  height: 18px;
  background: var(--helldiver-yellow);
  border: 1px solid #090d16;
  border-radius: 0;
  cursor: pointer;
}

/* =========================================================
   INDIKATOR 3 PELURU & STATUS RELOAD 2 DETIK
   ========================================================= */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ammo-rack {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.ammo-pip {
  width: 8px;
  height: 21px;
  background: url('assets/ammo_icon.png') center / contain no-repeat;
  image-rendering: pixelated;
  display: inline-block;
  transition: opacity 0.15s, filter 0.15s;
}

.ammo-pip.empty {
  filter: grayscale(1) brightness(0.55);
  opacity: 0.4;
}

.status-pill.reloading {
  background: rgba(245, 158, 11, 0.25);
  color: #fde047;
  border: 1px solid rgba(250, 204, 21, 0.55);
  animation: timerPulse 0.45s infinite alternate;
}

.options-matrix.deck-reloading .tac-opt-btn {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.tac-opt-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

/* =========================================================
   KREDIT PEMBUAT & GRID 20 TANTANGAN MATEMATIKA
   ========================================================= */
.start-meta {
  margin-top: 18px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

/* Pelat kredit & tautan "Tentang" (gambar dari assets/ui) */
.plate-credit,
.about-link {
  display: block;
  width: clamp(190px, 46%, 270px);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.plate-credit img,
.about-link img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.about-link:hover,
.about-link:focus-visible {
  outline: none;
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.12) drop-shadow(0 0 12px rgba(56, 189, 248, 0.6));
}

.about-link:active {
  transform: scale(0.97);
}


.math-hero-symbol {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--helldiver-yellow);
  letter-spacing: 2px;
}

.sector-grid.math-mode {
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.sector-card.math-tile {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  min-height: 86px;
}

.math-tile-symbol {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1.65rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.1;
}

.sector-card.math-tile.featured .math-tile-symbol {
  color: var(--helldiver-yellow);
}

.math-tile-label {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: #cbd5e1;
}

@media (max-width: 720px) {
  .sector-grid.math-mode {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 480px) {
  .sector-grid.math-mode {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* =========================================================
   ASET UI PIXEL-ART (assets/ui/) — PENYESUAIAN & RESPONSIF
   ========================================================= */

.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;
}

/* Dek perintah = wadah ukuran: tombol, soal, dan kalkulator menyesuaikan diri dengan ruangnya */
.command-deck {
  container-type: size;
  container-name: deck;
}

/* Tile tantangan Matematika di dalam bingkai kotak */
.sector-card.math-tile {
  padding: 4px 2px;
  min-height: 104px;
  gap: 4px;
}

.math-tile-symbol {
  text-shadow: 0 0 10px rgba(250, 204, 21, 0.25);
}

/* Teks pada kartu pilihan: terang di atas layar gelap bingkai */
.squad-card p,
.sector-card p {
  color: #a9b8cc;
}

/* Layar soal PPKn (kaca CRT) */
.question-text {
  font-size: 1rem;
  font-size: clamp(0.95rem, 2.3cqw, 1.7rem);
  font-weight: 700;
  line-height: 1.35;
  color: #e6fffb;
  text-shadow: 0 0 10px rgba(45, 212, 191, 0.25);
}

.question-terminal .status-pill {
  align-self: flex-end;
}

/* ---------- Kokpit solo: sayap kiri & kanan layar lebar ---------- */
#screen-game {
  position: relative;
  --solo-w: 920px;
}

.arena-wrapper {
  position: relative;
  z-index: 1;
}

.cockpit-wing {
  display: none;
  position: absolute;
  top: 36px; /* di bawah bilah timer */
  bottom: 0;
  width: calc((100% - var(--solo-w)) / 2);
  z-index: 0;
  pointer-events: none;
  image-rendering: pixelated;
  background-repeat: no-repeat;
  background-size: auto 100%, 100% 100%;
}

.cockpit-wing.left {
  left: 0;
  background-image:
    url('assets/ui/hud-canyon-cockpit.gif'),
    linear-gradient(180deg, #0d0d18 0%, #2a1a2c 42%, #8a4a2e 64%, #1b1119 100%);
  background-position: left center, 0 0;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 64px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 64px), transparent);
}

.cockpit-wing.right {
  right: 0;
  background-image:
    url('assets/ui/hud-canyon-cockpit.gif'),
    linear-gradient(180deg, #0d0d18 0%, #2a1a2c 42%, #8a4a2e 64%, #1b1119 100%);
  background-position: right center, 0 0;
  -webkit-mask-image: linear-gradient(270deg, #000 calc(100% - 64px), transparent);
  mask-image: linear-gradient(270deg, #000 calc(100% - 64px), transparent);
}

#screen-game.solo-mode .cockpit-wing {
  display: block;
}

/* Sayap hanya muncul bila ada ruang kosong cukup di kiri-kanan arena */
@media (max-width: 1199px), (max-height: 600px) {
  #screen-game.solo-mode .cockpit-wing {
    display: none;
  }
}

/* ---------- Layar kecil: bingkai dikecilkan agar konten lega ---------- */
@media (max-width: 820px) {
  .squad-card { --bw: 20px; }
  .sector-card { --bw: 16px; }
  .sector-card.featured,
  .sector-card.math-tile { --bw: 14px; }
  .sector-card.math-tile { min-height: 92px; }
  .question-terminal { border-width: 11px 10px 11px 17px; }
  .arena-wrapper.duo .question-terminal {
    min-height: 0;
    border-width: 8px 8px 8px 12px;
    padding: 0 8px;
  }
  .arena-wrapper.duo .question-text { font-size: 0.74rem; line-height: 1.2; }
}

@media (max-width: 560px) {
  .btn-back { min-height: 42px; font-size: 0.8rem; }
  .plate-credit,
  .about-link { width: min(100%, 300px); }
  .squad-card { --bw: 18px; }
}

@media (max-height: 560px) {
  .question-terminal {
    min-height: 0;
    border-width: 8px 8px 8px 12px;
    padding: 0 8px;
  }
  .question-text { font-size: 0.8rem; line-height: 1.2; }
}

@media (max-height: 800px) {
  .sector-card.math-tile { min-height: 92px; }
}

/* =========================================================
   BACKGROUND ANIMASI (GIF dari Kling AI)
   ========================================================= */

/* Menu utama: assets/bg_menu.gif (gambarnya dipasang renderer.js lewat --menu-bg).
   Lapisan gelap dibuat tipis: lebih pekat di kiri (teks), lebih terang di tengah & kanan. */
#screen-start {
  background-image:
    linear-gradient(90deg, rgba(9, 13, 22, 0.62) 0%, rgba(9, 13, 22, 0.25) 50%, rgba(9, 13, 22, 0.38) 100%),
    var(--menu-bg, none);
  background-size: 100% 100%, cover;
  background-position: center, center bottom;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}

.hero-desc,
.mission-tag {
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
}

/* Layar pilih pemain, mata pelajaran, dan materi: ruang komando animasi (assets/ui/bg_lobby.gif).
   Lapisan gelap tipis menjaga kartu tetap terbaca tanpa meredupkan radar/hologram. */
#screen-players,
#screen-subjects,
#screen-topics {
  background-color: #070b12;
  background-image:
    linear-gradient(rgba(9, 13, 22, 0.42), rgba(9, 13, 22, 0.42)),
    url('assets/ui/bg_lobby.gif');
  background-size: 100% 100%, cover;
  background-position: center;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}

#screen-players .header-titles h2,
#screen-subjects .header-titles h2,
#screen-topics .header-titles h2 {
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}

/* =========================================================
   PINTU BLAST: transisi antar layar & penutup saat arena disiapkan
   ========================================================= */
html { background: #0c0e14; }   /* terlihat sekilas saat layar bergetar */

#blast-doors {
  position: fixed;
  inset: 0;
  z-index: 90;            /* di atas layar & tombol utilitas (50), di bawah #countdown-modal (110) */
  pointer-events: none;
  visibility: hidden;     /* sembunyikan total saat pintu terbuka agar tidak ada garis subpiksel */
}

/* Selama pintu bergerak atau tertutup, tampilkan overlay & blokir klik ke layar di belakangnya */
#blast-doors.engaged {
  pointer-events: auto;
  visibility: visible;
}

.blast-door {
  position: fixed;
  left: 0;
  width: 100%;
  /* +1px overlap di garis tengah agar tidak ada celah 1px pada layar dengan tinggi ganjil / DPI pecahan */
  height: calc(50vh + 1px);
  height: calc(50dvh + 1px);
  background-color: #1b1f27;
  background-repeat: no-repeat;
  background-size: cover;
  image-rendering: pixelated;
  /* Membuka: 0.95s, melambat di akhir. Samakan dengan DOOR_OPEN_MS (950) di game.js. */
  transition: transform 0.95s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  backface-visibility: hidden;
}

.blast-door.top {
  top: 0;
  background-image: url('assets/ui/blast-door-top.png');
  background-position: bottom center;   /* sisi hazard bawah rapat di garis 50dvh */
  transform: translateY(calc(-100% - 2px));
}

.blast-door.bottom {
  bottom: 0;
  background-image: url('assets/ui/blast-door-bottom.png');
  background-position: top center;      /* sisi hazard atas rapat di garis 50dvh */
  transform: translateY(calc(100% + 2px));
}

/* Menutup: 0.95s, makin berat ke akhir sehingga bantingan jatuh tepat saat pintu bertemu */
#blast-doors.closed .blast-door {
  transform: translateY(0);
  transition: transform 0.95s cubic-bezier(0.45, 0, 0.88, 0.6);
}

/* Getaran singkat saat pintu membanting tertutup */
body.door-impact { animation: doorImpact 0.28s ease-out; }

@keyframes doorImpact {
  0%   { transform: translateY(0); }
  18%  { transform: translateY(6px); }
  36%  { transform: translateY(-5px); }
  54%  { transform: translateY(3px); }
  72%  { transform: translateY(-2px); }
  100% { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .blast-door,
  #blast-doors.closed .blast-door { transition-duration: 0.12s; }
  body.door-impact { animation: none; }
}

/* Countdown 3-2-1: tampil di depan pintu yang tertutup, latar transparan agar pintu terlihat */
#countdown-modal {
  z-index: 110;
  background: transparent;
}

/* Pelat HUD gelap di belakang teks: garis hazard kuning-hitam di pintu tidak lagi mengganggu keterbacaan,
   sementara pintu baja di sekelilingnya tetap terlihat penuh. */
.countdown-hud-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: min(88vw, 460px);
  max-width: 100%;
  background: rgba(9, 13, 22, 0.92);
  border: 2px solid #facc15;
  padding: 20px 44px;
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.95), inset 0 0 18px rgba(250, 204, 21, 0.2);
}

#countdown-modal .cd-label {
  margin-bottom: 4px;
  color: var(--tactical-cyan);
  font-size: clamp(0.78rem, 2.4vw, 1rem);
  text-shadow: 0 0 10px rgba(56, 189, 248, 0.45);
}

#countdown-modal .countdown-number {
  line-height: 1.1;
  -webkit-text-stroke: 2px #090d16;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #090d16, 0 0 28px rgba(250, 204, 21, 0.65);
}

@media (max-width: 560px) {
  .countdown-hud-box { padding: 14px 22px; }
}

/* =========================================================
   MODE MATEMATIKA: STATUS "SIAP TEMBAK" + 3 PELURU DI .lane-topbar
   Urutan: nyawa | nama tim (menyusut) | status & peluru | skor.
   Nama tim menyerap sisa lebar dan dipotong (…) atau disembunyikan di lane sempit,
   sehingga pil status tidak pernah meluap, baik di Solo, Duo kiri-kanan, maupun Duo atas-bawah di HP.
   ========================================================= */
.lane-topbar.has-status {
  container-type: inline-size;
  container-name: topbar;
  gap: 8px;
  min-width: 0;
}

.lane-topbar.has-status .hearts-box { flex: none; }

.lane-topbar.has-status .squad-tag {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lane-topbar.has-status .score-tag {
  flex: none;
  white-space: nowrap;
}

/* !important: aturan lama menyembunyikan .status-pill di layar pendek / Duo HP (untuk pil di terminal PPKn) */
.lane-topbar .status-pill {
  display: inline-flex !important;
  flex: none;
  justify-content: center;
  gap: 6px;
  padding: 2px 8px;
  font-size: clamp(0.6rem, 1.4vw, 0.74rem);
}

.lane-topbar .ammo-pip {
  width: 7px;
  height: 18px;
}

/* Selektor diawali .lane-topbar agar spesifisitasnya mengalahkan aturan dasar di atas */
@container topbar (max-width: 440px) {
  .lane-topbar .status-pill { padding: 2px 6px; gap: 5px; font-size: 0.6rem; }
  .lane-topbar .ammo-pip { width: 6px; height: 16px; }
  .lane-topbar .ammo-rack { gap: 2px; }
  .lane-topbar .hearts-box .ico { height: 17px; }
  .lane-topbar .score-tag { font-size: 0.85rem; }
}

@container topbar (max-width: 360px) {
  .lane-topbar .squad-tag { display: none; }
}


/* =========================================================
   MODAL LAPORAN AKHIR MISI (#gameover-modal)
   Bingkai pixel-art + tombol aksi bergambar.
   Aset: assets/ui/gameover-frame.png, btn-replay.png, btn-wide-players.png
   Semua selector diawali #gameover-modal agar modal PANDUAN (#rules-modal,
   yang juga memakai .modal-card) tidak ikut berubah.
   ========================================================= */

#gameover-modal {
  padding: 10px;
}

/* ---------- Kartu / bingkai ---------- */
#gameover-modal .go-card {
  /* Mode 1 pemain (default) */
  /* Bezel bingkai: ~10.8% tinggi (atas), ~9.8% (bawah), ~5.6% lebar (kiri/kanan).
     Padding vertikal diberi lantai 56px supaya isi tidak menyentuh bezel di HP. */
  --go-pad-y: clamp(56px, 11vw, 66px);
  --go-pad-x: clamp(30px, 6vw, 46px);
  --go-btn-h: 54px;

  width: min(560px, 92vw, 100%);
  max-width: none;
  padding: var(--go-pad-y) var(--go-pad-x);

  background: url('assets/ui/gameover-frame.png') center / 100% 100% no-repeat;
  background-color: transparent;
  image-rendering: pixelated;
  border: none;
  clip-path: none;
  box-shadow: none;

  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Mode 2 pemain (kelas di-toggle oleh endMatch() di game.js) */
#gameover-modal .go-card.two-player {
  width: min(680px, 94vw, 100%);
  --go-pad-x: clamp(34px, 6vw, 46px);
}

#gameover-modal .go-card .modal-badge {
  font-size: clamp(0.66rem, 2.2vw, 0.75rem);
  margin-bottom: 4px;
}

#gameover-modal .go-card h2 {
  font-size: clamp(1.3rem, 4.8vw, 1.9rem);
  line-height: 1.15;
  margin-bottom: 4px;
  text-shadow: 0 2px 0 #090d16;
}

/* ---------- Kartu skor (transparan agar tekstur grid bingkai terlihat) ---------- */
#gameover-modal .result-stats {
  width: 100%;
  flex-direction: row;
  gap: 12px;
  margin: 12px 0 16px;
}

#gameover-modal .stat-pill {
  min-width: 0;
  background: rgba(9, 13, 22, 0.65);
  padding: clamp(10px, 2.6vw, 14px);
}

#gameover-modal .stat-pill h3 {
  font-size: clamp(0.72rem, 2.4vw, 0.82rem);
}

/* ---------- Baris tombol aksi ---------- */
#gameover-modal .modal-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: stretch;
  justify-content: stretch;
}

#gameover-modal .modal-actions > * {
  width: 100%;
  min-width: 0;
  min-height: var(--go-btn-h);
}

/* GANTI TANTANGAN (btn-back): samakan tinggi dengan tombol cyan di sebelahnya */
#gameover-modal .modal-actions .btn-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  font-size: clamp(0.74rem, 2.4vw, 0.9rem);
  padding: 4px 10px 4px 6px;
}

/* ---------- ULANGI MISI ---------- */
.btn-replay,
.btn-wide-players {
  background: url('assets/ui/btn-replay.png') center / 100% 100% no-repeat;
  background-color: transparent;
  border: none;
  image-rendering: pixelated;
  color: #e0f2fe;
  text-shadow: 0 2px 0 #090d16;
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.btn-replay {
  font-size: clamp(0.8rem, 2.6vw, 0.98rem);
  padding: 0 clamp(14px, 11%, 28px);
}

.btn-wide-players {
  background-image: url('assets/ui/btn-wide-players.png');
  width: min(100%, 340px);
  min-height: 56px;
  font-size: clamp(0.76rem, 2.6vw, 0.92rem);
  padding: 0 9%;
}

.btn-wide-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-wide-label .ico {
  height: 20px;
}

.btn-replay:hover,
.btn-replay:focus-visible,
.btn-wide-players:hover,
.btn-wide-players:focus-visible {
  outline: none;
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.btn-replay:active,
.btn-wide-players:active {
  transform: scale(0.98);
  filter: brightness(1.05);
}

/* Baris tombol lebar PILIH JUMLAH PEMAIN (dibuat oleh endMatch()) */
.go-nav-row {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

/* ---------- Layar sempit (HP tegak) ---------- */
@media (max-width: 459.98px) {
  /* Kartu jadi tinggi (isi bertumpuk) -> bezel atas/bawah ikut menebal, tambah padding vertikal */
  #gameover-modal .go-card { --go-pad-y: 64px; }
  #gameover-modal .go-card.two-player { --go-pad-y: 78px; }

  #gameover-modal .go-card.two-player .stat-pill { padding: 8px 10px; }

  #gameover-modal .go-card.two-player .result-stats {
    flex-direction: column;
    gap: 8px;
  }

  #gameover-modal .modal-actions {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  #gameover-modal .modal-actions > * {
    width: min(100%, 320px);
    justify-self: center;
  }

  .btn-wide-players {
    width: min(100%, 320px);
  }
}

/* ---------- HP mendatar / layar pendek ---------- */
@media (max-height: 560px) {
  #gameover-modal .go-card {
    --go-btn-h: 44px;
    --go-pad-y: clamp(46px, 14vh, 56px);
  }

  #gameover-modal .go-card .result-stats { margin: 8px 0 10px; }
  #gameover-modal .stat-pill .big-score { font-size: 1.5rem; }
  .btn-wide-players { min-height: 46px; }
  .go-nav-row { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn-replay,
  .btn-wide-players {
    transition: none;
  }
}
