/* YHW Listening Master v1.0 — Frontend CSS */
:root {
  --yhwl-primary:   #4f46e5;
  --yhwl-primary-h: #4338ca;
  --yhwl-success:   #10b981;
  --yhwl-danger:    #ef4444;
  --yhwl-warning:   #f59e0b;
  --yhwl-text:      #1e1e2e;
  --yhwl-muted:     #64748b;
  --yhwl-bg:        #f8faff;
  --yhwl-card:      #ffffff;
  --yhwl-border:    #e2e8f0;
  --yhwl-radius:    14px;
  --yhwl-shadow:    0 2px 12px rgba(79,70,229,.08);
}

.yhwl-wrapper {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--yhwl-text);
  line-height: 1.7;
  max-width: 860px;
  margin: 0 auto;
  box-sizing: border-box;
}
.yhwl-wrapper *, .yhwl-wrapper *::before, .yhwl-wrapper *::after { box-sizing: border-box; }
.yhwl-error { background:#fef2f2;border:1px solid #fecaca;border-radius:8px;padding:12px 16px;color:#b91c1c; }

/* ════ PLAYER BAR ════ */
.yhwl-player-bar {
  background: linear-gradient(135deg, #3730a3 0%, #4f46e5 100%);
  border-radius: var(--yhwl-radius) var(--yhwl-radius) 0 0;
  padding: 18px 20px;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 4px 20px rgba(79,70,229,.35);
}
.yhwl-player-inner { max-width: 100%; }

/* Play controls row */
.yhwl-play-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.yhwl-btn-play, .yhwl-btn-back, .yhwl-btn-fwd {
  background: rgba(255,255,255,.15);
  border: 1.5px solid rgba(255,255,255,.3);
  color: #fff;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}
.yhwl-btn-play { padding: 10px 22px; font-size: 16px; }
.yhwl-btn-play:hover, .yhwl-btn-back:hover, .yhwl-btn-fwd:hover {
  background: rgba(255,255,255,.28);
  transform: translateY(-1px);
}
.yhwl-speed-wrap select.yhwl-speed-select {
  background: rgba(255,255,255,.15);
  border: 1.5px solid rgba(255,255,255,.3);
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
.yhwl-speed-select option { color: #1e1e2e; background: #fff; }
.yhwl-play-count {
  font-size: 13px;
  background: rgba(255,255,255,.15);
  border-radius: 8px;
  padding: 6px 12px;
  white-space: nowrap;
}
.yhwl-play-count strong { color: #fde68a; }

/* Progress bar */
.yhwl-progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.yhwl-time-cur, .yhwl-time-dur {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: .85;
  white-space: nowrap;
  min-width: 36px;
}
.yhwl-progress-bar-wrap {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,.2);
  border-radius: 99px;
  position: relative;
  cursor: grab;
  /* Touch target lớn hơn mà không ảnh hưởng visual */
  padding: 8px 0;
  margin: -8px 0;
  box-sizing: content-box;
}
.yhwl-progress-bar {
  height: 100%;
  background: #a5b4fc;
  border-radius: 99px;
  width: 0%;
  pointer-events: none;
  transition: width .2s linear;
}
.yhwl-progress-handle {
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 50%; left: 0%;
  transform: translate(-50%,-50%);
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  transition: left .2s linear, width .15s, height .15s, box-shadow .15s;
}
/* Khi đang kéo: handle to hơn, cursor thay đổi */
.yhwl-progress-bar-wrap.yhwl-seeking { cursor: grabbing; }
.yhwl-progress-bar-wrap.yhwl-seeking .yhwl-progress-handle,
.yhwl-progress-bar-wrap:hover .yhwl-progress-handle {
  width: 18px; height: 18px;
  box-shadow: 0 0 0 4px rgba(165,180,252,.5), 0 2px 6px rgba(0,0,0,.3);
  transition: width .1s, height .1s, box-shadow .1s;
}
/* Pause transition khi đang seek để không lag */
.yhwl-progress-bar-wrap.yhwl-seeking .yhwl-progress-bar,
.yhwl-progress-bar-wrap.yhwl-seeking .yhwl-progress-handle {
  transition: none;
}

/* ── Section audio player — thanh đỏ (chỉ override màu bar) ── */
.yhwl-sec-player { margin-bottom: 14px; border-radius: 10px; overflow: hidden; }
.yhwl-sec-player .yhwl-player-bar { border-radius: 10px; position: static; box-shadow: none; }
.yhwl-sec-progress-bar { background: #ef4444; }

.yhwl-section-marker {
  position: absolute;
  top: -4px;
  width: 3px; height: 14px;
  background: #fde68a;
  border-radius: 2px;
  transform: translateX(-50%);
  cursor: default;
}
.yhwl-section-marker::after {
  content: attr(title);
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.75);
  color: #fff;
  font-size: 10px;
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.yhwl-section-marker:hover::after { opacity: 1; }

/* YouTube / SoundCloud */
.yhwl-yt-frame {
  /* Player cần tồn tại trong DOM với kích thước ≥1px để API hoạt động */
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}
.yhwl-yt-wrap { position: relative; }
.yhwl-sc-frame { width: 100%; height: 80px; border: none; border-radius: 8px; }

/* ════ QUESTIONS AREA ════ */
.yhwl-questions-area {
  background: var(--yhwl-bg);
  padding: 20px 16px;
}

/* Section block */
.yhwl-section-block {
  background: var(--yhwl-card);
  border: 1px solid var(--yhwl-border);
  border-radius: var(--yhwl-radius);
  margin-bottom: 20px;
  box-shadow: var(--yhwl-shadow);
  overflow: hidden;
}
.yhwl-section-title {
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.yhwl-type-fill_blank .yhwl-section-title   { background: linear-gradient(135deg,#0369a1,#0ea5e9); }
.yhwl-type-tfng .yhwl-section-title          { background: linear-gradient(135deg,#059669,#10b981); }
.yhwl-type-matching .yhwl-section-title      { background: linear-gradient(135deg,#b45309,#f59e0b); }
.yhwl-type-note_completion .yhwl-section-title { background: linear-gradient(135deg,#6d28d9,#8b5cf6); }
.yhwl-type-short_answer .yhwl-section-title  { background: linear-gradient(135deg,#be185d,#ec4899); }
.yhwl-type-map_labelling .yhwl-section-title { background: linear-gradient(135deg,#0d9488,#14b8a6); }
.yhwl-section-range { margin-left: auto; font-size: 12px; opacity: .85; white-space: nowrap; }
.yhwl-play-section-btn {
  background: rgba(255,255,255,.2); border: 1.5px solid rgba(255,255,255,.4);
  color: #fff; border-radius: 8px; padding: 4px 10px; font-size: 16px; cursor: pointer;
  transition: background .15s;
}
.yhwl-play-section-btn:hover { background: rgba(255,255,255,.35); }
.yhwl-section-instruction {
  font-size: 14px; color: var(--yhwl-muted); font-style: italic;
  padding: 12px 18px 4px; border-bottom: 1px solid var(--yhwl-border);
}

/* Question block */
.yhwl-question-block {
  padding: 16px 18px;
  border-bottom: 1px solid var(--yhwl-border);
  transition: background .15s;
}
.yhwl-question-block:last-child { border-bottom: none; }
.yhwl-question-block.yhwl-answered-correct { background: #f0fdf4; border-left: 4px solid var(--yhwl-success); }
.yhwl-question-block.yhwl-answered-wrong   { background: #fff1f2; border-left: 4px solid var(--yhwl-danger); }
.yhwl-question-block.yhwl-answered-skip    { background: #f8faff; border-left: 4px solid #cbd5e1; }
.yhwl-q-num        { font-weight: 800; color: var(--yhwl-primary); font-size: 13px; margin-right: 4px; }
.yhwl-q-num-label  { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--yhwl-primary); margin-bottom: 6px; }
.yhwl-multi-badge  { font-size: 10px; background: #e0e7ff; color: #4f46e5; border-radius: 6px; padding: 2px 7px; font-weight: 700; }
.yhwl-q-text       { font-size: 16px; font-weight: 600; margin-bottom: 14px; line-height: 1.55; }
.yhwl-q-statement  { font-size: 15px; color: var(--yhwl-text); margin: 6px 0 12px; }
.yhwl-q-instruction{ font-size: 14px; color: var(--yhwl-muted); font-style: italic; margin-bottom: 8px; }

/* Multiple Choice */
.yhwl-mc-options { display: flex; flex-direction: column; gap: 8px; }
.yhwl-mc-option {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 10px;
  border: 2px solid var(--yhwl-border);
  background: var(--yhwl-bg); cursor: pointer;
  transition: all .15s; font-size: 15px;
}
.yhwl-mc-option:hover:not(.yhwl-locked *) { border-color: var(--yhwl-primary); background: #eef2ff; }
.yhwl-mc-option.yhwl-selected             { border-color: var(--yhwl-primary); background: #e0e7ff; }
.yhwl-mc-option.yhwl-mc-correct           { border-color: var(--yhwl-success); background: #d1fae5; }
.yhwl-mc-option.yhwl-mc-wrong             { border-color: var(--yhwl-danger);  background: #fee2e2; }
.yhwl-mc-letter {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--yhwl-card); border: 2px solid var(--yhwl-border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0; color: var(--yhwl-muted);
}
.yhwl-mc-option.yhwl-selected   .yhwl-mc-letter { background: var(--yhwl-primary); color: #fff; border-color: var(--yhwl-primary); }
.yhwl-mc-option.yhwl-mc-correct .yhwl-mc-letter { background: var(--yhwl-success); color: #fff; border-color: var(--yhwl-success); }
.yhwl-mc-option.yhwl-mc-wrong   .yhwl-mc-letter { background: var(--yhwl-danger);  color: #fff; border-color: var(--yhwl-danger); }
.yhwl-mc-text { flex: 1; }

/* T/F/NG */
.yhwl-tfng-options { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.yhwl-tfng-btn {
  padding: 10px 22px;
  border-radius: 10px;
  border: 2.5px solid var(--yhwl-border);
  background: var(--yhwl-bg);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  color: var(--yhwl-muted);
  transition: all .15s;
  user-select: none;
  font-family: inherit;
  letter-spacing: .3px;
}
.yhwl-tfng-btn:hover:not(:disabled)  { border-color: var(--yhwl-primary); background: #e0e7ff; color: var(--yhwl-primary); transform: translateY(-1px); }
.yhwl-tfng-btn.yhwl-selected         { border-color: var(--yhwl-primary); background: #e0e7ff; color: var(--yhwl-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.18); }
.yhwl-tfng-btn.yhwl-tfng-correct     { border-color: var(--yhwl-success); background: #d1fae5; color: #065f46; }
.yhwl-tfng-btn.yhwl-tfng-wrong       { border-color: var(--yhwl-danger);  background: #fee2e2; color: #991b1b; }
.yhwl-tfng-btn.yhwl-tfng-ng          { border-color: #a5b4fc; color: #4f46e5; }
.yhwl-tfng-btn.yhwl-tfng-ng.yhwl-selected { border-color: #6366f1; background: #e0e7ff; color: #3730a3; }
.yhwl-locked .yhwl-tfng-btn          { cursor: default; }

/* Fill / Note / Short Answer */
.yhwl-fill-list { padding: 8px 0; }
.yhwl-fill-block { }
.yhwl-fill-row { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; font-size: 15px; }
.yhwl-fill-question { flex: 1; color: var(--yhwl-text); font-size: 15px; }
.yhwl-note-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.yhwl-note-label { font-size: 14px; color: var(--yhwl-muted); font-weight: 600; min-width: 140px; }
.yhwl-fill-input {
  width: 100%; padding: 9px 12px;
  border: 2px solid var(--yhwl-border); border-radius: 10px;
  font-size: 15px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
  background: var(--yhwl-bg);
  margin-top: 6px;
}
.yhwl-note-row .yhwl-fill-input { width: auto; flex: 1; min-width: 120px; margin-top: 0; }
.yhwl-fill-input:focus { outline: none; border-color: var(--yhwl-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.yhwl-fill-input.yhwl-input-correct { border-color: var(--yhwl-success); background: #f0fdf4; color: #065f46; }
.yhwl-fill-input.yhwl-input-wrong   { border-color: var(--yhwl-danger);  background: #fff1f2; color: #991b1b; }
.yhwl-answer-hint {
  margin-top: 6px; font-size: 13px; color: #065f46;
  background: #d1fae5; border-radius: 7px; padding: 5px 12px;
  display: inline-block;
}

/* Matching */
.yhwl-matching-col-a { display: flex; flex-direction: column; gap: 10px; }
.yhwl-matching-item-a {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 10px;
  border: 2px solid var(--yhwl-border); background: var(--yhwl-bg);
}
.yhwl-matching-item-a.yhwl-match-ok  { border-color: var(--yhwl-success); background: #f0fdf4; }
.yhwl-matching-item-a.yhwl-match-err { border-color: var(--yhwl-danger);  background: #fff1f2; }
.yhwl-match-num  { font-weight: 800; color: var(--yhwl-primary); min-width: 28px; }
.yhwl-match-text-a { flex: 1; font-size: 15px; }
.yhwl-match-answer-slot { flex-shrink: 0; }
.yhwl-match-select {
  padding: 7px 10px; border: 2px solid var(--yhwl-border);
  border-radius: 8px; font-size: 14px; background: var(--yhwl-card);
  cursor: pointer; min-width: 140px;
}
.yhwl-match-hint {
  font-size: 12px; color: #065f46; font-weight: 700;
  background: #d1fae5; border-radius: 6px; padding: 3px 8px;
  white-space: nowrap;
}

/* Map image */
.yhwl-map-image-wrap { padding: 14px 18px 0; }
.yhwl-map-image { max-width: 100%; border-radius: 10px; border: 1px solid var(--yhwl-border); box-shadow: var(--yhwl-shadow); }

/* Explain box */
.yhwl-explain-box {
  display: flex; gap: 8px; align-items: flex-start;
  background: #fef9c3; border: 1px solid #fde047; border-radius: 8px;
  padding: 8px 12px; margin-top: 10px; font-size: 13px; color: #713f12;
}

/* ════ SUBMIT ════ */
.yhwl-submit-wrap {
  background: var(--yhwl-card); border: 1px solid var(--yhwl-border);
  border-radius: 0 0 var(--yhwl-radius) var(--yhwl-radius);
  padding: 18px 20px; display: flex; align-items: center;
  justify-content: space-between; gap: 14px; flex-wrap: wrap;
  box-shadow: var(--yhwl-shadow);
}
.yhwl-submit-status { font-size: 15px; color: var(--yhwl-muted); font-weight: 500; }
.yhwl-submit-status strong { color: var(--yhwl-primary); }

/* ════ BUTTONS ════ */
.yhwl-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 26px; border-radius: 99px; border: none;
  cursor: pointer; font-size: 15px; font-weight: 600;
  transition: all .2s; background: var(--yhwl-primary); color: #fff;
}
.yhwl-btn:hover { background: var(--yhwl-primary-h); transform: translateY(-1px); box-shadow: 0 5px 18px rgba(79,70,229,.3); }
.yhwl-btn-outline { background: transparent; color: var(--yhwl-primary); border: 2px solid var(--yhwl-primary); }
.yhwl-btn-outline:hover { background: var(--yhwl-primary); color: #fff; }
.yhwl-btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ════ RESULT ════ */
.yhwl-result-wrap { margin-top: 20px; }
.yhwl-result-card {
  background: var(--yhwl-card); border-radius: var(--yhwl-radius);
  box-shadow: 0 8px 32px rgba(79,70,229,.12); padding: 36px 28px;
  text-align: center; border: 1px solid var(--yhwl-border);
  max-width: 500px; margin: 0 auto 24px;
}
.yhwl-result-card.yhwl-pass { border-color: var(--yhwl-success); box-shadow: 0 8px 32px rgba(16,185,129,.2); }
.yhwl-result-card.yhwl-fail { border-color: var(--yhwl-danger);  box-shadow: 0 8px 32px rgba(239,68,68,.2); }
.yhwl-result-badge { font-size: 60px; display: block; margin-bottom: 8px; }
.yhwl-result-title { font-size: 24px; font-weight: 700; margin: 0 0 16px; }
.yhwl-score-circle { position: relative; width: 130px; height: 130px; margin: 0 auto 20px; }
.yhwl-score-circle svg { width: 120px; height: 120px; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); }
.yhwl-score-ring { transition: stroke-dashoffset 1s cubic-bezier(.4,0,.2,1); }
.yhwl-score-inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.yhwl-score-pct { font-size: 28px; font-weight: 800; color: var(--yhwl-primary); }
.yhwl-score-lbl { font-size: 11px; color: var(--yhwl-muted); font-weight: 600; }
.yhwl-result-stats { display: flex; justify-content: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.yhwl-stat { background: var(--yhwl-bg); border-radius: 10px; padding: 12px 18px; text-align: center; min-width: 72px; }
.yhwl-stat-n { font-size: 24px; font-weight: 800; display: block; color: var(--yhwl-primary); }
.yhwl-stat-l { font-size: 12px; color: var(--yhwl-muted); display: block; }
.yhwl-stat-correct .yhwl-stat-n { color: var(--yhwl-success); }
.yhwl-stat-wrong   .yhwl-stat-n { color: var(--yhwl-danger); }
.yhwl-result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ════ TRANSCRIPT ════ */
.yhwl-transcript-box {
  background: var(--yhwl-card); border: 1px solid var(--yhwl-border);
  border-radius: var(--yhwl-radius); padding: 20px; margin-top: 16px;
  box-shadow: var(--yhwl-shadow);
}
.yhwl-transcript-label { font-weight: 700; font-size: 15px; color: var(--yhwl-primary); margin-bottom: 12px; }
.yhwl-transcript-text  { font-size: 15px; line-height: 1.9; color: var(--yhwl-text); white-space: pre-wrap; }
.yhwl-transcript-toggle { text-align: center; margin-bottom: 12px; }
mark.yhwl-transcript-highlight {
  background: #fef08a; color: #713f12;
  border-radius: 3px; padding: 0 2px;
}

/* ════ RESPONSIVE ════ */
@media (max-width: 600px) {
  .yhwl-player-bar { padding: 12px 12px; border-radius: 10px 10px 0 0; position: static; }
  .yhwl-play-row   { gap: 7px; }
  .yhwl-btn-play   { padding: 8px 16px; font-size: 14px; }
  .yhwl-btn-back, .yhwl-btn-fwd { padding: 7px 12px; font-size: 13px; }
  .yhwl-mc-options { gap: 7px; }
  .yhwl-mc-option  { padding: 9px 11px; font-size: 14px; }
  .yhwl-tfng-options { gap: 8px; }
  .yhwl-tfng-btn   { padding: 7px 14px; font-size: 13px; }
  .yhwl-fill-input { font-size: 16px; } /* Prevent iOS zoom */
  .yhwl-match-select { font-size: 14px; min-width: 100px; }
  .yhwl-matching-item-a { flex-direction: column; align-items: flex-start; gap: 8px; }
  .yhwl-questions-area { padding: 12px 10px; }
  .yhwl-question-block { padding: 13px 12px; }
  .yhwl-result-card    { padding: 24px 16px; }
}
@media (max-width: 400px) {
  .yhwl-result-stats { gap: 8px; }
  .yhwl-stat { padding: 10px 12px; min-width: 60px; }
}
