:root {
  --crimson: #a31d38;
  --crimson-deep: #7c1229;
  --ink: #2a1418;
  --ink-soft: #6d5257;
  --paper: #fff8f3;
  --card: #ffffff;
  --line: #f0dcd4;
  --salmon: #f28b77;
  --green: #17936a;
  --amber: #e2a11b;
  --radius: 24px;
  --shadow: 0 14px 40px rgba(124, 18, 41, 0.14);
  --amp: 0;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 50% -180px, #ffd9cf 0%, rgba(255, 217, 207, 0) 70%),
    var(--paper);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-wrap: pretty;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { max-width: 760px; margin: 0 auto; padding: 16px 16px 40px; }

/* ---------- Màn chào ---------- */
.start { display: grid; place-items: center; min-height: calc(100dvh - 56px); }

.start-card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 32px 24px 24px;
  text-align: center;
}

.start-face {
  width: 96px; height: 96px; border-radius: 50%;
  object-fit: cover;
  border: 4px solid #fff;
  box-shadow: 0 0 0 3px var(--crimson), 0 10px 24px rgba(163, 29, 56, 0.25);
}

.eyebrow {
  margin: 16px 0 4px;
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--crimson);
}

h1 { margin: 0; font-size: clamp(1.7rem, 6vw, 2.3rem); line-height: 1.15; font-weight: 800; text-wrap: balance; }
h1 span { color: var(--crimson); }

.lead { margin: 12px auto 20px; max-width: 46ch; color: var(--ink-soft); line-height: 1.6; }

.notice {
  margin: 0 auto 16px; max-width: 52ch;
  padding: 12px 14px; border-radius: 14px;
  background: #fff4d6; border: 1px solid #f1d58a; color: #6b4a00;
  font-size: 0.92rem; line-height: 1.5; text-align: left;
}

#start-form { display: grid; gap: 16px; max-width: 420px; margin: 0 auto; text-align: left; }

.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 0.95rem; }

.login-box { display: grid; gap: 12px; padding: 14px; border-radius: 18px; background: #fff3ee; border: 1px solid var(--line); }

input[type="text"], input[type="password"] {
  width: 100%; padding: 13px 16px;
  border: 2px solid var(--line); border-radius: 14px; background: #fffdfb;
  font-size: 1.05rem; outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--salmon); }

.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chips button {
  padding: 12px 4px; border-radius: 14px;
  border: 2px solid var(--line); background: #fffdfb;
  font-weight: 600; font-size: 0.98rem;
}
.chips button.on { border-color: var(--crimson); background: var(--crimson); color: #fff; }

.btn-primary {
  border: 0; border-radius: 16px; padding: 15px 22px;
  background: var(--crimson); color: #fff; font-weight: 700; font-size: 1.1rem;
  box-shadow: 0 8px 20px rgba(163, 29, 56, 0.28);
  transition: transform 0.12s, background 0.15s;
}
.btn-primary:hover { background: var(--crimson-deep); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: progress; }
.btn-primary.small { padding: 12px 18px; font-size: 1rem; box-shadow: none; }

.btn-link { border: 0; background: none; color: var(--crimson); font-weight: 600; text-decoration: underline; padding: 4px; justify-self: center; }

.btn-ghost {
  border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 14px; font-weight: 600; font-size: 0.9rem; color: var(--ink-soft);
}
.btn-ghost:hover { border-color: var(--salmon); color: var(--ink); }

.small-print {
  margin: 24px auto 0; padding: 16px 0 0 18px; max-width: 54ch;
  border-top: 1px dashed var(--line);
  text-align: left; font-size: 0.84rem; line-height: 1.55; color: var(--ink-soft);
}
.small-print li + li { margin-top: 6px; }
.small-print strong { color: var(--ink); }

/* ---------- Lớp học ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px var(--crimson); }
.brand strong { display: block; font-size: 1.02rem; line-height: 1.2; white-space: nowrap; }
.badge-ai {
  display: inline-block; margin-top: 2px; padding: 2px 8px; border-radius: 999px;
  background: #ffe7df; color: var(--crimson-deep); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
}
.top-actions { display: flex; gap: 8px; flex-shrink: 0; }

.demo-banner {
  margin-bottom: 12px; padding: 9px 14px; border-radius: 12px;
  background: #fff4d6; border: 1px solid #f1d58a; color: #6b4a00;
  font-size: 0.88rem; font-weight: 600; text-align: center;
}

.stage {
  position: relative; overflow: hidden;
  aspect-ratio: 1100 / 862;
  max-height: min(56dvh, 600px);
  width: 100%;
  border-radius: var(--radius);
  background: #7c1229;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.poses { position: absolute; inset: 0; animation: breathe 5.5s ease-in-out infinite; transform-origin: 50% 70%; }
.stage[data-phase="talking"] .poses { animation: talk-bob 1.9s ease-in-out infinite; }

.pose {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 36%;
  opacity: 0; transition: opacity 0.42s ease;
}
.pose.on { opacity: 1; }

@keyframes breathe { 0%, 100% { transform: scale(1.015); } 50% { transform: scale(1.035); } }
@keyframes talk-bob {
  0%, 100% { transform: scale(1.03) translateY(0); }
  30% { transform: scale(1.045) translateY(-0.5%); }
  65% { transform: scale(1.035) translateY(0.3%); }
}

.stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: linear-gradient(180deg, rgba(42, 12, 20, 0) 62%, rgba(42, 12, 20, 0.55) 100%);
}

.status {
  position: absolute; left: 14px; bottom: 14px; z-index: 2;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(30, 10, 16, 0.68); color: #fff;
  font-weight: 600; font-size: 0.92rem;
  backdrop-filter: blur(6px);
}
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: #bbb; }
.stage[data-phase="talking"] .dot { background: var(--salmon); animation: pulse 0.9s ease-in-out infinite; }
.stage[data-phase="listening"] .dot { background: #3ddc97; animation: pulse 0.9s ease-in-out infinite; }
.stage[data-phase="thinking"] .dot { background: var(--amber); animation: pulse 0.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.6); opacity: 0.55; } }

.wave { position: absolute; right: 16px; bottom: 16px; z-index: 2; display: flex; align-items: flex-end; gap: 4px; height: 30px; opacity: 0; transition: opacity 0.2s; }
.stage[data-phase="talking"] .wave { opacity: 1; }
.wave i { width: 5px; border-radius: 3px; background: #fff; height: 30%; animation: bar 0.7s ease-in-out infinite; }
.wave i:nth-child(2) { animation-delay: 0.12s; }
.wave i:nth-child(3) { animation-delay: 0.26s; }
.wave i:nth-child(4) { animation-delay: 0.08s; }
.wave i:nth-child(5) { animation-delay: 0.2s; }
@keyframes bar { 0%, 100% { height: 22%; } 50% { height: 100%; } }
/* Khi có âm lượng thật (giọng thầy), sóng chạy theo âm lượng */
.stage[data-amp] .wave i { animation: none; height: calc(18% + var(--amp) * 82%); transition: height 0.07s linear; }
.stage[data-amp] .wave i:nth-child(odd) { height: calc(14% + var(--amp) * 60%); }

.level-chip {
  position: absolute; right: 14px; top: 14px; z-index: 2;
  padding: 7px 14px; border-radius: 999px;
  background: #fff; color: var(--crimson-deep); font-weight: 800; font-size: 0.9rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.caption { min-height: 104px; padding: 18px 6px 4px; text-align: center; }
.cap-prev { margin: 0 0 6px; color: #a48c90; font-size: 0.98rem; line-height: 1.45; min-height: 1.45em; }
.cap-main { margin: 0; font-size: clamp(1.25rem, 4.6vw, 1.6rem); font-weight: 700; line-height: 1.35; text-wrap: balance; }
.cap-main[data-lang="vi"] { color: var(--crimson-deep); font-weight: 600; }

.fix-card, .result-card {
  margin: 10px 0; padding: 16px 18px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 8px 22px rgba(124, 18, 41, 0.08);
  animation: pop 0.28s ease;
}
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.card-label { font-size: 0.76rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--crimson); margin-bottom: 8px; }
.fix-said { color: #a48c90; text-decoration: line-through; text-decoration-color: rgba(163, 29, 56, 0.45); font-size: 1rem; }
.fix-better { margin-top: 4px; font-size: 1.3rem; font-weight: 700; color: var(--green); line-height: 1.35; }

.result-card { border: 2px solid var(--crimson); background: linear-gradient(180deg, #fff 0%, #fff3ee 100%); }
.result-level { font-size: 2rem; font-weight: 800; color: var(--crimson); line-height: 1.1; }
.result-meaning { margin: 4px 0 10px; font-weight: 600; }
.result-note { margin: 0 0 12px; line-height: 1.55; }
.result-disclaimer { margin: 0; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 0.82rem; line-height: 1.5; color: var(--ink-soft); }

.heard { margin: 8px 0 0; text-align: center; color: var(--ink-soft); font-size: 0.98rem; min-height: 1.5em; }
.heard-label { font-weight: 600; }
.heard.interim #heard-text { opacity: 0.6; }

.controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin-top: 16px; }
.controls > :first-child { justify-self: start; }
.controls > :last-child { justify-self: end; }

.lang-switch { display: inline-flex; padding: 3px; border-radius: 999px; background: #f6e6df; }
.lang-switch button { border: 0; background: none; padding: 8px 12px; border-radius: 999px; font-weight: 600; font-size: 0.85rem; color: var(--ink-soft); }
.lang-switch button.on { background: #fff; color: var(--crimson-deep); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08); }

.mic {
  position: relative; width: 86px; height: 86px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: var(--crimson); color: #fff;
  box-shadow: 0 10px 26px rgba(163, 29, 56, 0.35);
  transition: background 0.2s, transform 0.12s;
}
.mic:active { transform: scale(0.96); }
.mic::before { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 3px solid transparent; }
.mic[data-phase="listening"] { background: var(--green); box-shadow: 0 10px 26px rgba(23, 147, 106, 0.4); }
.mic[data-phase="listening"]::before { border-color: rgba(23, 147, 106, 0.45); animation: ring 1.2s ease-out infinite; }
.mic[data-phase="thinking"] { background: #c9b6b0; box-shadow: none; cursor: progress; }
.mic[data-phase="talking"] { background: #d98a7c; }
@keyframes ring { from { transform: scale(0.9); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }

.type-form { display: flex; gap: 8px; margin-top: 14px; }
.type-form input { flex: 1; }

.hint { margin: 14px 0 0; text-align: center; color: var(--ink-soft); font-size: 0.95rem; min-height: 1.5em; }
.error { margin: 10px 0 0; padding: 12px 14px; border-radius: 14px; background: #ffe3e3; border: 1px solid #f3b4b4; color: #8a1c1c; font-size: 0.93rem; line-height: 1.5; text-align: center; }

/* ---------- Phiếu nhận xét cuối buổi ---------- */
.class[data-ended] .controls,
.class[data-ended] .type-form,
.class[data-ended] .heard,
.class[data-ended] .hint,
.class[data-ended] .fix-card,
.class[data-ended] .result-card { display: none; }

.report {
  margin-top: 12px; padding: 22px 20px 18px; border-radius: 24px;
  background: var(--card); border: 2px solid var(--crimson);
  box-shadow: var(--shadow);
  animation: pop 0.3s ease;
}
.report-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.report h2 { margin: 0; font-size: 1.45rem; line-height: 1.2; font-weight: 800; }
.report-meta { margin: 4px 0 0; color: var(--ink-soft); font-size: 0.92rem; }
.report h3 { margin: 0 0 6px; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--crimson); }

.score {
  flex-shrink: 0; width: 92px; height: 92px; border-radius: 50%;
  display: grid; place-content: center; text-align: center;
  background: var(--crimson); color: #fff;
  box-shadow: 0 8px 20px rgba(163, 29, 56, 0.3);
}
.score strong { font-size: 2rem; line-height: 1; font-weight: 800; font-variant-numeric: tabular-nums; }
.score span { font-size: 0.8rem; opacity: 0.85; }

.report-nograde { margin: 14px 0 0; padding: 10px 14px; border-radius: 12px; background: #fff4d6; color: #6b4a00; font-size: 0.93rem; line-height: 1.5; }

.criteria { display: grid; gap: 10px; margin: 18px 0 4px; }
.criterion { display: grid; grid-template-columns: minmax(0, 11.5em) 1fr 2.4em; align-items: center; gap: 10px; font-size: 0.95rem; }
.criterion .bar { height: 10px; border-radius: 6px; background: #f6e6df; overflow: hidden; }
.criterion .bar i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--salmon), var(--crimson)); }
.criterion b { text-align: right; font-variant-numeric: tabular-nums; }

.report-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.report ul { margin: 0; padding-left: 18px; line-height: 1.55; }
.report li + li { margin-top: 6px; }
.report-line { margin-top: 16px; }
.report-line p { margin: 0; line-height: 1.55; }
.report .best { font-size: 1.2rem; font-weight: 700; color: var(--green); }

.cheer { margin-top: 18px; padding: 16px 18px; border-radius: 18px; background: linear-gradient(180deg, #fff3ee 0%, #ffe7df 100%); }
.cheer-text { margin: 0; font-size: 1.05rem; line-height: 1.6; font-weight: 500; }
.cheer blockquote { margin: 12px 0 0; padding: 0 0 0 14px; border-left: 4px solid var(--crimson); }
.cheer blockquote p { margin: 0; font-size: 1.2rem; font-weight: 800; color: var(--crimson-deep); line-height: 1.35; }
.cheer blockquote footer { margin-top: 2px; color: var(--ink-soft); font-size: 0.93rem; }
.cheer-sign { margin: 10px 0 0; text-align: right; font-weight: 700; color: var(--crimson-deep); font-size: 0.92rem; }

.report .result-disclaimer { margin-top: 16px; }
.report-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

@media (max-width: 480px) {
  .report-cols { grid-template-columns: 1fr; gap: 14px; }
  .criterion { grid-template-columns: minmax(0, 9em) 1fr 2.2em; font-size: 0.9rem; }
  .score { width: 80px; height: 80px; }
  .score strong { font-size: 1.7rem; }
}

@media print {
  body { background: #fff; }
  .topbar .top-actions, .demo-banner, .stage, .caption, .controls, .type-form, .heard, .hint, .error, .report-actions, .fix-card, .result-card { display: none !important; }
  .report { border: 1px solid #999; box-shadow: none; animation: none; }
  .score, .criterion .bar i { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Nhật ký ---------- */
.log-dialog { width: min(640px, calc(100vw - 24px)); max-height: 82dvh; border: 0; border-radius: 24px; padding: 0; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3); color: var(--ink); }
.log-dialog::backdrop { background: rgba(42, 12, 20, 0.45); }
.log-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.log-list { padding: 14px 18px; display: grid; gap: 10px; }
.log-item { max-width: 86%; padding: 10px 14px; border-radius: 16px; line-height: 1.5; font-size: 0.96rem; }
.log-item.thay { background: #fff0ea; justify-self: start; border-bottom-left-radius: 4px; }
.log-item.con { background: #e6f6ef; justify-self: end; border-bottom-right-radius: 4px; }
.log-item.sua { background: #f3fbf7; border: 1px dashed #8fd2b6; justify-self: start; color: #0f6e4d; font-weight: 600; }
.log-who { display: block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; opacity: 0.6; margin-bottom: 2px; }
.log-foot { margin: 0; padding: 12px 18px 16px; font-size: 0.8rem; color: var(--ink-soft); }

@media (max-width: 480px) {
  #app { padding: 12px 12px 32px; }
  .start-card { padding: 26px 18px 20px; border-radius: 26px; }
  .controls { gap: 8px; }
  .lang-switch button { padding: 8px 8px; font-size: 0.76rem; white-space: nowrap; }
  .top-actions .btn-ghost { padding: 7px 11px; font-size: 0.84rem; }
  .mic { width: 78px; height: 78px; }
  .caption { min-height: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .poses, .stage[data-phase="talking"] .poses, .wave i, .dot, .mic::before { animation: none !important; }
}
