/* =========================================================
   TARIK TAMBANG MATEMATIKA - GAME STYLES
   Optimized for Multi-Touch Responsive Displays
   ========================================================= */

:root {
  --bg-sky-top: #70a1ff;
  --bg-sky-bottom: #a4b0be;
  --color-grass: #2ed573;
  --color-soil: #eccc68;
  
  --p1-primary: #ff4757;
  --p1-light: #ff6b81;
  --p1-dark: #c0392b;
  --p1-glow: rgba(255, 71, 87, 0.4);
  
  --p2-primary: #1e90ff;
  --p2-light: #70a1ff;
  --p2-dark: #0984e3;
  --p2-glow: rgba(30, 144, 255, 0.4);

  --font-display: 'Fredoka', 'Nunito', sans-serif;
  --font-number: 'Nunito', sans-serif;
  
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: fixed;
  background-color: #1e272e;
  font-family: var(--font-display);
  touch-action: none;
}

#game-app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #5352ed 0%, #2f3542 100%);
  position: relative;
  overflow: hidden;
}

/* =========================================================
   TOP UTILITY BAR
   ========================================================= */
#top-bar {
  height: 52px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn-icon:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.3);
}

.top-actions {
  display: flex;
  gap: 10px;
}

.game-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.game-badge.level {
  background: #ffa502;
  color: #2f3542;
  font-weight: 800;
}

/* =========================================================
   ARENA CANVAS & VISUAL TUG OF WAR
   ========================================================= */
#arena-container {
  flex: 0 0 38%;
  min-height: 180px;
  max-height: 300px;
  position: relative;
  width: 100%;
  background: #2f3542;
  overflow: hidden;
  box-shadow: inset 0 -10px 20px rgba(0, 0, 0, 0.4);
}

#arena-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Tug Meter Floating Bar */
#tug-meter-wrapper {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 650px;
  height: 38px;
  background: rgba(18, 20, 24, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 24px;
  display: flex;
  align-items: center;
  padding: 2px 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
  z-index: 10;
}

.meter-player {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 0.9rem;
  white-space: nowrap;
}

.meter-player.left {
  color: #ff6b81;
}

.meter-player.right {
  color: #70a1ff;
}

.meter-player .score {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.95rem;
}

.meter-bar-container {
  flex: 1;
  height: 14px;
  background: #1e272e;
  border-radius: 8px;
  margin: 0 10px;
  position: relative;
  overflow: visible;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.meter-indicator-center {
  position: absolute;
  left: 50%;
  top: -4px;
  bottom: -4px;
  width: 3px;
  background: #ffffff;
  transform: translateX(-50%);
  z-index: 2;
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
}

.meter-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 6px;
  transition: width 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.meter-fill.left {
  right: 50%;
  background: linear-gradient(90deg, #ff4757, #ff6b81);
  width: 0%;
}

.meter-fill.right {
  left: 50%;
  background: linear-gradient(90deg, #70a1ff, #1e90ff);
  width: 0%;
}

.meter-pin {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.1rem;
  z-index: 5;
  transition: left 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

/* =========================================================
   TOUCH CONTROLS / PLAYER ZONES
   ========================================================= */
#touch-controls {
  flex: 1;
  display: flex;
  position: relative;
  background: #1e272e;
  padding: 10px 14px;
  gap: 12px;
  box-sizing: border-box;
}

.player-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: var(--radius-lg);
  padding: 12px;
  position: relative;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
}

.player-zone.left {
  background: linear-gradient(145deg, #2d1519, #4a1c22);
  border: 3px solid rgba(255, 71, 87, 0.6);
}

.player-zone.right {
  background: linear-gradient(145deg, #10243d, #1b3558);
  border: 3px solid rgba(30, 144, 255, 0.6);
}

/* Zone Headers (Streak & Tarik Feedback) */
.zone-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 32px;
  padding: 0 4px;
}

.streak-badge {
  background: rgba(255, 255, 255, 0.15);
  color: #f1f2f6;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 12px;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.2s ease;
}

.streak-badge.active {
  opacity: 1;
  transform: scale(1);
  background: linear-gradient(90deg, #ffa502, #ff7f50);
  color: #000;
  box-shadow: 0 0 10px rgba(255, 165, 2, 0.6);
}

.pull-indicator {
  font-size: 0.95rem;
  font-weight: 900;
  color: #2ed573;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pull-indicator.show {
  opacity: 1;
  transform: translateY(0);
}

/* Question Boxes */
.question-box {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
  min-height: 52px;
  max-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.question-text {
  font-size: clamp(1.4rem, 2.6vw, 2.2rem);
  font-weight: 900;
  color: #2f3542;
  font-family: var(--font-number);
  letter-spacing: 1px;
}

/* Penalty Overlay on Wrong Answer */
.penalty-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(235, 47, 6, 0.95);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 10;
}

.penalty-overlay.active {
  opacity: 1;
  pointer-events: auto;
  animation: shakeBox 0.4s ease-in-out;
}

.penalty-text {
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 1px;
}

.penalty-bar {
  width: 60%;
  height: 6px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  margin-top: 6px;
  overflow: hidden;
}

.penalty-bar .bar-fill {
  width: 100%;
  height: 100%;
  background: #ffffff;
  transform-origin: left;
}

.penalty-overlay.active .bar-fill {
  animation: drainPenalty 0.9s linear forwards;
}

@keyframes drainPenalty {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

@keyframes shakeBox {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* Answer Choices Grid */
.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 440px;
  margin: 8px auto 0 auto;
  flex: 1;
  max-height: 150px;
}

.choice-btn {
  border: none;
  border-radius: 12px;
  font-family: var(--font-number);
  font-size: clamp(1.2rem, 2.2vw, 1.8rem);
  font-weight: 900;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 6px 12px;
  min-height: 42px;
  max-height: 64px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 6px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.08s ease, filter 0.08s ease, box-shadow 0.08s ease;
  touch-action: none;
}

/* Left Player Buttons */
.player-zone.left .choice-btn {
  background: linear-gradient(180deg, #ff6b81 0%, #ff4757 100%);
  border-top: 2px solid rgba(255, 255, 255, 0.4);
}

.player-zone.left .choice-btn:active,
.player-zone.left .choice-btn.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  background: #ee5253;
}

/* Right Player Buttons */
.player-zone.right .choice-btn {
  background: linear-gradient(180deg, #70a1ff 0%, #1e90ff 100%);
  border-top: 2px solid rgba(255, 255, 255, 0.4);
}

.player-zone.right .choice-btn:active,
.player-zone.right .choice-btn.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  background: #0984e3;
}

/* Correct & Wrong Flash Effects */
.choice-btn.correct-flash {
  background: #2ed573 !important;
  color: #ffffff !important;
  transform: scale(0.96);
  box-shadow: 0 0 15px #2ed573 !important;
}

.choice-btn.wrong-flash {
  background: #eb2f06 !important;
  color: #ffffff !important;
  transform: scale(0.96);
}

/* Arena Divider */
.arena-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 32px;
  position: relative;
}

.divider-line {
  flex: 1;
  width: 3px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.vs-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ffa502;
  color: #1e272e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.95rem;
  box-shadow: 0 0 15px rgba(255, 165, 2, 0.5);
  margin: 8px 0;
  border: 2px solid #ffffff;
}

/* =========================================================
   MODAL BACKDROP & DIALOGS
   ========================================================= */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 15, 25, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 16px;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #2f3542;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-lg);
  padding: 24px 30px;
  width: 100%;
  max-width: 680px;
  max-height: 94vh;
  overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Main Menu Card */
.menu-title-group {
  margin-bottom: 12px;
}

.game-logo-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 4px;
}

.game-title {
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-weight: 900;
  background: linear-gradient(90deg, #ff4757, #ffa502, #1e90ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  letter-spacing: 1px;
}

.game-subtitle {
  font-size: 0.95rem;
  color: #ced6e0;
  margin-top: 2px;
}

/* Quick Utility Bar in Menu */
.menu-top-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
  width: 100%;
}

.btn-quick-util {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-quick-util:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
}

.btn-quick-util:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.25);
}

.btn-quick-util.active {
  background: linear-gradient(135deg, #ffa502, #ff7f50);
  border-color: #ffffff;
  color: #2f3542;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(255, 165, 2, 0.4);
}

.menu-settings {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 18px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
}

.setting-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: #f1f2f6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.pill-btn {
  flex: 1;
  min-width: 100px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-btn.active {
  background: linear-gradient(135deg, #ffa502, #ff7f50);
  border-color: #ffffff;
  color: #2f3542;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(255, 165, 2, 0.4);
  transform: translateY(-2px);
}

.pill-btn:active {
  transform: scale(0.96);
}

.how-to-play-box {
  background: rgba(0, 0, 0, 0.3);
  border-left: 4px solid #ffa502;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  text-align: left;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #dcdde1;
  margin-bottom: 20px;
  width: 100%;
}

.how-to-play-box strong {
  color: #ffa502;
}

.btn-primary-large {
  width: 100%;
  padding: 16px 24px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(135deg, #2ed573, #10ac84);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(46, 213, 115, 0.4), 0 4px 0 #0d8768;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn-primary-large:active {
  transform: translateY(4px);
  box-shadow: 0 2px 10px rgba(46, 213, 115, 0.4), 0 1px 0 #0d8768;
}

.btn-secondary {
  width: 100%;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 10px;
  transition: all 0.15s ease;
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.98);
}

.app-footer {
  margin-top: 14px;
  font-size: 0.8rem;
  color: #a4b0be;
  width: 100%;
  text-align: center;
}

.app-footer p {
  margin: 0;
}

.company-link {
  color: #ffa502;
  font-weight: 800;
  text-decoration: none;
  transition: color 0.15s ease, text-shadow 0.15s ease;
}

.company-link:hover {
  color: #ff7f50;
  text-shadow: 0 0 8px rgba(255, 165, 2, 0.5);
  text-decoration: underline;
}

/* =========================================================
   VICTORY CARD & STATS
   ========================================================= */
.trophy-bounce {
  font-size: 4.5rem;
  animation: bounceTrophy 1s infinite alternate cubic-bezier(0.28, 0.84, 0.42, 1);
  margin-bottom: 6px;
}

@keyframes bounceTrophy {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-15px) scale(1.1); }
}

.victory-title {
  font-size: clamp(1.8rem, 3.8vw, 2.5rem);
  font-weight: 900;
  margin-bottom: 4px;
}

.victory-title.p1-win {
  color: #ff6b81;
  text-shadow: 0 0 20px rgba(255, 71, 87, 0.6);
}

.victory-title.p2-win {
  color: #70a1ff;
  text-shadow: 0 0 20px rgba(30, 144, 255, 0.6);
}

.victory-subtitle {
  font-size: 1rem;
  color: #ced6e0;
  margin-bottom: 18px;
}

.match-stats {
  display: flex;
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
  gap: 12px;
}

.stat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.stat-header {
  font-weight: 900;
  font-size: 1.05rem;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-col.p1 .stat-header { color: #ff6b81; }
.stat-col.p2 .stat-header { color: #70a1ff; }

.stat-row {
  display: flex;
  justify-content: space-between;
  color: #dcdde1;
}

.stat-row strong {
  color: #ffffff;
}

.stat-divider {
  width: 2px;
  background: rgba(255, 255, 255, 0.1);
}

.victory-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* =========================================================
   COUNTDOWN OVERLAY
   ========================================================= */
.countdown-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: opacity 0.2s ease;
}

.countdown-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.countdown-number {
  font-size: clamp(5rem, 15vw, 10rem);
  font-weight: 900;
  color: #ffa502;
  text-shadow: 0 8px 30px rgba(255, 165, 2, 0.8), 0 0 10px #ffffff;
  animation: countdownPop 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes countdownPop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* =========================================================
   PORTRAIT / ROTATE PROMPT
   ========================================================= */
#rotate-device-prompt {
  display: none;
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #ffa502;
  color: #2f3542;
  padding: 10px 18px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 80;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.rotate-icon {
  font-size: 1.2rem;
}

.btn-small {
  padding: 4px 8px;
  background: #2f3542;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
}

@media (orientation: portrait) {
  #rotate-device-prompt {
    display: flex;
  }
}

/* Confetti Canvas */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 150;
}

.hidden {
  display: none !important;
}

/* =========================================================
   RESPONSIVE OPTIMIZATIONS
   ========================================================= */
@media (max-height: 560px) {
  #top-bar { height: 40px; padding: 0 10px; }
  .btn-icon { width: 34px; height: 34px; }
  #arena-container { flex: 0 0 34%; min-height: 130px; }
  .player-zone { padding: 8px 10px; }
  .question-box { min-height: 44px; max-height: 56px; padding: 4px 8px; }
  .question-text { font-size: clamp(1.2rem, 2.2vw, 1.6rem); }
  .choices-grid { gap: 6px; margin-top: 4px; max-height: 110px; }
  .choice-btn { min-height: 36px; max-height: 50px; font-size: clamp(1.05rem, 1.8vw, 1.4rem); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
  #tug-meter-wrapper { height: 30px; top: 4px; }
  .trophy-bounce { font-size: 2.8rem; }
  .modal-content { padding: 14px 20px; }
  .menu-top-bar { margin-bottom: 8px; gap: 8px; }
  .btn-quick-util { padding: 4px 10px; font-size: 0.75rem; }
}
