:root {
  --gold: #e9c46a;
  --gold2: #b8892f;
  --ink: #0d1424;
  --panel: rgba(16, 24, 44, .92);
  --text: #f4ecd8;
  --muted: #a9b0c2;
  --blue: #4f8cff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); overflow: hidden;
  font-family: "Noto Serif TC", "PingFang TC", "Microsoft JhengHei", serif; user-select: none; -webkit-user-select: none; touch-action: none; }
canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: var(--text); background: linear-gradient(#26324f, #18213a); border: 2px solid var(--gold2);
  border-radius: 10px; padding: 10px 22px; cursor: pointer; min-width: 120px; font-size: 17px; }
button:hover { border-color: var(--gold); }
button:active { transform: translateY(1px); }
button.big { background: linear-gradient(#e9c46a, #b8892f); color: #20160a; font-weight: 700; font-size: 20px; border-color: #f7e2a5; }
button:disabled { opacity: .45; cursor: default; }

/* 畫面 */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); overflow-y: auto;
  background: radial-gradient(ellipse at 50% 30%, rgba(40,60,110,.55), rgba(8,12,24,.94)); z-index: 10; }
.screen.modal { background: rgba(6, 10, 20, .78); z-index: 20; }
.screen h3 { margin: 0; font-size: 28px; color: var(--gold); letter-spacing: 2px; text-shadow: 0 2px 0 #000; }
.screen h3 small { font-size: 16px; color: var(--text); margin-left: 8px; }
.sub { margin: -8px 0 0; color: var(--muted); font-size: 14px; }
.menu { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.foot { display: flex; gap: 18px; color: var(--muted); font-size: 14px; }
.panel { background: var(--panel); border: 1px solid rgba(233,196,106,.35); border-radius: 12px; padding: 14px 18px; max-width: 560px; width: 100%; }
.help p { margin: 8px 0; line-height: 1.6; font-size: 15px; }
.logo { text-align: center; }
.logo img { max-width: min(80vw, 520px); display: none; }
.logo img.ok { display: block; }
.logo img.ok ~ h1, .logo img.ok ~ h2 { display: none; }
.logo h1 { font-size: clamp(44px, 12vw, 84px); margin: 0; color: var(--gold); letter-spacing: 8px;
  text-shadow: 0 3px 0 #6b4a12, 0 0 30px rgba(233,196,106,.5); }
.logo h2 { margin: 0; font-size: clamp(20px, 5vw, 30px); letter-spacing: 12px; color: #dfe6f5; font-weight: 400; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; width: 100%; max-width: 760px; }
.card { background: var(--panel); border: 2px solid rgba(233,196,106,.3); border-radius: 12px; padding: 12px; text-align: center;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; }
.card:hover { border-color: var(--gold); }
.card.locked { filter: grayscale(.7); }
.card .pic { width: 84px; height: 84px; display: flex; align-items: center; justify-content: center; font-size: 46px; }
.card .pic img { max-width: 100%; max-height: 100%; }
.card b { font-size: 17px; color: var(--gold); }
.card small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.card .cost { margin-top: 4px; font-size: 14px; color: var(--text); }
.card .rank { font-size: 13px; color: var(--gold); }

#cards { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 520px; }
.opt { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 2px solid rgba(233,196,106,.35);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; text-align: left; }
.opt:hover, .opt:focus { border-color: var(--gold); outline: none; }
.opt .ic { width: 54px; height: 54px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 34px;
  background: rgba(255,255,255,.06); border-radius: 10px; }
.opt .ic img { max-width: 100%; max-height: 100%; }
.opt .tx { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.opt .tx b { color: var(--gold); font-size: 17px; }
.opt .tx em { font-style: normal; font-size: 12px; color: #9fd0ff; }
.opt .tx span { font-size: 14px; color: var(--text); line-height: 1.4; }
.opt.evo { border-color: #ff7ad9; box-shadow: 0 0 18px rgba(255,122,217,.35); }
#chestlist { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 520px; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#xpbar { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; height: 16px; background: rgba(0,0,0,.6);
  border-bottom: 1px solid rgba(233,196,106,.4); }
#xpfill { height: 100%; width: 0; background: linear-gradient(90deg, #3fa7ff, #7ad0ff); transition: width .1s; }
#lvl { position: absolute; right: 8px; top: 0; font-size: 12px; line-height: 16px; font-weight: 700; text-shadow: 0 1px 2px #000; }
#hudrow { position: absolute; top: calc(env(safe-area-inset-top) + 20px); left: 8px; right: 54px; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
#slots { display: grid; grid-template-columns: repeat(6, 26px); gap: 3px; }
#slots div { width: 26px; height: 26px; background: rgba(0,0,0,.55); border: 1px solid rgba(233,196,106,.4); border-radius: 5px;
  font-size: 15px; display: flex; align-items: center; justify-content: center; position: relative; }
#slots div img { max-width: 22px; max-height: 22px; }
#slots div i { position: absolute; right: 1px; bottom: -2px; font-size: 9px; font-style: normal; font-weight: 700; text-shadow: 0 0 2px #000, 0 0 2px #000; }
#slots div.evo { border-color: #ff7ad9; }
#timer { font-size: 26px; font-weight: 700; text-shadow: 0 2px 3px #000; letter-spacing: 1px; position: absolute; left: 50%; transform: translateX(-50%); top: 0; }
#stats { display: flex; flex-direction: column; align-items: flex-end; font-size: 14px; text-shadow: 0 1px 2px #000; gap: 2px; }
#pausebtn { pointer-events: auto; position: absolute; top: calc(env(safe-area-inset-top) + 22px); right: 8px; min-width: 0; width: 40px; height: 40px; padding: 0; font-size: 14px; }
#bossbar { position: absolute; top: calc(env(safe-area-inset-top) + 82px); left: 50%; transform: translateX(-50%); width: min(80vw, 520px); text-align: center; }
#bossname { font-size: 15px; color: #ffb3b3; text-shadow: 0 1px 2px #000; margin-bottom: 3px; }
#bosshp { height: 12px; background: rgba(0,0,0,.6); border: 1px solid #ff6b6b; border-radius: 6px; overflow: hidden; }
#bossfill { height: 100%; background: linear-gradient(90deg, #c0304a, #ff6b6b); width: 100%; }
#joy { position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.06); z-index: 6; pointer-events: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px; border-radius: 50%; background: rgba(233,196,106,.55); }
#flash { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(transparent 50%, rgba(220,30,30,.55)); opacity: 0; transition: opacity .25s; z-index: 4; }
#toast { position: fixed; left: 50%; top: 28%; transform: translateX(-50%); font-size: clamp(22px, 6vw, 36px); font-weight: 700; color: var(--gold);
  text-shadow: 0 3px 0 #000, 0 0 20px rgba(0,0,0,.8); pointer-events: none; z-index: 6; opacity: 0; transition: opacity .4s; text-align: center; white-space: nowrap; }
#toast.on { opacity: 1; }
#evolist h4 { margin: 0 0 8px; color: var(--gold); }
#evolist div { font-size: 14px; line-height: 1.8; }
#endinfo div, #pauseinfo div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed rgba(255,255,255,.1); font-size: 15px; }
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .card .pic { width: 64px; height: 64px; font-size: 38px; }
  #timer { font-size: 22px; top: 32px; }
  #slots { grid-template-columns: repeat(6, 22px); }
  #slots div { width: 22px; height: 22px; font-size: 13px; }
}
#fx3d { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 1; }
#hud { z-index: 5; }
.logo.small h1 { font-size: clamp(36px, 10vw, 60px); }
.authbox { max-width: 380px; display: flex; flex-direction: column; gap: 10px; }
.authbox form { display: flex; flex-direction: column; gap: 10px; }
.authbox input { font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 9px; border: 1px solid rgba(233,196,106,.4); background: rgba(0,0,0,.35); color: var(--text); }
.tabs { display: flex; gap: 6px; justify-content: center; }
.tabs button { min-width: 0; flex: 1; padding: 8px 12px; font-size: 15px; background: transparent; border-color: rgba(233,196,106,.3); }
.tabs button.on { background: rgba(233,196,106,.18); border-color: var(--gold); color: var(--gold); }
#aErr { color: #ff8a8a; font-size: 14px; min-height: 1em; }
.foot a { color: var(--muted); }
#lblist { max-width: 460px; }
#lblist div { display: grid; grid-template-columns: 36px 1fr auto auto; gap: 10px; padding: 7px 0; border-bottom: 1px dashed rgba(255,255,255,.1); font-size: 15px; }
#lblist div.me { color: var(--gold); }
#lblist i { font-style: normal; color: var(--muted); font-size: 13px; }
