:root {
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-soft: #f7f7f7;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --ink: #3c3c3c;
  --ink-strong: #2b2b2b;
  --muted: #777777;
  --green: #58cc02;
  --green-dark: #46a302;
  --green-soft: #d7ffb8;
  --green-ink: #3d8c00;
  --blue: #1cb0f6;
  --blue-dark: #1899d6;
  --blue-soft: #ddf4ff;
  --blue-ink: #1278ab;
  --gold: #ffc800;
  --gold-dark: #e5a500;
  --gold-soft: #fff5d1;
  --gold-ink: #9c6500;
  --orange: #ff9600;
  --orange-dark: #cd7900;
  --red: #ff4b4b;
  --red-dark: #ea2b2b;
  --red-soft: #ffdfe0;
  --red-ink: #c62828;
  --purple: #ce82ff;
  --purple-dark: #a568cc;
  --purple-soft: #f6ebff;
  font-family: 'Nunito', 'Segoe UI Rounded', 'Quicksand', 'SF Pro Rounded', ui-rounded, 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.55;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
}

/* Tactile Duolingo 3D Buttons */
button, .button {
  border: 0;
  border-bottom: 4px solid var(--green-dark);
  background: var(--green);
  color: #ffffff;
  padding: 0.78rem 1.3rem;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, filter 0.14s ease, background 0.14s ease;
  user-select: none;
}

button:hover:not(:disabled), .button:hover:not(:disabled) {
  filter: brightness(1.05);
}

button:active:not(:disabled), .button:active:not(:disabled) {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

button.secondary, .button.secondary {
  background: var(--surface);
  color: var(--blue-dark);
  border: 2px solid var(--border);
  border-bottom: 4px solid var(--border);
}

button.secondary:hover:not(:disabled), .button.secondary:hover:not(:disabled) {
  background: #f2faff;
  border-color: #bfe8fc;
  border-bottom-color: #9dd9f7;
  filter: none;
}

button.btn-blue, .button.btn-blue {
  background: var(--blue);
  color: #ffffff;
  border: 0;
  border-bottom: 4px solid var(--blue-dark);
}

button.btn-gold, .button.btn-gold {
  background: var(--gold);
  color: #5c3d00;
  border: 0;
  border-bottom: 4px solid var(--gold-dark);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* Form Controls */
input, select, textarea {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem 0.95rem;
  background: var(--surface-soft);
  color: var(--ink-strong);
  font-weight: 600;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  background: var(--surface);
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 3px #1cb0f629;
}

input[type="file"] {
  background: #f2faff;
  border: 2px dashed #84d8ff;
  padding: 1rem;
  cursor: pointer;
}

input[type="checkbox"], input[type="radio"] {
  accent-color: var(--green);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

label {
  display: block;
  font-weight: 800;
  font-size: 0.94rem;
  color: var(--ink);
  margin: 0.9rem 0 0.35rem;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  font-size: 1.95rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.25;
  color: var(--ink-strong);
  margin-bottom: 0.6rem;
}

h2 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ink-strong);
  margin-bottom: 0.65rem;
}

h3 {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink-strong);
}

small, .muted {
  color: var(--muted);
}

small {
  font-size: 0.875rem;
  font-weight: 600;
}

a {
  color: var(--blue-dark);
  font-weight: 700;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

/* App Shell Layout */
.shell {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
}

aside {
  background: var(--surface);
  border-right: 2px solid var(--border);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px;
}

.brand-owl {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.brand {
  font-size: 1.45rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--green);
  line-height: 1.1;
}

.brand span {
  color: var(--blue);
}

.brand-sub {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

nav {
  display: grid;
  gap: 8px;
  margin: 26px 0 auto;
}

nav button {
  background: transparent;
  border: 2px solid transparent;
  border-bottom: 2px solid transparent;
  border-radius: 14px;
  padding: 0.72rem 0.9rem;
  justify-content: flex-start;
  text-align: left;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

nav button:hover:not(.active) {
  background: var(--surface-soft);
  color: var(--ink-strong);
  filter: none;
}

nav button:active:not(:disabled) {
  transform: none;
  border-bottom-width: 2px;
}

nav button.active {
  background: var(--blue-soft);
  color: var(--blue-dark);
  border: 2px solid #84d8ff;
}

.nav-icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 24px;
  height: 24px;
}

.nav-label-short {
  display: none;
}

.aside-foot {
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--green-soft);
  border: 2px solid #b5f286;
  color: var(--green-ink);
}

.aside-foot p {
  margin: 0 0 4px;
  font-weight: 800;
  font-size: 0.92rem;
  line-height: 1.35;
}

.aside-foot small {
  color: var(--green-ink);
  opacity: 0.85;
}

main {
  padding: 26px 3.5vw 48px;
  max-width: 1360px;
  min-width: 0;
  width: 100%;
  margin: 0 auto;
}

/* Top Bar */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding: 12px 18px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 18px;
}

.top-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--blue-soft);
  border: 2px solid #84d8ff;
  color: var(--blue-dark);
  font-weight: 900;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.top-avatar.teacher {
  background: var(--purple-soft);
  border-color: #d7a8ff;
  color: var(--purple-dark);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  font-size: 0.78rem;
  font-weight: 900;
  color: var(--green-dark);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

/* Duolingo Hero Banner */
.hero {
  background: linear-gradient(135deg, #58cc02, #46b500);
  color: #ffffff;
  border-radius: 22px;
  border: 0;
  border-bottom: 5px solid var(--green-dark);
  padding: 26px 28px;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.hero.teacher-hero {
  background: linear-gradient(135deg, #1cb0f6, #1493d4);
  border-bottom-color: #0e76ad;
}

.hero .eyebrow {
  color: #e9ffd6;
  margin-bottom: 6px;
}

.hero.teacher-hero .eyebrow {
  color: #d6f3ff;
}

.hero h1 {
  color: #ffffff;
  margin-bottom: 8px;
}

.hero p {
  max-width: 620px;
  margin-bottom: 0;
  color: #ffffffeb;
  font-weight: 600;
}

.hero-mascot {
  width: 96px;
  height: 96px;
  flex-shrink: 0;
  filter: drop-shadow(0 6px 0 #00000018);
}

/* Grids & Cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-bottom: 4px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  margin-bottom: 18px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 0;
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.stat-icon svg {
  width: 28px;
  height: 28px;
}

.stat-icon.green { background: var(--green-soft); color: var(--green-dark); }
.stat-icon.blue { background: var(--blue-soft); color: var(--blue-dark); }
.stat-icon.gold { background: var(--gold-soft); color: var(--gold-ink); }
.stat-icon.purple { background: var(--purple-soft); color: var(--purple-dark); }

.metric {
  font-size: 1.9rem;
  font-weight: 900;
  color: var(--ink-strong);
  line-height: 1.15;
}

/* Student Assignment Cards */
.lesson-card {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.lesson-card:hover {
  transform: translateY(-2px);
  border-color: #d0d8e0;
}

.lesson-card h2 {
  margin: 10px 0 8px;
  font-size: 1.2rem;
}

.lesson-card .lesson-meta {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 14px;
  flex: 1;
}

.lesson-actions {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.lesson-actions button {
  width: 100%;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.between {
  justify-content: space-between;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--green-soft);
  color: var(--green-ink);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: fit-content;
}

.badge.active-work {
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.badge.pending-work {
  background: var(--gold-soft);
  color: var(--gold-ink);
}

.badge.warn {
  background: var(--red-soft);
  color: var(--red-ink);
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

/* Login Page (Duolingo Welcome) */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background: radial-gradient(circle at top center, #e6f8ff 0%, #f7f9fb 65%);
}

.login {
  width: min(460px, 100%);
  margin: 0;
  padding: 32px 28px;
  border-radius: 26px;
  box-shadow: 0 12px 36px #183a5812;
}

.login-mascot {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.login-mascot svg {
  width: 68px;
  height: 68px;
  flex-shrink: 0;
}

.login .brand {
  font-size: 1.7rem;
  margin-bottom: 2px;
}

.login h1 {
  font-size: 1.65rem;
  margin-bottom: 6px;
}

.login button {
  width: 100%;
  margin-top: 20px;
  font-size: 1.05rem;
  padding: 0.9rem 1.2rem;
}

.login #err {
  color: var(--red-dark);
  font-weight: 800;
  margin: 12px 0 0;
  min-height: 1.2em;
}

.login-note {
  display: block;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 2px solid var(--border);
}

/* Questions & Quiz Options (Duolingo Interactive Tiles) */
.question {
  border: 2px solid var(--border);
  border-bottom: 4px solid var(--border);
  border-left: 6px solid var(--blue);
  border-radius: 18px;
  padding: 18px 20px;
  margin: 18px 0;
  background: var(--surface);
}

.question legend {
  font-weight: 800;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--blue-dark);
  background: var(--blue-soft);
  padding: 4px 12px;
  border-radius: 999px;
}

.question label.option {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-bottom: 4px solid var(--border);
  padding: 13px 15px;
  border-radius: 14px;
  font-weight: 700;
  margin: 10px 0;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.question label.option:hover {
  background: #f7fbff;
  border-color: #bfe8fc;
}

.question label.option:has(input:checked) {
  background: var(--blue-soft);
  border-color: var(--blue);
  border-bottom-color: var(--blue-dark);
  color: var(--blue-ink);
}

.option input {
  width: auto;
  min-width: 22px;
  height: 22px;
  margin: 0;
  cursor: pointer;
}

.confirm-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 2px solid var(--border);
  cursor: pointer;
  font-weight: 700;
}

.confirm-check {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Tables, Progress & Materials */
.scroll {
  overflow: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 650px;
}

th, td {
  text-align: left;
  border-bottom: 2px solid #f0f0f0;
  padding: 13px 12px;
  font-size: 0.94rem;
}

th {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

progress {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 14px;
  border: 0;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 12px;
}

progress::-webkit-progress-bar {
  background: var(--border);
  border-radius: 999px;
}

progress::-webkit-progress-value {
  background: var(--green);
  border-radius: 999px;
}

progress::-moz-progress-bar {
  background: var(--green);
  border-radius: 999px;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-soft);
  border: 2px solid var(--border);
  padding: 16px;
  border-radius: 14px;
  font-weight: 700;
}

.material {
  white-space: pre-wrap;
  line-height: 1.7;
  background: #f6fbff;
  border: 2px solid #d5ecfb;
  border-radius: 14px;
  padding: 16px 18px;
}

.student-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-soft);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  margin: 4px 6px 4px 0;
  font-weight: 700;
  font-size: 0.92rem;
}

.set-card {
  background: var(--surface-soft);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.result-score-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--green-soft);
  color: var(--green-ink);
  border: 2px solid #a8eb76;
  padding: 8px 16px;
  border-radius: 16px;
  font-size: 1.5rem;
  font-weight: 900;
  margin-bottom: 10px;
}

.feedback-bubble {
  background: var(--blue-soft);
  border: 2px solid #a8e2ff;
  border-radius: 16px;
  padding: 12px 16px;
  color: var(--ink-strong);
  font-weight: 700;
  margin-top: 10px;
}

/* Toast Notice */
.stats-note {
  background: var(--blue-soft);
  border: 2px solid #a8e2ff;
  border-radius: 14px;
  padding: 12px 16px;
}

.first-answer-control {
  margin-top: 16px;
}

.first-answer-control p {
  margin-bottom: 0;
}

.first-stats-table {
  min-width: 820px;
}

.first-stats-table caption {
  text-align: left;
  padding: 12px 0;
}

.first-stats-table td {
  vertical-align: top;
}

.first-stats-table td:first-child {
  min-width: 250px;
  max-width: 430px;
  overflow-wrap: anywhere;
}

.first-stats-table details {
  margin-top: 8px;
  font-size: 0.875rem;
}

.first-stats-table summary {
  cursor: pointer;
  color: var(--blue-dark);
  font-weight: 800;
}

.first-stats-table details p, .first-stats-table details ul {
  margin: 8px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.first-stats-table ul {
  padding-left: 20px;
  min-width: 160px;
}

.answer-rate {
  width: 240px;
  max-width: 100%;
  min-width: 190px;
}

.answer-rate-bar, .answer-rate-empty {
  display: block;
  width: 100%;
  height: 22px;
  border-radius: 999px;
  overflow: hidden;
}

.answer-rate-correct {
  fill: var(--green);
}

.answer-rate-wrong {
  fill: var(--red);
}

.answer-rate-empty {
  background: var(--border);
  margin-bottom: 6px;
}

.answer-rate-legend {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  font-size: 0.875rem;
  font-weight: 800;
}

.answer-rate-correct-label {
  color: var(--green-ink);
}

.answer-rate-wrong-label {
  color: var(--red-ink);
}

#notice {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-strong);
  color: #ffffff;
  font-weight: 800;
  padding: 13px 22px;
  border-radius: 16px;
  border-bottom: 4px solid #141414;
  box-shadow: 0 12px 30px #00000033;
  max-width: 90vw;
  z-index: 120;
  display: none;
}

/* Sticky Lesson Timer */
.timer {
  font-weight: 800;
  color: var(--orange-dark);
  position: sticky;
  top: 12px;
  z-index: 20;
  background: var(--gold-soft);
  border: 2px solid #ffd86b;
  border-bottom: 4px solid #f0bf42;
  padding: 12px 18px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

@media (max-width: 760px) {
  .shell {
    display: block;
  }

  aside {
    height: auto;
    position: static;
    padding: 14px 16px 10px;
    border-right: 0;
    border-bottom: 2px solid var(--border);
  }

  nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    margin: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    gap: 2px;
    overflow: hidden;
  }

  nav button {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 2px;
    font-size: 0.65rem;
    text-align: center;
    border-radius: 12px;
  }

  .nav-label-full {
    display: none;
  }

  .nav-label-short {
    display: block;
    font-size: 0.59rem;
    font-weight: 800;
    text-transform: none;
    letter-spacing: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .aside-foot {
    display: none;
  }

  main {
    padding: 18px 14px 96px;
  }

  .split, .grid {
    grid-template-columns: 1fr;
  }

  .top {
    padding: 10px 14px;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 20px;
  }

  .hero-mascot {
    width: 72px;
    height: 72px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .card {
    padding: 18px;
  }

  #notice {
    bottom: 84px;
  }
}

[hidden] {
  display: none !important;
}

/* Quản trị lớp: tên học sinh bấm được để sửa */
button.student-chip {
  margin: 4px;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* Ảnh minh họa trong câu hỏi và học liệu */
.q-img, .material-img {
  display: block;
  max-width: min(100%, 520px);
  max-height: 360px;
  height: auto;
  margin: 10px 0;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
}
.q-img-row { align-items: center; gap: 12px; flex-wrap: wrap; }
.q-img-row .q-img { max-height: 120px; }

/* Biểu đồ báo cáo */
.chart { margin: 16px 0; }
.chart svg { width: 100%; height: auto; max-width: 720px; border: 2px solid var(--border); border-radius: 12px; }
.chart figcaption { margin-top: 6px; }

/* Phiếu khảo sát */
.scale { display: flex; flex-wrap: wrap; gap: 6px; }
.scale .option { flex: 1 1 150px; }

/* Sao chép bài */
.copy-form { margin-top: 10px; padding-top: 10px; border-top: 2px dashed var(--border); }
