.pill.warning {
  color: #fff;
  background: #7d1730;
  border-color: var(--red);
  box-shadow: 0 0 18px #ff668566;
}

.pill.warning strong { color: #fff; }

.quit {
  position: fixed;
  z-index: 5;
  top: 16px;
  right: 18px;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid #ff668588;
  border-radius: 12px;
  background: #32152bdd;
  color: #fff;
  font: 800 .72rem Nunito, sans-serif;
  letter-spacing: .06em;
  cursor: pointer;
  touch-action: manipulation;
}

.quit:hover { background: #5a1d38; border-color: var(--red); }

@media (max-width: 760px) {
  /* The live game uses .desktop-card/.quiz-* classes.  Keep all of the
     desktop styling above intact and make the actual rendered screens
     comfortably scrollable and tappable on phone-sized viewports. */
  html { min-height: 100%; background: #030817; }
  body { min-height: 100dvh; overflow-x: clip; background-attachment: scroll; }
  .app {
    width: 100%; min-height: 100dvh; padding: 0;
    align-content: start;
  }
  .desktop-card {
    min-height: 100dvh;
    padding: max(58px, calc(env(safe-area-inset-top) + 48px))
             max(16px, env(safe-area-inset-right))
             max(86px, calc(env(safe-area-inset-bottom) + 72px))
             max(16px, env(safe-area-inset-left));
  }
  .brand {
    margin: 0 0 18px;
    padding-top: 0;
    text-align: left;
  }
  .brand b { font-size: .92rem; }
  .brand span { font-size: .61rem; }
  .home-screen h1, .subject-screen h1, .result-screen h1 {
    margin: 12px 0;
    font-size: clamp(2rem, 10vw, 2.75rem);
  }
  .home-copy, .screen-copy { font-size: .95rem; line-height: 1.45; }
  .name-box { margin: 28px auto 22px; padding: 12px 16px; }
  .name-box input { min-height: 42px; font-size: 16px; }
  .mission-btn, .back-btn { min-height: 48px; padding: 14px 24px; }
  .mission-meta { margin: 22px 0; line-height: 1.6; }
  .features { gap: 12px; margin-top: 38px; }
  .features div { flex: 1; }
  .features span { font-size: .72rem; }
  .grade-grid { margin: 24px auto; }
  .grade-card { min-height: 102px; padding: 14px 10px; gap: 10px; border-radius: 16px; }
  .grade-card > b { font-size: 1.08rem; }
  .grade-card button { min-height: 38px; padding: 8px; font-size: .68rem; }
  .subject-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 24px 0; }
  .subject-card { min-height: 196px; padding: 16px 9px; border-radius: 16px; }
  .subject-card i { width: 58px; height: 58px; font-size: 1.1rem; }
  .subject-card h3 { margin-top: 9px; font-size: 1rem; line-height: 1.05; }
  .subject-card p { min-height: 30px; margin: 7px 0; font-size: .66rem; }
  .subject-card button { min-height: 42px; font-size: .72rem; }
  .rules { gap: 8px; line-height: 1.5; }
  .subject-screen > .back-btn { margin-top: 24px; }
  .quiz-layout { gap: 0; }
  .quiz-stage > h2 { font-size: 1rem; }
  .quiz-score { margin: 7px 0 12px; font-size: .72rem; }
  .lifelines { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin: 10px 0; }
  .lifelines button { min-height: 44px; padding: 7px 3px; font-size: .7rem; }
  .lockline { font-size: .66rem; }
  .timer-wrap { margin-bottom: 10px; }
  .question-panel { margin: 9px 0; padding: 12px; border-radius: 16px; }
  .question-panel h3 { min-height: 0; margin-bottom: 10px; font-size: .94rem; line-height: 1.35; overflow-wrap: anywhere; }
  .answer-grid { gap: 8px; }
  .answer { min-height: 52px; padding: 9px 11px; font-size: .84rem; line-height: 1.25; overflow-wrap: anywhere; }
  .quiz-status { min-height: 64px; padding: 10px 0; line-height: 1.45; }
  .quiz-status button { min-height: 44px; margin-top: 8px; }
  .lost-screen { min-height: calc(100dvh - 20px); }
  .lost-box { padding: 26px 16px; border-radius: 22px; }
  .lost-box h1 { font-size: clamp(2.25rem, 13vw, 3.3rem); }
  .lost-box h2 { font-size: 1.65rem; }
  .lost-box h3, .lost-box p { overflow-wrap: anywhere; }
  .result-stats { margin: 24px auto; padding: 16px 8px; }
  .result-stats b { font-size: 1.55rem; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions .mission-btn, .actions .back-btn { width: 100%; }
  .btn, .answer, .subject-card button, .sound, .quit { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  /* Keep fixed controls out of the scrolling subject-card area.  On smaller
     phones the old bottom-right sound button could sit over the final SELECT
     button (most noticeably for Class 6+ Mixed). */
  .sound {
    left: max(10px, env(safe-area-inset-left)); right: auto;
    top: max(10px, env(safe-area-inset-top)); bottom: auto;
    width: 42px; height: 42px;
  }
  .quit { top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); min-height: 42px; }
}

@media (max-width: 390px) {
  .desktop-card { padding-inline: 12px; }
  .subject-card h3 { font-size: .92rem; }
  .lifelines button { font-size: .62rem; }
  .grade-grid { gap: 9px; }
}

/* Short landscape phones need the controls to remain reachable without a
   fixed element covering the game content. */
@media (max-height: 520px) and (orientation: landscape) and (max-width: 900px) {
  .desktop-card { min-height: 100dvh; padding-top: 52px; }
  .brand { margin-bottom: 8px; }
  .home-screen h1, .subject-screen h1, .result-screen h1 { font-size: 2rem; }
  .features { margin-top: 22px; }
  .grade-grid, .subject-grid { margin: 16px auto; }
  .quiz-stage { padding-bottom: 8px; }
}

/* Keep every subject action above mobile overlays and reliably tappable. */
@media (max-width: 760px) { .subject-card, .subject-card button { position: relative; z-index: 6; pointer-events: auto; } .subject-card button { touch-action: manipulation; } }
@media (max-width: 760px) { .subject-card { cursor: pointer; -webkit-tap-highlight-color: transparent; } }
