:root {
  --bg-deep: #0e1430;
  --bg-mid: #1a2d6a;
  --frame-glow: #67dcff;
  --ink-dark: #171214;
  --paper: #f4e48a;
  --paper-border: #332c12;
  --hp-good: #31d77b;
  --hp-bad: #ff4b5c;
  --btn-shadow: #5f3a00;
  --text-light: #f5fbff;
  --mint: #b8ffdd;
  --pink: #ffd5ea;
  --font-en: "Press Start 2P", cursive;
  --font-zh-game: "ZCOOL KuaiLe", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  font-family: var(--font-en);
  color: var(--text-light);
  background:
    radial-gradient(circle at 10% 8%, #4158bd 0%, transparent 36%),
    radial-gradient(circle at 84% 20%, #2b5876 0%, transparent 34%),
    linear-gradient(180deg, #1d2c7e 0%, #09102b 74%);
}

.phone-frame {
  width: min(96vw, 440px);
  height: min(96vh, 870px);
  border-radius: 22px;
  border: 4px solid var(--frame-glow);
  box-shadow: 0 0 0 4px #18305d, 0 0 30px rgba(106, 208, 255, 0.35), 0 28px 40px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(180deg, #1f2857 0%, #0e1331 100%);
}

.phone-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(161, 223, 255, 0.18), transparent 28%),
    radial-gradient(circle at 80% 0%, rgba(255, 138, 200, 0.14), transparent 24%),
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.04) 0 1px, rgba(0, 0, 0, 0.15) 2px 3px);
  pointer-events: none;
}

.hud-top {
  text-align: center;
  padding: 10px 12px 8px;
  position: relative;
  z-index: 1;
}

.brand-cn {
  margin: 0;
  font-size: 11px;
  color: #9dd9ff;
  letter-spacing: 1px;
  font-family: var(--font-zh-game);
  text-shadow: 0 1px 0 #12224a;
}

.hud-top h1 {
  margin: 6px 0 4px;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 1px;
  color: #ffffff;
  text-shadow: 0 2px 0 #13204a, 0 0 10px rgba(155, 220, 255, 0.5);
}

.brand-status {
  margin: 0;
  font-size: 11px;
  color: #8ce6ff;
}

.screen {
  display: none;
  height: calc(100% - 88px);
  padding: 10px 12px 12px;
  position: relative;
  z-index: 1;
}

.screen.active {
  display: block;
  animation: reveal 220ms steps(6);
}

.version-tag {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  margin: 0;
  text-align: center;
  font-size: 8px;
  color: rgba(226, 232, 240, 0.42);
  letter-spacing: 0.6px;
  z-index: 2;
  pointer-events: none;
}

@keyframes reveal {
  from { opacity: 0.35; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.mode-card {
  background: linear-gradient(180deg, rgba(91, 139, 255, 0.2), rgba(16, 33, 73, 0.4));
  border: 2px solid #7dd8ff;
  border-radius: 12px;
  padding: 12px 10px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.06);
}

.story-banner-wrap {
  margin: 4px 0 10px;
  border: 3px solid #111;
  box-shadow: 0 4px 0 #2f4f80;
  background: #0f1732;
  height: clamp(104px, 18vh, 146px);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.story-banner-wrap picture {
  width: 100%;
}

.story-banner {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  object-fit: cover;
  object-position: center 34%;
}

.mode-card h2 {
  margin: 0;
  text-align: center;
  font-size: 34px;
  color: #f8fbff;
  font-family: var(--font-zh-game);
  letter-spacing: 1px;
  text-shadow: 0 2px 0 #1a2f63;
}

.mode-sub {
  margin: 8px 0 0;
  text-align: center;
  font-size: 20px;
  line-height: 1.3;
  color: #cde9ff;
  font-family: var(--font-zh-game);
}

.btn-grid,
.character-grid,
.option-list {
  display: grid;
  gap: 8px;
}

.difficulty-grid {
  margin-top: 12px;
}

.retro-btn {
  border: 3px solid #121212;
  color: var(--ink-dark);
  font-family: inherit;
  cursor: pointer;
  background: linear-gradient(180deg, #ffe675 0%, #f4cf37 100%);
  box-shadow: 0 4px 0 var(--btn-shadow), inset 0 -3px rgba(0, 0, 0, 0.18);
  padding: 14px 12px;
  transition: transform 80ms steps(2), filter 100ms linear;
}

.retro-btn:hover {
  filter: brightness(1.06);
}

.retro-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--btn-shadow), inset 0 -2px rgba(0, 0, 0, 0.24);
}

.difficulty-btn {
  display: grid;
  gap: 8px;
  text-align: left;
}

.difficulty-btn span {
  font-size: 18px;
  font-family: var(--font-zh-game);
}

.difficulty-btn small {
  font-size: 16px;
  color: rgba(23, 18, 20, 0.8);
  font-family: var(--font-zh-game);
}

.difficulty-btn.low { background: linear-gradient(180deg, #fff88c, #f3dd47); }
.difficulty-btn.mid { background: linear-gradient(180deg, #9bf7ff, #58d2ff); }
.difficulty-btn.high { background: linear-gradient(180deg, #ffc36a, #ff8d4f); }

.tips {
  margin: 12px 2px 0;
  font-size: 18px;
  color: #b8cdf7;
  line-height: 1.35;
  font-family: var(--font-zh-game);
}

.character-grid {
  margin-top: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.character-card {
  background: linear-gradient(180deg, #dff3ff, #88cbff);
  border: 3px solid #101114;
  box-shadow: 0 4px 0 #2f4f80;
  padding: 8px 8px 10px;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: transform 80ms steps(2), filter 100ms linear;
  display: grid;
  gap: 6px;
}

.character-card:hover {
  filter: brightness(1.05);
}

.character-card:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #2f4f80;
}

.character-card .name {
  display: block;
  font-size: 18px;
  color: #0a1021;
  margin-bottom: 6px;
  font-family: var(--font-zh-game);
}

.character-card .type {
  display: inline-block;
  font-size: 14px;
  padding: 4px 6px;
  border: 2px solid #111;
  background: rgba(255, 255, 255, 0.62);
  font-family: var(--font-zh-game);
}

.char-pixel {
  width: 100%;
  height: 98px;
  border: 2px solid #101114;
  background: #d9ebff;
  image-rendering: pixelated;
}

.retro-btn.secondary {
  margin-top: 12px;
  background: linear-gradient(180deg, #deecff, #a7c4ff);
  box-shadow: 0 4px 0 #5c76ab;
}

.battle-wrap {
  height: 37%;
  border: 3px solid #0b0f17;
  box-shadow: inset 0 0 0 2px #4568a3;
  background: linear-gradient(180deg, #2e4a8f 0%, #061022 100%);
}

#battle-canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.question-wrap {
  height: calc(63% - 6px);
  margin-top: 6px;
  border: 3px solid var(--paper-border);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.22);
  background: linear-gradient(180deg, #f4e694 0%, #e8d36f 100%);
  color: #171214;
  padding: 8px;
  overflow: hidden;
}

.question-head {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.info-pill {
  margin: 0;
  border: 2px solid #111;
  padding: 4px 5px;
  background: #fff9cf;
  font-size: 13px;
  line-height: 1.2;
  font-family: var(--font-zh-game);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#stage-line {
  background: #fff0ad;
}

#timer-line {
  background: #bdf0ff;
}

#pressure-line {
  background: #ffd9ea;
  font-size: 11px;
  padding-left: 4px;
  padding-right: 4px;
}

.info-pill.danger {
  background: #ffd4d4 !important;
  color: #7f1111;
}

#idiom-word {
  margin: 8px 0 10px;
  text-align: center;
  font-size: 44px;
  line-height: 1.1;
  font-family: "Noto Serif TC", "PMingLiU", "Songti TC", serif;
  font-weight: 900;
  text-shadow: 0 2px 0 #f6efbc;
}

.answer-btn {
  border: 2px solid #111;
  background: #fff8d7;
  color: #1a1515;
  font-family: var(--font-zh-game);
  font-size: 28px;
  line-height: 1.2;
  text-align: left;
  padding: 5px 10px;
  min-height: 72px;
}

.answer-btn:hover {
  background: #fffef0;
}

.answer-btn:disabled {
  opacity: 0.92;
}

.answer-btn.correct {
  background: #d2ffd8;
}

.answer-btn.wrong {
  background: #ffd6d6;
}

.result-card {
  margin-top: 18%;
  border: 3px solid #111;
  background: linear-gradient(180deg, #ffe39f 0%, #fdbf6f 100%);
  box-shadow: 0 6px 0 #8a4f11;
  padding: 14px 10px;
  text-align: center;
  color: #1f1713;
}

.result-card h2 {
  margin: 0;
  color: #1f1713;
}

#result-desc,
#result-score {
  font-size: 18px;
  line-height: 1.7;
  font-family: var(--font-zh-game);
}

.fail-wrap {
  margin: 10px 0 12px;
  text-align: left;
}

.fail-wrap h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-family: var(--font-zh-game);
}

.fail-list {
  display: grid;
  gap: 8px;
  max-height: 170px;
  overflow: auto;
}

.fail-item {
  border: 2px solid #111;
  background: #fff7cf;
  text-align: left;
  padding: 8px;
  font-family: var(--font-zh-game);
  font-size: 18px;
  cursor: pointer;
}

.fail-item:hover {
  background: #fffce6;
}

.fail-modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 20, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}

.fail-modal.hidden {
  display: none;
}

.fail-modal-card {
  width: min(95vw, 420px);
  border: 3px solid #111;
  background: linear-gradient(180deg, #fff0b2, #ffd580);
  box-shadow: 0 8px 0 #8a4f11;
  padding: 12px 10px;
  position: relative;
  color: #1f1713;
}

.fail-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 2px solid #111;
  background: #fff;
  font-family: inherit;
  cursor: pointer;
}

.fail-modal-card h3 {
  margin: 0 34px 10px 0;
  font-size: 13px;
}

.modal-idiom {
  margin: 0 0 10px;
  font-size: 38px;
  line-height: 1.2;
  text-align: center;
  font-family: var(--font-zh-game);
}

.modal-line {
  margin: 8px 0;
  font-size: 20px;
  line-height: 1.45;
  font-family: var(--font-zh-game);
}

@media (max-width: 390px) {
  .hud-top h1 {
    font-size: 20px;
  }

  #idiom-word {
    font-size: 36px;
  }

  .difficulty-btn span {
    font-size: 12px;
  }

  .difficulty-btn small,
  .tips,
  .info-pill {
    font-size: 12px;
  }

  #pressure-line {
    font-size: 10px;
  }

  .answer-btn {
    font-size: 24px;
    min-height: 66px;
    padding: 5px 9px;
  }

  .fail-item {
    font-size: 16px;
  }

  .modal-idiom {
    font-size: 32px;
  }

  .modal-line {
    font-size: 17px;
  }

  .story-banner-wrap {
    height: clamp(92px, 16vh, 118px);
  }
}
