:root {
  --ink: #1f3324;
  --leaf: #3a9d4a;
  --leaf-dark: #2b7a38;
  --sun: #ffc93c;
  --cream: #fffaf0;
  --glass: rgba(20, 30, 25, 0.48);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; color: var(--ink); }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

/* ───────── 1. 공룡 고르기 ───────── */
#home {
  overflow-y: auto;
  background:
    radial-gradient(circle at 85% 12%, #fff6c9 0 60px, transparent 61px),
    linear-gradient(#bfe6ff 0%, #e6f6ff 55%, #b9e39a 55.1%, #8fcf6b 100%);
  padding: calc(18px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}
#home.active { display: flex; flex-direction: column; align-items: center; }
.hero { text-align: center; margin: 8px 0 6px; }
.hero h1 {
  margin: 0; font-size: clamp(30px, 6.4vw, 58px); line-height: 1.15; font-weight: 900; letter-spacing: -0.02em;
  color: #24452c; text-shadow: 0 3px 0 #fff;
}
.hero h1 span { color: #e8590c; }
.hero p { margin: 10px 0 0; font-size: clamp(17px, 2.6vw, 24px); font-weight: 700; color: #3c5b44; }

.cards {
  width: min(980px, 100%);
  display: grid; gap: 16px;
  grid-template-columns: repeat(2, 1fr);
}
.card {
  --c: #5cbf4a;
  position: relative; display: flex; flex-direction: column; align-items: center;
  background: var(--cream); border-radius: 28px; padding: 10px 10px 16px;
  border: 4px solid color-mix(in srgb, var(--c) 70%, white);
  box-shadow: 0 8px 0 color-mix(in srgb, var(--c) 75%, black), 0 14px 24px rgba(0, 0, 0, 0.14);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
@media (min-width: 900px) and (min-aspect-ratio: 1/1) { .cards { grid-template-columns: repeat(4, 1fr); } }
.card:active { transform: translateY(6px); box-shadow: 0 2px 0 color-mix(in srgb, var(--c) 75%, black), 0 6px 12px rgba(0, 0, 0, 0.14); }
.card .pic {
  width: 100%; aspect-ratio: 16 / 13; border-radius: 20px;
  background: radial-gradient(circle at 50% 70%, color-mix(in srgb, var(--c) 30%, white), color-mix(in srgb, var(--c) 12%, white));
  display: grid; place-items: center; overflow: hidden;
}
.card .pic img { width: 100%; height: 100%; object-fit: contain; }
.card .pic .ph { font-size: 72px; }
.card b { margin-top: 10px; font-size: clamp(19px, 2.6vw, 25px); font-weight: 900; letter-spacing: -0.02em; }
.foot { margin-top: auto; padding-top: 18px; font-size: 15px; font-weight: 700; color: #1f4a26; text-align: center; opacity: 0.85; }

/* ───────── 2. 카메라 + 공룡 ───────── */
#stage { background: linear-gradient(#8fc9ee, #d7eefc 60%, #a5d68a 60.1%, #7cbf5d); touch-action: none; }
#cam, #gl, #gl canvas, #touch { position: absolute; inset: 0; width: 100%; height: 100%; }
#cam { object-fit: cover; background: transparent; }
#cam.mirror { transform: scaleX(-1); }
#gl { pointer-events: none; }
#touch { touch-action: none; }

.cam-msg {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%);
  width: min(560px, calc(100% - 32px)); padding: 16px 18px; border-radius: 18px;
  background: rgba(255, 255, 255, 0.92); font-size: 17px; font-weight: 700; line-height: 1.5; text-align: center;
  pointer-events: none;
}

.bar { position: absolute; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; pointer-events: none; }
.bar > *, .bar .group > * { pointer-events: auto; }
.bar .group { display: flex; gap: 10px; align-items: center; }
.bar.top { top: 0; padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) 0 calc(14px + var(--safe-l)); }
.bar.bottom { bottom: 0; justify-content: center; gap: clamp(28px, 9vw, 80px); padding: 0 0 calc(18px + var(--safe-b)); }

.pill, .round {
  background: var(--glass); color: #fff; font-weight: 800;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.pill { height: 48px; padding: 0 18px; border-radius: 24px; font-size: 17px; }
.pill.primary { background: var(--leaf); }
.pill.ar { background: #1971c2; }
.round { width: 52px; height: 52px; border-radius: 50%; font-size: 24px; display: grid; place-items: center; line-height: 1; }
.round.big { width: 72px; height: 72px; font-size: 30px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.round.big small { font-size: 12px; font-weight: 800; }
.round.ghost { visibility: hidden; }
.pill:active, .round:active { transform: scale(0.94); }

#shutter {
  width: 88px; height: 88px; border-radius: 50%; padding: 0;
  background: rgba(255, 255, 255, 0.35); border: 5px solid #fff;
  display: grid; place-items: center; box-shadow: 0 3px 14px rgba(0, 0, 0, 0.25);
}
#shutter span { width: 66px; height: 66px; border-radius: 50%; background: #fff; transition: transform 0.1s; }
#shutter:active span { transform: scale(0.86); background: #ffe8a3; }

.side {
  position: absolute; right: calc(12px + var(--safe-r)); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 12px;
}

.hint {
  position: absolute; left: 50%; bottom: calc(118px + var(--safe-b)); transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px);
  background: rgba(255, 255, 255, 0.94); color: var(--ink); border-radius: 18px; padding: 10px 16px;
  font-size: 16px; font-weight: 800; line-height: 1.55; text-align: center;
  opacity: 0; transition: opacity 0.4s; pointer-events: none;
}
.hint.on { opacity: 1; }

#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { 0% { opacity: 0.95; } 100% { opacity: 0; } }

/* 찍은 사진 미리보기 */
.preview {
  position: absolute; inset: 0; z-index: 20; background: rgba(12, 20, 15, 0.86);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: calc(16px + var(--safe-t)) 16px calc(18px + var(--safe-b));
}
.preview .frame { background: #fff; padding: 10px 10px 34px; border-radius: 10px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); transform: rotate(-1.5deg); animation: drop 0.35s ease-out; max-width: 100%; }
@keyframes drop { from { transform: translateY(-30px) rotate(-6deg); opacity: 0; } }
.preview img { display: block; max-width: min(88vw, 900px); max-height: 62vh; border-radius: 4px; }
.preview .row { display: flex; gap: 14px; }
.preview .pill { height: 56px; font-size: 19px; padding: 0 24px; }
.save-tip { margin: 0; color: #fff; font-size: 15px; font-weight: 700; text-align: center; opacity: 0.9; }
.save-tip:empty { display: none; }

/* ───────── 3. AR ───────── */
#arView { background: linear-gradient(#cfe9fb, #f3fbff 60%, #cfeab8); }
#mv { position: absolute; inset: 0; width: 100%; height: 100%; --poster-color: transparent; background: transparent; }
#arView .bar.top .pill, #arView .bar.top .round { background: rgba(31, 51, 36, 0.75); }
.ar-go {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%);
  height: 64px; font-size: 20px; padding: 0 28px; white-space: nowrap; box-shadow: 0 6px 0 var(--leaf-dark), 0 10px 22px rgba(0, 0, 0, 0.2);
}
.ar-info {
  position: absolute; left: 50%; top: calc(76px + var(--safe-t)); transform: translateX(-50%);
  width: min(560px, calc(100% - 32px)); background: rgba(255, 255, 255, 0.9); border-radius: 18px;
  padding: 12px 16px; font-size: 15px; font-weight: 600; line-height: 1.6; text-align: center; pointer-events: none;
}
.ar-info b:first-child { display: block; font-size: 17px; margin-bottom: 2px; }
.ar-info.warn { background: #fff3bf; }

.toast {
  position: fixed; left: 50%; top: calc(80px + var(--safe-t)); transform: translate(-50%, -20px); z-index: 50;
  background: #1f3324; color: #fff; padding: 12px 20px; border-radius: 24px; font-size: 17px; font-weight: 800;
  opacity: 0; transition: 0.3s; pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 560px) {
  .round.big { width: 60px; height: 60px; }
  #shutter { width: 74px; height: 74px; }
  #shutter span { width: 54px; height: 54px; }
  .hint { bottom: calc(96px + var(--safe-b)); }
  .side { gap: 8px; }
  .round { width: 46px; height: 46px; font-size: 21px; }
}

/* 공룡 묶음 제목 */
.sec { width: min(980px, 100%); margin: 18px 0 10px; font-size: clamp(20px, 3vw, 28px); font-weight: 900; color: #24452c; text-shadow: 0 2px 0 #fff; }
.cards.real { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 900px) and (min-aspect-ratio: 1/1) { .cards.real { grid-template-columns: repeat(5, 1fr); } }
.cards.real .card .pic { background: radial-gradient(circle at 50% 70%, #f4efe2, #e2dccb); }
.cards.real .card b { font-size: clamp(16px, 2.2vw, 21px); }
.foot { padding-bottom: 4px; }

/* 불러오는 중 */
.loading {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.94); border-radius: 22px; padding: 16px 24px;
  font-size: 19px; font-weight: 800; display: flex; align-items: center; gap: 10px; pointer-events: none;
}
.loading span { font-size: 30px; display: inline-block; animation: bob 0.8s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-8px); } }
#walk.on { background: #e8590c; }
