/* ============================================================
   Shadowing Portal — giao diện
   Bảng màu / kích thước lấy đúng theo UI_Styling.md của
   portal Transcription (05- Transcription Portal).
   ============================================================ */

:root {
  /* Nền gradient 4 màu (house style) */
  --bg-1: #ee7752;
  --bg-2: #e73c7e;
  --bg-3: #23a6d5;
  --bg-4: #23d5ab;

  /* Card kính */
  --card-bg: rgba(255, 255, 255, 0.1);
  --card-border: rgba(255, 255, 255, 0.2);
  --card-shadow: 0 16px 40px rgba(0, 0, 0, 0.1);

  /* Ô nhập */
  --input-bg: rgba(255, 255, 255, 0.05);
  --input-border: rgba(255, 255, 255, 0.3);

  /* Nút */
  --green: #27ae60;
  --green-dark: #219a52;
  --pink: #e73c7e;

  /* Trạng thái từ — bảng màu mặc định: KHÔNG dùng đỏ */
  --word-ro: #2ed573;
  --word-hoi-nhe: #f39c12;
  --word-doc-lai: #d9822b;
  --word-thieu: #d9822b;

  --radius: 12px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Bảng màu thay thế: đỏ (bật trong bảng thử nghiệm) */
[data-palette="red"] {
  --word-doc-lai: #e74c3c;
  --word-thieu: #e74c3c;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;

  font-family: "Outfit", -apple-system, sans-serif;
  color: #fff;

  background-image: linear-gradient(-45deg, var(--bg-1), var(--bg-2), var(--bg-3), var(--bg-4));
  background-size: 400% 400%;
  animation: gradientBG 15s ease infinite;
}

/* Lớp phủ tối nhẹ: giữ đúng card kính nhưng bảo đảm chữ và màu từ đọc rõ */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 0%, rgba(0, 0, 0, 0.16), rgba(0, 0, 0, 0.44));
  pointer-events: none;
  z-index: 0;
}

@keyframes gradientBG {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ---------------- Card ---------------- */

.card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  margin-block: auto;
  padding: 48px 40px;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  box-shadow: var(--card-shadow);
}

/* ---------------- Màn hình ---------------- */

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

.screen.is-enter {
  animation: slideIn 0.32s ease both;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.title {
  margin: 0 0 10px;
  font-size: 1.8rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  outline: none;
}

/* Màn 5: gạch nhấn để đổi giọng phần đầu */
.title--retry::after {
  content: "";
  display: block;
  width: 44px;
  height: 3px;
  margin-top: 12px;
  border-radius: 2px;
  background: var(--pink);
}

.helper {
  margin: 0 0 20px;
  font-size: 0.95rem;
  font-weight: 300;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.85);
}

.subtitle {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
}

/* ---------------- Ô nhập ---------------- */

.input {
  width: 100%;
  min-height: 132px;
  margin-bottom: 16px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: #fff;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  outline: none;
  resize: vertical;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.input:focus {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.1);
}

/* ---------------- Nút ---------------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.2;
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease),
    transform 0.2s var(--ease), box-shadow 0.2s var(--ease), opacity 0.2s var(--ease);
}

.btn + .btn {
  margin-top: 10px;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: scale(0.96);
}

.btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: var(--green);
}

.btn--primary:hover:not(:disabled) {
  background: var(--green-dark);
  box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.28);
}

.btn--ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.25);
}

.btn--sm {
  min-height: 44px;
  width: auto;
  padding: 10px 16px;
  font-size: 0.9rem;
}

.btn svg {
  flex: 0 0 auto;
}

/* ---------------- Câu tiếng Anh (màn 2) ---------------- */

.sentence-box {
  margin-bottom: 16px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius);
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.sentence-box p {
  margin: 0;
  font-size: clamp(1.25rem, 5.4vw, 1.6rem);
  font-weight: 500;
  line-height: 1.35;
}

.sentence-box.is-locked {
  background: rgba(255, 255, 255, 0.14);
}

.lock-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 16px;
  padding: 14px 16px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
}

.lock-note svg {
  flex: 0 0 auto;
  margin-top: 1px;
}

/* ---------------- Hàng điều khiển ---------------- */

.row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 16px;
}

.row .btn {
  flex: 1 1 auto;
  width: auto;
}

.speed {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.speed__label {
  font-size: 0.8rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
}

.speed__opts {
  display: flex;
  gap: 6px;
}

.speed__btn {
  min-width: 52px;
  min-height: 44px;
  padding: 0 10px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.speed__btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.speed__btn[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.6);
}

/* ---------------- Câu mẫu có highlight (màn 3 & 5) ---------------- */

.ref {
  position: relative;
  margin-bottom: 16px;
  padding: 18px 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius);
}

.ref__lock {
  position: absolute;
  top: 12px;
  right: 12px;
  color: rgba(255, 255, 255, 0.6);
  line-height: 0;
}

.ref__text {
  display: flex;
  flex-wrap: wrap;
  margin: 0;
  padding-right: 24px;
  font-size: clamp(1.15rem, 4.8vw, 1.4rem);
  font-weight: 500;
  line-height: 1.45;
}

.ref-word {
  margin-right: 0.26em;
  padding: 2px 4px;
  border-radius: 6px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: background-color 0.1s linear, color 0.1s linear;
}

.ref-word.is-speaking {
  background: rgba(255, 255, 255, 0.3);
}

/* ---------------- Ghi âm ---------------- */

.rec {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 8px 0 16px;
}

.rec__timer {
  font-size: 2.2rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.rec__btn {
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  color: var(--pink);
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(255, 255, 255, 0.2);
  transition: transform 0.2s var(--ease), background-color 0.2s var(--ease),
    border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), color 0.2s var(--ease);
}

.rec__btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 255, 255, 0.3);
}

.rec__btn:active:not(:disabled) {
  transform: scale(0.96);
}

.rec__btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 4px;
}

.rec__btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.rec__btn.is-recording {
  color: #fff;
  background: rgba(255, 71, 87, 0.15);
  border-color: rgba(255, 71, 87, 0.5);
  animation: pulse 2s infinite;
}

.rec__btn .icon-stop {
  display: none;
}

.rec__btn.is-recording .icon-mic {
  display: none;
}

.rec__btn.is-recording .icon-stop {
  display: block;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.45); }
  50% { box-shadow: 0 0 0 16px rgba(255, 71, 87, 0); }
}

.rec__label {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
}

/* ---------------- Hộp trạng thái ---------------- */

.status {
  padding: 14px 16px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
}

.status p {
  margin: 0 0 10px;
}

.status p:last-child {
  margin-bottom: 0;
}

.status--busy {
  display: flex;
  align-items: center;
  gap: 10px;
}

.spinner {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------------- Từ (màn 4) ---------------- */

.words {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -6px 16px;
  font-size: clamp(1.25rem, 5.6vw, 1.5rem);
  font-weight: 600;
  line-height: 1.3;
}

.words--sm {
  margin: 0 -6px;
  font-size: 1.05rem;
  font-weight: 500;
}

.word {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  padding: 6px 6px;
  font: inherit;
  color: #fff;
  text-align: left;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s var(--ease);
}

.word:hover {
  background: rgba(255, 255, 255, 0.14);
}

.word:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.word.is-replaying {
  background: rgba(255, 255, 255, 0.24);
}

.word--ro {
  color: var(--word-ro);
}

.word--hoiNhe {
  color: var(--word-hoi-nhe);
}

.word--docLai {
  color: var(--word-doc-lai);
  text-decoration: underline dotted;
  text-decoration-color: currentColor;
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
}

.word--thieu {
  color: var(--word-thieu);
  text-decoration: underline dotted;
  text-decoration-color: currentColor;
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
}

/* Dấu chấm nhỏ bên trái: từ không nghe ra — không chỉ dựa vào màu */
.word--thieu::before {
  content: "";
  flex: 0 0 auto;
  width: 5px;
  height: 5px;
  background: currentColor;
  border-radius: 50%;
  opacity: 0.9;
}

/* ---------------- Chi tiết từ ---------------- */

.detail {
  margin-bottom: 16px;
  padding: 14px 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius);
}

/* ---------------- Tổng kết ---------------- */

.summary {
  margin-bottom: 16px;
  padding: 16px 18px;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
}

.rework {
  margin-bottom: 16px;
}

/* ---------------- Footer + bảng thử nghiệm ---------------- */

.footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
}

.dev-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}

.dev-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.22);
}

.dev-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.dev {
  width: min(420px, 92vw);
  padding: 0;
  color: #fff;
  background: rgba(24, 24, 34, 0.9);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.dev::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
}

.dev__inner {
  padding: 20px 20px 22px;
}

.dev__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.dev__head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.dev__close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
}

.dev__close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
}

.dev__label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
}

.dev__note {
  margin: 18px 0 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.6);
}

.seg {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.seg--col {
  flex-direction: column;
  gap: 6px;
}

.seg__btn {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  text-align: left;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.seg--col .seg__btn {
  flex: 0 0 auto;
}

.seg__btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.seg__btn[aria-pressed="true"] {
  color: #fff;
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 255, 255, 0.55);
  font-weight: 600;
}

.seg__btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ---------------- Màn hình hẹp ---------------- */

@media (max-width: 420px) {
  body {
    padding: 16px 12px;
  }

  .card {
    padding: 32px 24px;
  }

  .title {
    font-size: 1.5rem;
  }

  .rec__btn {
    width: 104px;
    height: 104px;
  }
}

/* ---------------- Giảm chuyển động ---------------- */

@media (prefers-reduced-motion: reduce) {
  body {
    animation: none;
  }

  .screen.is-enter {
    animation: none;
  }

  .rec__btn.is-recording,
  .spinner {
    animation: none;
  }

  .btn,
  .word,
  .ref-word,
  .input,
  .speed__btn,
  .seg__btn,
  .rec__btn {
    transition: none;
  }

  .btn:hover,
  .rec__btn:hover:not(:disabled) {
    transform: none;
  }
}
