:root {
  --bg: #0b1220;
  --fg: #e8eef8;
  --muted: #93a4bd;
  --accent: #3dd6c6;
  --danger: #ff6b6b;
  --ok: #5ee09a;
  --panel: rgba(16, 28, 48, 0.88);
  --line: rgba(255, 255, 255, 0.12);
  font-family: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 800px at 20% -10%, #1a2b4a 0%, var(--bg) 55%);
  color: var(--fg);
}

a {
  color: var(--accent);
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  margin: 0 0 0.5rem;
  letter-spacing: 0.02em;
}

.lead {
  color: var(--muted);
  line-height: 1.55;
  margin: 0 0 1.5rem;
}

.actions {
  display: grid;
  gap: 0.85rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #1c2f4d, #14233c);
  color: var(--fg);
  border-radius: 12px;
  padding: 0.95rem 1.1rem;
  font-size: 1.05rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  border-color: rgba(61, 214, 198, 0.45);
  box-shadow: 0 0 0 1px rgba(61, 214, 198, 0.15) inset;
}

.btn.ghost {
  background: transparent;
}

.hint {
  margin-top: 1.5rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.hint code {
  color: var(--accent);
  font-size: 0.86em;
}

/* Display */
.display-body {
  overflow: hidden;
  height: 100vh;
  background: #1a1040;
}

.screen {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(100vw, 200vh);
  height: min(50vw, 100vh);
  transform: translate(-50%, -50%);
  overflow: hidden;
  background: transparent;
  container-type: size;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.guide {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 5%;
  transform: translateX(-50%);
  width: min(92%, 980px);
  text-align: center;
  pointer-events: none;
  padding: 0.8rem 1.2rem 1rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  color: #2a1848;
}

.guide h2 {
  margin: 0;
  font-size: clamp(3.2rem, 8vw, 6.4rem);
  line-height: 1.12;
}

.guide p {
  margin: 0.45rem 0 0;
  font-size: clamp(1.3rem, 3vw, 2.2rem);
  color: #5c3d78;
}

.guide.up {
  top: 5%;
  bottom: auto;
  z-index: 6;
}

.guide.to-right,
.guide.to-left {
  top: 50%;
  bottom: auto;
  width: min(46%, 520px);
  z-index: 6;
}

.guide.to-right {
  left: auto;
  right: 3%;
  transform: translateY(-50%);
}

.guide.to-left {
  left: 3%;
  right: auto;
  transform: translateY(-50%);
}

.guide.play {
  top: 1.2rem;
  bottom: auto;
  width: auto;
  padding: 0.45rem 1.1rem 0.6rem;
  background: #ffe14a;
  color: #2a1848;
  border-radius: 16px;
}

body.in-game .hud,
body.choosing .hud,
body.choosing .guide,
body.ending .hud,
body.ending .guide {
  display: none;
}

.chooser {
  display: none;
}

body.choosing .chooser {
  display: flex;
  position: absolute;
  inset: 0;
  z-index: 8;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 2% 2.5% 2%;
  background: #1a1040;
}

.chooser-title,
.chooser-hint {
  margin: 0;
  text-align: center;
}

.chooser-title {
  font-size: 5.5cqh;
  font-weight: 800;
  line-height: 1.1;
  color: #fff;
  text-shadow: 0 2px 10px rgba(80, 20, 60, 0.28);
}

.chooser-hint {
  font-size: 3.2cqh;
  line-height: 1.1;
  color: rgba(255, 255, 255, 0.92);
}

.chooser-row {
  width: 96%;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: 1fr;
  gap: 1.4cqh;
}

.choice {
  appearance: none;
  border: 4px solid transparent;
  border-radius: 22px;
  color: #fff;
  font: 800 6cqh "Segoe UI", "Microsoft JhengHei", sans-serif;
  box-shadow: 0 10px 24px rgba(60, 16, 50, 0.22);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.choice-emoji {
  font-size: 1.4em;
  line-height: 1;
}

#game-fruit {
  background: linear-gradient(160deg, #ff8a9a, #ff3d68);
}

#game-bubble {
  background: linear-gradient(160deg, #8ec8ff, #3d7dff);
}

#game-order {
  background: linear-gradient(160deg, #fff3a0, #ffc107);
  color: #3a2410;
}

#game-shoot {
  background: linear-gradient(160deg, #b6ff8a, #22c55e);
  color: #143018;
}

#game-galaxy {
  background: linear-gradient(160deg, #ffb347, #ff6a00);
  color: #3a1608;
}

.choice.hot {
  border-color: #fff;
}

#chooser-dot,
#end-dot {
  position: absolute;
  z-index: 9;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -14px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(61, 214, 198, 0.85);
  pointer-events: none;
}

.endask {
  display: none;
}

body.ending .endask {
  display: flex;
  position: absolute;
  inset: 0;
  z-index: 8;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 3% 4%;
  background: #1a1040;
}

.endask-title,
.endask-hint {
  margin: 0;
  text-align: center;
  color: #fff;
}

.endask-title {
  font-size: 8cqh;
  font-weight: 800;
  line-height: 1.1;
}

.endask-hint {
  font-size: 3.4cqh;
  line-height: 1.1;
}

.endask-row {
  width: 86%;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.4cqh;
}

.end-choice {
  appearance: none;
  border: 4px solid transparent;
  border-radius: 22px;
  font: 800 9cqh "Segoe UI", "Microsoft JhengHei", sans-serif;
  cursor: pointer;
}

#end-yes {
  background: #ff4d6d;
  color: #fff;
}

#end-no {
  background: #3ef0c8;
  color: #143018;
}

.end-choice.hot {
  border-color: #fff;
}

.guide.play h2 {
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  color: #2a1848;
  text-shadow: none;
}

.guide.play p {
  font-size: 1rem;
  color: #4a3068;
  text-shadow: none;
}

.hud {
  display: none;
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 2;
  min-width: 220px;
  max-width: min(92vw, 360px);
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(8px);
  font-size: 0.86rem;
  line-height: 1.45;
}

.hud .row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.hud .label {
  color: var(--muted);
}

.hud .ok {
  color: var(--ok);
}

.hud .bad {
  color: var(--danger);
}

#hud-clear {
  margin-top: 0.45rem;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.hud .url {
  margin-top: 0.55rem;
  word-break: break-all;
  color: var(--accent);
  font-size: 0.78rem;
}

/* Controller */
.controller-body {
  min-height: 100vh;
}

.controller-body.only-round {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
  background: #1a1040;
}

.round {
  width: min(92vw, 92dvh);
  height: min(92vw, 92dvh);
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5ef0df, #14998c 62%, #0c6e66);
  color: #06221f;
  font: 800 2.6rem/1.1 "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  letter-spacing: 0.04em;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  touch-action: manipulation;
}

.round:active:not(:disabled) {
  transform: scale(0.98);
}

.round.locked,
.round:disabled {
  background: #243044;
  color: #9aabbe;
  box-shadow: none;
  cursor: default;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 1rem;
  margin-bottom: 1rem;
}

.status-line {
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
}

#pad {
  width: 100%;
  aspect-ratio: 1;
  max-height: 55vh;
  border-radius: 16px;
  border: 1px dashed rgba(61, 214, 198, 0.35);
  background:
    radial-gradient(circle at 50% 50%, rgba(61, 214, 198, 0.08), transparent 55%),
    #0a1424;
  position: relative;
  touch-action: none;
  overflow: hidden;
}

#padDot {
  position: absolute;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  background: rgba(61, 214, 198, 0.85);
  box-shadow: 0 0 18px rgba(61, 214, 198, 0.45);
  left: 50%;
  top: 50%;
  pointer-events: none;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.err {
  color: var(--danger);
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
}

.mode-row {
  margin-bottom: 0.85rem;
  grid-template-columns: 1fr 1fr 1fr;
}

#cam-box video {
  width: 100%;
  max-height: 28vh;
  margin-top: 0.85rem;
  border-radius: 12px;
  background: #000;
  object-fit: cover;
}

.gain {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.flow {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.home {
  min-height: 100vh;
  background: #1a1040;
  color: #fff;
}

.home-wrap {
  max-width: 920px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 1.4rem 1.2rem 1.6rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-sizing: border-box;
}

.home-kicker {
  margin: 0 0 0.6rem;
  font-size: clamp(1.15rem, 2.4vw, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.home h1 {
  margin: 0 0 1.6rem;
  font-size: clamp(2.8rem, 8vw, 5.2rem);
  line-height: 1.05;
  text-shadow: 0 8px 24px rgba(70, 10, 40, 0.28);
}

.home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.home-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  min-height: 180px;
  padding: 1.3rem 1.3rem 1.4rem;
  border-radius: 28px;
  color: #1a1230;
  text-decoration: none;
  font-size: clamp(1.7rem, 4vw, 2.8rem);
  font-weight: 800;
  line-height: 1.05;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
}

.home-btn span {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.42em;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.home-btn.desk {
  background: #ffe14a;
}

.home-btn.phone {
  background: #3ef0c8;
}

.home-steps {
  margin: 1.5rem 0 0;
  padding: 1.1rem 1.2rem 1.1rem 2.4rem;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.16);
  font-size: clamp(1.15rem, 2.4vw, 1.45rem);
  font-weight: 700;
  line-height: 1.7;
}

@media (max-width: 680px) {
  .home-actions {
    grid-template-columns: 1fr 1fr;
  }

  .home-btn {
    min-height: 148px;
  }
}

.step {
  margin: 0 0 0.85rem;
  text-align: center;
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1.35;
  white-space: pre-line;
}

.btn.reach {
  width: 100%;
  margin-bottom: 0.85rem;
  padding: 1.05rem 1rem;
  font-size: 1.35rem;
}
