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

.panel { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: radial-gradient(120% 80% at 50% 0%, rgba(30,24,80,.75), rgba(5,7,20,.94) 70%); }
.panel[hidden], #hud[hidden], #count[hidden] { display: none; }

.brand { font-size: 44px; font-weight: 900; letter-spacing: 2px; line-height: 1.05; text-align: center;
  text-shadow: 0 0 24px rgba(255,60,90,.45); }
.brand span { display: block; font-size: 88px; font-style: italic; color: #FF3B5C; letter-spacing: -2px; }

form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; }
input, select { width: 100%; height: 58px; border-radius: 14px; border: 2px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.07); color: #fff; font-size: 20px; padding: 0 18px; font-weight: 700; outline: none; }
input:focus, select:focus { border-color: #FF3B5C; }
select option { color: #000; }
#code { text-align: center; letter-spacing: 12px; font-size: 26px; }
.go { height: 62px; width: min(340px, 100%); border: 0; border-radius: 16px; font-size: 22px; font-weight: 900; letter-spacing: 4px;
  color: #fff; background: linear-gradient(180deg, #FF4D6A, #D81E3E); box-shadow: 0 10px 30px rgba(255,40,80,.35); }
.go:active { transform: translateY(2px) scale(.99); }
.go:disabled { opacity: .5; }
.err { min-height: 22px; color: #FF8A9B; text-align: center; font-weight: 700; }

#preview { width: min(360px, 92vw); height: min(260px, 36vh); }
.pick { display: flex; align-items: center; gap: 18px; }
.pick h2 { width: 150px; text-align: center; font-size: 30px; font-weight: 900; letter-spacing: 3px; }
.arrow { width: 56px; height: 56px; border-radius: 50%; border: 2px solid rgba(255,255,255,.18); background: rgba(255,255,255,.06);
  color: #fff; font-size: 34px; line-height: 1; }
.swatches { display: flex; gap: 12px; }
.swatches button { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.25); }

.big { font-size: 96px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.sub { font-size: 18px; opacity: .6; letter-spacing: 2px; }
.howto { display: flex; gap: 14px; margin: 18px 0; }
.howto div { width: 140px; padding: 18px 0; border-radius: 16px; background: rgba(255,255,255,.06); text-align: center; font-weight: 700; }
.howto b { display: block; font-size: 44px; line-height: 1; margin-bottom: 6px; color: #FF3B5C; }

#hud { position: fixed; inset: 0; pointer-events: none; font-variant-numeric: tabular-nums; }
#hud .top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; justify-content: space-between; gap: 8px; }
#hud .cell { min-width: 84px; padding: 8px 12px; border-radius: 14px; background: rgba(0,0,0,.45); backdrop-filter: blur(6px); text-align: center; }
#hud .cell b { font-size: 26px; font-weight: 900; }
#hud .rank b { font-size: 34px; color: #FFD447; }
#hud .rank span { font-size: 15px; opacity: .7; margin-left: 4px; }
#hud .bottom { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: flex-end; }
#hud .spd b { font-size: 54px; font-weight: 900; font-style: italic; text-shadow: 0 2px 10px rgba(0,0,0,.6); }
#hud .spd span, #hud .dist span { font-size: 16px; opacity: .75; margin-left: 4px; }
#hud .dist b { font-size: 30px; font-weight: 900; text-shadow: 0 2px 10px rgba(0,0,0,.6); }
#hBoost.hot { color: #FFD447; }
#hBoost.max { color: #FF7A2E; }
.pop { position: absolute; top: 22%; left: 0; right: 0; text-align: center; font-size: 34px; font-weight: 900; font-style: italic;
  text-shadow: 0 3px 14px rgba(0,0,0,.7); opacity: 0; transition: opacity .25s, transform .25s; transform: scale(.8); }
.pop.show { opacity: 1; transform: scale(1); }
.pop.bad { color: #FF5A6E; }
.pop.good { color: #5EF0FF; }

#count { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  font-size: 180px; font-weight: 900; font-style: italic; text-shadow: 0 0 40px rgba(255,60,90,.7), 0 6px 0 rgba(0,0,0,.4); }
#count.go { color: #5EF0FF; font-size: 120px; }

.dist2 { font-size: 22px; opacity: .85; }
.dist2 b { font-size: 40px; font-weight: 900; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(340px, 100%); margin-top: 8px; }
.stats div { padding: 12px 0; border-radius: 14px; background: rgba(255,255,255,.06); text-align: center; }
.stats b { display: block; font-size: 28px; font-weight: 900; }
.stats span { font-size: 14px; opacity: .6; }

#snd { position: fixed; z-index: 20; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right));
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(6px); display: grid; place-items: center; }
#snd svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#snd svg path:first-child { fill: #fff; }
#snd .off, #snd.muted .on { display: none; }
#snd.muted .off { display: inline; }
#hud .top { right: max(62px, env(safe-area-inset-right)); }

/* RWD：字級隨螢幕縮放 */
.brand { font-size: clamp(28px, 7vmin, 52px); }
.brand span { font-size: clamp(54px, 15vmin, 110px); }
.big { font-size: clamp(56px, 13vmin, 120px); }
#hud .cell b { font-size: clamp(20px, 4.2vmin, 32px); }
#hud .rank b { font-size: clamp(26px, 5.6vmin, 44px); }
#hud .spd b { font-size: clamp(40px, 9vmin, 72px); }
#hud .dist b { font-size: clamp(24px, 5vmin, 38px); }
#count { font-size: clamp(110px, 30vmin, 240px); }
#count.go { font-size: clamp(80px, 20vmin, 170px); }

/* 橫式手機：內容改左右排，避免上下擠不下 */
@media (orientation: landscape) and (max-height: 560px) {
  .panel { gap: 10px; }
  #join { flex-direction: row; gap: 40px; }
  #join form { width: min(320px, 45vw); }
  input, select, .go { height: 50px; }
  #garage { display: grid; grid-template-columns: 1fr minmax(260px, 40vw); grid-template-rows: 1fr auto auto auto 1fr; column-gap: 24px; row-gap: 12px; align-items: center; justify-items: center; }
  #preview { grid-column: 1; grid-row: 1 / 6; width: 50vw; height: 70vh; }
  #garage .pick { grid-column: 2; grid-row: 2; }
  #garage .swatches { grid-column: 2; grid-row: 3; }
  #garage .go { grid-column: 2; grid-row: 4; }
  .howto { margin: 6px 0; }
  .howto div { padding: 10px 0; }
  #result { display: grid; grid-template-columns: 1fr 1fr; align-content: center; column-gap: 30px; }
  #result .sub:first-child, #result .big, #result .dist2 { grid-column: 1; justify-self: center; }
  #result .stats, #result #rMsg { grid-column: 2; justify-self: center; }
  #result .stats { grid-row: 1 / 3; }
}
/* 平板、電腦：內容不要拉太寬 */
@media (min-width: 900px) and (min-height: 600px) {
  .panel { gap: 24px; }
  #preview { width: min(520px, 50vw); height: min(340px, 38vh); }
}
#result .code { font-size: 22px; font-weight: 900; letter-spacing: 3px; padding: 8px 18px; border-radius: 12px; background: rgba(255,212,71,.14); color: #FFD447; }
#hud.sprint .top .cell:first-child { background: rgba(255,40,70,.75); animation: beat .5s ease-in-out infinite alternate; }
@keyframes beat { to { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { #hud.sprint .top .cell:first-child { animation: none; } }
