:root {
  --bg: #fff7e8;
  --bg2: #ffe9c2;
  --ink: #3b2a1a;
  --muted: #8a6f55;
  --card: #ffffff;
  --line: #f0dcc0;
  --gold: #f5b02e;
  --gold-deep: #d98a0a;
  --fur: #f2b56b;
  --fur-shade: #e29b4a;
  --belly: #fff1dc;
  --stripe: #c9782d;
  --coin: #ffd54a;
  --coin-edge: #b9800f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1610;
    --bg2: #2a1f15;
    --ink: #f6e8d3;
    --muted: #b9a084;
    --card: #2b2118;
    --line: #41321f;
  }
}

body.boosted {
  --fur: #ffd23f;
  --fur-shade: #f2b01e;
  --belly: #fff6cf;
  --stripe: #d99a0b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: clip;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 60%);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

.app {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: .12em;
}

.tagline {
  margin: 2px 0 0;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--gold-deep);
}

.pill-btn {
  font: inherit;
  font-size: .8rem;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

/* 分數 */
.score { text-align: center; margin-top: 4px; }
.score-label { font-size: .85rem; color: var(--muted); letter-spacing: .2em; }
.score-num {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(2.4rem, 12vw, 3.4rem);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.score-sub { font-size: .9rem; color: var(--muted); }
body.boosted .score-sub { color: #e0530f; font-weight: 800; }

.coin {
  display: inline-grid;
  place-items: center;
  width: .8em;
  height: .8em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, var(--coin) 45%, var(--coin-edge));
  box-shadow: inset 0 0 0 .06em var(--coin-edge);
}
.coin::after { content: "$"; font: 800 .5em/1 sans-serif; color: var(--coin-edge); }

/* 舞台與貓 */
.stage {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 4px;
}
/* 背景房間：六個場景疊在一起，等級到了才淡入；加持時的金光蓋在最上面 */
.room {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #12151d;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .25);
  pointer-events: none;
}
.room::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(closest-side at 50% 62%, rgba(255, 200, 60, .55), transparent);
  opacity: 0;
  transition: opacity .4s;
}
body.boosted .room::after { opacity: 1; animation: aura 1.2s ease-in-out infinite alternate; }
@keyframes aura { from { transform: scale(.94); } to { transform: scale(1.04); } }

.room-art { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.room-name {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
  z-index: 1;
}

.scene { opacity: 0; transition: opacity 1.4s ease; }
.scene.on { opacity: 1; }
.room.instant .scene { transition: none; }

/* 場景動畫：只有目前最上層的場景才會動 */
.rain { animation: rain .55s linear infinite; }
@keyframes rain { to { transform: translate(-11.13px, 44.63px); } } /* 剛好一個圖樣週期，接縫不會跳 */
.flicker { animation: flicker 2.4s steps(1) infinite; }
@keyframes flicker { 0%, 100% { opacity: 1; } 46% { opacity: .55; } 50% { opacity: 1; } 78% { opacity: .75; } }
.sway { animation: sway 4s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(-2.5deg); } to { transform: rotate(2.5deg); } }
.beam { animation: beam 3.6s ease-in-out infinite alternate; }
@keyframes beam { from { opacity: .14; } to { opacity: .3; } }
.cf { animation: fall 5s linear infinite; }
@keyframes fall { from { transform: translateY(-20px); } to { transform: translateY(330px); } }
.tw { animation: twinkle 2.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes twinkle { 0%, 100% { transform: scale(.3); opacity: .2; } 50% { transform: scale(1); opacity: 1; } }
.scene .anim { animation-play-state: paused; }
.scene.top .anim { animation-play-state: running; }

.bubble {
  position: relative;
  min-height: 2.6em;
  display: grid;
  place-items: center;
  padding: 6px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-weight: 700;
  font-size: .95rem;
  text-align: center;
}
.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: var(--card);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}

.cat-btn {
  position: relative;
  width: min(62vw, 260px);
  aspect-ratio: 320 / 340;
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cat-btn:focus-visible { outline: 3px solid var(--gold-deep); outline-offset: 6px; }
.cat-btn > svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 5px 6px rgba(0, 0, 0, .3)); /* 讓貓咪從各種背景裡跳出來 */
}

/* 玩家自訂圖片：圖片依原比例縮進框內，下方固定放討錢碗 */
.cat-custom { position: relative; display: block; width: 100%; height: 100%; }
.cat-frame {
  position: absolute;
  inset: 0 0 14% 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cat-frame img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 26px;
  box-shadow: 0 0 0 5px var(--card), 0 12px 28px rgba(0, 0, 0, .28);
  user-select: none;
  -webkit-user-drag: none;
}
body.boosted .cat-frame img { box-shadow: 0 0 0 5px #ffd23f, 0 0 36px rgba(255, 190, 40, .85); }
.mini-bowl {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 44%;
  height: auto;
  transform: translateX(-50%);
}

.cat-tools { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }

.tail {
  transform-box: fill-box;
  transform-origin: 0% 100%;
  animation: sway 2.6s ease-in-out infinite alternate;
}
@keyframes sway { from { transform: rotate(-6deg); } to { transform: rotate(8deg); } }

.eyes-open {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink 4.5s infinite;
}
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }

.eyes-happy, .eyes-hungry { display: none; }
.cat-btn.happy .eyes-open { display: none; }
.cat-btn.happy .eyes-happy { display: inline; }
.cat-btn.starving .eyes-open { display: none; }
.cat-btn.starving .eyes-hungry { display: inline; }
.cat-btn.starving.happy .eyes-hungry { display: none; }

/* 吃東西：張嘴閉嘴 */
.mouth-open { transform-box: fill-box; transform-origin: center; transform: scaleY(0); }
.cat-btn.eating .mouth-open { animation: chomp .4s ease-in-out infinite alternate; }
@keyframes chomp { from { transform: scaleY(.15); } to { transform: scaleY(1); } }
.cat-btn.eating .mini-bowl { animation: nibble .4s ease-in-out infinite alternate; }
@keyframes nibble {
  from { transform: translateX(-50%) translateY(0); }
  to { transform: translateX(-50%) translateY(-3px); }
}

/* 點擊特效 */
.fx { position: absolute; inset: 0; pointer-events: none; }
.float {
  position: absolute;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--gold-deep);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .6), 0 0 6px rgba(255, 255, 255, .6);
  will-change: transform, opacity;
}
.float.big { font-size: 1.8rem; color: #e0530f; }
.drop {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, var(--coin) 45%, var(--coin-edge));
  box-shadow: inset 0 0 0 2px var(--coin-edge);
  will-change: transform, opacity;
}

/* 加持 */
.boost { width: 100%; display: grid; gap: 10px; margin-top: 10px; }

.status {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
}
.status-row { display: flex; justify-content: space-between; font-weight: 700; }
.bar { height: 10px; margin-top: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ffcf40, #ff8a2b);
  transition: width .2s linear;
}

.buy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border: 0;
  border-radius: 18px;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  color: #3b2200;
  background: linear-gradient(180deg, #ffd45a, #f5a91f);
  box-shadow: 0 4px 0 var(--gold-deep), 0 10px 20px rgba(217, 138, 10, .25);
  cursor: pointer;
}
.buy:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-deep), 0 4px 10px rgba(217, 138, 10, .25); }
.buy:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.price {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .95rem;
  background: #3b2200;
  color: #ffe9a8;
}
.fine { margin: 0; text-align: center; font-size: .82rem; color: var(--muted); }

/* 對話框 */
dialog {
  width: min(92vw, 420px);
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(30, 18, 6, .55); backdrop-filter: blur(2px); }
.dlg { display: grid; gap: 14px; padding: 20px; }
.dlg h2 { margin: 0; font-size: 1.25rem; }
.spec { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: .95rem; }
.spec dt { color: var(--muted); }
.spec dd { margin: 0; font-weight: 700; text-align: right; }
.food-note {
  margin: 0;
  font-weight: 800;
  text-align: center;
  color: var(--gold-deep);
}
.test-note {
  margin: 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fff1c9;
  color: #6b4500;
  font-size: .85rem;
}
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; line-height: 1.5; }
.check input { flex: none; width: 18px; height: 18px; margin-top: .28em; accent-color: var(--gold-deep); }
.actions { display: flex; gap: 10px; }
.btn {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.btn.primary {
  border: 0;
  background: linear-gradient(180deg, #ffd45a, #f5a91f);
  color: #3b2200;
  font-weight: 800;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* 帳號列 */
.account {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  font-size: .82rem;
  color: var(--muted);
}
.who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-actions { display: flex; flex: none; gap: 6px; }
.pill-btn:disabled { opacity: .5; cursor: default; }
.pill-btn.strong {
  border-color: transparent;
  background: linear-gradient(180deg, #ffd45a, #f5a91f);
  color: #3b2200;
  font-weight: 800;
}

/* 餵食：狀態列與體型 */
.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }
.stat {
  padding: 3px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: .82rem;
  color: var(--muted);
}
.stat b { color: var(--ink); font-variant-numeric: tabular-nums; }

.cat-zone { position: relative; display: flex; justify-content: center; width: 100%; padding-top: 52px; margin-top: 4px; }
.cat-size {
  position: relative;
  transform-origin: 50% 100%;
  transform: scale(var(--sx, 1), var(--sy, 1));
  transition: transform .3s ease-out;
}
.ground-shadow {
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 70%;
  height: 14px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .28);
  filter: blur(5px);
  transform: translateX(-50%);
}
.hint { margin-bottom: 2px; }
.drop.small { width: 12px; height: 12px; }

/* 排行榜 */
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
dialog { max-height: 92dvh; overflow: auto; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tab {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: linear-gradient(180deg, #ffd45a, #f5a91f); border-color: transparent; color: #3b2200; }
.board-list { display: grid; gap: 6px; margin: 0; padding: 0; max-height: 44vh; overflow: auto; list-style: none; }
.board-list li {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: .92rem;
}
.board-list li.me { border-color: var(--gold-deep); background: rgba(245, 176, 46, .16); font-weight: 800; }
.board-list .rk { color: var(--muted); font-variant-numeric: tabular-nums; }
.board-list .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .val { font-variant-numeric: tabular-nums; font-weight: 700; }
.board-list li.empty { display: block; text-align: center; color: var(--muted); border-style: dashed; }
.board-me { margin: 0; min-height: 1.4em; font-weight: 800; text-align: center; color: var(--gold-deep); }
.nick-form { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.nick-form label { flex: none; color: var(--muted); }
.nick-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
.nick-form .btn { flex: none; padding: 8px 14px; }
.privacy { margin: 0; font-size: .78rem; line-height: 1.5; color: var(--muted); }

/* 鬧：迷因字幕、連擊、彩帶、跑馬燈 */
.top-actions { display: flex; gap: 6px; }

.chaos-layer { position: absolute; inset: 0; z-index: 3; overflow: hidden; border-radius: 24px; pointer-events: none; }
.chaos-layer > * { position: absolute; }

.meme-doge {
  font-family: "Comic Sans MS", "Chalkboard SE", "Comic Neue", "Noto Sans TC", cursive;
  font-weight: 700;
  white-space: nowrap;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .65), 0 0 6px rgba(0, 0, 0, .5);
  will-change: transform, opacity;
}
.meme-pop, .meme-top, .meme-bottom, .meme-banner, .combo {
  font-family: Impact, "Arial Black", "Noto Sans TC", sans-serif;
  font-weight: 900;
  line-height: 1.15;
  color: #fff;
  -webkit-text-stroke: 3px #000;
  paint-order: stroke fill;
  will-change: transform, opacity;
}
.meme-pop { font-size: 1.9rem; white-space: nowrap; }
.meme-top, .meme-bottom { left: 4%; right: 4%; text-align: center; font-size: 1.3rem; letter-spacing: .02em; }
.meme-top { top: 38px; }
.meme-bottom { bottom: 12px; }
.meme-banner { left: 0; right: 0; top: 18%; text-align: center; font-size: 2.6rem; color: #ffe14d; -webkit-text-stroke: 4px #000; }

.combo {
  top: 10px;
  right: 12px;
  text-align: right;
  font-size: 2.2rem;
  color: #ffe14d;
  transform: rotate(6deg) scale(var(--s, 1));
  transform-origin: right top;
}
.combo small { display: block; font-size: .7rem; letter-spacing: .25em; color: #fff; -webkit-text-stroke: 2px #000; }

.confetti { width: 8px; height: 12px; border-radius: 2px; will-change: transform, opacity; }
.sweeper { left: 0; bottom: 50px; display: flex; align-items: flex-end; gap: 4px; will-change: transform; }
.sweeper b {
  font: 900 1.1rem/1 Impact, "Arial Black", "Noto Sans TC", sans-serif;
  color: #fff;
  -webkit-text-stroke: 3px #000;
  paint-order: stroke fill;
}

.ticker {
  display: flex;
  align-items: stretch;
  width: 100%;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 10px;
  background: #10233f;
  color: #fff;
  font-size: .85rem;
}
.ticker-label { flex: none; padding: 5px 10px; background: #d81e2b; font-weight: 800; letter-spacing: .15em; }
.ticker-view { display: flex; align-items: center; flex: 1; min-width: 0; overflow: hidden; }
.ticker-track {
  display: inline-block;
  padding-left: 100%;
  white-space: nowrap;
  animation: marquee 30s linear infinite;
  will-change: transform;
}
@keyframes marquee { to { transform: translateX(-100%); } }

/* 提示與頁尾 */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  padding: 10px 16px;
  border-radius: 999px;
  background: #3b2a1a;
  color: #fff;
  font-size: .9rem;
  opacity: 0;
  transform: translate(-50%, 20px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { margin-top: auto; padding-top: 16px; text-align: center; font-size: .78rem; color: var(--muted); }
.foot p { margin: 0 0 4px; }
.link-btn { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  .tail, .eyes-open, body.boosted .room::after,
  .cat-btn.eating .mouth-open, .cat-btn.eating .mini-bowl { animation: none; }
  .scene .anim { animation: none; }
  .scene { transition: none; }
  .ticker-track { display: block; animation: none; padding-left: 10px; overflow: hidden; text-overflow: ellipsis; }
  .ticker-view { display: block; padding: 5px 0; }
  .cat-size { transition: none; }
}
