:root {
  --wood-bg-1: #3b2210;
  --wood-bg-2: #211208;
  --board-light: #ecc589;
  --board-dark: #caa065;
  --accent-gold: #ffb830;
  --accent-green: #2ecc71;
  --accent-blue: #3498db;
  --accent-red: #e74c3c;
  --text-light: #fffdfa;
  --text-dark: #3a2211;
  --glass-bg: rgba(30, 16, 8, 0.75);
  --glass-border: rgba(255, 230, 190, 0.2);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.5);
  --font-main: 'Outfit', -apple-system, sans-serif;
  --font-fun: 'Fredoka', cursive, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  background-color: #1a0d05;
}

/* Warm vertical wood plank background like real game */
body {
  background: 
    radial-gradient(ellipse at center, rgba(230, 140, 40, 0.28) 0%, rgba(20, 10, 5, 0.85) 100%),
    repeating-linear-gradient(90deg, 
      #8c4a1b 0px, 
      #9e5522 38px, 
      #783c13 40px, 
      #a65e28 78px, 
      #6c350f 80px,
      #8c4a1b 120px
    );
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-light);
}

.game-wrapper {
  position: relative;
  width: 100%;
  max-width: 540px;
  height: 100vh;
  max-height: 940px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 16px;
  box-sizing: border-box;
}

/* Header & HUD */
.game-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hud-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: #ffdeaa;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: transform 0.15s ease, background 0.2s ease;
}

.hud-btn:hover {
  transform: translateY(-2px);
  background: rgba(60, 32, 16, 0.9);
  color: #fff;
}

.hud-btn:active {
  transform: translateY(1px) scale(0.96);
}

.hud-actions {
  display: flex;
  gap: 8px;
}

.level-info {
  text-align: center;
}

.level-info h1 {
  font-family: var(--font-fun);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #ffffff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6), 0 0 14px rgba(255, 184, 48, 0.4);
}

.level-progress-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 2px;
}

.level-progress-dots .dot {
  width: 22px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.3);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.level-progress-dots .dot.active {
  background: #2ecc71;
  box-shadow: 0 0 8px #2ecc71;
}

/* Timer & Planks counter */
.hud-timer-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
}

.timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 10, 4, 0.85);
  border: 2px solid rgba(255, 184, 48, 0.35);
  padding: 5px 14px;
  border-radius: 20px;
  font-family: var(--font-fun);
  font-size: 1.15rem;
  font-weight: 600;
  color: #ffdf9e;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.15);
}

.timer-pill.urgent {
  border-color: #e74c3c;
  color: #ff6b6b;
  animation: pulse-urgent 1s infinite;
}

@keyframes pulse-urgent {
  0%, 100% { transform: scale(1); box-shadow: 0 0 10px rgba(231, 76, 60, 0.4); }
  50% { transform: scale(1.06); box-shadow: 0 0 20px rgba(231, 76, 60, 0.8); }
}

.planks-left-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 10, 4, 0.85);
  border: 2px solid rgba(130, 215, 110, 0.35);
  padding: 5px 14px;
  border-radius: 20px;
  font-family: var(--font-fun);
  font-size: 0.95rem;
  color: #c9f2c7;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.badge-val {
  font-size: 1.1rem;
  font-weight: 700;
  color: #4cd964;
}

/* Canvas Area */
.canvas-container {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  margin: 6px 0;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  max-width: 480px;
  max-height: 720px;
  border-radius: 22px;
  box-shadow: 
    0 16px 40px rgba(0, 0, 0, 0.6),
    0 2px 6px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  touch-action: none;
}

/* Tutorial Hint */
.tutorial-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 9, 3, 0.92);
  border: 1px solid rgba(255, 184, 48, 0.5);
  padding: 8px 18px;
  border-radius: 24px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #ffdf9e;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: bounce-hint 2s infinite ease-in-out;
  z-index: 5;
  white-space: nowrap;
}

@keyframes bounce-hint {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-6px); }
}

/* Footer Controls */
.game-footer {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding-bottom: 6px;
  z-index: 10;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, #442410 0%, #281408 100%);
  border: 2px solid #73401e;
  color: #fedfa2;
  font-family: var(--font-fun);
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0,0,0,0.4), inset 0 1px 1px rgba(255,255,255,0.2);
  transition: all 0.15s ease;
  position: relative;
}

.action-btn:hover {
  transform: translateY(-2px);
  background: linear-gradient(180deg, #573016 0%, #351c0b 100%);
  border-color: #9d592b;
}

.action-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.action-btn .badge {
  background: #ffb830;
  color: #3b1e06;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 2px;
}

.highlight-btn {
  background: linear-gradient(180deg, #7c4c1a 0%, #4a2b0e 100%);
  border-color: #f39c12;
  color: #fff2cf;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 6, 2, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, #422513 0%, #241308 100%);
  border: 3px solid #8e5327;
  border-radius: 28px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.7), inset 0 1px 2px rgba(255, 230, 180, 0.3);
  position: relative;
  overflow: hidden;
}

.animate-pop {
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.trophy-icon, .lose-icon {
  font-size: 3.5rem;
  margin-bottom: 6px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
  animation: bounce-trophy 1.5s infinite ease-in-out;
}

@keyframes bounce-trophy {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.08); }
}

.modal-card h2 {
  font-family: var(--font-fun);
  font-size: 1.85rem;
  color: #fff4d9;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
  margin-bottom: 4px;
}

.win-sub, .lose-sub, .levels-sub {
  font-size: 0.95rem;
  color: #c9ad90;
  margin-bottom: 16px;
}

.stars-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 2.6rem;
  color: #4b3628;
  margin-bottom: 18px;
}

.stars-row .star.filled {
  color: #ffbb00;
  text-shadow: 0 0 16px rgba(255, 187, 0, 0.8), 0 3px 6px rgba(0,0,0,0.5);
  animation: starPop 0.4s ease forwards;
}

.star-1 { animation-delay: 0.1s; }
.star-2 { animation-delay: 0.25s; }
.star-3 { animation-delay: 0.4s; }

@keyframes starPop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

.win-stats {
  display: flex;
  justify-content: space-around;
  background: rgba(20, 10, 4, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 12px 8px;
  margin-bottom: 18px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-lbl {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #9d836f;
  letter-spacing: 0.5px;
}

.stat-val {
  font-family: var(--font-fun);
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
}

.stat-val.highlight {
  color: #ffbb00;
}

/* Auto next countdown */
.auto-next-bar {
  margin-bottom: 20px;
}

.auto-next-label {
  font-size: 0.85rem;
  color: #d1b499;
  margin-bottom: 6px;
}

.auto-next-label strong {
  color: #2ecc71;
  font-size: 1rem;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #2ecc71, #f1c40f);
  border-radius: 4px;
  transition: width 0.1s linear;
}

/* Modal Buttons */
.modal-actions {
  display: flex;
  gap: 12px;
}

.btn-primary, .btn-secondary {
  flex: 1;
  font-family: var(--font-fun);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 12px 14px;
  border-radius: 16px;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.btn-primary {
  background: linear-gradient(180deg, #2ecc71 0%, #219653 100%);
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(39, 174, 96, 0.4), inset 0 1px 2px rgba(255,255,255,0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  background: linear-gradient(180deg, #34d678 0%, #27ae60 100%);
}

.btn-primary:active {
  transform: translateY(2px);
}

.btn-secondary {
  background: linear-gradient(180deg, #53301a 0%, #341c0e 100%);
  border: 1px solid #7c4826;
  color: #e5cdb8;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.btn-secondary:hover {
  background: linear-gradient(180deg, #663b20 0%, #442412 100%);
}

/* Level Selection Grid */
.levels-card {
  max-width: 440px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.btn-close {
  background: none;
  border: none;
  color: #caa07e;
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-height: 380px;
  overflow-y: auto;
  padding: 8px 4px;
}

.level-btn {
  aspect-ratio: 1;
  background: linear-gradient(180deg, #4d2b17 0%, #2a160b 100%);
  border: 2px solid #754221;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-family: var(--font-fun);
  color: #ffffff;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, border-color 0.2s ease;
}

.level-btn .num {
  font-size: 1.25rem;
  font-weight: 700;
}

.level-btn .lvl-stars {
  font-size: 0.65rem;
  color: #ffbb00;
  margin-top: 2px;
}

.level-btn.current {
  border-color: #2ecc71;
  box-shadow: 0 0 12px rgba(46, 204, 113, 0.6);
}

.level-btn.locked {
  opacity: 0.45;
  cursor: not-allowed;
  background: #1c0e07;
  border-color: #3b1e10;
}

.level-btn:not(.locked):hover {
  transform: translateY(-3px) scale(1.05);
  border-color: #ffb830;
}

/* Confetti particles */
.confetti-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  border-radius: 2px;
  animation: confetti-fall 2.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(420px) rotate(720deg); opacity: 0; }
}

.hidden {
  display: none !important;
}

/* Responsive adjustments */
@media (max-height: 640px) {
  .game-wrapper { padding: 6px 10px; }
  .hud-btn { width: 38px; height: 38px; }
  .level-info h1 { font-size: 1.3rem; }
  .timer-pill, .planks-left-badge { padding: 3px 10px; font-size: 0.9rem; }
  .action-btn { padding: 7px 16px; font-size: 0.9rem; }
}
