/* =====================================================
   style.css (FINAL - COPY & USE)
   - PC: main left, nav right (always same row), no nav scrollbar
   - Mobile: nav bottom, one-row horizontal scroll
===================================================== */

/* =========================
   RESET & BASE
========================= */
* { margin: 0; padding: 0; box-sizing: border-box; }

html{
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body{
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: #f4f6f8;
  color: #2c3e50;
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@supports (padding: max(0px)) {
  body{
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* =========================
   HEADER
========================= */
.main-header{
  background: #2c3e50;
  color: #fff;
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}

.header-content{
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-content h2{
  font-size: 20px;
  line-height: 1.2;
  margin: 0;
}

.header-content > div{
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  font-size: 14px;
}

.main-header a{
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06);
}

.main-header a:hover{
  background: rgba(255,255,255,.10);
}

/* =========================
   WRAPPER
========================= */
.quiz-wrapper{
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 16px;
}

/* =========================
   CARD
========================= */
.quiz-card{
  background: #fff;
  border-radius: 16px;
  border: 1px solid #e6e9ee;
  box-shadow: 0 10px 30px rgba(0,0,0,.06);
  padding: 24px;
}

.quiz-card.quiz-standalone{
  max-width: 640px;
  margin: 20px auto;
  text-align: center;
}

/* =====================================================
   QUIZ LAYOUT (PC)
   - Use grid-template-areas to prevent "rơi hàng"
===================================================== */
.quiz-card.quiz-layout{
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: "main nav";
  gap: 22px;
  align-items: start;
}

.quiz-main{ grid-area: main; min-width: 0; }
.quiz-nav { grid-area: nav; }

/* =========================
   NAV (Question list)
========================= */
.quiz-nav{
  position: sticky;
  top: 20px;
  background: #f8f9fb;
  border: 1px solid #e6e9ee;
  border-radius: 16px;
  padding: 16px;

  /* HARD FIX: never show vertical scrollbar inside nav on PC */
  max-height: none;
  overflow: visible;
}

.nav-title{
  font-weight: 900;
  font-size: 15px;
  margin-bottom: 12px;
  color: #2c3e50;
}

.question-nav{
  display: grid;
  grid-template-columns: repeat(5, 44px);
  gap: 10px;

  /* HARD FIX */
  max-height: none;
  overflow: visible;
}

.q-dot{
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;

  font-weight: 900;
  font-size: 13px;
  text-decoration: none !important;

  background: #e9edf2;
  color: #2c3e50;

  border: 2px solid transparent;
  transition: transform .14s ease, background .14s ease, border-color .14s ease;
  user-select: none;
}

.q-dot:hover:not(.current){
  transform: scale(1.06);
}

.q-dot.answered{
  background: #28a745;
  color: #fff;
}

.q-dot.current{
  background: #fff;
  border-color: #2c3e50;
  transform: scale(1.10);
}

/* =========================
   MAIN CONTENT
========================= */
.quiz-header{
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-weight: 900;
}

.quiz-header > div:first-child{
  font-size: 15px;
  color: #2c3e50;
}

#timer{
  background: #fdecea;
  color: #e74c3c;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 14px;
  white-space: nowrap;
}

.quiz-question{
  font-size: 18px;
  font-weight: 900;
  line-height: 1.5;
  margin: 10px 0 16px;
}

/* Options */
.quiz-options{
  display: grid;
  gap: 12px;
}

.quiz-option{
  display: grid;
  grid-template-columns: 22px auto;
  gap: 12px;
  align-items: start;

  padding: 14px 14px;
  border-radius: 14px;
  border: 2px solid #e6e9ee;
  background: #fff;
  cursor: pointer;

  transition: background .14s ease, border-color .14s ease, transform .14s ease;
}

.quiz-option:hover{
  background: #f5faff;
  border-color: #3498db;
}

.quiz-option input{
  transform: scale(1.25);
  margin-top: 4px;
  cursor: pointer;
}

.quiz-option strong{
  font-weight: 900;
}

/* =========================
   ACTION BUTTONS
========================= */
.quiz-actions{
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.quiz-actions button{
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 14px 12px;
  min-height: 48px;

  font-weight: 900;
  font-size: 15px;
  color: #fff;
  cursor: pointer;

  transition: transform .12s ease, filter .12s ease;
}

.quiz-actions button:active{ transform: scale(0.98); }
.quiz-actions button:hover{ filter: brightness(1.03); }

.quiz-actions button[name="cancel_quiz"]{ background: #e74c3c; }
.quiz-actions button[name="submit_answer"]{ background: #3498db; }
.quiz-actions button[name="finish_quiz"]{ background: #28a745; }

/* =========================
   START / RESULT
========================= */
.start-card .start-head{
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.start-card .start-icon{
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: #f0f3f7;
  font-size: 22px;
}

.start-title{ font-weight: 1000; font-size: 22px; }
.start-sub{ color: #6b7785; margin-top: 2px; font-size: 13px; }

.start-meta{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0 10px;
}

.start-meta .meta-item{
  border: 1px solid #e6e9ee;
  background: #f8f9fb;
  border-radius: 14px;
  padding: 12px;
  text-align: left;
}

.meta-label{ font-size: 12px; opacity: .7; }
.meta-value{ font-size: 15px; font-weight: 1000; margin-top: 2px; }

.start-note{
  margin: 14px 0 18px;
  padding: 14px;
  text-align: left;
  border-radius: 14px;
  border: 1px solid #e6e9ee;
  background: #f8f9fb;
  border-left: 4px solid #2c3e50;
}

.start-note ul{ margin-top: 8px; padding-left: 18px; }
.start-note li{ margin: 6px 0; font-size: 14px; }

.start-actions{
  display: flex;
  justify-content: center;
}

.btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  border-radius: 14px;
  border: 1px solid rgba(44,62,80,.18);
  background: #fff;
  color: #2c3e50;

  padding: 14px 18px;
  font-weight: 1000;
  font-size: 16px;

  cursor: pointer;
  user-select: none;
  text-decoration: none;
  box-shadow: 0 10px 20px rgba(0,0,0,.08);
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}

.btn:hover{
  transform: translateY(-2px);
  box-shadow: 0 14px 26px rgba(0,0,0,.12);
}

.btn:active{
  transform: translateY(0);
  box-shadow: 0 10px 20px rgba(0,0,0,.08);
}

.btn-primary{
  color: #fff;
  border: 1px solid rgba(255,255,255,.18);
  background: linear-gradient(135deg, #2c3e50, #34495e);
  box-shadow: 0 14px 28px rgba(44,62,80,.28);
}

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

/* =====================================================
   TABLET
===================================================== */
@media (max-width: 1024px){
  .quiz-wrapper{ margin: 14px auto; padding: 0 14px; }
  .quiz-card{ padding: 20px 16px; }
  .quiz-card.quiz-layout{ grid-template-columns: minmax(0,1fr) 300px; gap: 18px; }
  .question-nav{ grid-template-columns: repeat(5, 42px); }
  .q-dot{ width: 42px; height: 42px; }
}

/* =====================================================
   MOBILE (Quan trọng)
   - Nav số câu FIXED dưới đáy => không làm trang dài
   - Nội dung có padding-bottom để không bị che
   - Không ảnh hưởng PC vì nằm trong media query
===================================================== */
@media (max-width: 768px){

  /* Header gọn */
  .header-content{
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .main-header a{ margin-left: 8px; padding: 6px 10px; }

  /* Layout 1 cột */
  .quiz-card.quiz-layout{
    display: block; /* bỏ grid trên mobile */
  }

  /* Chừa chỗ cho thanh nav fixed dưới đáy */
  .quiz-wrapper{
    padding-bottom: 110px;
  }

  /* Nội dung full-width, không lệch */
  .quiz-card{
    padding: 18px 14px;
    border-radius: 12px;
  }

  /* Timer + header */
  .quiz-header{
    flex-direction: row;
    gap: 10px;
  }
  #timer{ padding: 6px 12px; font-size: 13px; }

  .quiz-question{ font-size: 17px; margin-bottom: 14px; }

  .quiz-option{
    grid-template-columns: 20px auto;
    gap: 10px;
    padding: 12px;
    align-items: center;
  }
  .quiz-option input{ transform: scale(1.15); margin-top: 0; }

  /* Nút dọc cho dễ bấm */
  .quiz-actions{
    flex-direction: column;
    gap: 10px;
  }
  .quiz-actions button{
    width: 100%;
    min-height: 48px;
    font-size: 15px;
  }

  /* ===== NAV FIXED BOTTOM (không làm trang dài) ===== */
  .quiz-nav{
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto !important;

    z-index: 2000;

    margin: 0;
    border-radius: 14px 14px 0 0;
    background: rgba(248,249,251,.98);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    padding: 10px 12px;
    border: 1px solid #e1e4e8;
    box-shadow: 0 -10px 24px rgba(0,0,0,.10);

    max-height: none;
    overflow: hidden;
  }

  .nav-title{
    font-size: 14px;
    margin-bottom: 8px;
  }

  /* Dãy số vuốt ngang */
  .question-nav{
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .question-nav::-webkit-scrollbar{ height: 4px; }
  .question-nav::-webkit-scrollbar-track{ background: #f1f1f1; border-radius: 2px; }
  .question-nav::-webkit-scrollbar-thumb{ background: #cfcfcf; border-radius: 2px; }

  .q-dot{
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    font-size: 13px;
  }

  /* Start screen */
  .start-meta{ grid-template-columns: 1fr; gap: 10px; }
  .quiz-standalone .btn{ min-width: 100%; }
}

/* =====================================================
   PRINT
===================================================== */
@media print{
  .quiz-nav, .quiz-actions, .main-header, .quiz-standalone .btn{ display:none !important; }
  .quiz-card{ box-shadow:none; border:1px solid #ddd; }
  body{ background:#fff; color:#000; }
}