:root {
  color-scheme: dark;
  --bg: #11110f;
  --panel: #f6efe1;
  --ink: #1c1a16;
  --muted: #71685d;
  --gold: #d7a846;
  --line: rgba(255, 255, 255, 0.14);
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 18%, rgba(215, 168, 70, 0.16), transparent 29%),
    linear-gradient(135deg, #171511, #080808 58%, #18100d);
  color: white;
  font-family:
    ui-rounded,
    "SF Pro Rounded",
    "Noto Sans TC",
    "Inter",
    system-ui,
    sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button,
img {
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
}

.game-shell {
  width: 100vw;
  height: 100svh;
  max-height: 100dvh;
  min-height: 0;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: grid;
  place-items: center;
  overflow: visible;
}

.play-stage {
  width: min(1160px, 100%);
  height: 100%;
  max-height: min(780px, 100%);
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(34px, auto) minmax(0, 1fr);
  gap: clamp(14px, 3vh, 28px);
  position: relative;
  overflow: visible;
}

.loading-mask {
  position: absolute;
  inset: -2px;
  z-index: 30;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 50% 42%, rgba(246, 239, 225, 0.16), transparent 42%),
    rgba(12, 10, 8, 0.86);
  backdrop-filter: blur(16px) saturate(1.12);
  -webkit-backdrop-filter: blur(16px) saturate(1.12);
  color: rgba(246, 239, 225, 0.94);
  opacity: 1;
  pointer-events: auto;
  transition: opacity 260ms ease, visibility 260ms ease;
}

.loading-mask.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-spinner {
  width: clamp(54px, 8vw, 82px);
  aspect-ratio: 1 / 1;
  border-radius: 999px;
  background:
    conic-gradient(from 0deg, transparent 0 23%, #d7a846 24% 42%, transparent 43% 100%),
    radial-gradient(circle, transparent 50%, rgba(246, 239, 225, 0.24) 52% 57%, transparent 59%);
  filter: drop-shadow(0 14px 26px rgba(0, 0, 0, 0.38));
  animation: loadingSpin 920ms linear infinite;
}

.loading-mask span:last-child {
  font-size: clamp(16px, 2.6vw, 24px);
  font-weight: 850;
  letter-spacing: 0;
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.42);
}

.top-line {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 34px;
  position: relative;
}

.round-counter {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  min-width: 72px;
  color: rgba(255, 255, 255, 0.74);
  font-size: clamp(16px, 2.6vh, 22px);
  font-weight: 800;
  letter-spacing: 0;
  text-align: left;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4.6vh, 42px);
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
  text-shadow: 0 8px 28px rgba(0, 0, 0, 0.42);
}

.choices {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(14px, 3vw, 34px);
  min-height: 0;
  height: 100%;
  max-height: 100%;
  align-items: stretch;
  perspective: 1400px;
}

.choice {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(8px, 1.4vw, 14px);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: var(--shadow);
  color: inherit;
  cursor: pointer;
  overflow: hidden;
  transform: translateZ(0) scale(1);
  transition:
    transform 520ms cubic-bezier(0.2, 0.9, 0.2, 1),
    opacity 420ms ease,
    background 360ms ease,
    border-color 360ms ease,
    box-shadow 520ms ease;
}

.vs-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  width: clamp(58px, 8vw, 92px);
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.56);
  border-radius: 999px;
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.15) 20%, transparent 21%),
    linear-gradient(145deg, #b72424, #2f0d0d 62%, #d7a846);
  color: white;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.52);
  font-size: clamp(20px, 3vw, 34px);
  font-weight: 950;
  letter-spacing: 0;
  transform: translate(-50%, -50%) rotate(-8deg);
  pointer-events: none;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
}

.choice::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent 34%, rgba(215, 168, 70, 0.1));
  opacity: 0;
  transition: opacity 360ms ease;
}

.choice:active {
  transform: scale(0.985);
}

.choice:hover::before,
.choice:focus-visible::before {
  opacity: 1;
}

.choice:focus-visible {
  outline: 3px solid rgba(215, 168, 70, 0.78);
  outline-offset: 3px;
}

.image-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: 6px;
  padding: clamp(10px, 1.5vw, 18px);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 255, 255, 0.08), transparent 54%),
    #151411;
}

.image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
  transform: scale(0.96);
  transition: transform 620ms cubic-bezier(0.16, 1, 0.3, 1), filter 420ms ease;
}

.reveal-copy {
  display: none;
}

.choice.is-faded {
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.94);
}

.choices.is-revealed {
  grid-template-columns: 1fr;
}

.choices.is-revealed .vs-badge {
  display: none;
}

.choices.is-revealed .choice.is-faded {
  display: none;
}

.choices.is-revealed .choice.is-correct {
  width: min(920px, 100%);
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(260px, 0.88fr) minmax(260px, 1fr);
  gap: clamp(16px, 3vw, 32px);
  padding: clamp(12px, 2vw, 18px);
  background: var(--panel);
  border-color: rgba(215, 168, 70, 0.58);
  color: var(--ink);
  cursor: pointer;
  transform: translateY(-4px) scale(1.02);
}

.choices.is-revealed .choice.is-correct .image-wrap {
  min-height: 340px;
  aspect-ratio: 1 / 1;
}

.choices.is-revealed .choice.is-correct .image-wrap img {
  transform: scale(0.96);
  filter: saturate(1.04) contrast(1.03);
}

.choices.is-revealed .choice.is-correct .reveal-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(10px, 2vh, 18px);
  text-align: left;
  animation: copyIn 520ms ease both 150ms;
}

.reveal-copy strong {
  font-size: clamp(28px, 4.4vw, 54px);
  line-height: 0.98;
  letter-spacing: 0;
}

.reveal-copy small {
  width: fit-content;
  border-top: 2px solid var(--gold);
  padding-top: 10px;
  color: var(--muted);
  font-size: clamp(18px, 2.2vw, 28px);
  font-weight: 800;
}

.reveal-copy span {
  color: #39342e;
  font-size: clamp(16px, 1.55vw, 22px);
  line-height: 1.55;
}

.wrong-mark,
.correct-mark {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(72%, 360px);
  aspect-ratio: 1 / 1;
  opacity: 0;
  transform: scale(0.55) rotate(-10deg);
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.48));
  pointer-events: none;
}

.wrong-mark {
  background: url("./red-wrong-cross.png") center / contain no-repeat;
}

.correct-mark {
  width: min(82%, 440px);
  background: url("./red-brush-circle.png") center / contain no-repeat;
  transform: scale(0.62) rotate(-5deg);
}

.choice.is-wrong .image-wrap img {
  filter: grayscale(0.25) brightness(0.78);
}

.choice.is-wrong .wrong-mark {
  animation: crossIn 360ms cubic-bezier(0.18, 1.35, 0.25, 1) both;
}

.choice.is-correct-pending .correct-mark {
  animation: circleIn 320ms cubic-bezier(0.18, 1.35, 0.25, 1) both;
}

.choices.is-locked .choice {
  pointer-events: none;
}

.choices.is-revealed .choice.is-correct {
  pointer-events: auto;
}

.result-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  border-radius: 8px;
  background: rgba(246, 239, 225, 0.96);
  color: var(--ink);
  box-shadow: var(--shadow);
  animation: resultIn 520ms ease both;
  padding: clamp(18px, 4vw, 44px);
  text-align: center;
}

.result-panel[hidden] {
  display: none;
}

.result-panel span {
  font-size: clamp(26px, 5vw, 52px);
  font-weight: 850;
}

.result-panel strong {
  font-size: clamp(56px, 14vw, 150px);
  line-height: 0.92;
  color: #9a2525;
}

.share-row {
  width: min(520px, 100%);
  margin: 4px 0 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  color: #51483d;
  font-size: clamp(14px, 2.1vw, 18px);
  font-weight: 750;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(28, 26, 22, 0.07);
}

.share-row[hidden] {
  display: none;
}

.share-row a {
  flex: none;
  border-radius: 8px;
  padding: 9px 14px;
  background: #9a2525;
  color: #fff7e8;
  text-decoration: none;
  box-shadow: 0 10px 22px rgba(154, 37, 37, 0.24);
  font-weight: 900;
}

.result-replay,
.challenge-button {
  border: 0;
  border-radius: 8px;
  padding: 12px 20px;
  background: #1f1b16;
  color: #f6efe1;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  font-weight: 850;
  letter-spacing: 0;
}

.review-stage {
  width: min(1180px, 100%);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(14px, 2.8vh, 28px);
  overflow: hidden;
}

.review-stage[hidden] {
  display: none;
}

.play-stage.is-reviewing {
  grid-template-rows: minmax(44px, auto);
  height: auto;
  max-height: none;
  overflow: hidden;
}

.play-stage.is-reviewing .top-line {
  min-height: 44px;
  padding-top: 0;
}

.play-stage.is-reviewing .choices,
.play-stage.is-reviewing .result-panel,
.play-stage.is-reviewing .loading-mask,
.play-stage.is-reviewing .round-counter {
  display: none;
}

.play-stage.is-reviewing h1 {
  max-width: min(920px, 100%);
  font-size: clamp(22px, 4vw, 46px);
  line-height: 1.08;
}

.review-gallery {
  min-height: 0;
  overflow: auto;
  padding: clamp(12px, 2.2vw, 24px);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  align-content: start;
  gap: clamp(12px, 2.2vw, 24px);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    #17130f;
  background-size: 34px 34px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), var(--shadow);
}

.review-frame {
  position: relative;
  margin: 0;
  aspect-ratio: 1 / 1;
  padding: clamp(8px, 1.8vw, 14px);
  background: #f4ead7;
  border: 1px solid rgba(87, 61, 35, 0.28);
  border-radius: 4px;
  box-shadow:
    0 18px 34px rgba(0, 0, 0, 0.34),
    inset 0 0 0 5px #fffaf0;
  transform: rotate(var(--tilt, -1deg));
}

.review-frame:nth-child(3n) {
  --tilt: 1.3deg;
}

.review-frame:nth-child(4n) {
  --tilt: -1.8deg;
}

.review-frame:nth-child(5n) {
  --tilt: 0.8deg;
}

.review-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 2px;
  filter: saturate(1.02) contrast(1.03);
}

.review-frame.is-wrong img {
  filter: grayscale(0.22) brightness(0.86);
}

.review-cross {
  position: absolute;
  inset: 8%;
  background: url("./red-wrong-cross.png") center / contain no-repeat;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.44));
  pointer-events: none;
}

.challenge-button {
  justify-self: center;
  background: #9a2525;
  font-size: clamp(17px, 2.2vw, 22px);
}

@keyframes copyIn {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes crossIn {
  0% {
    opacity: 0;
    transform: scale(0.55) rotate(-10deg);
  }
  70% {
    opacity: 1;
    transform: scale(1.08) rotate(2deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

@keyframes circleIn {
  0% {
    opacity: 0;
    transform: scale(0.62) rotate(-5deg);
  }
  75% {
    opacity: 1;
    transform: scale(1.05) rotate(1deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

@keyframes resultIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes loadingSpin {
  to {
    transform: rotate(1turn);
  }
}

@media (orientation: portrait), (max-width: 760px) {
  .game-shell {
    min-height: 0;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .play-stage {
    height: 100%;
    max-height: 100%;
    gap: 12px;
  }

  .top-line {
    min-height: 58px;
    padding-top: 22px;
  }

  .round-counter {
    top: 0;
    transform: none;
    font-size: 16px;
  }

  .choices {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: clamp(10px, 2.2vh, 16px);
  }

  .vs-badge {
    width: clamp(48px, 15vw, 72px);
    font-size: clamp(18px, 6vw, 28px);
  }

  .choices.is-revealed {
    grid-template-rows: 1fr;
  }

  .choices.is-revealed .choice.is-correct {
    height: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 0.72fr) auto;
    gap: 14px;
    transform: translateY(0) scale(1);
  }

  .choices.is-revealed .choice.is-correct .image-wrap {
    min-height: 0;
    aspect-ratio: auto;
  }

  .choices.is-revealed .choice.is-correct .reveal-copy {
    justify-content: start;
    gap: 9px;
  }

  .reveal-copy strong {
    font-size: clamp(26px, 8vw, 42px);
  }

  .reveal-copy small {
    font-size: clamp(17px, 5vw, 24px);
    padding-top: 8px;
  }

  .reveal-copy span {
    font-size: clamp(15px, 4vw, 19px);
    line-height: 1.45;
  }

  .share-row {
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }

  .review-stage {
    gap: 12px;
  }

  .review-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 12px;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  .game-shell {
    min-height: 0;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  h1 {
    font-size: clamp(18px, 5vh, 24px);
  }

  .play-stage {
    grid-template-rows: minmax(24px, auto) minmax(0, 1fr);
    gap: 6px;
  }

  .top-line {
    min-height: 24px;
    padding-top: 0;
  }

  .round-counter {
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
  }

  .choices {
    gap: clamp(8px, 2vw, 18px);
  }

  .choices.is-revealed .choice.is-correct .image-wrap {
    min-height: 0;
  }
}
