:root{
  --bg:#1d1a2e; --card:#2a2542; --ink:#fff8ec; --muted:#c9bfe0;
  --sun:#ffc94d; --pink:#ff7aa8; --mint:#5fe3b8; --sky:#6cc6ff;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);
  font-family:"PingFang TC","Noto Sans TC","Microsoft JhengHei",system-ui,sans-serif;font-size:20px}
button,.button-link{font:inherit;cursor:pointer;border:0;border-radius:18px;padding:16px 28px;
  background:var(--sun);color:#3a2600;font-weight:800;box-shadow:0 6px 0 #c9912a;transition:transform .08s}
button:active,.button-link:active{transform:translateY(4px);box-shadow:0 2px 0 #c9912a}
button.ghost,.button-link.ghost{background:var(--card);color:var(--ink);box-shadow:0 6px 0 #17132a}
.hidden{display:none!important}

:root { color-scheme: dark; }
a { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 3px solid #fff9e8;
  outline-offset: 5px;
}
button:disabled { cursor: wait; opacity: .65; }
button.compact { font-size: .82rem; padding: 8px 15px; border-radius: 12px; }
input {
  min-width: 0;
  border: 2px solid #80749f;
  background: #201931;
  color: var(--ink);
  border-radius: 12px;
  font: inherit;
  padding: 8px 12px;
}
h1, p { margin: 0; }
p { line-height: 1.5; }

.camera-page {
  height: auto;
  min-height: 100%;
  background: radial-gradient(ellipse at 80% 0, #382c4e, var(--bg) 64%);
}
.camera-layout {
  width: min(100%, 550px);
  margin: auto;
  padding: 24px 20px 32px;
  display: grid;
  gap: 20px;
}
.camera-layout h1 { font-size: clamp(2rem, 8vw, 3rem); margin: 12px 0 6px; }
.back, .camera-layout header p, .fine-print { font-size: .82rem; color: var(--muted); }
.camera-controls { display: grid; justify-items: start; gap: 16px; min-width: 0; }
.camera-controls form { width: 100%; }
.camera-controls label { display: block; font-weight: 700; margin-bottom: 6px; }
.pair-input { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pair-input input {
  width: 6ch;
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: .08em;
  text-align: center;
}
.pair-input button { padding: 12px 18px; }
#status { min-height: 3em; color: var(--mint); font-weight: 700; }
.preview {
  display: grid;
  place-items: center;
  width: min(100%, 320px);
  aspect-ratio: 4 / 3;
  background: #15101f;
  border: 2px solid #514462;
  border-radius: 16px;
  overflow: hidden;
}
.preview video { width: 100%; height: 100%; object-fit: contain; }
.preview .mirror { transform: scaleX(-1); }
@media (orientation: landscape) and (max-height: 600px) and (min-width: 550px) {
  .camera-layout { width: min(100%, 900px); grid-template-columns: minmax(300px, 1fr) minmax(160px, .7fr); gap: 12px 24px; }
  .camera-layout header { grid-column: 1 / -1; }
  .camera-layout h1 { margin-top: 2px; font-size: 1.5rem; }
  .camera-layout .preview { align-self: start; }
}

.screen-layout {
  min-height: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.screen-header {
  padding: 10px clamp(12px, 2.6vw, 36px) 12px;
  min-height: 63px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #1d192d;
  border-bottom: 1px solid #4a405b;
}
.brand { flex-shrink: 0; font-size: clamp(.9rem, 2vw, 1.3rem); font-weight: 900; text-decoration: none; }
#screen-status { color: var(--muted); margin-right: auto; font-size: clamp(.68rem, 1.5vw, .95rem); }
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  background: #171326;
}
.pair-panel {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: clamp(12px, 3vh, 42px) 18px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: clamp(9px, 2vh, 20px);
  text-align: center;
  background:
    radial-gradient(circle at 18% 68%, #362e52 0 2.6vw, transparent 2.7vw),
    radial-gradient(circle at 79% 22%, #443153 0 4vw, transparent 4.1vw),
    radial-gradient(circle at 82% 35%, #2e3354 0 2vw, transparent 2.1vw),
    #201a34;
}
.pair-panel h1 { font-size: clamp(2.2rem, 5.8vw, 4.6rem); font-weight: 900; line-height: 1.1; }
#pair-instruction { color: var(--muted); font-size: clamp(.82rem, 2vw, 1.3rem); }
.pair-details { display: flex; flex-wrap: wrap; gap: clamp(12px, 5vw, 76px); align-items: center; justify-content: center; }
.code-display { display: grid; align-content: center; text-align: left; }
.code-display span { color: var(--muted); font-weight: 700; }
#pair-code {
  color: var(--sun);
  font-size: clamp(3.6rem, min(12vw, 21vh), 10.5rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  letter-spacing: .07em;
}
.qr {
  width: clamp(120px, min(21vw, 29vh), 260px);
  display: block;
  border-radius: 13px;
  overflow: hidden;
  background: white;
}
.qr canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }
#pair-error { color: #ffd5aa; font-size: .86rem; }
#pair-error:empty { display: none; }

.arena {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  background: #2d2446;
  overflow: hidden;
  container-type: size;
}
#game-video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#game-canvas { display: block; width: 100%; height: 100%; }
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  justify-items: center;
  text-align: center;
  padding: 9px;
  background: linear-gradient(180deg, #181226c9 0%, #18122635 38%, #1812262b 64%, #181226d9 100%);
}
.overlay h1 {
  font-size: clamp(1.05rem, min(6vw, 9vh), 3.6rem);
  font-size: clamp(1rem, min(7cqw, 13cqh), 3.6rem);
  line-height: 1.1;
  text-shadow: 0 2px 8px #171126;
  align-self: start;
}
.menu { grid-template-rows: 1fr auto 1fr; gap: 10px; }
.menu h1 { align-self: end; }
.game-choices {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  justify-items: center;
  gap: 15px;
}
.choice {
  display: grid;
  gap: 5px;
  justify-items: center;
  align-content: center;
  width: min(65%, 285px);
  min-height: 96px;
  min-height: clamp(38px, 25cqh, 150px);
  padding: 5px;
  border-radius: 44% 46% 42% 45% / 35% 42% 40% 40%;
  border: 2px solid #fff6d9a6;
}
.choice-title {
  white-space: nowrap;
  font-size: clamp(1rem, 4vw, 2.4rem);
  font-size: clamp(.68rem, 5.5cqw, 2.4rem);
  line-height: 1.1;
}
.choice small { font-weight: 700; font-size: clamp(.55rem, 2.6cqw, 1.05rem); }
.choice:focus-visible, .actions button:focus-visible { outline-offset: 4px; }
.bubble-choice { background: #ffca64f2; color: #322144; box-shadow: 0 6px 0 #aa662e; }
.jump-choice { background: #b9a5fff5; color: #2c1852; box-shadow: 0 6px 0 #674eaa; }
.game-note {
  align-self: start;
  font-size: clamp(.7rem, 2vw, 1.15rem);
  font-size: clamp(.48rem, 3cqw, 1.15rem);
  font-weight: 700;
  text-shadow: 0 2px 7px #100d18;
}
.center-overlay {
  align-content: center;
  gap: clamp(5px, 3cqh, 21px);
  background: #1c142d75;
}
.height-fields, .actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.height-fields {
  color: var(--ink);
  font-weight: 700;
  font-size: clamp(.55rem, 3cqw, .9rem);
}
.height-fields label { background: #20182de0; padding: 4px 7px; border-radius: 10px; }
.height-fields input { width: 4.6em; padding: 4px 6px; }
.actions button {
  font-size: clamp(.6rem, min(4cqw, 11cqh), 1.35rem);
  padding: clamp(4px, 2cqh, 15px) clamp(10px, 4cqw, 30px);
}
.result-scores { display: grid; gap: 3px; font-size: clamp(.7rem, 4cqw, 1.45rem); text-shadow: 0 2px 7px #100d18; }
.result-scores p { color: var(--ink); }
.hold-cursor {
  position: absolute;
  pointer-events: none;
  width: 44px;
  width: clamp(23px, 9cqh, 65px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid var(--hand-color, white);
  background: conic-gradient(var(--hand-color, white) var(--hold-angle, 0deg), transparent 0);
  box-shadow: 0 0 8px #171226;
}
.hold-cursor::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: inherit;
  background: #231532bb;
  border: 1px solid #fff;
}
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 5px;
  padding: clamp(4px, 1.4cqw, 20px);
  font-size: clamp(.6rem, 3.7cqw, 1.25rem);
  pointer-events: none;
}
.hud > strong, .player-hud span {
  color: var(--player, var(--ink));
  border-radius: 12px;
  background: #1c1729df;
  padding: 4px 9px;
}
.hud > strong:empty { display: none; }
.player-hud { margin-right: auto; display: grid; gap: 4px; }
.hud button { pointer-events: auto; flex-shrink: 0; font-size: clamp(.45rem, 3cqw, .82rem); padding: 5px 9px; }
.announcement {
  position: absolute;
  top: 43%;
  left: 50%;
  width: max-content;
  max-width: 92%;
  transform: translate(-50%, -50%);
  border-radius: 22px;
  padding: .3em .6em;
  text-align: center;
  font-size: clamp(.75rem, 6cqw, 2.5rem);
  font-weight: 900;
  background: #1b132bea;
  color: var(--ink);
  pointer-events: none;
}
.announcement.countdown {
  font-size: clamp(2rem, min(21cqw, 35cqh), 8rem);
  color: var(--sun);
  padding: 0 .32em;
}
.play-video { position: absolute; bottom: 12%; z-index: 1; }
@media (max-width: 530px) {
  .screen-header { padding-inline: 9px; gap: 6px; min-height: 46px; }
  .screen-header button { padding: 4px 6px; font-size: .63rem; }
  .choice { width: 85%; }
}
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}

.game-choices { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(4px, 2cqw, 18px); }
.choice { width: min(95%, 285px); }
.choice-title { font-size: clamp(.53rem, 4.7cqw, 2.4rem); }
.harp-choice { background: #76e6cfee; color: #17382e; box-shadow: 0 6px 0 #358971; }
.harp-tools {
  position: absolute;
  top: clamp(5px, 2cqh, 14px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: clamp(4px, 2cqw, 14px);
}
.harp-tools button {
  font-size: clamp(.48rem, 3.7cqw, 1rem);
  padding: .4em .75em;
  border-radius: 12px;
}
.harp-help {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: .35em .85em;
  text-align: center;
  font-size: clamp(.45rem, 3.1cqw, 1.02rem);
  font-weight: 750;
  text-shadow: 0 1px 4px #121018;
  background: #211533d9;
  pointer-events: none;
}
