/* ---------- Phase 9: Game Hub & Listening Challenge ---------- */
.game-hub {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.game-hub-btn {
  text-align: left;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 14px;
  padding: 11px 12px;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.game-hub-btn strong {
  font-size: 14.5px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.game-hub-btn span {
  font-size: 11.5px;
  color: var(--dim);
  line-height: 1.3;
}
.game-hub-btn.on {
  border-color: var(--teal);
  background: var(--teal-soft);
}
.game-hub-btn.on strong {
  color: var(--teal);
}
.game-hub-btn:focus-visible,
.listen-type-btn:focus-visible,
.listen-opt:focus-visible,
.listen-play-hero:focus-visible,
.listen-input:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}
@media (max-width: 350px) {
  .game-hub { gap: 8px; }
  .game-hub-btn { padding: 9px 10px; }
  .game-hub-btn strong { font-size: 13.5px; }
}

/* ---------- Listening Lobby ---------- */
.listen-hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.listen-hero h1 {
  font-size: 22px;
  font-weight: 900;
  margin-top: 2px;
}
.listen-badge-status {
  font-size: 12px;
  font-weight: 800;
  color: var(--teal);
  background: var(--teal-soft);
  border-radius: 999px;
  padding: 5px 10px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.listen-config-group {
  margin-top: 14px;
}
.listen-config-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--dim);
  margin-bottom: 8px;
}
.listen-config-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 560px) {
  .listen-config-row { grid-template-columns: 1fr; }
}
.listen-type-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
@media (max-width: 480px) {
  .listen-type-grid { grid-template-columns: 1fr; }
}
.listen-type-btn {
  text-align: left;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.listen-type-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}
.listen-type-head strong {
  font-size: 14.5px;
  font-weight: 800;
}
.listen-cnt-tag {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--teal);
  background: var(--teal-soft);
  border-radius: 999px;
  padding: 2px 8px;
  flex-shrink: 0;
}
.listen-type-btn > span {
  font-size: 12px;
  color: var(--dim);
  line-height: 1.35;
}
.listen-type-btn.on {
  border-color: var(--teal);
  background: var(--teal-soft);
}
.listen-rule-box {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--surface2);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--dim);
  line-height: 1.45;
}
.listen-rule-box strong { color: var(--ink); }
.listen-cap-note {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 13px;
  font-weight: 600;
}
.listen-start-btn {
  margin-top: 16px;
  min-height: 52px;
  font-size: 16px;
}
.listen-error,
.listen-warn {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--red-soft);
  color: var(--red);
}
.listen-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  text-align: center;
}
@media (max-width: 520px) {
  .listen-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.listen-stat-grid > div {
  background: var(--surface2);
  border-radius: 11px;
  padding: 10px 8px;
}
.listen-stat-grid .num {
  font-size: 17px;
  font-weight: 900;
  color: var(--ink);
}
.listen-stat-grid .lbl {
  font-size: 12px;
  color: var(--dim);
  margin-top: 2px;
}
.listen-subhead {
  font-size: 14.5px;
  font-weight: 800;
  margin: 16px 0 8px;
}
.listen-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.listen-hist-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--surface2);
}
.listen-score-pill {
  font-size: 12.5px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  white-space: nowrap;
}
.listen-hist-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

/* ---------- Fullscreen Listening Match & Result Screen ---------- */
.listening-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.listening-screen[hidden] { display: none; }
.listen-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
  flex-shrink: 0;
}
.listen-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.listen-q-counter {
  font-size: 13px;
  font-weight: 800;
  color: var(--dim);
  text-align: center;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.listen-timer-pill {
  min-width: 52px;
  text-align: center;
  font-size: 14px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  flex-shrink: 0;
}
.listen-timer-pill.urgent {
  background: var(--red-soft);
  color: var(--red);
}
.listen-timer-pill.practice {
  font-size: 12px;
  background: var(--surface2);
  color: var(--dim);
}
.listen-hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 0 6px;
}
.listen-score-box {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--surface2);
  padding: 4px 10px;
  border-radius: 9px;
}
.listen-score-box .lbl { font-size: 11px; font-weight: 800; color: var(--dim); }
.listen-score-box .val { font-size: 18px; font-weight: 900; color: var(--teal); }
.listen-combo-box {
  font-size: 13px;
  font-weight: 800;
  color: var(--amber);
}
.listen-level-pill {
  font-size: 11.5px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 7px;
  border: 1px solid var(--line);
  color: var(--dim);
}
.listen-time-line {
  height: 4px;
  border-radius: 99px;
  background: var(--surface2);
  overflow: hidden;
  margin-top: 5px;
}
.listen-time-line > div {
  height: 100%;
  background: var(--amber);
  transition: width .15s linear;
}

.listen-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px calc(24px + env(safe-area-inset-bottom, 0px));
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.listen-audio-card {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 22px;
  padding: 18px 16px;
  text-align: center;
  box-shadow: 0 10px 26px -10px rgba(12, 42, 34, .14), var(--shadow);
  margin-bottom: 14px;
  transition: border-color var(--motion-normal) var(--ease-apple), box-shadow var(--motion-normal) var(--ease-apple);
}
.listen-audio-card.is-speaking {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 18%, transparent), 0 12px 28px -8px color-mix(in srgb, var(--teal) 26%, transparent);
}
.listen-q-dir {
  font-size: 12px;
  font-weight: 800;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.listen-play-hero {
  margin-top: 12px;
  width: 100%;
  max-width: 340px;
  min-height: 54px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 2px solid var(--teal);
  border-bottom-width: 4px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 15.5px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 6px 14px color-mix(in srgb, var(--teal) 16%, transparent);
  transition: transform var(--motion-fast) var(--ease-duo),
              background-color var(--motion-normal) var(--ease-apple),
              color var(--motion-normal) var(--ease-apple),
              box-shadow var(--motion-normal) var(--ease-apple);
}
.listen-play-hero:not(:disabled):active { transform: translateY(2px) scale(0.98); }
.listen-play-hero.speaking {
  background: var(--teal);
  color: var(--teal-ink);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--teal) 32%, transparent);
}
.listen-play-hero:disabled {
  opacity: .55;
  border-color: var(--line);
  background: var(--surface2);
  color: var(--dim);
  cursor: default;
}
.listen-wave {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 16px;
}
.listen-wave span {
  width: 3px;
  height: 7px;
  border-radius: 2px;
  background: currentColor;
}
.listen-play-hero.speaking .listen-wave span:nth-child(1) { animation: listenWave .75s ease-in-out infinite; }
.listen-play-hero.speaking .listen-wave span:nth-child(2) { animation: listenWave .75s ease-in-out .15s infinite; }
.listen-play-hero.speaking .listen-wave span:nth-child(3) { animation: listenWave .75s ease-in-out .3s infinite; }
@keyframes listenWave {
  0%, 100% { transform: scaleY(.65); }
  50% { transform: scaleY(1.9); }
}
.listen-audio-sub {
  font-size: 12.5px;
  color: var(--dim);
  margin-top: 8px;
}
.listen-q-prompt {
  font-size: clamp(16px, 4.5vw, 19px);
  font-weight: 800;
  color: var(--ink);
  margin-top: 10px;
  line-height: 1.35;
  word-break: break-word;
}

.listen-audio-err {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--red-soft);
  border: 1px solid var(--red);
  color: var(--red);
}
.listen-audio-err strong { display: block; font-size: 14px; font-weight: 800; }
.listen-audio-err p { font-size: 13px; margin-top: 4px; color: var(--ink); }
.listen-err-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

/* ---------- Options & Mobile-Keyboard-Safe Dictation Input ---------- */
.listen-opts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}
.listen-opt {
  width: 100%;
  min-height: 54px;
  padding: 12px 15px;
  border-radius: 15px;
  border: 1.5px solid var(--line);
  border-bottom-width: 3.5px;
  background: var(--surface);
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font-size: 15.5px;
  font-weight: 700;
  transition: transform var(--motion-fast) var(--ease-duo),
              border-color var(--motion-fast) var(--ease-standard),
              background-color var(--motion-fast) var(--ease-standard);
}
.listen-opt:not(:disabled):active { transform: translateY(2px) scale(0.985); }
.listen-opt-key {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--dim);
  font-size: 13px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.listen-opt-txt {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}
.listen-opt.right {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  animation: icRightPop .32s var(--ease-duo);
}
.listen-opt.wrong {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red);
  animation: tileShake .32s ease;
}
.listen-opt:disabled { opacity: 1; cursor: default; }

.listen-dict-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.listen-input {
  width: 100%;
  min-height: 50px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  /* >= 16px prevents iOS Safari automatic zoom on input focus */
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}
.listen-input:focus {
  outline: none;
  border-color: var(--teal);
}
.listen-input:disabled {
  opacity: .6;
  background: var(--surface2);
}
.listen-dict-hint {
  font-size: 13px;
  font-weight: 700;
  color: var(--amber);
  text-align: center;
}
.listen-submit-btn {
  min-height: 48px;
  font-size: 15.5px;
}
.listen-dict-review {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.listen-dict-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 14.5px;
}
.listen-dict-row strong.ok { color: var(--green); font-size: 16px; }
.listen-dict-row strong.bad { color: var(--red); text-decoration: line-through; }

.listen-feedback {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.listen-feedback.right { background: var(--green-soft); border: 1px solid var(--green); }
.listen-feedback.wrong { background: var(--red-soft); border: 1px solid var(--red); }
.listen-fb-head { font-weight: 800; color: var(--ink); }
.listen-feedback.right .listen-fb-head { color: var(--green); }
.listen-feedback.wrong .listen-fb-head { color: var(--red); }
.listen-fb-word { color: var(--ink); font-size: 14.5px; }
.listen-ipa { color: var(--teal); font-weight: 700; }
.listen-fb-exp { font-size: 13px; color: var(--dim); line-height: 1.45; }
.listen-combo-tag { color: var(--amber); font-weight: 900; }
.listen-next-row { margin-top: 12px; }
.listen-next-row .btn { min-height: 50px; font-size: 15.5px; }

/* ---------- Result Screen ---------- */
.listen-result-card {
  text-align: center;
  animation: fcEnter .36s var(--ease-duo);
}
.listen-result-emoji { font-size: 44px; line-height: 1; margin-bottom: 8px; }
.listen-big-score {
  margin: 12px auto;
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--surface2);
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  min-width: 150px;
}
.listen-big-score .lbl { font-size: 12px; font-weight: 700; color: var(--dim); }
.listen-big-score strong { font-size: 32px; font-weight: 900; color: var(--teal); line-height: 1.1; }
.listen-type-breakdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.listen-tb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface2);
  font-size: 13.5px;
}
.listen-result-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 16px;
}
.listen-wrong-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.listen-wrong-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--surface2);
}
.listen-wrong-main { min-width: 0; flex: 1; }
.listen-wrong-vi { font-size: 13.5px; color: var(--ink); margin-top: 2px; }

/* Landscape & Short-Viewport Mobile Keyboard Fit */
@media (max-height: 520px) {
  .listen-header {
    padding-top: calc(4px + env(safe-area-inset-top, 0px));
    padding-bottom: 5px;
  }
  .listen-hud-row { margin: 4px 0; }
  .listen-audio-card { padding: 10px 12px; margin-bottom: 8px; }
  .listen-play-hero { min-height: 44px; margin-top: 6px; }
  .listen-opts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .listen-time-line > div,
  .listen-play-hero,
  .listen-audio-card,
  .listen-opt,
  .listen-result-card,
  .listen-play-hero.speaking .listen-wave span {
    transition: none !important;
    animation: none !important;
  }
}
