/* ============================================================
   끼니TI — 모바일 우선 스타일시트
   기준 뷰포트 375~430px / 데스크톱에서는 폰 카드 형태로 중앙 정렬
   ============================================================ */

:root {
  --bg: #FFFCF6;
  --card: #FFFFFF;
  --green: #22B573;
  --green-dark: #148A57;
  --green-light: #E1F8ED;
  --orange: #FF7D3D;
  --orange-light: #FFEBDD;
  --amber: #FFC63D;
  --amber-light: #FFF5DA;
  --coral: #FF6B6B;
  --coral-light: #FFE8E8;
  --ink: #23211D;
  --ink-muted: #96907F;
  --border: #F1ECDD;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(60, 50, 30, 0.07);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #E7F7CE;
  color: var(--ink);
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  word-break: keep-all;
  overflow-wrap: break-word;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.app-frame {
  width: 100%;
  max-width: 448px;
  min-height: 100dvh;
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
  box-shadow: var(--shadow);
}

@media (min-width: 480px) {
  html, body { background: #EAFBF1; }
  .app-frame { margin: 24px 0; min-height: calc(100dvh - 48px); border-radius: 32px; overflow: hidden; }
}

/* ---------- 공통 레이아웃 ---------- */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding: calc(20px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
  animation: fadeUp 0.32s ease;
}
.screen.active { display: flex; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(0.98); }

.primary-btn {
  margin-top: auto;
  position: sticky;
  bottom: calc(14px + var(--safe-bottom));
  width: 100%;
  padding: 17px 18px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(34, 181, 115, 0.32);
  transition: transform 0.12s ease, background 0.15s ease;
}
.primary-btn:hover { background: var(--green-dark); }
.primary-btn:disabled { background: var(--border); color: var(--ink-muted); box-shadow: none; }

.reset-history-btn {
  width: 100%;
  text-align: center;
  padding: 10px;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.secondary-btn {
  width: 100%;
  padding: 15px 18px;
  border-radius: 999px;
  background: var(--green-light);
  color: var(--green-dark);
  font-size: 15px;
  font-weight: 700;
  margin-top: 12px;
  margin-bottom: 16px;
}

.link-btn {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 6px 4px;
}
.link-btn.back { color: var(--green-dark); }

/* ---------- 인트로 / 소개 ---------- */
#screen-intro { justify-content: flex-start; }

.friend-banner {
  background: var(--orange-light);
  color: #C24A0F;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 14px;
  text-align: center;
}
.friend-banner b { color: var(--orange); }
.friend-banner.return-banner { background: var(--green-light); color: var(--green-dark); }
.friend-banner.return-banner b { color: var(--green-dark); }

.intro-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.intro-logo {
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  margin: 4px 0 18px;
}
.intro-logo span { color: var(--green); }
.intro-mascots { margin: 0 0 18px; }
.intro-mascots img { width: 100%; height: auto; display: block; border-radius: var(--radius-md); }
.intro-copy {
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--ink-muted);
  margin: 0 0 14px;
  text-align: left;
  word-break: normal;
}
.intro-copy:last-of-type { margin-bottom: 0; }

/* ---------- 선택 스텝 ---------- */
.step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.back-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--card);
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.step-count { font-size: 13px; color: var(--ink-muted); font-weight: 600; }

.progress { display: flex; gap: 8px; justify-content: center; margin: 4px 0 22px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border); transition: all 0.2s; }
.dot.on { background: var(--green); width: 22px; border-radius: 5px; }
.dot.done { background: var(--green-light); border: 1.5px solid var(--green); }

.step-title { font-size: 21px; font-weight: 800; line-height: 1.4; margin: 0 0 4px; text-align: center; }
.step-sub { font-size: 13.5px; color: var(--ink-muted); text-align: center; margin: 0 0 20px; }
.step-sub strong { color: var(--green-dark); font-weight: 800; }

/* ---------- 식판 미리보기 (실제 식판 그래픽 위에 칸 맞춰 사진이 얹힘) ---------- */
.tray-wrap {
  position: relative;
  width: 100%;
  max-width: 210px;
  aspect-ratio: 1 / 1;
  margin: 0 auto 16px;
}
.tray-wrap.tray-wrap--result { max-width: 270px; margin-bottom: 20px; }
.tray-base-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.tray-slot {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tray-food-img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(60, 40, 20, 0.16));
}
.tray-food-emoji { font-size: 22px; display: flex; align-items: center; justify-content: center; width: 82%; height: 82%; }

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 10px;
}
.menu-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border: 2px solid transparent;
  box-shadow: 0 2px 10px rgba(60,50,30,0.06);
  transition: border-color 0.15s ease, transform 0.12s ease;
}
.menu-card.selected { border-color: var(--green); background: var(--green-light); }
.menu-card.disabled { opacity: 0.4; pointer-events: none; }
.menu-card:disabled { opacity: 0.4; }
.menu-thumb {
  width: 72px; height: 72px;
  border-radius: 0;
  background: none;
  display: flex; align-items: center; justify-content: center;
  overflow: visible;
  margin-bottom: 10px;
}
.menu-thumb img { width: 100%; height: 100%; object-fit: contain; }
.menu-emoji { font-size: 30px; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.menu-text strong { display: block; font-size: 14.5px; font-weight: 700; margin-bottom: 4px; }
.menu-text em { display: block; font-style: normal; font-size: 11.5px; color: var(--ink-muted); line-height: 1.4; }
.menu-check {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--green); color: #fff;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: scale(0.5);
  transition: all 0.15s ease;
}
.menu-card.selected .menu-check { opacity: 1; transform: scale(1); }

/* ---------- 이름 입력 ---------- */
.name-input-wrap { text-align: center; margin-top: 12vh; }
.name-input-emoji { font-size: 44px; margin: 0 0 12px; }
.name-input-wrap .step-title { margin-bottom: 6px; }
.name-input-wrap .step-sub { margin-bottom: 28px; }
.name-input {
  width: 100%;
  padding: 15px 18px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  font-family: inherit;
}
.name-input:focus { outline: none; border-color: var(--green); }
.name-input::placeholder { color: var(--ink-muted); font-weight: 500; }

/* ---------- 로딩 ---------- */
#screen-loading { align-items: center; justify-content: center; text-align: center; }
.loading-spin {
  width: 56px; height: 56px; border-radius: 50%;
  border: 5px solid var(--green-light); border-top-color: var(--green);
  animation: spin 0.9s linear infinite; margin: 0 auto 18px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 15px; font-weight: 600; color: var(--ink-muted); }

/* ---------- 결과 공통 ---------- */
.result-topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.result-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.balance-sub { font-size: 13.5px; color: var(--ink-muted); font-weight: 700; margin: 0 0 6px; }

/* ---------- 유형 결과 카드 ---------- */
.type-card { text-align: center; position: relative; padding-top: 34px; }
.level-pill {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  padding: 5px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 800;
  background: var(--green-light); color: var(--green-dark);
}
.level-pill.lv1 { background: var(--coral-light); color: var(--coral); }
.level-pill.lv2 { background: var(--amber-light); color: #9A7415; }
.level-pill.lv3 { background: var(--green-light); color: var(--green-dark); }
.mascot-slot { margin: 8px 0 10px; display: flex; justify-content: center; }
.mascot-img { width: auto; height: auto; max-width: 78%; max-height: 260px; object-fit: contain; }
.mascot-emoji { font-size: 110px; display: flex; align-items: center; justify-content: center; height: 220px; }
.type-kicker { font-size: 12.5px; color: var(--ink-muted); margin: 0 0 4px; }
.type-name { font-size: 24px; font-weight: 800; margin: 0 0 12px; line-height: 1.35; }
.hashtags { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 18px; }
.hashtags span {
  font-size: 12.5px; font-weight: 700; color: var(--coral);
  background: var(--coral-light); padding: 5px 11px; border-radius: 999px;
}
.type-comment { font-size: 14.5px; line-height: 1.7; color: var(--ink); text-align: left; margin: 0 0 18px; word-break: normal; }
.chosen-menu-label { font-size: 12px; font-weight: 700; color: var(--ink-muted); border-top: 1px solid var(--border); padding-top: 16px; margin: 0 0 10px; text-align: left; }

/* ---------- 211 밸런스 ---------- */
.balance-title { font-size: 19px; font-weight: 800; margin: 0 0 2px; }
.balance-explain {
  background: var(--green-light); border-radius: var(--radius-sm);
  padding: 13px 14px; font-size: 12.5px; line-height: 1.6; color: var(--green-dark);
  margin: 14px 0 20px;
}
.balance-explain strong { display: block; margin-bottom: 4px; font-size: 13px; }
.bar-list { display: flex; flex-direction: column; gap: 16px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-icon { font-size: 20px; width: 28px; text-align: center; flex-shrink: 0; }
.bar-main { flex: 1; min-width: 0; }
.bar-label { font-size: 13.5px; font-weight: 700; margin-bottom: 6px; }
.bar-label span { font-weight: 500; color: var(--ink-muted); font-size: 11.5px; }
.bar-track { height: 9px; border-radius: 999px; background: #E7E4DC; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
.bar-fill.good { background: var(--green); }
.bar-fill.mid { background: var(--amber); }
.bar-fill.low { background: var(--coral); }
.bar-score { font-size: 16px; font-weight: 800; width: 28px; text-align: center; flex-shrink: 0; }
.bar-chip { font-size: 11.5px; font-weight: 700; padding: 4px 0; border-radius: 999px; white-space: nowrap; width: 76px; text-align: center; flex-shrink: 0; }
.bar-chip.good { background: var(--green-light); color: var(--green-dark); }
.bar-chip.mid { background: var(--amber-light); color: #9A7415; }
.bar-chip.low { background: var(--coral-light); color: var(--coral); }

/* ---------- 211 식사법 장점 — 뒤집는 카드 ---------- */
.benefit-hint { font-size: 11.5px; color: var(--ink-muted); margin: -6px 0 14px; }
.benefit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.flip-card { aspect-ratio: 1 / 1; perspective: 1000px; }
.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
}
.flip-card.flipped .flip-card-inner { transform: rotateY(180deg); }
.flip-card-front, .flip-card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.flip-card-front { font-size: 32px; background: var(--green-light); box-shadow: inset 0 0 0 1.5px rgba(0,0,0,0.03); }
.flip-card-front.eco { background: var(--orange-light); }
.flip-card-back {
  background: var(--card);
  border: 1.5px solid var(--border);
  transform: rotateY(180deg);
  flex-direction: column;
  text-align: center;
  gap: 5px;
  overflow-y: auto;
}
.flip-card-back strong { font-size: 11.5px; font-weight: 800; color: var(--ink); line-height: 1.3; }
.flip-card-back p { font-size: 9.5px; color: var(--ink-muted); line-height: 1.4; margin: 0; }

/* ---------- 유형 도감 ---------- */
.dex-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.dex-cell {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--bg); border-radius: var(--radius-sm); padding: 10px 4px 12px;
}
.dex-cell.locked { opacity: 0.55; }
.dex-cell img { width: 68px; height: 68px; object-fit: contain; }
.dex-cell.locked img { filter: grayscale(1); }
.dex-emoji { font-size: 32px; width: 68px; height: 68px; display: flex; align-items: center; justify-content: center; }
.dex-name { font-size: 10.5px; font-weight: 700; color: var(--ink-muted); text-align: center; line-height: 1.3; }
.dex-cell.owned .dex-name { color: var(--ink); }

/* ---------- 탄소발자국 ---------- */
.carbon-number { font-size: 40px; font-weight: 800; color: var(--green-dark); margin: 6px 0 20px; }
.carbon-number span { font-size: 15px; font-weight: 700; margin-left: 6px; color: var(--ink-muted); }
.carbon-gauge { margin-bottom: 22px; }
.carbon-gauge-track { position: relative; height: 8px; border-radius: 999px; background: linear-gradient(90deg, var(--green-light), var(--coral-light)); margin-bottom: 8px; }
.carbon-gauge-dot { position: absolute; top: 50%; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid var(--green); transform: translate(-50%, -50%); }
.carbon-gauge-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-muted); }
.carbon-analogy { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.analogy-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.55; background: var(--green-light); padding: 12px 14px; border-radius: var(--radius-sm); }
.analogy-row strong { color: var(--green-dark); }
.carbon-footnote { font-size: 10.5px; color: var(--ink-muted); line-height: 1.5; margin: 0; }
.last-chem-note { text-align: center; margin: -8px 0 14px; word-break: normal; }
.refresh-footnote { margin-top: 14px; word-break: normal; }

/* ---------- 친구 케미 ---------- */
.chemi-avatars { display: flex; justify-content: center; align-items: center; gap: -8px; margin: 16px 0 8px; }
.chemi-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.chemi-avatar.mine { background: var(--green-light); margin-right: -14px; z-index: 2; }
.chemi-avatar.theirs { background: var(--orange-light); margin-left: -14px; }
.chemi-avatars.solo .chemi-avatar { margin: 0; }
.chemi-names { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-muted); font-weight: 600; padding: 0 6px; margin-bottom: 14px; }
.chemi-pct { text-align: center; font-size: 42px; font-weight: 800; color: var(--green-dark); margin-bottom: 6px; }
.chemi-desc { text-align: center; font-size: 14.5px; font-weight: 700; color: var(--ink); margin: 0 0 8px; }
.chemi-subdesc { text-align: center; font-size: 11.5px; color: var(--ink-muted); line-height: 1.6; margin: 0 0 20px; }
.chemi-empty { text-align: center; font-size: 14px; line-height: 1.7; color: var(--ink-muted); margin: 10px 0 18px; }
.rank-list { border-top: 1px solid var(--border); padding-top: 14px; margin-bottom: 12px; }
.rank-title { font-size: 12.5px; font-weight: 700; color: var(--ink-muted); margin: 0 0 10px; }
.rank-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.refresh-btn { font-size: 12.5px; font-weight: 700; color: #9A7415; background: var(--amber-light); padding: 6px 12px; border-radius: 999px; flex-shrink: 0; }
.refresh-btn:disabled { opacity: 0.6; }
.rank-row-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  padding: 9px 8px;
  border-radius: 10px;
  text-align: left;
}
.rank-row-toggle.linked { background: var(--amber-light); }
.rank-chevron { color: var(--ink-muted); flex-shrink: 0; display: block; transition: transform 0.2s ease; }
.rank-row-toggle.open .rank-chevron { transform: rotate(180deg); color: var(--green-dark); }
.rank-num { width: 16px; color: var(--ink-muted); font-weight: 700; flex-shrink: 0; }
.rank-name { flex: 1; font-weight: 600; line-height: 1.4; }
.rank-type { font-weight: 500; color: var(--ink-muted); }
.rank-attempt { font-size: 10.5px; font-weight: 600; color: var(--ink-muted); }
.rank-row-toggle strong { color: var(--green-dark); flex-shrink: 0; }
.rank-panel {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding: 0 10px;
  margin: 0;
  border-width: 1px;
  border-style: solid;
  border-color: transparent;
  border-radius: var(--radius-sm);
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.25s ease, margin 0.25s ease, border-color 0.2s ease;
}
.rank-panel.open { max-height: 130px; opacity: 1; padding: 10px 10px 12px; margin: 0 0 8px; border-color: var(--border); }
.rank-panel-desc { font-size: 12.5px; font-weight: 700; color: var(--ink); margin: 0 0 4px; }
.rank-panel-menu { font-size: 11.5px; color: var(--ink-muted); line-height: 1.5; margin: 0; word-break: normal; }
.tip-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--green-light);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin: 0 0 14px;
  word-break: normal;
}
.tip-badge {
  background: var(--green);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* ---------- 반응형 미세 조정 ---------- */
@media (max-width: 359px) {
  .menu-thumb { width: 56px; height: 56px; }
  .type-name { font-size: 21px; }
  .carbon-number { font-size: 34px; }
}
