:root {
  --cream: #fbf3e2;
  --ink: #3a2a1c;
  --ink2: #6a5440;
  --red: #c23b2f;
  --yellow: #e0b23a;
  --green: #4f8a4a;
  --blue: #3f6fa6;
  --band: repeating-linear-gradient(90deg, var(--red) 0 14px, var(--yellow) 14px 28px, var(--green) 28px 42px, var(--blue) 42px 56px, #e9dfc8 56px 70px);
  --font: "Yuanti TC", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #c8d6e6; font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none; }
#c { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }

/* ---------- screens and cards ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
#loading { background: radial-gradient(circle at 50% 40%, #f4e6c8, #c9b08a); }
.overlay { background: radial-gradient(circle at 50% 50%, rgba(40, 28, 18, 0.15), rgba(40, 28, 18, 0.55)); }
.card {
  position: relative; background: var(--cream); border-radius: 26px; padding: 26px 30px 22px;
  max-width: 640px; width: 100%; max-height: calc(100vh - 32px); overflow: auto;
  box-shadow: 0 18px 50px rgba(40, 24, 10, 0.45), inset 0 0 0 3px #fff8ea;
  text-align: center;
}
.card::before {
  content: ''; position: absolute; left: 18px; right: 18px; top: -7px; height: 14px; border-radius: 7px;
  background: var(--band); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18), inset 0 -3px 0 rgba(0, 0, 0, 0.15), inset 0 3px 0 rgba(255, 255, 255, 0.35);
}
.loadCard { text-align: center; width: min(420px, 90vw); }
.bandTitle { font-size: clamp(22px, 4vw, 30px); line-height: 1.25; color: var(--ink2); letter-spacing: 0.08em; }
.bandTitle b {
  display: inline-block; font-size: clamp(40px, 8vw, 64px); letter-spacing: 0.12em; color: var(--ink);
  text-shadow: 3px 3px 0 var(--yellow), 6px 6px 0 rgba(194, 59, 47, 0.6);
  margin-top: 2px;
}
.bandTitle.small b { font-size: clamp(34px, 7vw, 52px); }
.loadBar { height: 16px; border-radius: 8px; background: #e8d8b8; margin: 22px 0 10px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2); }
.loadBar i { display: block; height: 100%; width: 0; background: var(--band); background-size: 70px 100%; transition: width 0.2s; animation: roll 1s linear infinite; }
@keyframes roll { to { background-position: 70px 0; } }
#loadText { color: var(--ink2); font-size: 15px; }
.story { font-size: 16px; line-height: 1.7; color: var(--ink2); margin: 14px 0 12px; }
.story b { color: var(--red); }
.rules { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; text-align: left; font-size: 14px; line-height: 1.5; margin: 6px 0 16px; }
.rules div { background: #f3e6cb; border-radius: 12px; padding: 8px 10px; display: flex; gap: 8px; align-items: flex-start; }
.rules i { font-style: normal; font-size: 18px; }
.rules b { color: var(--ink); }
button {
  font-family: var(--font); font-size: 16px; color: var(--ink); background: #f0e2c4; border: 0; border-radius: 14px;
  padding: 10px 18px; margin: 4px; cursor: pointer; box-shadow: 0 3px 0 #c9b08a; transition: transform 0.08s, box-shadow 0.08s;
}
button:hover { background: #f6eacf; }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 #c9b08a; }
button.sel { background: var(--ink); color: var(--cream); box-shadow: 0 3px 0 #1c140c; }
button.big { font-size: 22px; padding: 14px 40px; background: var(--red); color: #fff6e4; box-shadow: 0 4px 0 #7a2018; margin: 12px 6px 6px; letter-spacing: 0.1em; }
button.big:hover { background: #d4483a; }
.diffRow { margin-top: 4px; }
.diffInfo { font-size: 13px; color: var(--ink2); margin: 6px 0 0; min-height: 18px; }
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: 13px; color: var(--ink2); margin-top: 12px; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; margin-right: 2px; border-radius: 6px; background: #fff; box-shadow: 0 2px 0 #c9b08a; font-family: var(--font); font-size: 12px; color: var(--ink); }
.touchOnly { display: none; }
body.touch .touchOnly { display: flex; }
body.touch .desktopOnly { display: none; }
h2 { margin: 6px 0 8px; font-size: 28px; letter-spacing: 0.06em; }
.stars { font-size: 44px; color: #e8b030; letter-spacing: 0.15em; text-shadow: 0 3px 0 #b07a18; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 6px; }
.stats div { background: #f3e6cb; border-radius: 12px; padding: 10px 4px; }
.stats b { display: block; font-size: 24px; }
.stats span { font-size: 12px; color: var(--ink2); }
.setRow { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.seg button { padding: 8px 14px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.panel {
  background: rgba(251, 243, 226, 0.88); border-radius: 16px; padding: 8px 12px; box-shadow: 0 6px 18px rgba(30, 18, 8, 0.25);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.label { font-size: 12px; color: var(--ink2); letter-spacing: 0.1em; }
.hudTop { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.beak { display: flex; flex-direction: column; gap: 4px; }
#beakSlots { display: flex; gap: 6px; }
.slot { width: 30px; height: 30px; border-radius: 50%; border: 2px dashed #c9b08a; position: relative; }
.slot.full { border: 2px solid var(--ink); background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.5), transparent 40%), var(--c); }
.slot.full::after { content: ''; position: absolute; inset: 6px; border-radius: 50%; border: 3px solid rgba(0, 0, 0, 0.25); }
.slot.gold { box-shadow: 0 0 10px #ffd040; }
.center { flex: 0 1 380px; display: flex; flex-direction: column; gap: 4px; }
.center .row { display: flex; align-items: center; gap: 8px; }
.center b { min-width: 54px; text-align: right; font-size: 16px; }
.fed, .sunTrack, .dz { flex: 1; height: 12px; border-radius: 6px; background: #e8d8b8; position: relative; overflow: visible; box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.18); }
.fed i { display: block; height: 100%; width: 0; border-radius: 6px; background: var(--band); background-size: 70px 100%; transition: width 0.4s; }
.sunTrack { background: linear-gradient(90deg, #9fc4e8, #f4c27a 70%, #e87a4a); }
.sunTrack i { position: absolute; top: -7px; left: 0; transform: translateX(-50%); font-style: normal; font-size: 18px; transition: left 0.5s linear; }
.score { text-align: center; min-width: 80px; }
.score b { font-size: 22px; }
.dizzy { position: absolute; left: 12px; bottom: max(14px, env(safe-area-inset-bottom)); width: min(260px, 40vw); display: flex; align-items: center; gap: 8px; }
.dz i { display: block; height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, #8ac46a, #e0b23a 55%, #d04a30); transition: width 0.15s; }
.dizzy.hot { animation: wob 0.5s ease-in-out infinite; background: rgba(255, 220, 200, 0.92); }
@keyframes wob { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
.tweetCd {
  position: absolute; left: calc(12px + min(260px, 40vw) + 12px); bottom: max(10px, env(safe-area-inset-bottom)); width: 46px; height: 46px; border-radius: 50%;
  background: conic-gradient(rgba(58, 42, 28, 0.55) var(--p, 0deg), rgba(251, 243, 226, 0.9) 0); display: flex; align-items: center; justify-content: center;
  font-size: 18px; box-shadow: 0 4px 12px rgba(30, 18, 8, 0.25);
}
.tweetCd.ready { background: #ffe9a8; box-shadow: 0 0 0 3px #e0b23a, 0 4px 12px rgba(30, 18, 8, 0.25); }
.tweetCd span::after { content: ' Q'; font-size: 10px; color: var(--ink2); }
body.touch .tweetCd { display: none; }
#minimap { position: absolute; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); width: min(210px, 30vw); height: min(210px, 30vw); border-radius: 50%; box-shadow: 0 8px 22px rgba(30, 18, 8, 0.4); }
body.touch #minimap { top: 86px; bottom: auto; width: 150px; height: 150px; z-index: 2; }
body.touch .hudTop { padding-right: 58px; }
#toasts { position: absolute; top: 96px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(560px, 90vw); }
.toast {
  background: rgba(251, 243, 226, 0.94); padding: 8px 16px; border-radius: 14px; font-size: 16px; box-shadow: 0 4px 14px rgba(30, 18, 8, 0.25);
  animation: pop 0.25s ease-out; transition: opacity 0.4s, transform 0.4s; border-left: 6px solid var(--blue);
}
.toast.good { border-left-color: var(--green); }
.toast.bad { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--yellow); }
.toast.gold { border-left-color: #f2c230; background: #fff3c4; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes pop { from { transform: scale(0.8); opacity: 0; } }
#hint { position: absolute; bottom: 90px; left: 50%; transform: translateX(-50%); font-size: 17px; padding: 8px 16px; border-radius: 14px; background: rgba(58, 42, 28, 0.75); color: #fff3d8; opacity: 0; transition: opacity 0.2s; }
#hint.on { opacity: 1; }
#bigText {
  position: absolute; top: 36%; left: 0; right: 0; text-align: center; font-size: clamp(34px, 7vw, 64px); color: #fff8e6; letter-spacing: 0.1em;
  text-shadow: 3px 3px 0 var(--red), 6px 6px 0 rgba(0, 0, 0, 0.25); opacity: 0; transform: scale(0.6);
}
#bigText.on { animation: big 1.6s ease-out forwards; }
@keyframes big { 0% { opacity: 0; transform: scale(0.5) rotate(-4deg); } 15% { opacity: 1; transform: scale(1.12) rotate(2deg); } 25% { transform: scale(1) rotate(0); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(1.05); } }

/* ---------- touch ---------- */
#touch { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#stickZone { position: absolute; left: 0; bottom: 0; width: 50%; height: 70%; pointer-events: auto; }
#stickBase { position: absolute; left: 40px; bottom: 60px; width: 140px; height: 140px; border-radius: 50%; background: rgba(251, 243, 226, 0.25); border: 3px solid rgba(251, 243, 226, 0.6); opacity: 0.5; pointer-events: none; }
#stickBase.on { opacity: 1; bottom: auto; }
#stickKnob { position: absolute; left: 40px; top: 40px; width: 60px; height: 60px; border-radius: 50%; background: rgba(251, 243, 226, 0.9); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); }
.tbtn { position: absolute; pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; font-size: 26px; padding: 0; background: rgba(251, 243, 226, 0.88); }
.tbtn.down { transform: scale(0.92); background: #fff; }
.tbtn.peck { right: 30px; bottom: 40px; width: 92px; height: 92px; background: var(--red); color: #fff6e4; font-size: 32px; }
.tbtn.tweet { right: 140px; bottom: 30px; }
.tbtn.boost { right: 40px; bottom: 150px; }
.tbtn.pause { right: 14px; top: 14px; width: 48px; height: 48px; font-size: 18px; }
body.touch .dizzy { bottom: auto; top: 86px; left: 12px; }
body.touch #toasts { top: 150px; }

@media (orientation: portrait) {
  body.touch #minimap { top: 168px; width: 116px; height: 116px; right: 10px; }
  body.touch .dizzy { top: 168px; width: calc(100vw - 150px); }
  body.touch #toasts { top: 300px; }
  body.touch #bigText { top: 42%; }
}
@media (max-width: 700px) {
  .rules { grid-template-columns: 1fr; }
  .hudTop { flex-wrap: wrap; }
  .center { order: 3; flex-basis: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
