/* ── 쿠키 클리커 — 모바일 퍼스트 ─────────────────────────── */

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

:root {
  --bg-dark: #1a1310;
  --bg-panel: #241a14;
  --bg-card: #2f2219;
  --bg-card-hover: #3a2b1f;
  --border: #4a3626;
  --gold: #f5c542;
  --gold-dim: #b8933a;
  --text: #f0e6d8;
  --text-dim: #a89880;
  --text-faint: #6f6252;
  --green: #7ec96f;
  --red: #e07a5f;
  --blue: #6fb4c9;
  --purple: #b58aef;
  --orange: #f0944a;
  --tabbar-h: 56px;
}

html, body {
  height: 100%;
  background: var(--bg-dark);
  color: var(--text);
  font-family: 'Apple SD Gothic Neo', 'Pretendard', 'Malgun Gothic', sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ── 앱 골격: 100dvh + safe-area ─────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  max-width: 640px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ── 상단 고정 영역 ─────────────────────────── */

#top {
  flex: none;
  height: 45dvh;
  display: flex;
  flex-direction: column;
  padding: 6px 12px 2px;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(245, 197, 66, 0.07), transparent 65%),
    var(--bg-dark);
  border-bottom: 1px solid var(--border);
}

#counters { text-align: center; flex: none; }

#cookie-count {
  font-size: clamp(22px, 3.6dvh, 32px);
  font-weight: 800;
  color: var(--gold);
  line-height: 1.15;
  text-shadow: 0 1px 6px rgba(245, 197, 66, 0.25);
}

#cookie-unit {
  display: inline-block;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: -2px;
}

#sub-counters {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 1px;
}

.dot-sep { color: var(--text-faint); margin: 0 4px; }

#cookie-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
}

#big-cookie {
  font-size: min(19dvh, 34vw);
  line-height: 1;
  padding: 8px;
  border-radius: 50%;
  transition: transform 90ms ease-out;
  touch-action: none;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5));
  will-change: transform;
}

#big-cookie.pressed { transform: scale(0.9); }

/* ── 버프 바 ─────────────────────────── */

#buff-bar {
  flex: none;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  min-height: 26px;
  padding: 1px 2px;
}

#buff-bar::-webkit-scrollbar { display: none; }

.buff-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  white-space: nowrap;
}

.buff-chip .buff-time { font-weight: 700; }
.buff-frenzy { border-color: var(--gold); color: var(--gold); }
.buff-storm { border-color: var(--blue); color: var(--blue); }
.buff-rush { border-color: var(--green); color: var(--green); }
.buff-collapse { border-color: var(--red); color: var(--red); }
.buff-clickFrenzy { border-color: var(--purple); color: var(--purple); }
.buff-sale { border-color: var(--orange); color: var(--orange); }

/* ── 뉴스 티커 ─────────────────────────── */

#news {
  flex: none;
  height: 18px;
  overflow: hidden;
  text-align: center;
}

#news-text {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 100%;
  transition: opacity 0.3s;
}

#news-text.fade { opacity: 0; }

/* ── 콘텐츠 영역 ─────────────────────────── */

#content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--bg-panel);
}

.panel { display: none; padding: 10px 12px 24px; }
.panel.active { display: block; }

.panel-title {
  font-size: 15px;
  color: var(--gold);
  margin: 4px 0 10px;
}

.sub-title {
  font-size: 12px;
  color: var(--text-dim);
  margin: 16px 0 8px;
}

.info-line { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.empty-note { font-size: 13px; color: var(--text-faint); padding: 18px 0; text-align: center; }

/* ── 상점 ─────────────────────────── */

.shop-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding: 6px 0;
}

.row-info {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 4px 6px;
  border-radius: 10px;
}

.row-info:active { background: var(--bg-card); }

.row-icon { font-size: 30px; flex: none; width: 38px; text-align: center; }

.shop-row.silhouette .row-icon { filter: brightness(0) opacity(0.55); }

.row-text { min-width: 0; }

.row-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.row-buy {
  flex: none;
  min-width: 96px;
  min-height: 56px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 8px;
}

.row-buy .buy-price { font-size: 13px; font-weight: 800; color: var(--red); }
.row-buy.afford .buy-price { color: var(--green); }
.row-buy.afford { border-color: var(--green); }
.row-buy.afford:active { background: var(--bg-card-hover); }
.row-buy.on-sale .buy-price { color: var(--orange); }
.row-buy.afford.on-sale { border-color: var(--orange); }
.row-buy.afford.on-sale .buy-price { color: var(--orange); }

/* ── 아이콘 그리드 (업그레이드/업적) ─────────────────────────── */

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
}

.icon-cell {
  min-height: 64px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 2px;
}

.icon-cell:active { background: var(--bg-card-hover); }
.icon-cell .cell-icon { font-size: 24px; line-height: 1.2; }

.icon-cell .cell-price {
  font-size: 10px;
  color: var(--red);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-cell.afford { border-color: var(--gold-dim); }
.icon-cell.afford .cell-price { color: var(--green); }

.icon-grid.owned .icon-cell { min-height: 48px; opacity: 0.85; }

.icon-cell.locked { opacity: 0.35; }
.icon-cell.locked .cell-icon { filter: grayscale(1); }
.icon-cell.done { border-color: var(--gold-dim); box-shadow: 0 0 6px rgba(245, 197, 66, 0.18); }

/* ── 통계 ─────────────────────────── */

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.stat-row span { color: var(--text-dim); }
.stat-row b { font-weight: 700; text-align: right; }

/* ── 카드 (환생/설정) ─────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
  font-size: 13px;
}

.card-row span { color: var(--text-dim); }
.card-row b { color: var(--gold); font-weight: 800; }

.card-head { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.card-note { font-size: 11px; color: var(--text-faint); margin: 6px 0; line-height: 1.5; }

.bar {
  height: 8px;
  border-radius: 4px;
  background: var(--bg-dark);
  overflow: hidden;
  margin: 4px 0 10px;
}

.bar > div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--purple), #d3b7f7);
  border-radius: 4px;
  transition: width 200ms linear;
}

.big-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  background: var(--gold);
  color: #241a05;
  font-size: 15px;
  font-weight: 800;
}

.big-btn:active { filter: brightness(0.85); }
.big-btn:disabled { background: var(--bg-card-hover); color: var(--text-faint); }
.big-btn.danger { background: var(--red); color: #2a0f08; }
.big-btn.half { display: inline-block; width: calc(50% - 4px); }

.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.danger-card { border-color: #6b3a2c; }

#save-io {
  width: 100%;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 11px;
  padding: 8px;
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}

/* ── 천상 상점 ─────────────────────────── */

.hv-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.hv-icon { font-size: 26px; flex: none; }
.hv-body { flex: 1; min-width: 0; }
.hv-name { font-size: 13px; font-weight: 700; }
.hv-desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; line-height: 1.4; }

.hv-buy {
  flex: none;
  min-width: 72px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--purple);
  color: var(--purple);
  font-size: 12px;
  font-weight: 700;
}

.hv-buy:disabled { border-color: var(--border); color: var(--text-faint); }
.hv-card.owned { border-color: var(--purple); }
.hv-card.owned .hv-buy { border: none; color: var(--purple); }

/* ── 하단 탭바 ─────────────────────────── */

#tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  background: var(--bg-dark);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-btn {
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-faint);
  position: relative;
}

.tab-btn .tab-icon { font-size: 18px; }
.tab-btn .tab-name { font-size: 9px; letter-spacing: -0.3px; }
.tab-btn.active { color: var(--gold); }

.tab-btn.noti::after {
  content: '';
  position: absolute;
  top: 7px;
  right: calc(50% - 16px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

/* ── 황금 쿠키 ─────────────────────────── */

#golden-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

#golden-cookie {
  position: absolute;
  width: 72px;
  height: 72px;
  font-size: 52px;
  line-height: 72px;
  text-align: center;
  pointer-events: auto;
  touch-action: none;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 197, 66, 0.4), rgba(245, 197, 66, 0.05) 70%);
  filter: sepia(1) saturate(3) brightness(1.15) drop-shadow(0 0 10px rgba(245, 197, 66, 0.8));
  animation: golden-pulse 1.1s ease-in-out infinite alternate;
}

@keyframes golden-pulse {
  from { transform: scale(1) rotate(-6deg); }
  to { transform: scale(1.12) rotate(6deg); }
}

/* ── 플로팅 텍스트 / 파티클 ─────────────────────────── */

#fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

.float-num {
  position: absolute;
  font-size: 16px;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  animation: float-up 0.8s ease-out forwards;
  will-change: transform, opacity;
}

@keyframes float-up {
  from { transform: translate(-50%, 0); opacity: 1; }
  to { transform: translate(-50%, -64px); opacity: 0; }
}

.crumb {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a5713c;
  animation: crumb-fly 0.55s ease-out forwards;
  will-change: transform, opacity;
}

@keyframes crumb-fly {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(0.4); opacity: 0; }
}

/* ── 토스트 ─────────────────────────── */

#toast-layer {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 80;
  pointer-events: none;
  width: min(92vw, 420px);
}

.toast {
  max-width: 100%;
  background: rgba(36, 26, 20, 0.94);
  border: 1px solid var(--gold-dim);
  color: var(--text);
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 18px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.25s ease-out;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast.out { opacity: 0; transition: opacity 0.3s; }

@keyframes toast-in {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── 오버레이 / 바텀시트 / 모달 ─────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 60;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.overlay.center { justify-content: center; align-items: center; }

.bottom-sheet {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 72dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: sheet-up 0.22s ease-out;
}

@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.sheet-icon { font-size: 36px; flex: none; }
.sheet-title { font-size: 16px; font-weight: 800; }
.sheet-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.sheet-desc { font-size: 13px; line-height: 1.55; margin: 8px 0; }

.sheet-quote {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  border-left: 3px solid var(--gold-dim);
  padding-left: 10px;
  margin: 10px 0;
  line-height: 1.5;
}

.sheet-unlock { font-size: 11px; color: var(--text-faint); margin: 8px 0; }

.sheet-buy {
  display: block;
  width: 100%;
  min-height: 50px;
  margin-top: 12px;
  border-radius: 12px;
  background: var(--gold);
  color: #241a05;
  font-size: 15px;
  font-weight: 800;
}

.sheet-buy:active { filter: brightness(0.85); }
.sheet-buy:disabled { background: var(--bg-card-hover); color: var(--text-faint); }

/* ── 선택의 쿠키 (비차단: 게임 진행 유지, 쿠키 클릭 가능) ── */

#choice-backdrop {
  background: transparent;
  pointer-events: none;
}

#choice-sheet {
  pointer-events: auto;
  border: 1px solid var(--gold-dim);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
}


#choice-title {
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 10px;
}

#choice-timer-track {
  height: 6px;
  border-radius: 3px;
  background: var(--bg-card);
  overflow: hidden;
  margin-bottom: 12px;
}

#choice-timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  border-radius: 3px;
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  padding: 10px 14px;
  margin-bottom: 8px;
  text-align: left;
}

.choice-btn:active { background: var(--bg-card-hover); border-color: var(--gold); }
.choice-icon { font-size: 28px; flex: none; }
.choice-name { font-size: 14px; font-weight: 800; }
.choice-desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; line-height: 1.4; }

#choice-hint { font-size: 11px; color: var(--text-faint); text-align: center; margin-top: 4px; }

/* ── 확인 다이얼로그 ─────────────────────────── */

#modal {
  width: min(88vw, 360px);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  animation: sheet-up 0.2s ease-out;
}

#modal-title { font-size: 16px; font-weight: 800; color: var(--gold); margin-bottom: 8px; }
#modal-msg { font-size: 13px; line-height: 1.6; color: var(--text); white-space: pre-line; }

#modal-actions { display: flex; gap: 8px; margin-top: 16px; }

#modal-actions button {
  flex: 1;
  min-height: 46px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
}

#modal-cancel { background: var(--bg-card); color: var(--text-dim); border: 1px solid var(--border); }
#modal-ok { background: var(--gold); color: #241a05; }
#modal-ok:active, #modal-cancel:active { filter: brightness(0.85); }
