:root {
  color-scheme: dark;
  --bg: #050914;
  --panel: rgba(13, 24, 45, 0.92);
  --panel-soft: rgba(20, 35, 62, 0.78);
  --line: rgba(120, 166, 255, 0.2);
  --text: #f5f8ff;
  --muted: #9eafd0;
  --cyan: #4de3ff;
  --blue: #6d7cff;
  --gold: #ffd75e;
  --green: #58f6a9;
  --red: #ff5b7f;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  font-family:
    Inter, Pretendard, "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at 50% -10%, rgba(71, 110, 255, 0.3), transparent 36%),
    radial-gradient(circle at 110% 65%, rgba(77, 227, 255, 0.13), transparent 36%),
    linear-gradient(160deg, #07101f 0%, #050914 58%, #090719 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 30px 30px;
  content: "";
  mask-image: linear-gradient(to bottom, black, transparent 80%);
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

.game-shell {
  width: min(100%, 780px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.screen {
  width: 100%;
}

.status-screen,
.result-screen {
  min-height: calc(100vh - 42px);
  min-height: calc(100dvh - 42px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.brand-mark {
  display: grid;
  width: 88px;
  height: 88px;
  margin-bottom: 24px;
  place-items: center;
  border: 1px solid rgba(77, 227, 255, 0.7);
  border-radius: 26px;
  color: var(--cyan);
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.08em;
  background: linear-gradient(145deg, rgba(77, 227, 255, 0.18), rgba(109, 124, 255, 0.14));
  box-shadow: 0 0 44px rgba(77, 227, 255, 0.18);
  transform: rotate(-4deg);
}

.error-mark {
  color: var(--red);
  border-color: rgba(255, 91, 127, 0.7);
  box-shadow: 0 0 44px rgba(255, 91, 127, 0.16);
}

.eyebrow,
.hud-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.status-screen h1,
.result-screen h1 {
  margin: 8px 0 12px;
  font-size: clamp(2rem, 9vw, 3.5rem);
  letter-spacing: -0.05em;
}

.status-screen > p:not(.eyebrow) {
  max-width: 520px;
  color: var(--muted);
  line-height: 1.65;
}

.auth-mark {
  letter-spacing: -0.04em;
}

.pass-form {
  display: grid;
  width: min(100%, 420px);
  gap: 14px;
  margin-top: 12px;
}

.pass-input {
  width: 100%;
  min-height: 68px;
  border: 1px solid rgba(77, 227, 255, 0.5);
  border-radius: 18px;
  color: var(--text);
  font: inherit;
  font-size: clamp(1.5rem, 7vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.28em;
  text-align: center;
  background: rgba(7, 16, 31, 0.9);
  box-shadow:
    inset 0 0 20px rgba(77, 227, 255, 0.06),
    0 12px 32px rgba(0, 0, 0, 0.24);
  outline: none;
}

.pass-input:focus {
  border-color: var(--cyan);
  box-shadow:
    0 0 0 3px rgba(77, 227, 255, 0.15),
    0 0 28px rgba(77, 227, 255, 0.14);
}

.pass-input::placeholder {
  color: rgba(158, 175, 208, 0.52);
  letter-spacing: 0.18em;
}

.pass-message {
  min-height: 1.5em;
  margin: 14px 0 0;
  color: var(--red) !important;
  font-weight: 700;
}

.pass-message.pending {
  color: var(--cyan) !important;
}

.pass-help {
  margin-top: 8px;
  font-size: 0.88rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.battle-header {
  position: sticky;
  top: max(8px, env(safe-area-inset-top));
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 106px 1fr;
  align-items: center;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(7, 16, 31, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.battle-header > div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
}

.battle-header strong {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-block {
  align-items: flex-end;
}

.timer-panel {
  align-items: center;
  justify-content: center;
  align-self: stretch;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

#timer {
  color: var(--cyan);
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 0 18px rgba(77, 227, 255, 0.5);
}

.timer-panel.danger {
  background: rgba(255, 91, 127, 0.12);
  animation: danger-pulse 0.8s ease-in-out infinite alternate;
}

.timer-panel.danger #timer {
  color: var(--red);
  text-shadow: 0 0 20px rgba(255, 91, 127, 0.7);
}

.progress-track {
  height: 5px;
  margin: 12px 6px 16px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
  box-shadow: 0 0 16px rgba(77, 227, 255, 0.65);
  transition: width 0.35s ease;
}

.combo-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stage-chip,
.combo-chip {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: rgba(15, 27, 49, 0.8);
}

.combo-chip.active {
  color: var(--gold);
  border-color: rgba(255, 215, 94, 0.42);
  box-shadow: 0 0 22px rgba(255, 215, 94, 0.14);
}

.question-card {
  padding: clamp(20px, 5vw, 34px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(145deg, rgba(24, 43, 76, 0.94), rgba(10, 20, 38, 0.94));
  box-shadow: var(--shadow);
}

.question-title {
  margin: 0 0 16px;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.passage {
  margin: 0;
  color: #f4f7ff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.04rem, 4.3vw, 1.24rem);
  line-height: 1.82;
  overflow-wrap: anywhere;
}

/*
 * 빈칸.
 * 밑줄은 이 border-bottom 하나로만 그린다.
 * 안에 언더스코어 문자를 넣으면 선이 두 겹이 되고 이음새가 끊겨 보인다.
 * line-height를 1로 낮춰 밑줄이 글자 기준선 가까이 붙게 한다.
 */
.blank-token {
  display: inline-block;
  min-width: min(100%, 220px);
  margin: 0 3px;
  border-bottom: 2px solid var(--cyan);
  color: var(--cyan);
  line-height: 1;
  text-align: center;
  vertical-align: baseline;
  text-shadow: 0 0 12px rgba(77, 227, 255, 0.35);
}

.choices {
  display: grid;
  gap: 11px;
  margin-top: 16px;
}

.choice-button {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  min-height: 66px;
  padding: 10px 14px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--text);
  text-align: left;
  background: var(--panel-soft);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  cursor: pointer;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.choice-button:hover,
.choice-button:focus-visible {
  border-color: rgba(77, 227, 255, 0.68);
  background: rgba(31, 52, 88, 0.95);
  outline: none;
  transform: translateY(-2px);
}

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

.choice-button:disabled {
  cursor: default;
}

.choice-label {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid rgba(120, 166, 255, 0.32);
  border-radius: 11px;
  color: var(--cyan);
  font-size: 0.88rem;
  font-weight: 900;
  background: rgba(5, 11, 24, 0.55);
}

.choice-text {
  padding-left: 2px;
  font-size: 0.94rem;
  line-height: 1.45;
}

.choice-button.correct {
  border-color: var(--green);
  background: rgba(48, 160, 105, 0.2);
  box-shadow: 0 0 24px rgba(88, 246, 169, 0.16);
}

.choice-button.correct .choice-label {
  color: #04150d;
  border-color: var(--green);
  background: var(--green);
}

.choice-button.wrong {
  border-color: var(--red);
  background: rgba(180, 42, 79, 0.2);
}

.choice-button.wrong .choice-label {
  color: white;
  border-color: var(--red);
  background: var(--red);
}

.choice-button.dimmed {
  opacity: 0.48;
}

.feedback {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.feedback-banner {
  margin-bottom: 14px;
  font-size: 1.08rem;
  font-weight: 900;
  letter-spacing: 0.03em;
}

.feedback.correct-feedback .feedback-banner {
  color: var(--green);
}

.feedback.wrong-feedback .feedback-banner {
  color: var(--red);
}

.answer-panel {
  margin-bottom: 16px;
  padding: 15px;
  border: 1px solid rgba(255, 91, 127, 0.22);
  border-radius: 15px;
  background: rgba(5, 10, 22, 0.48);
}

.answer-heading {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.correct-answer {
  margin: 0 0 16px;
  color: var(--green);
  font-weight: 800;
  line-height: 1.5;
}

.explanation {
  margin: 0;
  color: #e6ecfb;
  line-height: 1.72;
  word-break: keep-all;
}

.primary-button {
  width: 100%;
  min-height: 56px;
  padding: 12px 18px;
  border: 0;
  border-radius: 16px;
  color: #04101b;
  font-weight: 900;
  background: linear-gradient(115deg, var(--cyan), #9c8cff);
  box-shadow: 0 12px 28px rgba(77, 227, 255, 0.2);
  cursor: pointer;
}

.primary-button:hover,
.primary-button:focus-visible {
  filter: brightness(1.08);
  outline: 2px solid rgba(255, 255, 255, 0.78);
  outline-offset: 3px;
}

.primary-button:disabled {
  cursor: wait;
  filter: grayscale(0.35);
  opacity: 0.7;
}

.battle-effect {
  position: fixed;
  top: 43%;
  left: 50%;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  font-size: clamp(2rem, 11vw, 4rem);
  font-weight: 1000;
  font-style: italic;
  letter-spacing: -0.04em;
  text-align: center;
  text-transform: uppercase;
  transform: translate(-50%, -50%) scale(0.4) rotate(-7deg);
}

.battle-effect.critical {
  color: var(--gold);
  text-shadow:
    0 0 14px rgba(255, 215, 94, 0.9),
    4px 4px 0 #db4167;
  animation: battle-pop 0.85s ease-out;
}

.battle-effect.damage {
  color: white;
  text-shadow:
    0 0 14px rgba(255, 91, 127, 0.9),
    4px 4px 0 var(--red);
  animation: battle-pop 0.85s ease-out;
}

.screen-shake {
  animation: screen-shake 0.34s linear;
}

.grade {
  display: grid;
  width: 130px;
  height: 130px;
  margin-bottom: 8px;
  place-items: center;
  border: 2px solid var(--gold);
  border-radius: 36px;
  color: var(--gold);
  font-size: 5rem;
  font-weight: 1000;
  line-height: 1;
  background: rgba(255, 215, 94, 0.08);
  box-shadow:
    0 0 48px rgba(255, 215, 94, 0.22),
    inset 0 0 26px rgba(255, 215, 94, 0.1);
  transform: rotate(-4deg);
}

.result-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.result-grid > div {
  display: flex;
  min-height: 82px;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--panel-soft);
}

.result-grid span {
  color: var(--muted);
  font-size: 0.78rem;
}

.result-grid strong {
  color: var(--cyan);
  font-size: 1.45rem;
}

@keyframes danger-pulse {
  from {
    box-shadow: inset 0 0 0 rgba(255, 91, 127, 0);
  }
  to {
    box-shadow: inset 0 0 28px rgba(255, 91, 127, 0.25);
  }
}

@keyframes battle-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4) rotate(-7deg);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.18) rotate(-4deg);
  }
  72% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(-4deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -70%) scale(1.1) rotate(-4deg);
  }
}

@keyframes screen-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-7px);
  }
  50% {
    transform: translateX(7px);
  }
  75% {
    transform: translateX(-4px);
  }
}

@media (min-width: 640px) {
  .game-shell {
    padding-top: 30px;
    padding-bottom: 40px;
  }

  .choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .choice-button:last-child {
    grid-column: 1 / -1;
  }

  .result-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .game-shell {
    padding-right: 11px;
    padding-left: 11px;
  }

  .battle-header {
    grid-template-columns: 1fr 90px 1fr;
  }

  .battle-header > div {
    padding-right: 9px;
    padding-left: 9px;
  }

  #timer {
    font-size: 1.75rem;
  }

  .question-card {
    padding: 18px;
  }

  .blank-token {
    min-width: min(100%, 160px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
