:root {
  --bg: #0b0d1c; --panel: #151935; --line: #2b3270; --ink: #eef0ff; --dim: #8d94c7;
  --gold: #ffcf3a; --red: #ff3d4f; --blue: #3d8bff;
  --font: "Arial Black", Impact, "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif; }
body { background:
  repeating-linear-gradient(115deg, rgba(255,255,255,.025) 0 2px, transparent 2px 26px),
  radial-gradient(1200px 600px at 50% -10%, #2a1d5c 0%, transparent 60%), var(--bg); }
#app { min-height: 100%; }
.screen { display: none; }
.screen.on { display: block; }

/* ---------- 共用外框 ---------- */
#shell { max-width: 980px; margin: 0 auto; padding: 18px 16px 28px; }
#shell.off { display: none; }
#logo { text-align: center; padding: 6px 0 14px; }
.logo-sub { font: 700 12px/1 var(--font); letter-spacing: .42em; color: var(--gold); }
#logo h1 { margin: 6px 0 4px; font: italic 900 clamp(44px, 9vw, 84px)/1 var(--font); letter-spacing: .06em;
  background: linear-gradient(180deg, #fff6c9 0%, #ffcf3a 45%, #ff7a1a 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(4px 5px 0 #b3122a) drop-shadow(0 0 22px rgba(255,90,60,.35)); transform: skewX(-6deg); }
.logo-bar { height: 22px; display: flex; justify-content: center; align-items: center; gap: 10px;
  border-top: 3px solid var(--red); border-bottom: 1px solid var(--line); margin: 10px auto 0; max-width: 520px; }
#conn { font-size: 12px; letter-spacing: .15em; }
#conn.on { color: #58e08a; } #conn.off { color: var(--red); }

.panel { background: linear-gradient(180deg, #1a1f45, var(--panel)); border: 2px solid var(--line); border-left: 6px solid var(--gold);
  padding: 14px 16px; margin-top: 14px; box-shadow: 0 6px 0 rgba(0,0,0,.35); }
.panel-h { font: 900 15px/1 var(--font); letter-spacing: .2em; color: var(--gold); margin-bottom: 12px; }
.panel-h small { font: 400 12px/1 system-ui; letter-spacing: .05em; color: var(--dim); margin-left: 8px; }
.row { display: flex; gap: 12px; }
.txt { flex: 1; min-width: 0; width: 100%; background: #0b0e24; border: 2px solid var(--line); color: var(--ink); padding: 0 14px; font-size: 18px; height: 54px; outline: none; font-family: inherit; border-radius: 0; }
.txt:focus { border-color: var(--gold); }
.txt.pin { font: 900 24px/1 var(--font); letter-spacing: .4em; text-align: center; }
.txt.pin::placeholder { font: 400 15px/1 system-ui; letter-spacing: .05em; color: var(--dim); }
select.txt { height: 48px; font-size: 16px; } .opt .txt.pin { height: 48px; }
.opts { display: grid; grid-template-columns: 1fr 1.2fr 1.4fr; gap: 14px; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.opt { display: grid; gap: 6px; align-content: start; font-size: 13px; color: #c9cdf0; }
.opt small { color: var(--dim); } .opt b { color: var(--gold); margin-left: 6px; font-size: 15px; }
.opt input[type=range] { width: 100%; height: 30px; margin: 9px 0 0; accent-color: var(--gold); }
.opt .scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); } .opt .scale i { font-style: normal; }
.rule { margin-left: 12px; font-size: 13px; color: #c9cdf0; }
.room .tag { font-size: 12px; color: var(--dim); white-space: nowrap; }
.room .who { min-width: 0; }
#pwBox { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(5,6,18,.75); z-index: 15; }
#pwBox.on { display: flex; }
#pwBox .end-box { width: min(340px, 90vw); }
.pw-h { font: 900 18px/1 var(--font); letter-spacing: .15em; color: var(--gold); }
#pwBox .row { justify-content: center; align-items: center; gap: 18px; }

.btn { font: 900 16px/1 var(--font); letter-spacing: .12em; color: #1a0b00; background: linear-gradient(180deg, #ffe27a, #ffb21a);
  border: 0; padding: 12px 20px; cursor: pointer; box-shadow: 0 5px 0 #a35a00; transform: skewX(-8deg); transition: transform .06s, box-shadow .06s; }
.btn:active { transform: skewX(-8deg) translateY(4px); box-shadow: 0 1px 0 #a35a00; }
.btn.big { font-size: 22px; height: 54px; padding: 0 30px; }
.btn.wide { display: block; width: min(420px, 100%); margin: 16px auto 0; }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid var(--line); box-shadow: none; font-size: 13px; padding: 8px 14px; }
.btn.on { background: linear-gradient(180deg, #7dffae, #1fc866); box-shadow: 0 5px 0 #0b7a3a; }
.btn:disabled { filter: grayscale(1) brightness(.6); cursor: default; }

.rooms { display: grid; gap: 8px; min-height: 60px; }
.rooms .empty { color: var(--dim); padding: 16px 4px; font-size: 14px; }
.room { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: #0e1230; border: 2px solid var(--line); color: var(--ink);
  padding: 12px 14px; font-size: 16px; cursor: pointer; font-family: inherit; }
.room:hover:not(:disabled) { border-color: var(--gold); background: #171c48; }
.room:disabled { opacity: .45; cursor: default; }
.room .no { font: 900 22px/1 var(--font); color: var(--gold); letter-spacing: .08em; }
.room .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room .cnt { color: var(--dim); font-size: 13px; }
.room .go { font: 900 14px/1 var(--font); color: #1a0b00; background: var(--gold); padding: 7px 12px; transform: skewX(-8deg); }

.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; font-size: 13.5px; line-height: 1.9; color: #c9cdf0; }
.help-grid b { color: var(--ink); letter-spacing: .15em; }
kbd { display: inline-block; min-width: 22px; text-align: center; padding: 0 5px; margin: 0 2px; border: 1px solid #5a63b0; border-bottom-width: 3px; background: #0b0e24; font: 700 12px/18px system-ui; color: var(--ink); }
.k { display: inline-block; width: 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 50%; margin: 0 2px; font-size: 12px; font-weight: 700; color: #fff; }
.k.kp { background: #e23b3b; } .k.kk { background: #2f7de0; } .k.kg { background: #2fa85a; }
.lan { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 13px; color: var(--dim); }
.lan b { color: var(--gold); font-size: 15px; user-select: all; }

/* ---------- 選角 ---------- */
.selbar { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.roomid { font-size: 14px; color: var(--dim); white-space: nowrap; }
.roomid b { font: 900 26px/1 var(--font); color: var(--gold); letter-spacing: .1em; margin-left: 6px; }
.selmsg { flex: 1; text-align: center; font-size: 14px; color: #c9cdf0; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 14px; }
.card { position: relative; background: linear-gradient(180deg, #1c2150, #10132c); border: 3px solid var(--line); color: var(--ink); padding: 0 0 12px;
  cursor: pointer; font-family: inherit; text-align: center; overflow: hidden; transition: transform .08s, border-color .08s; }
.card canvas { display: block; width: 100%; aspect-ratio: 11/12; }
.card .style { font: 900 24px/1.1 var(--font); letter-spacing: .1em; margin-top: 8px; }
.card .en { font: 700 10px/1 var(--font); letter-spacing: .25em; color: var(--dim); margin-top: 5px; }
.card .nm { font-size: 14px; margin-top: 8px; }
.card .desc { font-size: 12px; color: var(--dim); margin-top: 3px; }
.card .stats { margin: 8px 12px 0; font-size: 11px; color: var(--dim); display: grid; gap: 3px; }
.card .st { display: flex; align-items: center; gap: 6px; }
.card .st i { flex: 1; height: 6px; background: #0a0c20; position: relative; }
.card .st i::after { content: ""; position: absolute; inset: 0; width: var(--v); background: var(--acc); }
.card .bd { position: absolute; top: 8px; font: 900 15px/1 var(--font); padding: 5px 9px; transform: skewX(-8deg); display: none; z-index: 2; }
.card .bd.b0 { left: 8px; background: var(--red); color: #fff; }
.card .bd.b1 { right: 8px; background: var(--blue); color: #fff; }
.card.s0 .b0, .card.s1 .b1 { display: block; }
.card.mine { border-color: var(--gold); transform: translateY(-4px); box-shadow: 0 0 0 2px rgba(255,207,58,.25), 0 10px 24px rgba(0,0,0,.5); }
.vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 16px; }
.side { background: #0e1230; border: 2px solid var(--line); padding: 10px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-height: 52px; font-size: 14px; }
.side.p1 { border-left: 6px solid var(--red); } .side.p2 { border-right: 6px solid var(--blue); justify-content: flex-end; }
.side .tag { font: 900 16px/1 var(--font); } .side.p1 .tag { color: var(--red); } .side.p2 .tag { color: var(--blue); }
.side .pick { font-weight: 700; color: var(--gold); }
.side .rd { font: 900 12px/1 var(--font); color: #58e08a; letter-spacing: .1em; }
.side.me { background: #171c48; }
.vs-mid { font: italic 900 30px/1 var(--font); color: var(--gold); text-shadow: 3px 3px 0 #b3122a; }

/* ---------- 對戰 ---------- */
#game { position: fixed; inset: 0; background: #000; touch-action: none; user-select: none; -webkit-user-select: none; }
#game.on { display: flex; align-items: center; justify-content: center; }
#view { position: relative; width: min(100vw, calc(100dvh * 16 / 9)); aspect-ratio: 16/9; background: #111; }
#view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.gbar { position: absolute; bottom: max(6px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 12px; z-index: 5; opacity: .62; white-space: nowrap; }
.gbar .btn { font-size: 11px; padding: 5px 10px; background: rgba(8,10,26,.55); }
.stagebar { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.stage-h { font: 900 14px/1 var(--font); letter-spacing: .2em; color: var(--gold); white-space: nowrap; }
.stages { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; flex: 1; }
.chip { background: #0e1230; border: 2px solid var(--line); color: var(--ink); padding: 10px 6px; font: 700 14px/1.2 inherit; font-family: inherit; cursor: pointer; }
.chip.on { border-color: var(--gold); background: #2a2350; color: var(--gold); }
#touch { display: none; }
body.touch #touch { display: block; }
#stick { position: absolute; left: max(18px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom)); width: 150px; height: 150px; border-radius: 50%;
  background: rgba(255,255,255,.10); border: 2px solid rgba(255,255,255,.35); touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px; border-radius: 50%; background: rgba(255,255,255,.55); pointer-events: none; }
#pads { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); width: 210px; height: 160px; }
.pad { position: absolute; width: 76px; height: 76px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font: 900 24px/1 var(--font); color: #fff;
  border: 3px solid rgba(255,255,255,.7); opacity: .72; touch-action: none; }
.pad.g { left: 0; bottom: 0; background: #2fa85a; }
.pad.p { left: 68px; bottom: 78px; background: #e23b3b; }
.pad.k { right: 0; bottom: 14px; background: #2f7de0; }
.pad.dn { opacity: 1; transform: scale(.92); filter: brightness(1.3); }
@media (orientation: portrait) {
  #game.on { align-items: flex-start; padding-top: max(34px, env(safe-area-inset-top)); }
  #stick { bottom: 14vh; } #pads { bottom: 14vh; }
}
#end { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(5,6,18,.6); z-index: 6; }
#end.on { display: flex; }
.end-box { text-align: center; padding: 26px 40px; background: linear-gradient(180deg, #1a1f45, #10132c); border: 3px solid var(--gold); display: grid; gap: 14px; justify-items: center; }
#endTitle { font: italic 900 54px/1 var(--font); color: var(--gold); text-shadow: 4px 4px 0 #b3122a; letter-spacing: .1em; }
#endSub { color: #c9cdf0; font-size: 15px; }

#toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: var(--red); color: #fff; padding: 10px 18px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
#toast.on { opacity: 1; }

@media (max-width: 720px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .help-grid { grid-template-columns: 1fr; gap: 8px; }
  .opts { grid-template-columns: 1fr; }
  .stages { grid-template-columns: repeat(2, 1fr); }
  .room { flex-wrap: wrap; gap: 6px 12px; }
  .room .tag { order: 5; width: 100%; }
  .rule { display: block; margin: 4px 0 0; }
  .card .style { font-size: 20px; }
  .btn.big { padding: 0 18px; font-size: 19px; }
  .card .desc, .card .stats { display: none; }
}

.linkbtn { background: none; border: 0; color: var(--dim); font: 12px/1 inherit; font-family: inherit; letter-spacing: .1em; cursor: pointer; padding: 4px 6px; }
.linkbtn:hover { color: var(--gold); }
.btnMusic.mute { opacity: .55; text-decoration: line-through; }

/* 鍵盤選取中的項目 */
.btn.kfocus { outline: 3px solid #fff; outline-offset: 3px; box-shadow: 0 5px 0 #a35a00, 0 0 22px rgba(255,207,58,.85); }
.btn.ghost.kfocus { outline: 3px solid var(--gold); color: var(--gold); box-shadow: 0 0 18px rgba(255,207,58,.6); }
.room.kfocus { border-color: var(--gold); background: #1f2560; box-shadow: 0 0 0 2px rgba(255,207,58,.35), 0 0 18px rgba(255,207,58,.3); }
.room.kfocus::before { content: "▶"; color: var(--gold); font-size: 14px; margin-right: -4px; }

#verwarn { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 50; background: #b3122a; color: #fff; padding: 14px 20px; font-size: 16px; line-height: 1.6; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.5); max-width: 92vw; }
#verwarn b { font-size: 19px; }
