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

html, body {
  width: 100%;
  height: 100%;
  background: #0d141f;
  color: #f4f4f4;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#game-wrap {
  position: relative;
  aspect-ratio: 9 / 16;
  height: 100dvh;
  height: 100vh;
  max-width: 100vw;
  max-height: 100dvh;
  max-height: 100vh;
  overflow: hidden;
  background: #0d141f;
}

@supports (height: 100dvh) {
  #game-wrap { height: 100dvh; max-height: 100dvh; }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(#8ac4e7 0%, #cfe4f1 70%, #6b8f53 70%, #6b8f53 100%);
  image-rendering: pixelated;
}

#hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 0 #000, 0 0 8px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 2;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mute-btn {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  font-size: 18px;
  line-height: 1;
  color: #fff;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s ease, transform 0.1s ease;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: none;
  -webkit-tap-highlight-color: transparent;
}
.mute-btn:hover { opacity: 1; }
.mute-btn:active { transform: scale(0.94); }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 10, 20, 0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 3;
  text-align: center;
  gap: 16px;
}

.overlay.hidden { display: none; }
.hidden { display: none; }

.version {
  position: absolute;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  font-size: 11px;
  color: rgba(255, 255, 255, 0.38);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.5px;
  margin: 0;
  pointer-events: none;
}

h1 {
  font-size: clamp(48px, 12vw, 96px);
  color: #ffd84a;
  text-shadow: 0 4px 0 #000, 0 0 12px rgba(255, 216, 74, 0.6);
  letter-spacing: 4px;
}

h2 {
  font-size: clamp(44px, 10vw, 80px);
  color: #ff7a4a;
  text-shadow: 0 4px 0 #000;
}

.tag {
  font-size: clamp(14px, 3.6vw, 20px);
  color: #cde;
  margin-bottom: 12px;
}

.hint {
  font-size: clamp(13px, 3.4vw, 18px);
  color: #aab;
  margin-bottom: 20px;
  max-width: 520px;
  line-height: 1.5;
}

#final-score, #final-best {
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 700;
}

#final-best { color: #ffd84a; }

button {
  font-family: inherit;
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 800;
  color: #1a1a1a;
  background: #ffd84a;
  border: none;
  border-radius: 14px;
  padding: 18px 36px;
  margin-top: 12px;
  cursor: pointer;
  box-shadow: 0 6px 0 #b08a12, 0 10px 24px rgba(0, 0, 0, 0.3);
  transition: transform 0.08s, box-shadow 0.08s;
}

button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b08a12, 0 4px 10px rgba(0, 0, 0, 0.3);
}

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 10px 24px rgba(0, 0, 0, 0.3);
}
.btn-secondary:active {
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), 0 4px 10px rgba(0, 0, 0, 0.3);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%) translateY(12px);
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.update-banner {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(16px);
  background: rgba(15, 22, 35, 0.95);
  border: 1px solid rgba(255, 216, 74, 0.45);
  color: #fff;
  padding: 8px 8px 8px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  z-index: 150;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  max-width: 90vw;
}
.update-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.update-banner button {
  margin: 0;
  box-shadow: none;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
}
.update-banner .update-reload {
  background: #ffd84a;
  color: #1a1a1a;
}
.update-banner .update-dismiss {
  background: transparent;
  color: rgba(255, 255, 255, 0.55);
  font-size: 18px;
  padding: 2px 8px;
  font-weight: 400;
}

#credits-overlay {
  background: radial-gradient(ellipse at top, #1a2a3e 0%, #05080f 90%);
  padding: 0;
  overflow: hidden;
}

#credits-overlay.hidden { display: none; }

#credits-scroll {
  position: absolute;
  left: 0;
  right: 0;
  top: 18%;
  padding: 0 24px 160px;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: break-word;
  animation: creditScroll 48s linear forwards;
}

#credits-overlay::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 120px;
  background: linear-gradient(to top, #05080f 0%, #05080f 55%, rgba(5, 8, 15, 0) 100%);
  pointer-events: none;
  z-index: 3;
}

@keyframes creditScroll {
  0% { transform: translateY(0); }
  100% { transform: translateY(calc(-100% - 25vh)); }
}

.cr-title {
  font-size: clamp(32px, 8vw, 56px);
  color: #ffd84a;
  margin: 60px 0 40px;
  letter-spacing: 6px;
}

.cr-big {
  font-size: clamp(22px, 5.5vw, 32px);
  color: #fff;
  margin: 10px 0;
  font-weight: 700;
}

.cr-heading {
  font-size: clamp(26px, 6vw, 38px);
  color: #ffd84a;
  margin: 40px 0 18px;
  font-weight: 800;
}

.cr-narr {
  font-size: clamp(18px, 4.5vw, 24px);
  color: #cde;
  margin: 12px 0;
  line-height: 1.5;
}

.cr-narr.small { font-size: clamp(14px, 3.5vw, 18px); color: #8a9; }

.cr-twist {
  font-size: clamp(18px, 4.5vw, 24px);
  color: #aab;
  margin: 30px 0 10px;
  letter-spacing: 4px;
}

.cr-twist-big {
  font-size: clamp(28px, 7vw, 44px);
  color: #7ee0a1;
  margin: 10px 0 28px;
  font-weight: 900;
  text-shadow: 0 0 18px rgba(126, 224, 161, 0.4);
  line-height: 1.3;
}

.cr-tag {
  font-size: clamp(22px, 5.5vw, 30px);
  color: #ff8fb3;
  margin: 24px 0 14px;
  font-weight: 800;
  font-style: italic;
}

.cr-role {
  font-size: clamp(15px, 3.8vw, 20px);
  color: #ccd;
  margin: 6px 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.cr-divider {
  width: 60%;
  height: 2px;
  background: rgba(255, 216, 74, 0.4);
  margin: 36px auto;
}

.cr-disclaimer {
  font-size: clamp(13px, 3.2vw, 17px);
  color: #889;
  margin: 30px auto;
  line-height: 1.6;
  max-width: 520px;
  font-style: italic;
  opacity: 0.85;
}

#credits-overlay .btn-row {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  gap: 8px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

#credits-restart-btn,
#credits-share-btn {
  padding: 12px 18px;
  font-size: clamp(14px, 3.6vw, 20px);
  margin-top: 0;
  white-space: nowrap;
}
