* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #2a2150; color: #fff;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }

.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  text-align: center; z-index: 20;
}
#title {
  background: linear-gradient(180deg, rgba(42,30,90,.55) 0%, rgba(42,30,90,.15) 45%, rgba(30,20,60,.75) 100%), url(assets/title.jpg) center/cover no-repeat #2a2150;
  transition: opacity .6s ease;
}
#title.out { opacity: 0; pointer-events: none; }
.title-inner { max-width: 640px; width: 100%; }
.to-line {
  display: inline-block; margin: 0 0 clamp(8px, 2vh, 18px); padding: .35em 1em; border-radius: 999px;
  background: rgba(255,255,255,.18); backdrop-filter: blur(6px); font-size: clamp(15px, 2.6vw, 20px); letter-spacing: .05em;
}
#gameTitle {
  margin: 0; font-size: clamp(44px, 11vw, 96px); font-weight: 900; letter-spacing: .06em; line-height: 1.1;
  text-shadow: 0 4px 0 #3b2c78, 0 8px 24px rgba(20,10,60,.6);
}
.sub { margin: .5em 0 1.4em; font-size: clamp(16px, 3vw, 22px); opacity: .95; text-shadow: 0 2px 8px rgba(20,10,60,.8); }
.howto { text-wrap: balance; margin: 1.4em auto 0; font-size: clamp(13px, 2.2vw, 16px); line-height: 1.7; opacity: .92; text-shadow: 0 1px 6px rgba(20,10,60,.9); }

.btn {
  appearance: none; border: 2px solid rgba(255,255,255,.75); background: rgba(255,255,255,.14); color: #fff;
  font: inherit; font-size: clamp(16px, 2.8vw, 20px); font-weight: 700; padding: .75em 1.6em; border-radius: 999px;
  cursor: pointer; backdrop-filter: blur(6px); min-height: 48px; touch-action: manipulation;
}
.btn.primary { background: #d8404a; border-color: #ffd9a0; box-shadow: 0 6px 0 #8f2430, 0 10px 24px rgba(0,0,0,.35); }
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #8f2430; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-left, .hud-right { position: absolute; top: max(10px, env(safe-area-inset-top)); display: flex; align-items: center; gap: 8px; }
.hud-left { left: max(10px, env(safe-area-inset-left)); }
.hud-right { right: calc(max(10px, env(safe-area-inset-right)) + 52px); }
.avatar { width: clamp(36px, 7vw, 52px); height: clamp(36px, 7vw, 52px); display: block; border-radius: 50%; border: 3px solid #fff; background-size: cover; background-position: center; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.avatar.foe { width: clamp(30px, 5.5vw, 42px); height: clamp(30px, 5.5vw, 42px); border-width: 2px; transition: transform .15s; }
.avatar.foe.hit { animation: foehit .5s; }
@keyframes foehit { 0% { transform: scale(1.5) rotate(-12deg); filter: brightness(2); } 100% { transform: none; filter: none; } }
.score { background: rgba(30,20,70,.55); border-radius: 12px; padding: 4px 10px; display: flex; flex-direction: column; align-items: center; min-width: 46px; }
.score .label { font-size: 11px; opacity: .85; }
.score b { font-size: clamp(18px, 3.4vw, 24px); line-height: 1.1; }
.score.taken b { color: #bfe3ff; }
.timer {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: rgba(30,20,70,.55); border-radius: 999px; padding: 6px 16px; font-size: clamp(18px, 3.4vw, 24px); font-weight: 800; font-variant-numeric: tabular-nums;
}
.timer.low { background: rgba(216,64,74,.85); }
.ammo { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 6px; }
.ammo i { width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: inset -2px -3px 0 #c9d2f5, 0 1px 4px rgba(0,0,0,.4); transition: opacity .15s, transform .15s; }
.ammo i.off { opacity: .22; transform: scale(.7); }
.dot { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,.7); box-shadow: 0 0 0 1px rgba(40,30,80,.5); }
.charge { position: absolute; left: 50%; top: calc(50% + 34px); width: 90px; height: 8px; margin-left: -45px; border-radius: 4px; background: rgba(30,20,70,.5); opacity: 0; transition: opacity .1s; overflow: hidden; }
.charge.on { opacity: 1; }
.charge i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #fff, #ffd24a, #ff6a5a); }
.banner {
  position: absolute; left: 50%; top: 17%; transform: translateX(-50%); width: min(92vw, 560px); text-align: center;
  font-size: clamp(17px, 3.2vw, 28px); font-weight: 800; text-shadow: 0 3px 0 #3b2c78, 0 4px 14px rgba(0,0,0,.5); opacity: 0; transition: opacity .35s; line-height: 1.5;
}
.banner.on { opacity: 1; }
.banner small { display: block; font-size: .6em; font-weight: 600; opacity: .95; }

.mute {
  position: fixed; z-index: 30; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right));
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); background: rgba(30,20,70,.55); color: #fff; font-size: 20px; cursor: pointer;
}
.mute.off { opacity: .55; text-decoration: line-through; }

/* 觸控 */
#touch { position: fixed; inset: 0; z-index: 11; }
.joy-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 62%; }
.look-zone { position: absolute; right: 0; top: 0; width: 55%; height: 100%; }
.joy-base { position: absolute; left: 34px; bottom: 44px; width: 112px; height: 112px; border-radius: 50%; background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.4); pointer-events: none; }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: rgba(255,255,255,.75); }
.tbtn {
  position: absolute; border-radius: 50%; border: 3px solid rgba(255,255,255,.8); color: #fff; font: inherit; font-weight: 800; touch-action: none;
}
.tbtn.throw { right: max(22px, env(safe-area-inset-right)); bottom: max(54px, calc(env(safe-area-inset-bottom) + 40px)); width: 96px; height: 96px; font-size: 26px; background: rgba(216,64,74,.8); }
.tbtn.throw.on { background: #ff9a4a; transform: scale(1.08); }
.tbtn.crouch { right: max(128px, calc(env(safe-area-inset-right) + 110px)); bottom: max(40px, calc(env(safe-area-inset-bottom) + 26px)); width: 64px; height: 64px; font-size: 20px; background: rgba(60,80,160,.7); }
.tbtn.crouch.on { background: #4ad1a0; }

/* 被砸中的雪花濺痕 */
.splat { position: fixed; inset: 0; z-index: 12; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 30% 35%, #fff 0 9%, transparent 10%), radial-gradient(circle at 68% 30%, #fff 0 12%, transparent 13%),
    radial-gradient(circle at 55% 70%, #fff 0 10%, transparent 11%), radial-gradient(circle at 18% 75%, #fff 0 7%, transparent 8%), radial-gradient(circle at 84% 68%, #fff 0 8%, transparent 9%),
    radial-gradient(ellipse at center, transparent 40%, rgba(255,255,255,.75) 100%);
}
.splat.on { animation: splat .9s ease-out; }
@keyframes splat { 0% { opacity: .95; transform: scale(1.06); } 100% { opacity: 0; transform: scale(1) translateY(30px); } }
#floats { position: fixed; inset: 0; pointer-events: none; z-index: 12; }
.float { position: absolute; font-weight: 900; font-size: clamp(20px, 4vw, 30px); color: #ffe27a; text-shadow: 0 2px 0 #7a3a1a, 0 3px 10px rgba(0,0,0,.5); animation: floatup .9s ease-out forwards; transform: translate(-50%, -50%); white-space: nowrap; }
@keyframes floatup { to { opacity: 0; margin-top: -70px; } }

/* 賀卡 */
.card { background: radial-gradient(ellipse at center, rgba(30,18,70,.25) 0%, rgba(20,10,50,.72) 100%); animation: fadein 1.2s ease both; z-index: 25; }
@keyframes fadein { from { opacity: 0; } }
.card { background: linear-gradient(180deg, rgba(24,14,60,.78) 0%, rgba(24,14,60,.28) 46%, rgba(24,14,60,0) 62%, rgba(24,14,60,.7) 100%); }
.card-inner { width: min(94vw, 900px); height: 100%; display: flex; flex-direction: column; justify-content: space-between; padding: clamp(28px, 7vh, 80px) 0 clamp(6px, 3vh, 36px); }
.card-to { margin: 0 0 .6em; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: clamp(18px, 3.6vw, 30px); opacity: 0; animation: rise .9s .2s ease forwards; }
.card-big {
  margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 700; font-size: clamp(34px, 8.6vw, 88px); line-height: 1.15; letter-spacing: .01em;
  color: #fff6dc; text-shadow: 0 0 18px rgba(255,214,120,.9), 0 3px 0 #a8483a, 0 6px 22px rgba(0,0,0,.55);
}
.card-big .w { display: inline-block; white-space: nowrap; }
.card-big .ch { display: inline-block; opacity: 0; transform: translateY(.5em) scale(.4) rotate(-12deg); animation: pop .55s cubic-bezier(.2,1.6,.4,1) forwards; }
@keyframes pop { to { opacity: 1; transform: none; } }
.card-sub {
  margin: .7em 0 0; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-weight: 400; font-size: clamp(22px, 4.6vw, 44px);
  color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,.6); opacity: 0;
}
.card-sub.on { animation: rise 1.2s ease forwards; }
@keyframes rise { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }
.card-result, .card-btns, .share-msg { opacity: 0; }
.card-result.on, .card-btns.on { animation: rise .8s ease forwards; }
.card-result { margin: 0; font-size: clamp(14px, 2.6vw, 18px); text-shadow: 0 1px 6px rgba(0,0,0,.7); }
.card-btns { margin-top: 1.1em; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.share-msg { min-height: 1.4em; margin: .8em 0 0; font-size: 14px; transition: opacity .3s; }
.share-msg.on { opacity: 1; }

@media (max-height: 430px) {
  .howto { display: none; }
  .card-inner { padding-top: 14px; }
  .card-big { font-size: clamp(28px, 6.2vw, 60px); }
  .card-sub { font-size: clamp(18px, 3.6vw, 32px); margin-top: .4em; }
  .joy-base { bottom: 20px; }
}

@media (max-width: 480px) {
  .hud-left, .hud-right { gap: 5px; }
  .score { min-width: 40px; padding: 3px 7px; }
  .avatar.foe { width: 26px; height: 26px; }
  .hud-right { right: calc(max(10px, env(safe-area-inset-right)) + 50px); top: calc(max(10px, env(safe-area-inset-top)) + 9px); }
  .timer { padding: 5px 12px; }
}

/* 自動瞄準鎖定框 */
.dot.locked { background: #ff7a3a; box-shadow: 0 0 0 2px #fff; }
.lock.blocked { border-color: #b9bdd6; border-style: dashed; box-shadow: 0 0 0 2px rgba(40,30,80,.5); animation: none; opacity: .8; }
.lock { position: absolute; width: 64px; height: 64px; margin: -32px; border-radius: 50%; border: 3px solid #ff9a3a; box-shadow: 0 0 0 2px rgba(255,255,255,.85), 0 0 14px rgba(255,150,60,.8); animation: lockpulse .7s ease-in-out infinite alternate; }
.lock::before, .lock::after { content: ''; position: absolute; left: 50%; top: -9px; width: 3px; height: 14px; margin-left: -1.5px; background: #fff; border-radius: 2px; }
.lock::after { top: auto; bottom: -9px; }
@keyframes lockpulse { from { transform: scale(1.12); } to { transform: scale(.92); } }

/* 直向螢幕：改用直式主視覺，標題放天空、按鈕放底部 */
#title { background: linear-gradient(180deg, rgba(42,30,90,.5) 0%, rgba(42,30,90,0) 36%, rgba(30,20,60,0) 62%, rgba(24,14,56,.85) 100%), url(assets/title.jpg) center/cover no-repeat #2a2150; }
.title-inner { height: 100%; max-width: 900px; display: flex; flex-direction: column; justify-content: space-between; padding: clamp(10px, 4vh, 48px) 0 clamp(6px, 3vh, 32px); }
#gameTitle { font-size: clamp(38px, min(11vw, 15vh), 96px); }
.sub { margin-bottom: 0; }
.howto { margin-top: 1em; }
@media (orientation: portrait) {
  #title { background: linear-gradient(180deg, rgba(42,30,90,.35) 0%, rgba(42,30,90,0) 34%, rgba(30,20,60,0) 62%, rgba(24,14,56,.88) 100%), url(assets/title-portrait.jpg) center/cover no-repeat #2a2150; }
  .title-inner { padding-top: clamp(18px, 6vh, 64px); }
}

/* ---- 新首頁：兩行標題、英文名、署名、分享視窗 ---- */
#title { background: linear-gradient(180deg, rgba(30,24,90,.38) 0%, rgba(30,24,90,0) 40%, rgba(30,20,60,0) 66%, rgba(24,14,56,.8) 100%), url(assets/title.jpg) center 70%/cover no-repeat #2a2150; }
#gameTitle { font-size: clamp(34px, min(9.5vw, 11.5vh), 84px); letter-spacing: .04em; line-height: 1.15; }
#gameTitle span { display: block; }
#gameTitle span:last-child { color: #ffe9a8; font-size: 1.18em; transform: rotate(-2deg); }
.title-en { margin: .5em 0 0; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: clamp(14px, min(2.8vw, 3.6vh), 24px); text-shadow: 0 2px 8px rgba(20,10,60,.85); }
.sub { margin-top: .35em; font-size: clamp(13px, min(2.4vw, 3vh), 18px); opacity: .9; }
.link-btn { appearance: none; background: none; border: 0; color: #fff; font: inherit; font-size: clamp(13px, 2.2vw, 15px); text-decoration: underline; text-underline-offset: 3px; padding: 10px 12px; margin-top: 2px; cursor: pointer; text-shadow: 0 1px 6px rgba(20,10,60,.9); touch-action: manipulation; }
.credit { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); margin: 0; font-size: 11px; letter-spacing: .04em; opacity: .8; text-shadow: 0 1px 4px rgba(20,10,60,.9); pointer-events: none; }
@media (orientation: portrait) {
  #title { background: linear-gradient(180deg, rgba(30,24,90,.3) 0%, rgba(30,24,90,0) 38%, rgba(30,20,60,0) 70%, rgba(24,14,56,.82) 100%), url(assets/title-portrait.jpg) center/cover no-repeat #2a2150; }
  .title-bottom { padding-bottom: 14px; }
}
@media (max-height: 430px) { .link-btn { padding: 4px 12px; } .title-en { margin-top: .2em; } }

.modal { background: rgba(20,12,50,.72); z-index: 40; backdrop-filter: blur(4px); }
.modal-box { width: min(92vw, 400px); background: #fffaf0; color: #33284f; border-radius: 20px; padding: 22px 22px 18px; text-align: left; box-shadow: 0 18px 50px rgba(0,0,0,.45); }
.modal-box h3 { margin: 0 0 12px; font-size: 20px; text-align: center; }
.modal-box label { display: block; margin: 12px 0 6px; font-weight: 700; font-size: 15px; }
.modal-box input { width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border: 2px solid #cfc6e6; border-radius: 12px; background: #fff; color: #33284f; user-select: text; -webkit-user-select: text; touch-action: auto; }
.modal-box input:focus { outline: none; border-color: #d8404a; }
.modal-err { min-height: 1.3em; margin: 8px 0 0; color: #c0303a; font-size: 13px; }
.modal-btns { display: flex; gap: 10px; margin-top: 8px; }
.modal-btns .btn { flex: 1; font-size: 16px; padding: .7em .6em; }
.modal-btns .btn:not(.primary) { color: #33284f; border-color: #cfc6e6; background: #fff; backdrop-filter: none; }
.share-result { margin-top: 14px; font-size: 13px; }
.share-result p { margin: 0 0 6px; }
.share-result input { font-size: 13px; padding: 9px 10px; }
