:root {
  --wood-dark: #4b2b15;
  --wood-mid: #754624;
  --cream: #fff8e7;
  --cream-border: #e5c694;
  --gold: #ffcf48;
  --gold-deep: #d69316;
  --accent: #e86b35;
  --accent-deep: #b84418;
  --ink: #341d0f;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #4e8ec8;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#gameCanvas:active {
  cursor: grabbing;
}

/* HUD */
.hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud button,
.stat-box {
  pointer-events: auto;
}

.pill-btn,
.icon-btn {
  border: 2px solid var(--wood-dark);
  background: linear-gradient(180deg, #fffaf0 0%, #f5e1ba 100%);
  color: var(--ink);
  font-weight: 800;
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--wood-dark), 0 6px 14px rgba(32, 16, 6, 0.2);
  cursor: pointer;
  transition: transform 0.08s ease;
}

.pill-btn:active,
.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--wood-dark);
}

.pill-btn {
  padding: 7px 14px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.peek-btn {
  background: linear-gradient(180deg, #ffe799 0%, #f2bd46 100%);
}

.stat-box {
  background: rgba(255, 248, 231, 0.94);
  border: 2px solid var(--wood-dark);
  border-radius: 14px;
  padding: 5px 12px;
  box-shadow: 0 3px 0 var(--wood-dark), 0 6px 14px rgba(32, 16, 6, 0.18);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 96px;
}

.shots-box {
  align-items: flex-start;
  min-width: 112px;
}

.stat-label {
  font-size: 11px;
  font-weight: 800;
  color: #7c4e2a;
  letter-spacing: 0.02em;
}

.stat-box strong {
  font-size: 20px;
  line-height: 1.1;
  font-weight: 900;
  color: var(--ink);
}

.best-line {
  font-size: 11px;
  font-weight: 700;
  color: #8b603b;
}

.shots-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.shots-icons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.shot-chip {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--chip, #c97b38);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #4a2610;
  opacity: 0.72;
}

.shot-chip.active {
  opacity: 1;
  transform: scale(1.12);
  box-shadow: 0 0 0 2px #ffcf48;
}

/* Bottom Hint Pill */
.hint-pill {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(52, 29, 15, 0.84);
  color: #fff8e7;
  font-size: 13.5px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid rgba(255, 224, 150, 0.45);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 9;
}

.hint-pill.highlight {
  background: linear-gradient(180deg, #ff9933 0%, #e0531c 100%);
  color: #fff;
  border-color: #ffe88f;
  animation: pulseHint 0.75s ease-in-out infinite alternate;
}

@keyframes pulseHint {
  from {
    transform: translateX(-50%) scale(1);
  }
  to {
    transform: translateX(-50%) scale(1.06);
  }
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(34, 20, 10, 0.54);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}

#stageModal {
  z-index: 30;
}

.hidden {
  display: none !important;
}

.card {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: linear-gradient(180deg, #fffaf0 0%, #fae9c8 100%);
  border: 4px solid var(--wood-dark);
  border-radius: 24px;
  padding: 24px 22px;
  box-shadow: 0 8px 0 var(--wood-dark), 0 20px 44px rgba(20, 10, 4, 0.4);
  text-align: center;
}

.eyebrow {
  display: inline-block;
  background: #67b044;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.title-card h1 {
  font-size: clamp(32px, 6vw, 46px);
  font-weight: 900;
  color: var(--wood-dark);
  letter-spacing: -0.02em;
  text-shadow: 0 3px 0 #f4cc70;
  margin-bottom: 10px;
}

.lead {
  font-size: 14.5px;
  line-height: 1.55;
  color: #5b371d;
  margin-bottom: 16px;
  word-break: keep-all;
}

.hero-roster {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 20px;
  text-align: left;
}

.hero-item {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(255, 255, 255, 0.72);
  border: 2px solid var(--cream-border);
  border-radius: 12px;
  padding: 8px 10px;
}

.hero-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--wood-dark);
  color: #fff;
  font-weight: 900;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hero-item strong {
  display: block;
  font-size: 13.5px;
  color: var(--ink);
}

.hero-item small {
  display: block;
  font-size: 11.5px;
  color: #7c5130;
}

.btn-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-btn,
.secondary-btn {
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  padding: 11px 22px;
  font-size: 15.5px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.08s ease;
}

.primary-btn {
  background: linear-gradient(180deg, #ff9944 0%, #e05a22 100%);
  color: #fff;
  box-shadow: 0 4px 0 #7a260a;
}

.secondary-btn {
  background: linear-gradient(180deg, #fffdf7 0%, #f0d7a8 100%);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--wood-dark);
}

.primary-btn:active,
.secondary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--wood-dark);
}

/* Result Card */
.result-card h2 {
  font-size: 26px;
  font-weight: 900;
  color: var(--wood-dark);
  margin-bottom: 8px;
}

.result-stars {
  font-size: 40px;
  letter-spacing: 6px;
  margin-bottom: 6px;
}

.result-stars .star {
  color: #d9c5a0;
}

.result-stars .star.lit {
  color: #ffb800;
  text-shadow: 0 2px 0 #a36500;
}

.result-score {
  font-size: 28px;
  font-weight: 900;
  color: var(--accent-deep);
  margin-bottom: 8px;
}

.result-desc {
  font-size: 14px;
  color: #633d20;
  margin-bottom: 20px;
}

/* Stage Select Modal */
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-head h2 {
  font-size: 22px;
  font-weight: 900;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.stage-card {
  background: #fffdf6;
  border: 2.5px solid var(--wood-dark);
  border-radius: 14px;
  padding: 12px 10px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--wood-dark);
  transition: transform 0.08s ease;
}

.stage-card.current {
  background: #fff3c7;
  border-color: var(--accent-deep);
}

.stage-card:active {
  transform: translateY(2px);
}

.stage-num {
  font-size: 11px;
  font-weight: 800;
  color: #8c5a2b;
}

.stage-name {
  font-size: 14.5px;
  font-weight: 900;
  color: var(--ink);
  margin: 3px 0 4px;
}

.stage-stars {
  font-size: 18px;
  color: #f0a500;
  letter-spacing: 2px;
}

.stage-best {
  font-size: 11.5px;
  font-weight: 700;
  color: #7c5636;
  margin-top: 4px;
}

/* Mobile Compact Tweaks */
@media (max-width: 640px) {
  .hud {
    top: max(6px, env(safe-area-inset-top));
    left: 8px;
    right: 8px;
  }

  .pill-btn {
    padding: 5px 10px;
    font-size: 12.5px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  .stat-box {
    padding: 4px 9px;
    min-width: 78px;
  }

  .stat-box strong {
    font-size: 16px;
  }

  .shots-icons {
    display: none;
  }

  .card {
    padding: 18px 16px;
    border-radius: 18px;
  }

  .hero-roster {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .hint-pill {
    font-size: 12px;
    padding: 6px 12px;
  }
}

/* Compact Mobile Landscape (e.g., 844x390) */
@media (max-height: 460px) {
  .overlay {
    padding: 8px 16px;
  }

  .card {
    width: min(640px, 100%);
    padding: 12px 16px;
    border-radius: 18px;
  }

  .eyebrow {
    font-size: 11px;
    padding: 2px 10px;
    margin-bottom: 4px;
  }

  .title-card h1 {
    font-size: 26px;
    margin-bottom: 6px;
  }

  .lead {
    font-size: 12.5px;
    line-height: 1.4;
    margin-bottom: 10px;
  }

  .hero-roster {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 12px;
  }

  .hero-item {
    padding: 6px 7px;
    gap: 6px;
  }

  .hero-dot {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }

  .hero-item strong {
    font-size: 12px;
  }

  .hero-item small {
    font-size: 10px;
  }

  .primary-btn,
  .secondary-btn {
    padding: 8px 16px;
    font-size: 13.5px;
  }

  .result-card h2 {
    font-size: 20px;
    margin-bottom: 4px;
  }

  .result-stars {
    font-size: 28px;
    margin-bottom: 2px;
  }

  .result-score {
    font-size: 22px;
    margin-bottom: 4px;
  }

  .result-desc {
    font-size: 12.5px;
    margin-bottom: 12px;
  }
}
