:root {
  --board: #2e5b4e;
  --board-dark: #1c3a32;
  --chalk: #f8f6ee;
  --glow: #3ce1ff;
  --danger: #ff5a4d;
  --gold: #ffe28a;
  --font: "Gaegu", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: #141d1a;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  color: var(--chalk);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  background: var(--board);
  overflow: hidden;
}

#hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 12px;
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

#lives {
  letter-spacing: 2px;
  font-size: 22px;
  color: var(--danger);
}

#lives .lost {
  color: rgba(255, 255, 255, 0.22);
}

#stage {
  color: var(--gold);
}

#score {
  margin-left: auto;
  font-weight: 400;
}

#score b {
  font-size: 24px;
  color: var(--glow);
}

#mute {
  width: 40px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 18px;
}

#timer {
  height: 6px;
  background: var(--board-dark);
}

#timer i {
  display: block;
  height: 100%;
  background: var(--glow);
  transform-origin: left center;
  transform: scaleX(0);
}

#stagebox {
  position: relative;
  flex: 1;
  min-height: 0;
}

#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#stagebox.shake {
  animation: shake 0.28s linear;
}

@keyframes shake {
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

@media (prefers-reduced-motion: reduce) {
  #stagebox.shake { animation: none; }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: calc(20px + env(safe-area-inset-top)) 22px calc(20px + env(safe-area-inset-bottom));
  background: rgba(22, 44, 38, 0.93);
  text-align: center;
  overflow-y: auto;
}

/* 내용이 화면보다 짧으면 가운데, 길면 위에서부터 스크롤 */
.overlay > :first-child { margin-top: auto; }
.overlay > :last-child { margin-bottom: auto; }

.eyebrow {
  margin: 0;
  font-size: 22px;
  color: var(--glow);
}

h1 {
  margin: 0;
  font-size: clamp(44px, 14vw, 64px);
  line-height: 1.05;
  word-break: keep-all;
}

.how {
  width: 100%;
  max-width: 340px;
  margin: 6px 0;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 21px;
  line-height: 1.2;
}

.how li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 0;
}

.how b {
  color: var(--glow);
}

.lens {
  flex: none;
  width: 46px;
  height: 30px;
  border: 3px solid #141414;
  border-radius: 9px;
}

.lens.glow {
  background: var(--glow);
  box-shadow: 0 0 14px var(--glow);
}

.lens.glint {
  background: linear-gradient(135deg, #fff 0 35%, rgba(255, 255, 255, 0.35) 36% 100%);
}

.heart {
  flex: none;
  width: 46px;
  text-align: center;
  font-size: 30px;
  color: var(--danger);
}

.challenge {
  margin: 0;
  padding: 8px 14px;
  border: 2px dashed var(--gold);
  border-radius: 12px;
  font-size: 21px;
  color: var(--gold);
}

.muted {
  margin: 0;
  font-size: 18px;
  color: rgba(248, 246, 238, 0.6);
}

.verdict {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  color: var(--gold);
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

.primary {
  width: 100%;
  max-width: 340px;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  background: var(--glow);
  color: #06323c;
  font-size: 28px;
  font-weight: 700;
  box-shadow: 0 5px 0 #1a94ab;
}

.primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #1a94ab;
}

/* 높이로 크기를 정하고 4:5 비율로 자리를 미리 잡아, 카드가 그려질 때 버튼이 밀리지 않게 한다. */
#card {
  height: min(46vh, 425px); /* dvh 미지원(iOS 15.3 이하) 폴백 */
  height: min(46dvh, 425px);
  width: auto;
  max-width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

/* 그려지기 전에는 깨진 이미지 아이콘 대신 빈 자리만 둔다. */
#card:not([src]) {
  visibility: hidden;
}

.share-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 340px;
}

.share-row button,
.share-row a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 2px;
  border: 2px solid rgba(248, 246, 238, 0.45);
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
}

.share-row button:active,
.share-row a:active {
  background: rgba(255, 255, 255, 0.12);
}

.follow {
  padding: 6px 4px;
  word-break: keep-all;
  font-size: 19px;
  font-weight: 700;
  color: var(--glow);
  text-decoration: underline;
  text-underline-offset: 4px;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 10;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.82);
  font-size: 19px;
  white-space: nowrap;
}

/* 키가 작은 화면(주소창·하단바가 큰 인앱 브라우저): 시작 버튼이 스크롤 없이 보이게 줄인다. */
@media (max-height: 640px) {
  .overlay { gap: 8px; padding-top: 12px; padding-bottom: 12px; }
  .eyebrow { font-size: 18px; }
  h1 { font-size: 38px; }
  .how { margin: 0; font-size: 18px; }
  .how li { padding: 4px 0; }
  .lens { width: 38px; height: 25px; }
  .heart { width: 38px; font-size: 25px; }
  .challenge { padding: 5px 12px; font-size: 18px; }
  .primary { padding: 10px; font-size: 24px; }
  .verdict { font-size: 22px; }
  #card { height: 40vh; height: 40dvh; }
  .muted { font-size: 16px; }
  .follow { font-size: 18px; }
}
