:root { --red: #ff4757; --blue: #2f86ff; --ink: #1b2340; --mint: #2ec4a6; --cream: #fffaf0; --sun: #ffd23f;
  font-size: clamp(10px, min(2.35vh, 1.55vw) + 3px, 26px); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0f6b63; touch-action: none; user-select: none; -webkit-user-select: none;
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Heiti TC", sans-serif; color: var(--ink); }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font-family: inherit; cursor: pointer; color: inherit; }
.hide { display: none !important; }

#hudBtns { position: fixed; top: max(6px, env(safe-area-inset-top)); right: 6px; display: flex; gap: 6px; z-index: 30; }
.round { width: 2.9rem; height: 2.9rem; min-width: 34px; min-height: 34px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; padding: 0.45rem; box-shadow: 0 3px 0 var(--ink); }
.round svg { width: 100%; height: 100%; fill: var(--ink); stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; }
.round .off { display: none; } .round.muted .on { display: none; } .round.muted .off { display: inline; }
#btnHome { position: fixed; left: 6px; top: max(6px, env(safe-area-inset-top)); }

.panel { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 0.6rem; z-index: 20; }
.panel.show { display: flex; }
.panel.dim { background: rgba(15, 30, 45, .45); }
.card { background: var(--cream); border: 0.25rem solid var(--ink); border-radius: 1.6rem; box-shadow: 0 0.45rem 0 var(--ink), 0 1rem 2rem rgba(0,0,0,.25);
  padding: 1rem 1.3rem; max-height: calc(100vh - 1.2rem); overflow-y: auto; text-align: center; position: relative;
  background-image: linear-gradient(45deg, rgba(46,196,166,.07) 25%, transparent 25%, transparent 75%, rgba(46,196,166,.07) 75%), linear-gradient(45deg, rgba(46,196,166,.07) 25%, transparent 25%, transparent 75%, rgba(46,196,166,.07) 75%);
  background-size: 2rem 2rem; background-position: 0 0, 1rem 1rem; }
h1, h2 { margin: 0; font-weight: 900; }
.mcard { width: min(50rem, 100%); }
.head { display: inline-block; background: var(--sun); border: 0.22rem solid var(--ink); border-radius: 1rem; padding: 0.25rem 1.4rem 0.35rem; transform: rotate(-1.5deg); margin-bottom: 0.6rem; box-shadow: 0 0.25rem 0 var(--ink); }
.head h1 { font-size: 2.5rem; letter-spacing: 0.15em; line-height: 1.1; }
.head .sub { font-size: 1.05rem; font-weight: 800; }
.vs { display: flex; align-items: stretch; justify-content: center; gap: 0.6rem; }
.pl { flex: 1; display: flex; align-items: center; gap: 0.6rem; border: 0.22rem solid var(--ink); border-radius: 1.2rem; padding: 0.5rem 0.7rem; text-align: left; }
.pl.p1 { background: #ffe1e4; } .pl.p2 { background: #dceaff; flex-direction: row-reverse; text-align: right; }
.ava { width: 5.2rem; height: auto; flex: none; filter: drop-shadow(0 0.2rem 0 rgba(0,0,0,.15)); }
.pinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.p2 .pinfo { align-items: flex-end; }
.tag { display: inline-block; align-self: flex-start; color: #fff; font-weight: 900; font-size: 0.85rem; padding: 0.1rem 0.6rem; border-radius: 0.6rem; border: 0.16rem solid var(--ink); }
.p1 .tag { background: var(--red); } .p2 .tag { background: var(--blue); align-self: flex-end; }
.pinfo input { width: 100%; max-width: 10rem; font: inherit; font-weight: 900; font-size: 1.15rem; padding: 0.2rem 0.5rem; border: 0.18rem solid var(--ink); border-radius: 0.6rem; background: #fff; color: var(--ink); user-select: text; -webkit-user-select: text; }
.p2 .pinfo input { text-align: right; }
.pinfo input:disabled { background: #eef1f6; color: #5a6380; }
.keys { display: flex; gap: 0.2rem; flex-wrap: wrap; }
.p2 .keys { justify-content: flex-end; }
.k { display: inline-flex; align-items: center; justify-content: center; min-width: 1.7rem; height: 1.7rem; padding: 0 0.3rem; font-size: 0.85rem; font-weight: 900; background: #fff; border: 0.15rem solid var(--ink); border-bottom-width: 0.3rem; border-radius: 0.4rem; }
.k.wide { min-width: 3.4rem; }
.x { align-self: center; font-weight: 900; font-size: 1.7rem; color: #fff; -webkit-text-stroke: 0.12rem var(--ink); paint-order: stroke; transform: rotate(-8deg); }
.seg { display: inline-flex; border: 0.18rem solid var(--ink); border-radius: 0.8rem; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; font-weight: 900; font-size: 0.95rem; padding: 0.3rem 0.7rem; }
.seg button + button { border-left: 0.15rem solid var(--ink); }
.seg button.sel { background: var(--mint); color: #fff; }
.seg.mini button { font-size: 0.8rem; padding: 0.2rem 0.5rem; }
.actions { display: flex; align-items: center; justify-content: center; gap: 0.7rem; margin-top: 0.7rem; flex-wrap: wrap; }
.big { border: 0.25rem solid var(--ink); background: var(--red); color: #fff; font-weight: 900; font-size: 1.6rem; padding: 0.45rem 2rem 0.55rem; border-radius: 1.1rem;
  box-shadow: 0 0.35rem 0 var(--ink); letter-spacing: 0.08em; text-shadow: 0 0.12rem 0 rgba(0,0,0,.25); }
.big:active { transform: translateY(0.2rem); box-shadow: 0 0.15rem 0 var(--ink); }
.small { border: 0.2rem solid var(--ink); background: #fff; font-weight: 900; font-size: 1rem; padding: 0.35rem 1rem; border-radius: 0.8rem; box-shadow: 0 0.25rem 0 var(--ink); }
.intro { font-size: 0.9rem; line-height: 1.45; margin: 0.7rem auto 0; max-width: 44rem; color: #3b4566; font-weight: 600; }
#record { font-weight: 900; color: var(--ink); }

.pcard { width: min(40rem, 100%); }
.pcard h2 { font-size: 1.8rem; margin-bottom: 0.6rem; }
#duelGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin-bottom: 0.7rem; }
.duelBtn { border: 0.22rem solid var(--ink); border-radius: 1rem; background: #fff; font-weight: 900; font-size: 1.15rem; padding: 0.6rem 0.4rem; display: flex; flex-direction: column; align-items: center; gap: 0.2rem; box-shadow: 0 0.25rem 0 var(--ink); }
.duelBtn:nth-child(odd) { background: #ffe1e4; } .duelBtn:nth-child(even) { background: #dceaff; }
.duelBtn .ic { font-size: 2.2rem; line-height: 1; }

.icard { width: min(42rem, 100%); }
.num { font-weight: 900; font-size: 1rem; color: #5a6380; }
.icard h2 { font-size: 2.2rem; }
.rule { font-size: 1rem; line-height: 1.5; margin: 0.4rem 0 0.6rem; font-weight: 600; text-align: left; }
.ctrl { display: flex; gap: 0.6rem; margin-bottom: 0.7rem; }
.cbox { flex: 1; border: 0.2rem solid var(--ink); border-radius: 1rem; padding: 0.4rem 0.6rem; display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }
.cbox b { font-size: 1.1rem; }
.c1 { background: #ffe1e4; } .c2 { background: #dceaff; }
.kl { display: flex; flex-wrap: wrap; gap: 0.3rem 0.7rem; justify-content: center; }
.kg { display: inline-flex; align-items: center; gap: 0.2rem; } .kg i { font-style: normal; font-weight: 800; font-size: 0.9rem; margin-left: 0.2rem; }
.th { font-size: 0.85rem; font-weight: 700; color: #3b4566; }
.cpu { font-weight: 900; }

.rcard, .fcard { width: min(36rem, 100%); }
.fcard { display: flex; align-items: center; gap: 1rem; width: min(44rem, 100%); }
.fcard img { width: 9rem; flex: none; animation: hop 0.9s ease-in-out infinite alternate; }
@keyframes hop { from { transform: translateY(0) rotate(-3deg); } to { transform: translateY(-0.6rem) rotate(3deg); } }
.fright { flex: 1; min-width: 0; }
.rw { font-size: 2rem; font-weight: 900; }
.w0 { color: var(--red); } .w1 { color: var(--blue); }
.rs { font-size: 2.4rem; font-weight: 900; margin: 0.1rem 0 0.4rem; }
.table { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.7rem; font-size: 0.95rem; }
.tr { display: grid; grid-template-columns: 1fr auto 3.6rem; gap: 0.6rem; align-items: center; background: #fff; border: 0.15rem solid var(--ink); border-radius: 0.6rem; padding: 0.15rem 0.6rem; text-align: left; font-weight: 700; }
.tr .sc { text-align: right; font-weight: 900; }
.btnrow { display: flex; gap: 0.6rem; justify-content: center; align-items: center; flex-wrap: wrap; }

/* short frames (store page window, landscape phones) */
@media (max-height: 560px) {
  .card { padding: 0.6rem 1rem; }
  .head { margin-bottom: 0.4rem; } .head h1 { font-size: 2rem; }
  .ava { width: 4.2rem; }
  .intro { margin-top: 0.4rem; font-size: 0.82rem; }
  .actions { margin-top: 0.5rem; }
  .big { font-size: 1.4rem; padding: 0.35rem 1.6rem 0.45rem; }
  .rule { font-size: 0.92rem; line-height: 1.4; }
  .fcard img { width: 7rem; }
}
@media (max-height: 400px) {
  .head { display: inline-flex; align-items: baseline; gap: 0.8rem; padding: 0.15rem 1rem; }
  .head h1 { font-size: 1.7rem; } .head .sub { font-size: 0.9rem; }
  .ava { width: 3.4rem; }
  .intro { display: none; }
  .table { font-size: 0.85rem; }
}
/* portrait phones */
@media (max-aspect-ratio: 4/5) {
  :root { font-size: clamp(11px, 3.6vw, 18px); }
  .vs { flex-direction: column; }
  .x { font-size: 1.4rem; }
  .ava { width: 4.6rem; }
  .ctrl { flex-direction: column; }
  .fcard { flex-direction: column; }
  .fcard img { width: 7rem; }
  #duelGrid { grid-template-columns: repeat(2, 1fr); }
}
@media (hover: none) and (pointer: coarse) { .pinfo .keys { display: none; } }
