/* Pick & Roll web shell - "Arena Broadcast" (DESIGN_V3 12). One base token: Arena Navy #0B1426,
   the same colour Godot clears to, so the reveal never flashes. Animations are CSS only
   (transform/opacity), so they keep running while the single-threaded engine is busy. */
:root {
  --navy: #0B1426;
  --court: #13203A;
  --court-2: #1A2A4A;
  --wood: #C8894A;
  --wood-hi: #E8BE86;
  --white: #F4F1EA;
  --red: #E03A3E;
  --amber: #FFB23F;
  --steel: #8A94A6;
  --ok: #5FD08A;
  --rating: #2E9B57;
  --line: rgba(244, 241, 234, .12);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", "Hiragino Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --gutter: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; background: var(--navy); color: var(--white); font-family: var(--font); }
html { overflow: hidden; }
/* Godot writes position:absolute and a pixel size on the canvas; during a rotation that size can be stale for a
   frame. A fixed, clipped body keeps it from widening the mobile layout viewport (zoom-out). */
body { position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--wood-hi); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- canvas (hidden until ready + tap) */
#canvas {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block; border: 0; outline: none;
  background: var(--navy); opacity: 0; pointer-events: none;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  transition: opacity .3s ease;
}
/* iPad 1106: Godot writes an inline px size from innerWidth/innerHeight; the canvas box always stays the full window. */
#canvas { width: 100% !important; height: 100% !important; }
#canvas.revealed { opacity: 1; pointer-events: auto; }
#hd-safe {
  position: fixed; inset: 0; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
/* iPad mini 1108: an iOS home-screen app can lay out in a box one status bar shorter than the screen while it draws
   from the screen top, so a strip of the page background stays under the canvas. shell.js (standaloneFill) sets
   html.hd-fill and --hd-fill-h (the measured 100lvh) only then; the root, the body, the canvas and the full-window
   layers reach the real bottom edge. #hd-safe keeps the plain inset-0 box: the shell measures the short box on it. */
html.hd-fill { height: var(--hd-fill-h, 100%); }
html.hd-fill body { bottom: auto; height: var(--hd-fill-h, 100%); }
html.hd-fill #canvas { bottom: auto; height: var(--hd-fill-h, 100%) !important; }
html.hd-fill .shell, html.hd-fill .rotate, html.hd-fill #hd-touchdebug { bottom: auto; height: var(--hd-fill-h, 100%); }
html.hd-fill dialog::backdrop { bottom: auto; height: var(--hd-fill-h, 100%); }

/* ---------------------------------------------------------------- overlay shell */
.shell {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter-r) max(10px, env(safe-area-inset-bottom)) var(--gutter);
  overflow: hidden auto; overscroll-behavior: contain;
  background:
    radial-gradient(120% 90% at 82% 58%, rgba(26, 42, 74, .95) 0%, rgba(11, 20, 38, 0) 60%),
    repeating-linear-gradient(97deg, rgba(200, 137, 74, .045) 0 26px, rgba(200, 137, 74, .018) 26px 52px),
    var(--navy);
  -webkit-user-select: none; user-select: none;
  transition: opacity .3s ease, visibility 0s linear 0s;
}
html[data-state="E"] .shell { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .3s ease, visibility 0s linear .3s; }

/* CSS-drawn arena art (D30: no concept art shipped) */
.art { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.art-court {
  position: absolute; right: -6vmin; top: 50%; width: 74vmin; height: 74vmin; transform: translateY(-50%) perspective(900px) rotateX(48deg) rotateZ(-14deg);
  border: 2px solid rgba(232, 190, 134, .28); border-radius: 4px;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 15%, rgba(232, 190, 134, .32) 15% calc(15% + 2px), transparent calc(15% + 2px)),
    linear-gradient(90deg, transparent calc(50% - 1px), rgba(232, 190, 134, .3) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    repeating-linear-gradient(90deg, rgba(200, 137, 74, .16) 0 18px, rgba(200, 137, 74, .07) 18px 36px);
  box-shadow: 0 0 120px rgba(255, 178, 63, .08);
}
.art-court::before, .art-court::after {
  content: ""; position: absolute; top: 31%; width: 19%; height: 38%; border: 2px solid rgba(232, 190, 134, .3);
  background: rgba(224, 58, 62, .12);
}
.art-court::before { left: -2px; }
.art-court::after { right: -2px; }
.art-stripe {
  position: absolute; left: -10%; right: -10%; bottom: 18%; height: 34px; transform: rotate(-4deg);
  background: linear-gradient(90deg, rgba(224, 58, 62, 0), rgba(224, 58, 62, .45) 30%, rgba(224, 58, 62, .45) 70%, rgba(224, 58, 62, 0));
}

.shell > * { position: relative; z-index: 1; }

/* in-app browser banner */
.inapp {
  display: flex; align-items: center; gap: 10px; margin: 0 0 8px; padding: 8px 10px; font-size: 13px; line-height: 1.5;
  background: rgba(255, 178, 63, .12); border-left: 4px solid var(--amber);
}
.inapp p { margin: 0; flex: 1; }
.inapp button { border: 0; background: var(--amber); color: var(--navy); font-weight: 800; padding: 6px 10px; min-height: 36px; }
.inapp .x { background: transparent; color: var(--white); font-size: 18px; min-width: 36px; }

/* header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.wordmark { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; line-height: 1; }
.wm-en { font-size: clamp(24px, 3.4vw, 40px); font-weight: 900; font-style: italic; letter-spacing: .02em; font-stretch: condensed; }
.wm-zh { font-size: clamp(15px, 1.7vw, 20px); font-weight: 800; color: var(--amber); letter-spacing: .12em; }
.wm-sub { flex-basis: 100%; font-size: 11px; letter-spacing: .32em; color: var(--steel); text-transform: uppercase; margin-top: 4px; }
.toplinks a, .footlinks a {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 2px; color: var(--white);
  font-size: 13px; text-decoration: none; border-bottom: 1px solid rgba(244, 241, 234, .35);
}
.toplinks a:focus-visible, .footlinks a:focus-visible, .btn:focus-visible, .enter:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }

/* main column */
.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; max-width: 640px; padding: 18px 0 12px; }
.pregame { display: flex; align-items: center; gap: 10px; }
.pg-tag { font-size: 12px; font-weight: 900; font-style: italic; letter-spacing: .2em; padding: 3px 10px; background: var(--red); transform: skewX(-14deg); }
.pg-hatch { flex: 1; height: 10px; background: repeating-linear-gradient(-60deg, rgba(244, 241, 234, .22) 0 2px, transparent 2px 9px); }

.progress { display: grid; gap: 10px; }
.row {
  display: grid; grid-template-columns: 28px 76px minmax(80px, 1fr) minmax(108px, auto); grid-template-rows: auto auto;
  align-items: center; column-gap: 10px; row-gap: 2px; font-size: 14px;
}
.row .num { font-weight: 900; font-style: italic; color: var(--steel); font-size: 15px; }
.row .label { font-weight: 800; letter-spacing: .06em; }
.row .val { font-variant-numeric: tabular-nums; text-align: right; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { grid-column: 3 / 5; font-size: 12px; color: var(--steel); font-variant-numeric: tabular-nums; min-height: 1.2em; }
.row[data-status="done"] .num { color: var(--ok); }
.row[data-status="active"] .num { color: var(--amber); }
.track, .total-track { position: relative; height: 12px; overflow: hidden; background: rgba(244, 241, 234, .1); transform: skewX(-18deg); }
.track .fill, .total-track .fill {
  position: absolute; inset: 0; background: linear-gradient(90deg, var(--wood), var(--amber)); transform-origin: 0 50%;
  transform: scaleX(0); transition: transform .25s linear;
}
.row[data-status="done"] .track .fill { background: linear-gradient(90deg, #3f9b67, var(--ok)); transform: scaleX(1); }
.track.sweep .fill { transform: translateX(-100%) scaleX(1); transition: none; background: linear-gradient(90deg, transparent, var(--amber), transparent); }
.row[data-status="active"] .track.sweep .fill { animation: hd-sweep 1.15s linear infinite; }
.row[data-status="done"] .track.sweep .fill { animation: none; transform: none; background: linear-gradient(90deg, #3f9b67, var(--ok)); }
@keyframes hd-sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.total { display: grid; grid-template-columns: 28px 76px 1fr auto; align-items: center; column-gap: 10px; margin-top: 4px; }
.total-label { grid-column: 1 / 3; font-size: 13px; color: var(--steel); letter-spacing: .1em; }
.total-pct { grid-column: 4; grid-row: 1; font-size: 26px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; text-align: right; }
.total-track { grid-column: 3; grid-row: 1; height: 16px; }
.total .note { grid-column: 3 / 5; font-size: 12px; color: var(--steel); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 22px; border: 0;
  font-weight: 800; letter-spacing: .06em; transform: skewX(-12deg);
}
.btn > * { transform: skewX(12deg); }
.btn.primary { background: var(--amber); color: var(--navy); }
.btn.ghost { background: transparent; color: var(--white); box-shadow: inset 0 0 0 2px rgba(244, 241, 234, .45); }
.btn:disabled { opacity: .45; cursor: default; }
.gate, .gate-note { display: none; }
html[data-gate="savedata"] .gate { display: inline-flex; justify-self: start; }
html[data-gate="savedata"] .gate-note { display: block; margin: 0; font-size: 12px; color: var(--steel); }

/* D: the 「進入球場」 card */
.ready { display: none; flex-direction: column; align-items: flex-start; gap: 8px; }
html[data-state="D"] .ready { display: flex; animation: hd-rise .35s ease-out both; }
@keyframes hd-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.enter {
  position: relative; display: inline-flex; align-items: center; gap: 22px; min-height: 64px; min-width: min(420px, 100%);
  padding: 0 30px; border: 0; background: var(--amber); color: var(--navy); transform: skewX(-12deg);
  box-shadow: 0 10px 40px rgba(255, 178, 63, .25);
}
.enter > * { transform: skewX(12deg); }
.enter::after { content: ""; position: absolute; top: 8px; bottom: 8px; right: 64px; border-left: 2px dashed rgba(11, 20, 38, .4); }
.enter-zh { font-size: 24px; font-weight: 900; letter-spacing: .14em; }
.enter-en { font-size: 14px; font-weight: 900; font-style: italic; letter-spacing: .2em; }
.enter-arrow { margin-left: auto; font-size: 34px; font-weight: 900; line-height: 1; }
.enter:hover { background: #FFC266; }
.enter:active { transform: skewX(-12deg) scale(.98); }
.enter-hint { margin: 0; font-size: 12px; color: var(--steel); }

/* F: errors */
.error { display: none; padding: 16px 18px; background: rgba(224, 58, 62, .12); border-left: 4px solid var(--red); }
html[data-state="F"] .error { display: block; }
html[data-state="F"] .progress, html[data-state="F"] .ready { display: none; }
.error h2 { margin: 0 0 6px; font-size: 20px; }
.error p { margin: 0 0 12px; font-size: 14px; line-height: 1.7; }
.error .actions { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
.error .code { margin: 0; font-size: 11px; color: var(--steel); word-break: break-all; }

/* tips and notices */
.tip { display: flex; gap: 10px; align-items: baseline; padding: 10px 12px; background: rgba(19, 32, 58, .82); border-left: 4px solid var(--wood); font-size: 14px; line-height: 1.6; }
.tip-tag { flex: none; font-size: 12px; font-weight: 800; color: var(--wood-hi); letter-spacing: .1em; }
.notice { margin: 0; padding: 8px 12px; font-size: 13px; background: rgba(255, 178, 63, .12); border-left: 4px solid var(--amber); }

/* footer: disclaimer, rating badge + warnings, legal links, studio credit */
.foot {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "disc links" "rating studio"; gap: 8px 18px; align-items: center;
  padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--steel);
}
.disclaimer { grid-area: disc; margin: 0; color: var(--white); opacity: .85; }
.rating { grid-area: rating; display: flex; align-items: center; gap: 10px; }
.rating-badge {
  flex: none; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 10px; background: var(--rating);
  color: #fff; font-size: 13px; font-weight: 900; letter-spacing: 0; line-height: 1; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55);
}
img.rating-mark { flex: none; width: 48px; height: 48px; object-fit: contain; }
.warnings { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 0 12px; line-height: 1.6; }
.footlinks { grid-area: links; display: flex; gap: 14px; justify-self: end; }
.footlinks a { font-size: 12px; color: var(--steel); }
.studio { grid-area: studio; justify-self: end; margin: 0; display: flex; align-items: center; gap: 8px; }
.studio-text { font-weight: 800; color: var(--white); letter-spacing: .08em; }
img.studio-mark { height: 26px; width: auto; max-width: 104px; object-fit: contain; display: block; }

/* G: portrait overlay (after E only) */
.rotate {
  position: fixed; inset: 0; z-index: 30; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: max(20px, env(safe-area-inset-top)) 24px max(20px, env(safe-area-inset-bottom)); text-align: center; background: var(--navy);
}
.rotate p { margin: 0; font-size: 14px; color: var(--steel); line-height: 1.6; }
.rotate .rotate-title { font-size: 20px; font-weight: 900; color: var(--white); }
.rotate-wordmark { font-size: 18px; font-weight: 900; font-style: italic; }
.phone { width: 54px; height: 92px; margin: 18px 0 10px; border: 4px solid var(--white); border-radius: 12px; position: relative; animation: hd-turn 2.4s ease-in-out infinite; }
.phone::after { content: ""; position: absolute; left: 50%; bottom: 6px; width: 14px; height: 4px; margin-left: -7px; border-radius: 2px; background: var(--white); }
@keyframes hd-turn { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
.rotate-status { margin-top: 8px !important; padding: 10px 16px; color: var(--white) !important; background: var(--court); border-left: 4px solid var(--amber); font-variant-numeric: tabular-nums; }
.rotate-status:empty { display: none; }
.rotate .rotate-tip { max-width: 340px; font-size: 13px; }
.rotate-foot .studio-text { color: var(--white); }
.rotate-foot img.studio-mark { display: inline-block; height: 18px; vertical-align: middle; }
.rotate-foot { display: flex; align-items: center; gap: 10px; margin-top: 18px; font-size: 12px; color: var(--steel); text-align: left; max-width: 320px; }
@media (orientation: portrait) and (max-width: 599px), (orientation: portrait) and (pointer: coarse) {
  html[data-state="E"] .rotate { display: flex; }
}

/* dialogs: text input, install guides, legal overlay */
dialog { color: var(--white); background: var(--court); border: 0; padding: 0; box-shadow: 0 20px 80px rgba(0, 0, 0, .6); }
dialog::backdrop { background: rgba(5, 10, 20, .72); }
.hd-text { position: fixed; top: 48px; left: 0; right: 0; margin: 0 auto; width: min(520px, calc(100% - 32px)); overflow: auto; }
.hd-text form { padding: 0 0 16px; border-top: 6px solid var(--amber); }
.hd-text .head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.hd-text h2 { margin: 0; font-size: 19px; font-weight: 900; letter-spacing: .04em; }
.hd-text .counter { font-size: 13px; color: var(--steel); font-variant-numeric: tabular-nums; }
.hd-text .hint { margin: 6px 18px 12px; font-size: 13px; color: var(--steel); line-height: 1.6; }
/* the input row: the field plus the optional extra button (隨機) inline, so the dialog is no taller (P 844x390) */
.hd-text .field { display: flex; gap: 10px; margin: 0 18px; }
.hd-text input {
  display: block; flex: 1 1 auto; min-width: 0; width: auto; margin: 0; padding: 12px 14px; font: inherit; font-size: 20px; font-weight: 700;
  color: var(--navy); background: var(--white); border: 0; border-bottom: 4px solid var(--wood); border-radius: 0; outline: none;
  -webkit-user-select: text; user-select: text;
}
.hd-text input:focus { border-bottom-color: var(--amber); }
.hd-text .extra { flex: none; padding: 0 16px; white-space: nowrap; }
.hd-text .msg { min-height: 1.6em; margin: 8px 18px 4px; font-size: 13px; line-height: 1.6; color: var(--steel); }
.hd-text .msg[data-tone="error"] { color: #FF8A8D; }
.hd-text .msg[data-tone="ok"] { color: var(--ok); }
.hd-text .actions { display: flex; justify-content: flex-end; gap: 12px; padding: 6px 18px 0; }
.hd-text .actions .link {
  display: inline-flex; align-items: center; min-height: 44px; margin-right: auto; padding: 0 2px;
  font-size: 13px; color: var(--steel); text-decoration: underline; text-underline-offset: 3px; white-space: nowrap;
}
.hd-text .actions .link:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
.guide { width: min(480px, calc(100% - 32px)); padding: 18px 20px; border-top: 6px solid var(--amber); }
.guide h2 { margin: 0 0 10px; font-size: 19px; }
.guide ol { margin: 0 0 10px; padding-left: 1.4em; line-height: 1.9; font-size: 15px; }
.guide p { margin: 0 0 12px; font-size: 13px; color: var(--steel); line-height: 1.6; }
.guide .actions { display: flex; justify-content: flex-end; gap: 12px; }
.legal-overlay { width: min(900px, 100%); height: min(100%, 100dvh); max-width: 100%; max-height: 100%; margin: auto; display: none; flex-direction: column; }
.legal-overlay[open] { display: flex; }
.legal-overlay .bar { display: flex; justify-content: flex-end; padding: max(8px, env(safe-area-inset-top)) 12px 8px; background: var(--navy); }
#hd-legal-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }

/* ---------------------------------------------------------------- phones held sideways (P profile) */
@media (max-height: 559px) {
  .shell { padding-top: max(8px, env(safe-area-inset-top)); }
  .wm-en { font-size: 22px; }
  .wm-sub { display: none; }
  .stage { gap: 8px; padding: 8px 0 6px; max-width: 600px; }
  .pregame { display: none; }
  .row { font-size: 13px; grid-template-columns: 22px 66px minmax(60px, 1fr) minmax(96px, auto); }
  .row .sub { font-size: 11px; }
  .progress { gap: 6px; }
  .total-pct { font-size: 20px; }
  .tip { font-size: 13px; padding: 6px 10px; }
  html[data-state="D"] .progress .row .sub, html[data-state="D"] .progress .total .note { display: none; }
  html[data-state="D"] .progress { grid-template-columns: repeat(3, auto); justify-content: start; column-gap: 18px; }
  html[data-state="D"] .progress .row { grid-template-columns: auto auto auto; }
  html[data-state="D"] .progress .row .track, html[data-state="D"] .total { display: none; }
  .enter { min-height: 56px; }
  .foot { gap: 4px 14px; padding-top: 6px; font-size: 11px; }
  .warnings { gap: 0 10px; }
  .art-court { width: 60vmax; height: 60vmax; right: -14vmax; opacity: .7; }
}
/* narrow screens (portrait loading is allowed; G only appears after entering) */
@media (max-width: 599px) {
  .stage { max-width: none; }
  .row { grid-template-columns: 22px 64px 1fr; }
  .row .val { grid-column: 2 / 4; grid-row: 2; text-align: left; }
  .row .sub { grid-column: 2 / 4; grid-row: 3; }
  .total { grid-template-columns: 1fr auto; }
  .total-label { grid-column: 1; }
  .total-track { grid-column: 1 / 3; grid-row: 2; }
  .total-pct { grid-column: 2; grid-row: 1; }
  .total .note { grid-column: 1 / 3; }
  .enter { min-width: 100%; }
  .foot { grid-template-columns: 1fr; grid-template-areas: "disc" "rating" "links" "studio"; }
  .footlinks, .studio { justify-self: start; }
  .art-court { opacity: .35; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .row[data-status="active"] .track.sweep .fill { transform: none; opacity: .5; }
}

/* ---------------------------------------------------------------- touch diagnostics (dev flag ?hd-touchdebug=1 or a
   three-finger 1.2 s hold; 補充規格 §4.2). Never takes input: the game canvas keeps every touch. */
#hd-touchdebug { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
#hd-touchdebug .hd-td-panel {
  position: absolute; left: max(8px, env(safe-area-inset-left)); top: max(56px, calc(env(safe-area-inset-top) + 48px));
  max-width: min(46vw, 460px); margin: 0; padding: 6px 8px; white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere;
  font: 11px/1.35 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; color: var(--white);
  background: rgba(7, 13, 26, .84); border-bottom: 2px solid #FF4FD8;
}
#hd-touchdebug .hd-td-cross { position: absolute; left: 0; top: 0; width: 0; height: 0; }
#hd-touchdebug .hd-td-cross::before, #hd-touchdebug .hd-td-cross::after { content: ""; position: absolute; background: #FF4FD8; }
#hd-touchdebug .hd-td-cross::before { left: -16px; top: -1px; width: 32px; height: 2px; }
#hd-touchdebug .hd-td-cross::after { left: -1px; top: -16px; width: 2px; height: 32px; }
