/* ============================================================
   PRACTICE MOBILE CSS - TỐI ƯU GIAO DIỆN MOBILE ĐẤU TRƯỜNG RÈN LUYỆN
   Chuẩn Typography (18-20px đề bài, 16-18px đáp án, 15-16px gợi ý/kết quả)
   Bố cục 3 phần: Header cố định, Body cuộn độc lập, Footer cố định
   Khóa cuộn nền triệt để, overscroll contain, safe-area-insets
   ============================================================ */

.practice-mobile-close-floating {
  display: none;
}
.practice-mobile-header {
  display: none;
}
.arena-question-scrollable {
  display: contents;
}
#topic-badge {
  display: none !important;
}
#visual-model-area:empty,
#visual-model-area.hidden {
  display: none !important;
}

@media (max-width: 767px) {
  /* Khóa cuộn trang nền */
  body.mobile-workout-open,
  body.is-scroll-locked {
    overflow: hidden !important;
    overscroll-behavior: none !important;
  }
  body.mobile-workout-open::before,
  body.is-scroll-locked::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 42;
    pointer-events: auto;
    background: rgba(48, 49, 46, 0.62);
    -webkit-backdrop-filter: blur(7px);
    backdrop-filter: blur(7px);
  }
  body.mobile-workout-open > nav,
  body.mobile-workout-open > aside {
    visibility: hidden;
  }

  /* Nút đóng popup nổi chuẩn WCAG 44x44px */
  .practice-mobile-close-floating {
    display: flex !important;
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    z-index: 20 !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    border-radius: 12px !important;
    background: #e4e2de !important;
    color: #3c4a42 !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12) !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
  }
  .practice-mobile-close-floating .material-symbols-outlined {
    font-size: 24px !important;
  }

  /* Khung Popup làm bài: Bố cục 3 phần trọn vẹn 100dvh */
  #section-practice:not(.hidden) {
    position: fixed !important;
    z-index: 45 !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
    width: calc(100% - 16px) !important;
    max-width: 480px !important;
    height: calc(100vh - 16px) !important;
    height: calc(100dvh - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    overflow: hidden !important;
    background: #fff !important;
    border-radius: 18px !important;
    border: 2px solid rgba(228, 226, 222, 0.85) !important;
    box-shadow: 0 18px 54px rgba(27, 28, 26, 0.28) !important;
    animation: none !important;
  }

  /* Ẩn các khối giao diện Desktop */
  .practice-desktop-header,
  .practice-desktop-selector,
  .practice-desktop-status,
  #level-selector-container,
  .practice-parent-tip {
    display: none !important;
  }

  /* PHẦN 1: HEADER CỐ ĐỊNH Ở ĐỈNH POPUP */
  #section-practice .practice-mobile-header {
    display: flex !important;
    position: relative;
    z-index: 5;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    padding: max(8px, env(safe-area-inset-top)) 10px 6px;
    background: #f5f3ef;
    border-bottom: 1px solid #e4e2de;
  }
  .practice-mobile-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
  }
  .practice-mobile-top-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 48px; /* Tránh đè lên nút đóng 44px */
  }
  .practice-mobile-book-switch {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: #efeeea;
    border-radius: 999px;
    flex-shrink: 0;
  }
  .practice-mobile-book-switch button {
    min-height: 28px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11.5px !important;
    font-weight: 800;
    color: #3c4a42;
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
  }
  .practice-mobile-book-switch button .material-symbols-outlined {
    font-size: 14px;
  }
  .practice-mobile-book-switch button.is-active {
    background: #10b981;
    color: #fff;
    box-shadow: 0 2px 0 #005236;
  }
  .practice-mobile-page {
    height: 28px;
    padding: 0 8px;
    border-radius: 999px;
    background: #ffddb8;
    color: #653e00;
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 11px !important;
    font-weight: 800;
    box-shadow: 0 2px 0 #b45309;
  }
  .practice-mobile-page .material-symbols-outlined {
    font-size: 13px;
  }
  .sound-toggle-btn.practice-mobile-page {
    background: #e8f5e9;
    color: #1b5e20;
    box-shadow: 0 2px 0 #2e7d32;
    cursor: pointer;
    min-width: 28px;
    padding: 0 6px;
    justify-content: center;
    border: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  .sound-toggle-btn.practice-mobile-page[aria-pressed="false"],
  .sound-toggle-btn.practice-mobile-page.sound-off {
    background: #efeeea;
    color: #717871;
    box-shadow: 0 2px 0 #c2c1bc;
  }
  .practice-mobile-book-pill {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }
  .practice-mobile-book-pill .material-symbols-outlined {
    font-size: 15px;
    color: #006c49;
    flex-shrink: 0;
  }
  #mobile-practice-title {
    min-width: 0;
    font-size: 15px !important;
    line-height: 1.4 !important;
    font-weight: 800 !important;
    color: #006c49;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .practice-mobile-lesson-nav {
    display: flex;
    gap: 4px;
  }
  .practice-mobile-lesson-nav button {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: #fff;
    color: #3c4a42;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    cursor: pointer;
  }
  .practice-mobile-lesson-nav .material-symbols-outlined {
    font-size: 17px;
  }

  .practice-mobile-level-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }
  .practice-mobile-level-grid button {
    min-width: 0;
    height: 32px !important;
    min-height: 32px !important;
    border-radius: 10px !important;
    background: #efeeea;
    color: #3c4a42;
    font-size: 12px !important;
    font-weight: 800 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 4px;
    cursor: pointer;
  }
  .practice-mobile-level-grid button span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .practice-mobile-level-grid button.is-active {
    background: #006c49;
    color: #fff;
    box-shadow: 0 2px 0 #00422b;
  }

  .practice-mobile-status-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: #efeeea;
    border-bottom: 1px solid #e4e2de;
    flex-shrink: 0;
  }
  .practice-mobile-streak {
    display: flex;
    gap: 2px;
    font-size: 13px !important;
    font-weight: 800 !important;
    color: #6b7280;
    white-space: nowrap;
  }
  #mobile-practice-streak {
    font-size: 13.5px !important;
    color: #855300;
  }
  .practice-mobile-progress-wrap {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
  }
  #mobile-practice-counter {
    font-size: 13px !important;
    font-weight: 800 !important;
    color: #006c49;
    white-space: nowrap;
  }
  .practice-mobile-progress-track {
    height: 7px;
    flex: 1;
    min-width: 28px;
    background: #e4e2de;
    border-radius: 999px;
    overflow: hidden;
  }
  .practice-mobile-progress-bar {
    height: 100%;
    background: #10b981;
    border-radius: 999px;
  }
  .practice-mobile-timer {
    display: flex;
    align-items: center;
    gap: 3px;
    background: #fff;
    padding: 3px 6px;
    border-radius: 999px;
    font-size: 12.5px !important;
    font-weight: 800 !important;
    color: #3c4a42;
    white-space: nowrap;
  }
  .practice-mobile-timer .material-symbols-outlined {
    font-size: 13px;
    color: #006c49;
  }

  /* Complete the mobile height chain on ALL phone heights.
     Without this flex chain, long question + visual content can grow the shell
     and push the action footer below the visible viewport on tall iPhones. */
  #desktop-practice-popup-shell {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  #practice-workspace {
    display: flex !important;
    flex: 1 1 0 !important;
    min-height: 0 !important;
    width: 100% !important;
    max-width: none !important;
    overflow: hidden !important;
    flex-direction: column !important;
    gap: 0 !important;
  }

  /* PHẦN 2: THẺ BÀI TẬP VÀ VÙNG CUỘN ĐỘC LẬP */
  #arena-question-card {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #fff !important;
    box-shadow: none !important;
    gap: 0 !important;
    display: flex !important;
    flex-direction: column !important;
  }
  #arena-question-card > div.absolute {
    display: none !important;
  }

  /* Vùng cuộn mượt mà độc lập của nội dung câu hỏi */
  .arena-question-scrollable {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overscroll-behavior-y: contain !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 10px 12px 14px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
  }
  /* Ẩn hàng huy hiệu chủ đề trùng lặp vì header mobile đã hiển thị */
  .arena-question-scrollable > div:first-of-type {
    display: none !important;
  }

  /* Khung câu hỏi tối ưu - Ưu tiên nội dung toán học */
  .arena-question-scrollable > div:has(#question-story),
  .question-story-card {
    flex: 0 0 auto !important;
    background: #f8f7f5 !important;
    border: 1px solid #eae8e4 !important;
    padding: 14px 16px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    border-radius: 16px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
    height: auto !important;
    min-height: 0 !important;
    text-align: left !important;
  }
  #mascot-emoji,
  #mascot-name {
    display: none !important;
  }

  /* Kích thước chữ đề bài: 19-20px, font-weight 600-700, line-height khoảng 1.45, text-align left */
  #question-story {
    font-size: 19.5px !important;
    line-height: 1.45 !important;
    font-weight: 700 !important;
    color: #1b1c1a !important;
    text-align: left !important;
    width: 100% !important;
    overflow-wrap: anywhere;
  }
  #question-subtext {
    font-size: 15px !important;
    line-height: 1.45 !important;
    color: #444746 !important;
    font-weight: 500 !important;
    text-align: left !important;
    width: 100% !important;
    margin-top: 2px !important;
  }
  #question-subtext:empty {
    display: none !important;
  }

  /* Mô hình trực quan: Ưu tiên diện tích, giữ đúng tỷ lệ, ẩn hoàn toàn khi rỗng */
  #visual-model-area,
  #hint-visual-area {
    max-width: 100%;
    overflow: hidden !important;
    flex: 0 0 auto !important;
  }
  #visual-model-area:empty,
  #visual-model-area.hidden,
  #hint-visual-area:empty,
  #hint-visual-area.hidden {
    display: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    height: 0 !important;
    min-height: 0 !important;
  }
  #visual-model-area:not(:empty):not(.hidden) {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #fff !important;
    border: 1px solid #eae8e4 !important;
    border-radius: 14px !important;
    padding: 10px 12px !important;
    margin: 4px 0 !important;
    max-height: 32dvh !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  #visual-model-area > *,
  #hint-visual-area > * {
    max-width: 100% !important;
    max-height: 100% !important;
  }
  #visual-model-area svg,
  #hint-visual-area svg {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 240px !important;
    display: block !important;
    margin: 0 auto !important;
  }
  #visual-model-area img,
  #hint-visual-area img {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 240px !important;
    object-fit: contain !important;
    display: block !important;
    margin: 0 auto !important;
  }

  /* Phương án trả lời: Tự động 2 cột (ngắn) hoặc 1 cột (dài), 17-18px, min-height 52px, touch targets >= 44x44px */
  #quiz-options:not(.hidden),
  #multi-options-container {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    flex: 0 0 auto !important;
    width: 100% !important;
  }
  #quiz-options.options-single-column,
  #multi-options-container.options-single-column {
    grid-template-columns: 1fr !important;
  }
  #quiz-options button,
  #multi-options-container .multi-option-card,
  #multi-options-container button {
    min-height: 52px !important;
    min-width: 44px !important;
    height: auto !important;
    border-radius: 14px !important;
    padding: 10px 14px !important;
    gap: 10px !important;
    white-space: normal !important;
    text-align: left !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
    box-sizing: border-box !important;
  }
  #quiz-options button span.text-on-surface,
  #multi-options-container .multi-option-card span.text-on-surface {
    font-size: 17.5px !important;
    line-height: 1.45 !important;
    font-weight: 700 !important;
    overflow-wrap: anywhere;
  }
  #quiz-options button span,
  #multi-options-container button span {
    overflow-wrap: anywhere;
  }
  #quiz-options button > div:first-child,
  #multi-options-container button > div:first-child {
    min-width: 0;
    flex: 1;
  }

  #all-combinations-area:not(.hidden) {
    flex: 0 0 auto !important;
    overflow: visible !important;
  }
  #input-number-area:not(.hidden) {
    flex: 0 0 auto !important;
    padding: 10px !important;
    gap: 8px !important;
    overflow: visible !important;
  }
  #keypad-container {
    gap: 6px !important;
  }
  #keypad-container button {
    min-height: 46px !important;
    height: 46px !important;
    font-size: 20px !important;
    border-radius: 10px !important;
    cursor: pointer !important;
  }
  #custom-number-input {
    font-size: 26px !important;
    max-width: 150px;
    height: 48px !important;
    border-radius: 12px !important;
  }

  /* Gợi ý & chẩn đoán lỗi: 15-16px, line-height 1.5 */
  #diagnostic-probe-card.hidden,
  #owl-hint-box.hidden,
  #result-banner.hidden {
    display: none !important;
  }
  #diagnostic-probe-card:not(.hidden),
  #owl-hint-box:not(.hidden) {
    flex: 0 0 auto !important;
    overflow: visible !important;
    padding: 12px !important;
    border-radius: 12px !important;
    gap: 8px !important;
  }
  #owl-hint-text,
  #probe-question {
    font-size: 15px !important;
    line-height: 1.5 !important;
    font-weight: 600 !important;
  }
  #probe-title {
    font-size: 13px !important;
    font-weight: 800 !important;
  }
  #probe-advice-box {
    font-size: 14px !important;
    line-height: 1.45 !important;
  }

  /* PHẦN 3: FOOTER CỐ ĐỊNH Ở ĐÁY POPUP (Nút hành động & Result Banner) */
  #arena-action-buttons {
    position: static !important;
    flex: 0 0 auto !important;
    z-index: 2 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 6px !important;
    padding: 6px 10px max(8px, env(safe-area-inset-bottom)) !important;
    margin: 0 !important;
    background: #fff !important;
    border-top: 1px solid #e4e2de !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  #btn-open-support {
    min-height: 44px !important;
    height: 44px !important;
    width: 100% !important;
    padding: 6px 12px !important;
    border-radius: 10px !important;
    box-shadow: none !important;
    border: 0 !important;
    background: #efeeea !important;
    color: #1b1c1a !important;
    font-size: 14.5px !important;
    font-weight: 800 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    cursor: pointer !important;
  }
  #btn-open-support .material-symbols-outlined {
    font-size: 18px !important;
  }
  #arena-action-buttons > div {
    display: grid !important;
    grid-template-columns: 1.08fr 1fr 2.05fr !important;
    gap: 6px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    align-items: stretch !important;
  }
  #arena-action-buttons > div button {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 5px !important;
    min-height: 56px !important;
    height: 56px !important;
    padding: 0 6px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    letter-spacing: -0.2px !important;
    border-radius: 12px !important;
    box-sizing: border-box !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    width: 100% !important;
    min-width: 0 !important;
    transition: all 0.15s ease-in-out !important;
    cursor: pointer !important;
  }
  #arena-action-buttons > div button span {
    display: inline-flex !important;
    align-items: center !important;
    white-space: nowrap !important;
  }
  #arena-action-buttons > div button .material-symbols-outlined {
    font-size: 19px !important;
    width: 19px !important;
    height: 19px !important;
    line-height: 19px !important;
    flex-shrink: 0 !important;
  }
  #btn-pause-session,
  #btn-skip-question {
    background: #f3f4f6 !important;
    color: #374151 !important;
    border: 1px solid #d1d5db !important;
    box-shadow: 0 3px 0 0 #d1d5db !important;
    width: 100% !important;
  }
  #btn-pause-session:active,
  #btn-skip-question:active {
    transform: translateY(2px) !important;
    box-shadow: 0 1px 0 0 #d1d5db !important;
  }
  #btn-submit {
    background: #10b981 !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 4px 0 0 #005236 !important;
    font-size: 16px !important;
    font-weight: 800 !important;
    width: 100% !important;
  }
  #btn-submit:active {
    transform: translateY(2px) !important;
    box-shadow: 0 1px 0 0 #005236 !important;
  }
  #btn-pause-session > span,
  #btn-skip-question > span,
  #btn-submit > span {
    display: inline-flex !important;
  }
  #btn-pause-session .pause-long {
    display: inline-flex !important;
  }
  #btn-pause-session .pause-short {
    display: none !important;
  }

  /* Result Banner thông báo kết quả: 15-16px to rõ */
  #result-banner:not(.hidden) {
    flex: 0 0 auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 10px 12px max(8px, env(safe-area-inset-bottom)) !important;
    margin: 0 !important;
    border-top: 1px solid #e4e2de !important;
    border-radius: 10px !important;
    box-shadow: none !important;
    background: #fff !important;
  }
  #result-title {
    font-size: 16px !important;
    font-weight: 800 !important;
    line-height: 1.4 !important;
  }
  #result-desc {
    font-size: 14px !important;
    line-height: 1.45 !important;
  }
  #btn-next-question {
    min-height: 48px !important;
    height: 48px !important;
    width: 100% !important;
    justify-content: center !important;
    font-size: 15.5px !important;
    font-weight: 800 !important;
    border-radius: 12px !important;
    cursor: pointer !important;
  }

  /* Các modal phụ: cấu hình, hỗ trợ, tạm nghỉ */
  #modal-support,
  #modal-pause-session,
  #completion-modal,
  #modal-session-config,
  #modal-mobile-support-detail {
    z-index: 60;
    padding: 8px;
  }
  #modal-support > div,
  #modal-pause-session > div,
  #completion-modal > div,
  #modal-session-config > div,
  #modal-mobile-support-detail > div {
    max-height: calc(100dvh - 16px);
    overflow: auto;
    padding: 14px;
  }
  #sgk-reader-modal {
    z-index: 65;
  }
  #section-practice button:focus-visible {
    outline: 3px solid #059669;
    outline-offset: 2px;
  }
}

/* Thích ứng màn hình nhỏ (<360px như iPhone SE 1st gen 320px) */
@media (max-width: 359px) {
  #arena-action-buttons > div {
    grid-template-columns: 1.08fr 1fr 2.05fr !important;
    gap: 4px !important;
  }
  #arena-action-buttons > div button {
    min-height: 52px !important;
    height: 52px !important;
    padding: 0 3px !important;
    font-size: 13.5px !important;
    gap: 2px !important;
  }
  #arena-action-buttons > div button .material-symbols-outlined {
    font-size: 17px !important;
    width: 17px !important;
    height: 17px !important;
    line-height: 17px !important;
  }
  #btn-submit {
    min-height: 52px !important;
    height: 52px !important;
    font-size: 14px !important;
    padding: 0 3px !important;
  }
  #quiz-options:not(.hidden),
  #multi-options-container {
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
  }
  #quiz-options button,
  #multi-options-container button {
    min-height: 48px !important;
    font-size: 14.5px !important;
    padding: 8px 8px !important;
  }
  #question-story {
    font-size: 17px !important;
  }
  .practice-mobile-level-grid button {
    font-size: 10.5px !important;
  }
  #btn-pause-session .pause-long {
    display: none !important;
  }
  #btn-pause-session .pause-short {
    display: inline-flex !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  #section-practice {
    scroll-behavior: auto;
  }
  #section-practice * {
    animation: none !important;
  }
}

/* Three supplied HTML references: fullscreen mobile practice layout. */
@media (max-width:767px) {
  #section-practice:not(.hidden) {
    inset: 0 !important; top: 0 !important; left: 0 !important;
    right: 0 !important; bottom: 0 !important; transform: none !important;
    width: 100% !important; max-width: none !important;
    height: 100vh !important; height: 100dvh !important;
    max-height: 100dvh !important; border: 0 !important;
    border-radius: 0 !important; box-shadow: none !important;
    background: #f8fafc !important;
    font-family: Quicksand, system-ui, sans-serif !important;
  }
  #section-practice .practice-mobile-header {
    background: #fff !important; border-color: #f1f5f9 !important;
    padding: max(10px, env(safe-area-inset-top)) 14px 8px !important;
  }
  #arena-question-card { background: #f8fafc !important; }
  .arena-question-scrollable {
    background: #f8fafc !important; padding: 10px 14px 16px !important;
    gap: 10px !important; justify-content: flex-start !important;
    touch-action: pan-y !important;
  }
  .arena-question-scrollable > div:has(#question-story), .question-story-card {
    background: #fff !important; border: 1px solid #f1f5f9 !important;
    border-radius: 11px !important; padding: 12px !important;
    box-shadow: 0 4px 14px rgba(0,0,0,.05) !important;
  }
  #question-story { font-size: 19px !important; line-height: 1.45 !important; }
  #visual-model-area:not(:empty):not(.hidden) {
    background: #f0f9ff !important; border: 1px solid #e0f2fe !important;
    border-radius: 11px !important; padding: 8px !important;
    max-height: none !important;
  }
  #visual-model-area svg, #visual-model-area img {
    max-height: min(230px, 29dvh) !important; object-fit: contain !important;
  }
  #quiz-options:not(.hidden), #multi-options-container {
    grid-template-columns: repeat(2,minmax(0,1fr)) !important;
    gap: 8px !important;
  }
  #quiz-options.options-single-column,
  #multi-options-container.options-single-column {
    grid-template-columns: minmax(0,1fr) !important;
  }
  #quiz-options button, #multi-options-container button,
  #multi-options-container .multi-option-card {
    background: #fff; border-radius: 11px !important; min-height: 52px !important;
    padding: 10px !important; max-width: 100% !important;
    overflow-wrap: anywhere !important; white-space: normal !important;
  }
  #quiz-options button > div, #multi-options-container button > div {
    min-width: 0 !important; max-width: 100% !important;
  }
  #quiz-options button span, #multi-options-container button span {
    white-space: normal !important; overflow-wrap: anywhere !important;
    word-break: normal !important;
  }
  #quiz-options button span.text-on-surface,
  #multi-options-container button span.text-on-surface {
    font-size: 17px !important; line-height: 1.4 !important;
  }
  #arena-action-buttons {
    background: #fff !important; border-top: 1px solid #f1f5f9 !important;
    padding-bottom: max(10px,env(safe-area-inset-bottom)) !important;
  }
}

/* Mobile feedback state: replace the action bar with the next-question panel.
   Prevents the feedback from being pushed below the fixed action footer. */
@media (max-width:767px) {
  #arena-question-card:has(#result-banner:not(.hidden)) #arena-action-buttons {
    display: none !important;
  }
  #arena-question-card #result-banner:not(.hidden) {
    position: relative !important;
    z-index: 6 !important;
    flex: 0 0 auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-height: min(42dvh, 260px) !important;
    overflow-y: auto !important;
    border-radius: 0 !important;
    border-top: 1px solid #e4e2de !important;
    padding: 10px 14px max(12px, env(safe-area-inset-bottom)) !important;
    background: #fff !important;
  }
  #arena-question-card #btn-next-question {
    width: 100% !important;
    min-height: 48px !important;
    flex-shrink: 0 !important;
  }
}

/* Wrong answers are non-blocking inline feedback, not the final-result footer. */
@media (max-width:767px) {
  #arena-question-card.practice-wrong-answer #arena-action-buttons:not(.hidden) {
    display: grid !important;
  }
  #arena-question-scrollable > #result-banner:not(.hidden) {
    position: static !important;
    z-index: auto !important;
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    flex: 0 0 auto !important;
    border: 1px solid #f0dfc3 !important;
    border-radius: 12px !important;
    margin: 8px 0 12px !important;
    padding: 12px !important;
    background: #fffaf1 !important;
  }
  #arena-question-card.practice-wrong-answer #result-banner #btn-next-question {
    min-height: 42px !important;
    height: auto !important;
  }
}

/* High-contrast answer reveal: mobile only. Keep desktop grading/UI unchanged. */
@media (max-width:767px) {
  #quiz-options .quiz-card.mobile-answer-correct,
  #multi-options-container .multi-option-card.mobile-answer-correct,
  #custom-number-input.mobile-answer-correct {
    background: #bbf7d0 !important;
    border: 3px solid #059669 !important;
    box-shadow: 0 4px 0 #047857 !important;
    color: #064e3b !important;
    opacity: 1 !important;
  }
  #quiz-options .quiz-card.mobile-answer-wrong,
  #multi-options-container .multi-option-card.mobile-answer-wrong,
  #custom-number-input.mobile-answer-wrong {
    background: #fecaca !important;
    border: 3px solid #dc2626 !important;
    box-shadow: 0 4px 0 #b91c1c !important;
    color: #7f1d1d !important;
    opacity: 1 !important;
  }
  #quiz-options .quiz-card.mobile-answer-correct *,
  #multi-options-container .multi-option-card.mobile-answer-correct *,
  #quiz-options .quiz-card.mobile-answer-wrong *,
  #multi-options-container .multi-option-card.mobile-answer-wrong * {
    color: inherit !important;
  }
  #quiz-options .quiz-card.mobile-answer-correct .check-icon::after { content: ' ✓'; }
  #quiz-options .quiz-card.mobile-answer-wrong .check-icon::after { content: ' ✕'; }
  #quiz-options .quiz-card[disabled] { cursor: default !important; }
  #arena-question-card #result-banner.hidden { display: none !important; }
}

/* Answer feedback must never resize the existing option cards.
   Color-only state: preserve original padding, border width, typography and grid. */
@media (max-width:767px) {
  #quiz-options .quiz-card.mobile-answer-correct,
  #multi-options-container .multi-option-card.mobile-answer-correct,
  #custom-number-input.mobile-answer-correct {
    border-width: 1px !important;
    border-color: #059669 !important;
    outline: 2px solid #059669 !important;
    outline-offset: -2px !important;
    box-shadow: 0 4px 0 #047857 !important;
    transform: none !important;
  }
  #quiz-options .quiz-card.mobile-answer-wrong,
  #multi-options-container .multi-option-card.mobile-answer-wrong,
  #custom-number-input.mobile-answer-wrong {
    border-width: 1px !important;
    border-color: #dc2626 !important;
    outline: 2px solid #dc2626 !important;
    outline-offset: -2px !important;
    box-shadow: 0 4px 0 #b91c1c !important;
    transform: none !important;
  }
  #quiz-options .quiz-card.mobile-answer-correct .check-icon::after,
  #quiz-options .quiz-card.mobile-answer-wrong .check-icon::after {
    content: none !important;
  }
  #quiz-options .quiz-card.mobile-answer-correct .check-icon,
  #quiz-options .quiz-card.mobile-answer-wrong .check-icon {
    font-size: 20px !important;
    flex-shrink: 0 !important;
  }
  #quiz-options .quiz-card.mobile-answer-correct > div,
  #quiz-options .quiz-card.mobile-answer-wrong > div {
    min-width: 0 !important;
  }
}

/* Nút Bật/Tắt âm thanh rèn luyện */
.sound-toggle-btn {
  touch-action: manipulation;
  user-select: none;
  transition: all 0.2s ease;
}
.sound-toggle-btn:active {
  transform: scale(0.95);
}
.sound-toggle-btn.sound-off {
  opacity: 0.65;
  filter: grayscale(0.5);
}

