:root {
  --paper: #efeadf;
  --ink: #2f2b25;
  --muted: #8a8272;
  --blue: #3a7cf6;
  --bar: rgba(255, 255, 255, 0.84);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: Inter, "Noto Sans TC", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
body { background: radial-gradient(ellipse at 50% 46%, #f7f3eb 0%, #eee8dc 62%, #e5ded0 100%); }
/* 紙紋 */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: 0.4; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.55 0 0 0 0 0.5 0 0 0 0 0.42 0 0 0 0.16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* 選取框 */
.box { position: fixed; left: 0; top: 0; border: 1.5px solid var(--blue); pointer-events: none; display: none; border-radius: 1px; }
.box.ghost { border-width: 1px; opacity: 0.55; }
.box .h { position: absolute; width: 8px; height: 8px; background: #fff; border: 1.5px solid var(--blue); border-radius: 1.5px; }
.h.tl { left: -5px; top: -5px; } .h.tr { right: -5px; top: -5px; }
.h.bl { left: -5px; bottom: -5px; } .h.br { right: -5px; bottom: -5px; }
.tag {
  position: fixed; left: 0; top: 0; display: none; pointer-events: none; white-space: nowrap;
  background: var(--blue); color: #fff; font-size: 11.5px; font-weight: 500; letter-spacing: 0.01em;
  line-height: 22px; height: 22px; padding: 0 8px; border-radius: 5px; font-variant-numeric: tabular-nums;
}
#marquee { position: fixed; display: none; pointer-events: none; border: 1px solid var(--blue); background: rgba(58, 124, 246, 0.08); border-radius: 2px; }

/* 工具列 */
.bar {
  background: var(--bar);
  -webkit-backdrop-filter: blur(16px) saturate(1.3); backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 28px rgba(70, 58, 30, 0.14), 0 1px 3px rgba(70, 58, 30, 0.08);
  border-radius: 13px; display: flex; align-items: center; gap: 2px; padding: 4px;
}
#toolbar { position: fixed; left: 0; top: 0; display: none; z-index: 5; }
.seg { display: flex; gap: 2px; }
.bar button {
  appearance: none; border: 0; background: transparent; font: inherit; font-size: 13.5px; font-weight: 500;
  color: #5a564d; padding: 0 12px; height: 32px; border-radius: 9px; cursor: pointer; line-height: 1;
  display: flex; align-items: center; gap: 6px; transition: background 0.12s, color 0.12s;
}
.bar button:hover { background: rgba(60, 50, 20, 0.06); color: #2f2b25; }
.bar button.on { background: #e2e7d8; color: #24221d; }
.bar button:disabled { opacity: 0.32; cursor: default; background: transparent; }
.bar .ic { padding: 0 8px; }
.bar .ic.txt { font-size: 12.5px; min-width: 32px; justify-content: center; }
.bar svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sep { width: 1px; height: 18px; background: rgba(60, 50, 20, 0.12); margin: 0 4px; flex: none; }
#grow.on { background: #dcefc6; color: #2f6b1c; }
#snd .x { display: none; }
#snd.off .x { display: inline; }
#snd.off .wave { display: none; }

/* 品牌 */
#brand { position: fixed; left: 24px; top: 20px; display: flex; flex-direction: column; gap: 2px; pointer-events: none; }
#brand b { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
#brand span { font-size: 12px; color: var(--muted); letter-spacing: 0.12em; }

/* 底部 dock */
#dock { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 4; }
#dock .count { display: flex; align-items: center; gap: 6px; padding: 0 8px; font-size: 13.5px; font-weight: 500; color: #5a564d; font-variant-numeric: tabular-nums; }
#hint {
  position: fixed; left: 50%; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 54px); transform: translateX(-50%);
  font-size: 12.5px; color: var(--muted); white-space: nowrap; transition: opacity 0.8s; pointer-events: none;
}
#hint.gone { opacity: 0; }

/* ───── 模式 ───── */
.mode-play .sandbox-only, .mode-sandbox .play-only, .mode-menu .play-only { display: none !important; }
.mode-menu #dock, .mode-menu #toolbar, .mode-menu #brand, .mode-menu #hint, .mode-play #hint { display: none !important; }
.pill { font-size: 11px; font-weight: 600; background: #5aa53a; color: #fff; border-radius: 99px; padding: 2px 7px; line-height: 1.2; }
.pill.empty { background: #d9534f; }
#shear svg { stroke-width: 1.9; }

/* HUD */
#hud { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 6; padding: 6px 10px; gap: 10px; font-variant-numeric: tabular-nums; }
.hday { display: flex; flex-direction: column; gap: 4px; min-width: 92px; }
#hDay { font-size: 13px; font-weight: 600; }
.sunbar { position: relative; height: 6px; border-radius: 6px; background: linear-gradient(90deg, #ffc58a, #fff1b8 30%, #fff1b8 70%, #ff9d6b); }
.sunbar i { position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: #ffb238; box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0,0,0,.2); }
.hstat { display: flex; align-items: center; gap: 5px; font-size: 15px; font-weight: 600; white-space: nowrap; flex: none; }
.hstat b { font-size: 15px; }
#hWoolBox.done { color: #3f8a22; }
.hearts { color: #e0535a; letter-spacing: 1px; font-size: 16px; }

#coach {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 6; display: none; max-width: min(560px, calc(100vw - 32px));
  background: #2f2b25; color: #fff; font-size: 13.5px; line-height: 1.45; padding: 9px 14px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
#coach.show { display: block; animation: rise .35s ease-out; }
#coach .step { display: inline-block; font-size: 11px; font-weight: 600; background: #5aa53a; border-radius: 99px; padding: 1px 7px; margin-right: 8px; }
#toasts { position: fixed; top: 128px; left: 50%; transform: translateX(-50%); z-index: 7; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: rgba(255,255,255,.95); color: var(--ink); font-size: 13.5px; font-weight: 500; padding: 7px 14px; border-radius: 99px; box-shadow: 0 4px 16px rgba(60,50,30,.15); animation: rise .3s ease-out; transition: opacity .5s, transform .5s; max-width: calc(100vw - 32px); text-align: center; }
.toast.good { background: #e7f5d8; color: #2f6b1c; }
.toast.bad { background: #ffe3dc; color: #a2341f; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }
.toast { animation-name: rise2; } @keyframes rise2 { from { opacity: 0; transform: translateY(6px); } }

/* 羊頭上的泡泡 */
#badges { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
.badge { position: fixed; left: 0; top: 0; margin: -34px 0 0 -16px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 16px; border: 0; padding: 0; pointer-events: none; }
.badge.shear { pointer-events: auto; cursor: pointer; background: #fff; color: var(--blue); font-weight: 700; box-shadow: 0 0 0 2.5px var(--blue), 0 4px 12px rgba(40,80,200,.3); animation: bob 1s ease-in-out infinite; }
.badge.shear:hover { background: var(--blue); color: #fff; }
.badge.hungry, .badge.starve { width: 24px; height: 24px; margin: -26px 0 0 -12px; font-size: 13px; background: #fff3d6; box-shadow: 0 0 0 2px #f0b440; }
.badge.starve { background: #ffe0d8; box-shadow: 0 0 0 2px #e0535a; animation: bob .5s ease-in-out infinite; }
.badge.wolf { pointer-events: auto; cursor: pointer; background: #e0535a; color: #fff; font-weight: 800; font-size: 18px; box-shadow: 0 0 0 3px #fff, 0 0 18px rgba(224,83,90,.7); animation: bob .45s ease-in-out infinite; }
@keyframes bob { 50% { margin-top: -40px; } }
.fly { position: fixed; left: -12px; top: -12px; font-size: 24px; z-index: 30; pointer-events: none; transition: transform .7s cubic-bezier(.5,-0.3,.6,1), opacity .7s; }

/* 卡片視窗 */
.overlay { position: fixed; inset: 0; z-index: 20; display: none; place-items: center; background: rgba(239,234,223,.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); padding: 16px; }
.overlay.show { display: grid; }
.card { width: min(400px, 100%); background: #fffdf8; border-radius: 22px; padding: 26px 26px 22px; text-align: center; box-shadow: 0 20px 60px rgba(70,58,30,.22); animation: pop .3s cubic-bezier(.3,1.4,.6,1); max-height: calc(100vh - 32px); overflow: auto; }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }
.card .logo { font-size: 40px; line-height: 1; }
.card h1 { margin: 8px 0 0; font-size: 26px; letter-spacing: -0.02em; }
.card h2 { margin: 4px 0 8px; font-size: 20px; }
.card .sub { margin: 2px 0 10px; color: var(--muted); letter-spacing: .2em; font-size: 13px; }
.card .tag2 { margin: 0 0 14px; color: #5a564d; font-size: 14px; line-height: 1.5; }
.how { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 0 0 18px; flex-wrap: wrap; }
.how div { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: #5a564d; background: #f4f1e8; border-radius: 12px; padding: 8px 8px; min-width: 70px; }
.how div span { font-size: 20px; }
.how i { color: #b3ab98; font-style: normal; }
.card button.primary, .card button.ghost { display: block; width: 100%; border: 0; font: inherit; font-size: 15px; font-weight: 600; border-radius: 12px; padding: 12px; cursor: pointer; margin-top: 8px; }
.card button.primary { background: #5aa53a; color: #fff; box-shadow: 0 4px 0 #3f7f25; }
.card button.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #3f7f25; }
.card button.ghost { background: #f1ede3; color: #4b463d; }
.best { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); min-height: 1em; }
.result { font-weight: 600; margin: 0 0 12px; }
.result.good { color: #3f8a22; } .result.bad { color: #c0392b; }
.stats { display: grid; gap: 6px; margin: 0 0 14px; text-align: left; }
.stats div { display: flex; justify-content: space-between; background: #f6f3ea; border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.stats b { font-variant-numeric: tabular-nums; }
.shopcard { width: min(440px, 100%); }
.shophead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.shophead h2 { margin: 0; }
.coins { font-weight: 700; font-size: 16px; }
.shoplist { display: grid; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; background: #f6f3ea; border-radius: 14px; padding: 10px 12px; text-align: left; }
.item .ico { font-size: 26px; width: 34px; text-align: center; }
.item .txt { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.item .txt b { font-size: 14.5px; }
.item .txt small { font-size: 12px; color: var(--muted); line-height: 1.35; }
.item button { border: 0; font: inherit; font-weight: 600; font-size: 13.5px; background: #5aa53a; color: #fff; border-radius: 10px; padding: 8px 10px; min-width: 70px; cursor: pointer; }
.item button:disabled { background: #d8d2c3; color: #8a8272; cursor: default; }

@media (max-width: 560px) {
  .mode-play #brand { display: none; }
  #hud { gap: 7px; padding: 5px 8px; }
  .hday { min-width: 70px; }
  #shopLabel { display: none; }
  #brand { left: 16px; top: 14px; }
  .bar button { font-size: 13px; padding: 0 9px; }
  #hint { white-space: normal; text-align: center; width: calc(100vw - 32px); }
  #all { display: none; }
  #growLabel { display: none; }
}
