/* 점심 결정소 — 모바일 우선(390px), PC에서는 가운데 폰 크기 카드 */
:root {
  --bg: #FFF6EC;
  --paper: #FFFFFF;
  --ink: #1D1915;
  --sub: #857A6F;
  --faint: #CBBFB2;
  --line: #EFE3D5;
  --accent: #FF5B2E;
  --accent-dark: #D9431B;
  --accent-soft: #FFE5DA;
  --ok: #138A50;
  --bad: #E0322F;
  --shadow: 0 18px 50px rgba(64, 33, 10, 0.14);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
          "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
img { display: block; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* 화면 낭독기·키보드 우회로: 포커스 받으면 보임 */
.skip-link {
  position: fixed; left: 12px; top: -120px; z-index: 100;
  max-width: calc(100% - 24px);
  background: var(--ink); color: #fff; text-decoration: none;
  padding: 12px 16px; border-radius: 12px; font-weight: 700; font-size: 15px;
}
.skip-link:focus { top: 12px; outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- 레이아웃 ---------- */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; justify-content: center; }
.app {
  width: 100%; max-width: 440px;
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--bg);
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) {
  body {
    background-color: #F4E6D6;
    background-image: radial-gradient(rgba(120, 72, 30, 0.10) 1.2px, transparent 0);
    background-size: 22px 22px;
  }
  .shell { align-items: center; padding: 28px; }
  .app {
    min-height: 0;
    height: min(860px, calc(100vh - 56px));
    height: min(860px, calc(100dvh - 56px));
    border-radius: 34px;
    box-shadow: var(--shadow), 0 0 0 1px rgba(64, 33, 10, 0.06);
    overflow: hidden;
  }
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 58px; padding: 0 20px;
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }
.brand img { border-radius: 7px; }
.timer {
  display: inline-flex; align-items: center;
  background: var(--paper); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px;
  font-size: 13px; color: var(--sub); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.timer b { color: var(--ink); font-weight: 800; }
.timer-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 7px; animation: blink 1s steps(2, start) infinite; }
.app[data-stage="result"] .timer-dot { animation: none; background: var(--ok); }

.progress { height: 4px; margin: 0 20px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .45s ease; }

.stage { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen { flex: 1; display: flex; flex-direction: column; padding: 22px 24px 24px; min-height: 0; }
.screen[hidden] { display: none; }
.screen.enter { animation: enter .35s cubic-bezier(.2, .8, .2, 1); }

h1, h2, h3, p { margin: 0; }
h1:focus, h2:focus { outline: none; }
h1 { font-size: 46px; line-height: 1.12; font-weight: 850; letter-spacing: -0.04em; margin-top: 12px; }
h2 { font-size: 28px; line-height: 1.25; font-weight: 850; letter-spacing: -0.035em; }
.eyebrow {
  align-self: flex-start;
  display: inline-block; font-size: 13px; font-weight: 800; color: var(--accent);
  background: var(--accent-soft); padding: 6px 11px; border-radius: 999px; letter-spacing: -0.01em;
}
.lead { font-size: 17px; line-height: 1.5; color: var(--sub); margin-top: 10px; letter-spacing: -0.02em; word-break: keep-all; }
.lead b { color: var(--ink); }
.meta { margin-top: 14px; font-size: 14px; color: var(--sub); }
.meta b { color: var(--ink); }
.hint { font-size: 14px; color: var(--sub); margin-top: 10px; line-height: 1.45; }
.muted { color: var(--sub); font-weight: 500; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 56px; padding: 0 24px; border-radius: 16px; border: 0;
  font-size: 17px; font-weight: 800; letter-spacing: -0.02em; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform .08s ease, box-shadow .08s ease, opacity .2s;
}
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 5px 0 var(--accent-dark); }
.btn-primary:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-dark); }
.btn-primary:disabled { background: var(--faint); box-shadow: 0 5px 0 #B3A698; cursor: not-allowed; }
.btn-ghost { background: var(--paper); color: var(--ink); border: 1.5px solid var(--line); }
.btn-ghost:active { transform: translateY(2px); }
.btn-block { width: 100%; }

/* ---------- 1. 시작 ---------- */
.hero { flex: 0 0 auto; }
.arena { flex: 1; position: relative; min-height: 280px; margin: 8px -12px 0; }
.runner {
  position: absolute; left: 0; top: 0;
  will-change: transform;
}
.runner.moving { transition: transform .22s cubic-bezier(.2, .9, .25, 1.15); }
.runner .btn { min-height: 64px; padding: 0 30px; font-size: 19px; white-space: nowrap; }
.runner.tired .btn { animation: wobble 1.2s ease-in-out infinite; }
.bubble {
  position: absolute; left: 50%; bottom: calc(100% + 12px);
  transform: translateX(-50%) scale(0);
  transform-origin: 50% 100%;
  background: var(--ink); color: #fff;
  font-size: 15px; font-weight: 800; white-space: nowrap;
  padding: 8px 13px; border-radius: 13px;
  pointer-events: none;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; top: 100%; margin-left: -7px;
  border: 7px solid transparent; border-top-color: var(--ink); border-bottom: 0;
}
.credit { text-align: center; font-size: 12px; font-weight: 700; color: var(--faint); margin-top: 6px; letter-spacing: 0; }
.bubble.show { transform: translateX(-50%) scale(1); transition: transform .18s cubic-bezier(.3, 1.6, .5, 1); }

/* ---------- 2. 약관 ---------- */
.terms {
  margin-top: 18px;
  height: clamp(210px, 40vh, 360px);
  height: clamp(210px, 40dvh, 360px);
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--paper); border: 1px solid var(--line); border-radius: 18px;
  padding: 18px 18px 22px;
  font-size: 15px; line-height: 1.7; letter-spacing: -0.015em;
}
.terms:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.terms h3 { font-size: 15px; font-weight: 800; margin-top: 16px; }
.terms h3:first-child { margin-top: 0; }
.terms p { color: #4B433B; }
.terms-end { text-align: center; color: var(--sub) !important; margin-top: 22px; font-size: 13px; }
.terms.rewind { animation: rewind .5s ease; }
.check {
  display: flex; align-items: center; gap: 10px; margin-top: 16px;
  font-size: 16px; font-weight: 700; cursor: pointer; letter-spacing: -0.02em;
}
.check input { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); flex: 0 0 auto; }
.check input:disabled + span { color: var(--faint); }
.check.unlocked { animation: pop .4s cubic-bezier(.3, 1.6, .5, 1); }
#termsHint { margin-top: 6px; margin-bottom: 14px; }
#termsHint.ready { color: var(--accent); font-weight: 700; }
#s-terms .btn-block { margin-top: auto; }

/* ---------- 3. 본인 확인 ---------- */
.target {
  margin-top: 20px; padding: 18px 16px;
  background: var(--paper); border: 2px dashed var(--line); border-radius: 18px;
  font-size: 24px; font-weight: 850; letter-spacing: -0.03em; line-height: 1.4;
  text-align: center; color: var(--faint); word-break: keep-all;
}
.target .ch { transition: color .12s; }
.target .ch.ok { color: var(--ink); }
.target .ch.bad { color: var(--bad); text-decoration: underline wavy var(--bad); text-underline-offset: 6px; }
.type-form { display: flex; gap: 8px; margin-top: 14px; }
.type-form input {
  flex: 1; min-width: 0; height: 56px; padding: 0 16px;
  border: 2px solid var(--line); border-radius: 16px; background: var(--paper);
  font-size: 18px; font-weight: 600; outline: none; letter-spacing: -0.02em;
}
.type-form input:focus { border-color: var(--accent); }
.type-form .btn { padding: 0 18px; flex: 0 0 auto; }
.shake { animation: shake .42s cubic-bezier(.36, .07, .19, .97); }

/* ---------- 4. 분석 중 ---------- */
#s-loading { justify-content: center; }
#s-loading h2 { text-align: center; }
.meter-num { text-align: center; font-size: 76px; font-weight: 900; letter-spacing: -0.05em; margin-top: 18px; font-variant-numeric: tabular-nums; }
.meter-num b { font-weight: 900; }
.meter { height: 16px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; }
.meter-msg { text-align: center; margin-top: 16px; font-size: 17px; font-weight: 700; color: var(--sub); min-height: 1.5em; letter-spacing: -0.02em; }
.meter-msg.oops { color: var(--bad); }

/* ---------- 5. 결과 ---------- */
.result-main { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
.result-line {
  margin-top: 18px;
  font-size: 40px; line-height: 1.22; font-weight: 900; letter-spacing: -0.045em; word-break: keep-all;
}
.result-line.reveal { animation: reveal .6s cubic-bezier(.2, 1.4, .4, 1); }
.result-time { margin-top: 18px; font-size: 17px; font-weight: 700; color: var(--ink); }
.result-time b { color: var(--accent); font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-direction: column; gap: 12px; }
.actions-row { display: flex; gap: 10px; }
.actions-row .btn { flex: 1; padding: 0 12px; }
.more { align-self: center; color: var(--sub); font-size: 14px; font-weight: 700; text-decoration: none; padding: 8px; }
.more:hover, .more:focus-visible { color: var(--ink); text-decoration: underline; }

/* ---------- 토스트 / 시트 ---------- */
.toast {
  position: fixed; left: 50%; top: calc(8px + env(safe-area-inset-top)); z-index: 50;
  transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  width: max-content; max-width: min(360px, calc(100vw - 32px));
  background: var(--ink); color: #fff;
  padding: 12px 16px; border-radius: 14px;
  font-size: 15px; font-weight: 700; line-height: 1.4; text-align: center; letter-spacing: -0.02em;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 640px) {
  .toast { top: calc((100vh - min(860px, 100vh - 56px)) / 2 + 8px); }
}

.sheet {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 14, 10, .58);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-panel {
  width: 100%; max-width: 440px; background: var(--bg);
  border-radius: 24px 24px 0 0; padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center;
  animation: sheet-up .28s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 640px) { .sheet { align-items: center; } .sheet-panel { border-radius: 24px; } }
.sheet-panel h3 { font-size: 17px; font-weight: 800; }
.sheet-panel img {
  margin-top: 12px; height: min(56vh, 520px); height: min(56dvh, 520px); width: auto; max-width: 100%;
  aspect-ratio: 9 / 16; object-fit: contain;
  border-radius: 14px; box-shadow: 0 8px 26px rgba(0, 0, 0, .15); background: var(--paper);
  -webkit-touch-callout: default;
}
.sheet-panel .hint { text-align: center; }
.sheet-panel .actions-row { width: 100%; margin-top: 14px; }

/* ---------- 애니메이션 ---------- */
@keyframes blink { to { visibility: hidden; } }
@keyframes enter { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
@keyframes rewind { 0% { transform: none; } 30% { transform: translateY(-6px) rotate(-.6deg); } 60% { transform: translateY(3px) rotate(.4deg); } 100% { transform: none; } }
@keyframes pop { 0% { transform: scale(.94); } 60% { transform: scale(1.04); } 100% { transform: none; } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); } }
@keyframes reveal { from { opacity: 0; transform: translateY(18px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
