/* ===================================================================
   English Practice Garden — Apple-like design language
   Quiet gray canvas, one blue accent, pill buttons, 18px cards,
   frosted top bar, custom media controls. No decoration.
   =================================================================== */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --fill: #e8e8ed;          /* secondary button / segmented track */
  --fill-2: #f2f2f7;        /* inset fields, audio pill */
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --hairline: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --accent-hover: #0d7df0;
  --tint: #eaf2fd;
  --green: #248a3d;
  --green-bg: #e9f6ee;
  --red: #d70015;
  --red-bg: #fdeeee;
  --amber: #8a6a00;
  --amber-bg: #fff4d1;
  --check: #d9480f;
  --check-hover: #bf3d0c;
  --r-lg: 18px;
  --r-md: 12px;
  --pill: 980px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.05);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI",
    "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.022em;
  margin: 0 0 14px;
}
h2 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.017em;
  margin: 34px 0 12px;
}
.muted { color: var(--text-2); font-size: 0.9rem; }
.error-msg { color: var(--red); font-size: 0.9rem; margin-top: 8px; min-height: 1.2em; white-space: pre-line; }

::selection { background: rgba(0, 113, 227, 0.18); }

/* ---------- top bar: frosted ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.topbar .spacer { flex: 1; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav button {
  border: none;
  background: none;
  padding: 6px 14px;
  border-radius: var(--pill);
  color: var(--text-2);
  font-weight: 500;
  font-size: 0.92rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.topbar nav button:hover { color: var(--text); }
.topbar nav button.active { background: var(--fill); color: var(--text); }
.topbar nav button { display: inline-flex; align-items: center; gap: 6px; }
.userchip { color: var(--text-2); font-size: 0.88rem; }

.tb-ic { width: 16px; height: 16px; flex: none; }
.topbar nav button.active .tb-ic { color: var(--accent); }
.tb-btn { display: inline-flex; align-items: center; gap: 6px; }
.btn.tb-logout {
  background: var(--red-bg);
  color: var(--red);
  padding: 8px 16px;
}
.btn.tb-logout:hover { background: var(--red); color: #fff; }
.tb-logout .tb-ic { width: 15px; height: 15px; }

@media (max-width: 720px) {
  .topbar nav button span, .tb-btn span { display: none; }
  .topbar nav button, .tb-btn { padding: 8px 11px; }
}

.main { max-width: 1020px; margin: 0 auto; padding: 36px 22px 130px; }

/* ---------- buttons: pills ---------- */
.btn {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 9px 22px;
  border-radius: var(--pill);
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--fill); color: var(--text); }
.btn.secondary:hover { background: #dfdfe4; }
.btn.ghost { background: none; color: var(--accent); padding: 9px 14px; }
.btn.ghost:hover { background: var(--tint); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.danger { background: var(--red); }
.btn.check-answers { background: var(--check); }

.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn-nav__icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  opacity: 0.78;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.btn-nav__icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.btn-nav__label { line-height: 1.2; }
.btn-nav:hover:not(:disabled) .btn-nav__icon { opacity: 1; }
.btn-nav--prev:hover:not(:disabled) .btn-nav__icon { transform: translateX(-1.5px); }
.btn-nav--next:hover:not(:disabled) .btn-nav__icon { transform: translateX(1.5px); }
.btn-nav:disabled .btn-nav__icon { opacity: 0.32; }

.chev {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  color: var(--text-2);
  opacity: 0.72;
  flex: none;
  transition: transform 0.2s ease, opacity 0.15s ease;
}
.chev svg {
  width: 100%;
  height: 100%;
  display: block;
}
.btn.check-answers:hover { background: var(--check-hover); }
.btn.check-answers:focus-visible { outline-color: var(--check); }
.btn.dev-fill {
  background: var(--surface);
  color: var(--text-2);
  border: 1px dashed rgba(0, 0, 0, 0.22);
  font-size: 0.88rem;
}
.btn.dev-fill:hover { background: var(--fill-2); color: var(--text); }
.btn.dev-fill:focus-visible { outline-color: var(--text-2); }

input[type="text"], input[type="password"], textarea, select.field {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.18);
}
button:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
label.f { display: block; margin: 14px 0 6px; font-weight: 500; font-size: 0.88rem; color: var(--text-2); }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 24px 26px;
}

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 400px; max-width: 100%; padding: 34px 32px; }
.auth-card .brand {
  display: block;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.022em;
  margin-bottom: 4px;
}
.auth-sub { text-align: center; color: var(--text-2); margin-bottom: 24px; font-size: 0.92rem; }
.auth-tabs {
  display: flex;
  background: var(--fill);
  border-radius: 10px;
  padding: 2px;
  margin-bottom: 10px;
}
.auth-tabs button {
  flex: 1;
  border: none;
  background: none;
  padding: 7px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.92rem;
  color: var(--text-2);
  transition: all 0.15s ease;
}
.auth-tabs button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.auth-card .btn { width: 100%; margin-top: 22px; padding: 11px; }
.lang-float { position: fixed; top: 14px; right: 16px; }

/* ---------- course shelf ---------- */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.course-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: none;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.course-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04), 0 16px 40px rgba(0, 0, 0, 0.09);
}
.course-tile {
  width: 54px;
  height: 54px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.course-body { flex: 1; min-width: 0; }
.course-body h3 { margin: 0 0 2px; font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.course-body .muted { font-size: 0.82rem; }
.progressbar {
  height: 4px;
  border-radius: 2px;
  background: var(--fill);
  overflow: hidden;
  margin-top: 10px;
}
.progressbar > div,
.progressbar > span { height: 100%; background: var(--accent); border-radius: 2px; display: block; }

/* ---------- course tree ---------- */
.crumbs { margin-bottom: 10px; font-size: 0.88rem; color: var(--text-2); }
.crumbs a { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 500; }
.crumbs a:hover { text-decoration: underline; }

.course-units {
  display: grid;
  grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.unit-nav-toggle {
  display: none;
  grid-column: 1 / -1;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 12px 16px;
}
.unit-nav-toggle-label {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unit-nav-toggle .chev {
  transform: rotate(90deg);
}
.unit-nav-backdrop {
  display: none;
}
.unit-nav-shell {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 96px);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  padding: 8px;
  display: flex;
  flex-direction: column;
}
.unit-nav {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 2px 0 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.22) transparent;
}
.unit-nav::-webkit-scrollbar {
  width: 5px;
}
.unit-nav::-webkit-scrollbar-track {
  background: transparent;
  margin-block: 4px;
}
.unit-nav::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: var(--pill);
  border: 1px solid transparent;
  background-clip: padding-box;
}
.unit-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
  background-clip: padding-box;
}
.unit-nav-item {
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  border-radius: var(--r-md);
  padding: 11px 12px;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.unit-nav-item:hover { background: var(--fill-2); }
.unit-nav-item.active {
  background: var(--tint);
  box-shadow: inset 0 0 0 1px rgba(0, 113, 227, 0.12);
}
.unit-nav-title {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: -0.01em;
  line-height: 1.35;
}
.unit-nav-meta {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.unit-nav-item .progressbar { margin-top: 8px; }
.unit-panel { min-width: 0; }
.unit-panel-title {
  margin: 0 0 16px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.017em;
}

.lesson-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 0;
  margin-bottom: 14px;
  overflow: hidden;
}
.lesson-head {
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--hairline);
}
.lesson-head:hover { background: rgba(0, 0, 0, 0.02); }
.lesson-head-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.lesson-head-main h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.4;
}
.lesson-head .pill { flex: none; margin-top: 2px; }
.lesson-head .chev { margin-top: 3px; }
.lesson-card.collapsed .lesson-head .chev { transform: rotate(0deg); }
.lesson-card:not(.collapsed) .lesson-head .chev { transform: rotate(90deg); }
.lesson-card.collapsed .activity-list { display: none; }
.lesson-card.collapsed .lesson-head { border-bottom: none; }

.skill-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--pill);
  letter-spacing: 0.01em;
  flex: none;
}
.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.activity-row {
  width: 100%;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  text-align: left;
  font-size: 0.9rem;
  transition: background 0.12s ease;
}
.activity-list li + li .activity-row { border-top: 1px solid var(--hairline); }
.activity-row:hover { background: #fbfbfd; }
.activity-row:active { background: var(--fill-2); }
.activity-title {
  flex: 1;
  min-width: 0;
  line-height: 1.4;
}
.activity-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.activity-row .done {
  color: var(--text-2);
  font-weight: 500;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}
.activity-row:hover .chev,
.lesson-head:hover .chev { opacity: 1; }
.activity-row.complete { background: rgba(36, 138, 61, 0.04); }
.activity-row.complete:hover { background: var(--green-bg); }
.activity-row.complete .done { color: var(--green); font-weight: 600; }

@media (min-width: 861px) {
  .unit-nav-shell {
    grid-column: 1;
    align-self: start;
    width: 100%;
  }
  .unit-panel {
    grid-column: 2;
    min-height: calc(100vh - 180px);
  }
}

@media (max-width: 860px) {
  .course-units {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .unit-nav-toggle {
    display: flex;
    position: sticky;
    top: 56px;
    z-index: 8;
  }
  .unit-nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 28;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  .course-units.nav-open .unit-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .unit-nav-backdrop[hidden] {
    display: none !important;
  }
  .unit-nav-shell {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(88vw, 320px);
    max-height: none;
    border-radius: 0;
    padding: 16px 8px 8px;
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    z-index: 30;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.18);
  }
  .unit-nav {
    padding: 0 2px 0 0;
  }
  .course-units.nav-open .unit-nav-shell {
    transform: translateX(0);
  }
  .unit-panel-title { display: none; }
}

/* ---------- player ---------- */
html:has(.player-shell),
body:has(.player-shell) {
  height: 100%;
  overflow: hidden;
}
#root:has(.player-shell) {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
#root:has(.player-shell) > .topbar {
  flex-shrink: 0;
}
.main:has(.player-shell) {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0 22px;
  max-width: 1020px;
  width: 100%;
  margin: 0 auto;
}
.player-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}
.player-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px 0;
}
.player-body > .instructions {
  max-width: 720px;
  margin: 8px auto 28px;
  padding: 16px 20px;
  line-height: 1.55;
}
.page-host {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}
.player-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
  padding: 12px 32px 12px 22px;
  margin: 0 -22px;
}
.player-topbar h1 { font-size: 1.35rem; flex: 1; margin: 0; }
.pageinfo {
  color: var(--text-2);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  padding-right: 2px;
}

.player-progress-line {
  flex-shrink: 0;
  height: 3px;
  background: var(--fill);
  margin: 0 -22px;
}
.player-progress-line > div {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.25s ease;
}

.instructions {
  background: var(--tint);
  border-radius: var(--r-md);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 0.92rem;
  color: #274b77;
}
.page-host > .readpanel,
.question-block {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 26px 28px;
  margin: 0 0 14px;
}
.question-block .readpanel {
  padding: 0;
  box-shadow: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.question-block .readpanel .aplayer { align-self: center; }
.qnum {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.q-image-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin: 10px 0 18px;
}
.q-image,
.readpanel img,
.md img {
  display: block;
  width: auto;
  max-width: min(100%, 720px);
  height: auto;
  max-height: clamp(200px, 42vw, 480px);
  margin: 0 auto;
  border-radius: var(--r-md);
  object-fit: contain;
}
.readpanel .md {
  font-size: 0.97rem;
  text-align: left;
  width: 100%;
}
.md p { margin: 0.5em 0; }
.md table { border-collapse: collapse; margin: 12px 0; width: 100%; font-size: 0.93rem; }
.md td, .md th { border-bottom: 1px solid var(--hairline); padding: 8px 10px; text-align: left; }
.md tr:last-child td { border-bottom: none; }
.md ul { padding-left: 22px; }

.qtext {
  font-size: 1.08rem;
  letter-spacing: -0.01em;
  margin-bottom: 14px;
  line-height: 1.65;
}

.player-footer {
  flex-shrink: 0;
  z-index: 12;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--hairline);
  padding: 12px 32px 12px 22px;
  margin: 0 -22px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}
.player-footer-actions { display: flex; gap: 10px; flex: none; }
.player-footer-actions .btn { white-space: nowrap; }
.player-footer-actions .btn[hidden] { display: none; }

/* ---------- custom audio player ---------- */
.aplayer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--fill-2);
  border-radius: var(--r-lg);
  padding: 8px 14px 10px;
  margin: 12px auto 16px;
  width: 100%;
  max-width: 460px;
}
.ap-main {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ap-btn,
.ap-stop {
  width: 36px;
  height: 36px;
  flex: none;
  border: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.ap-btn {
  background: var(--accent);
  color: #fff;
}
.ap-btn:hover { background: var(--accent-hover); }
.ap-btn:active,
.ap-stop:active { transform: scale(0.94); }
.ap-btn svg,
.ap-stop svg { width: 14px; height: 14px; fill: currentColor; }
.ap-stop {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-2);
}
.ap-stop:hover { background: rgba(0, 0, 0, 0.14); }
.ap-track {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.12);
  cursor: pointer;
  position: relative;
}
.ap-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 2px;
  background: var(--accent);
}
.ap-time {
  flex: none;
  font-size: 0.78rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  min-width: 34px;
  text-align: right;
}
.ap-extra {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}
.ap-speed {
  flex: none;
  min-width: 44px;
  height: 28px;
  padding: 0 10px;
  border: none;
  border-radius: var(--pill);
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.15s ease;
}
.ap-speed:hover { background: rgba(0, 0, 0, 0.1); }
.ap-vol {
  position: relative;
  flex: none;
}
.ap-vol-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.ap-vol-btn:hover,
.ap-vol.is-open .ap-vol-btn {
  background: rgba(0, 0, 0, 0.1);
  color: var(--text);
}
.ap-vol-btn svg { width: 15px; height: 15px; }
.ap-vol-pop {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  display: none;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.14), 0 0 0 1px rgba(0, 0, 0, 0.05);
  z-index: 12;
}
.ap-vol.is-open .ap-vol-pop { display: flex; }
.ap-vol-range {
  width: 108px;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}
.ap-label { font-size: 0.82rem; color: var(--text-2); margin: 14px 0 2px; font-weight: 500; }

/* ---------- recorder: one pill, three states (LINE voice-message style) ---------- */
.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
}
.rec-shell {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  min-height: 56px;
  padding: 6px;
  background: var(--fill-2);
  border-radius: var(--pill);
  transition: background 0.2s ease;
}
.rec-shell.is-recording { background: #fdf0f0; }

.rec-cbtn {
  width: 44px;
  height: 44px;
  flex: none;
  border: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  transition: background 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}
.rec-cbtn svg { width: 19px; height: 19px; fill: currentColor; }
.rec-cbtn:hover { transform: scale(1.06); }
.rec-cbtn:active { transform: scale(0.94); }
.rec-cbtn:disabled { opacity: 0.4; transform: none; cursor: not-allowed; }

.rec-mic { background: var(--accent); }
.rec-mic:hover { background: var(--accent-hover); }
.rec-stop {
  background: var(--red);
  animation: rec-breathe 1.8s ease-in-out infinite;
}
@keyframes rec-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(215, 0, 21, 0.30); }
  50% { box-shadow: 0 0 0 9px rgba(215, 0, 21, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .rec-stop { animation: none; }
  .course-card, .activity-row, .btn { transition: none; }
}
.rec-redo { background: var(--fill); color: var(--text-2); }
.rec-redo:hover { background: #dfdfe4; color: var(--text); }

/* submit lives on its own row, clearly separated from play / re-record */
.rec-submit-row {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: 420px;
  margin-top: 2px;
}
.rec-submit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 30px;
  background: var(--green);
  box-shadow: 0 3px 10px rgba(36, 138, 61, 0.32);
}
.rec-submit-btn:hover { background: #1e7735; }
.rec-submit-btn svg { width: 19px; height: 19px; fill: currentColor; }

.rec-idle-label {
  color: var(--text-2);
  font-size: 0.92rem;
  cursor: pointer;
  user-select: none;
}
.rec-wave {
  flex: 1;
  height: 34px;
  min-width: 0;
}
.rec-time {
  flex: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--red);
  font-variant-numeric: tabular-nums;
  margin-right: 10px;
}
.rec-shell.is-preview .aplayer {
  flex: 1;
  margin: 0;
  padding: 0 12px 0 0;
  background: none;
  max-width: none;
}
.rec-hint { font-size: 0.85rem; color: var(--text-2); min-height: 1.2em; text-align: center; max-width: 420px; line-height: 1.45; }
.rec-hint.is-error { color: var(--red); }

/* record_and_compare composition */
.rc-ref {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 10px 0 4px;
}
.rc-media { display: flex; justify-content: center; }
.rc-media .aplayer { width: 100%; max-width: 420px; }

/* ---------- answer options ---------- */
.opt-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  margin: 8px 0;
  padding: 13px 18px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  border-radius: var(--r-md);
  font-size: 0.97rem;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.opt-btn::before {
  content: "";
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid #c7c7cc;
  transition: all 0.15s ease;
}
.opt-btn:hover { border-color: #c7c7cc; }
.opt-btn.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}
.opt-btn.selected::before {
  border-color: var(--accent);
  border-width: 5.5px;
}
.opt-btn.correct { border-color: var(--green); background: var(--green-bg); }
.opt-btn.correct::before { border-color: var(--green); border-width: 5.5px; }
.opt-btn.wrong { border-color: var(--red); background: var(--red-bg); }
.opt-btn.wrong::before { border-color: var(--red); border-width: 5.5px; }

.blank-select, .blank-input {
  display: inline-block;
  width: auto;
  min-width: 110px;
  padding: 5px 10px;
  margin: 2px 4px;
  border: 1px solid var(--hairline);
  border-radius: 9px;
  background: var(--fill-2);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.blank-select:focus, .blank-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}
.blank-input.correct, .blank-select.correct { background: var(--green-bg); border-color: var(--green); }
.blank-input.wrong, .blank-select.wrong { background: var(--red-bg); border-color: var(--red); }

.dialogue-line {
  margin: 8px 0;
  font-size: 0.99rem;
  line-height: 2;
}
/* Listening-style blanks with audio: keep sentence centered, options stay left */
.question-block.layout-listening .dialogue-line {
  text-align: center;
  line-height: 2.2;
}
.dialogue-line .speaker { font-weight: 600; margin-right: 8px; }
.wsel { cursor: pointer; padding: 2px 4px; border-radius: 6px; transition: background 0.12s ease; }
.wsel:hover { background: var(--fill); }
.wsel.selected { background: var(--tint); color: var(--accent); font-weight: 600; }
.wsel.correct { background: var(--green-bg); color: var(--green); font-weight: 600; }
.wsel.missed { box-shadow: inset 0 -2px 0 var(--red); }
.wsel.wrong { background: var(--red-bg); color: var(--red); text-decoration: line-through; }

.match-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin: 14px 0;
}
.match-column { display: flex; flex-direction: column; gap: 8px; }
.match-column h4 {
  margin: 0 0 4px;
  font-size: 0.85rem;
  color: var(--text-2);
  font-weight: 600;
}
.match-left, .match-right {
  width: 100%;
  text-align: left;
  border: 1px solid var(--hairline);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 11px 14px;
  font-size: 0.94rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.match-left:hover, .match-right:hover { background: var(--fill-2); }
.match-left.selected {
  border-color: var(--accent);
  background: var(--tint);
  color: var(--accent);
  font-weight: 600;
}
.match-left.paired, .match-right.paired {
  border-color: var(--accent);
  background: var(--tint);
}
.match-right-main { display: block; }
.match-paired {
  display: block;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(0, 113, 227, 0.14);
  font-size: 0.78rem;
  color: var(--text-2);
  line-height: 1.35;
}
.match-paired__label {
  font-weight: 600;
  color: var(--accent);
  margin-right: 3px;
}
.match-left.correct, .match-right.correct { border-color: var(--green); background: var(--green-bg); }
.match-left.wrong, .match-right.wrong { border-color: var(--red); background: var(--red-bg); }

.feedback { margin-top: 4px; font-weight: 500; font-size: 0.92rem; min-height: 1.3em; }
.feedback.ok { color: var(--green); }
.feedback.ok::before { content: "✓  "; }
.feedback.no { color: var(--red); }
.feedback.no::before { content: "✕  "; }
.checkrow { display: flex; gap: 14px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.page-checkrow {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
}
.question-block .feedback { margin-top: 14px; }

.sub-status {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  line-height: 1.2;
  padding: 4px 12px;
  border-radius: var(--pill);
  font-weight: 600;
}
.sub-status.submitted { background: var(--amber-bg); color: var(--amber); }
.sub-status.graded { background: var(--green-bg); color: var(--green); }

.submission-panel {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--r-md);
  background: var(--fill-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.submission-panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.submission-attempt {
  font-size: 0.78rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.submission-audio-label {
  font-size: 0.82rem;
  color: var(--text-2);
  font-weight: 500;
}
.submission-panel .aplayer {
  width: 100%;
  max-width: 420px;
  margin: 0;
}
.submission-delete {
  color: var(--red) !important;
  font-size: 0.88rem;
}
.submission-report { display: flex; flex-direction: column; gap: 16px; }
.submission-report-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--hairline);
}
.submission-report-row:last-child { padding-bottom: 0; border-bottom: none; }
.submission-report-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.submission-question {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.submission-question-label {
  font-size: 0.78rem;
  color: var(--text-2);
  font-weight: 500;
}
.submission-question-text {
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.submission-answer {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.submission-answer-text {
  font-size: 0.92rem;
  line-height: 1.6;
  white-space: pre-wrap;
  padding: 12px 14px;
  background: var(--fill-2);
  border-radius: var(--r-md);
}
.submission-report-row .aplayer { width: 100%; max-width: 480px; margin: 0; }

textarea.writing { min-height: 220px; resize: vertical; line-height: 1.6; }
.wordcount { text-align: right; color: var(--text-2); font-size: 0.85rem; margin: 8px 0 14px; }

/* ---------- reports ---------- */
.report-page { position: relative; }
.report-grid { display: grid; gap: 14px; }
.report-section-h {
  margin-top: 28px;
  scroll-margin-top: 88px;
}
.report-section {
  scroll-margin-top: 88px;
}
.report-toc {
  position: fixed;
  top: 50%;
  right: max(14px, calc((100vw - 1020px) / 2 - 72px));
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 20;
  max-height: 70vh;
  overflow-y: auto;
  padding: 4px 0;
}
.report-toc-btn {
  border: 1px solid var(--hairline);
  border-radius: var(--pill);
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 5px 11px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.report-toc-btn:hover {
  background: var(--surface);
  color: var(--accent);
  border-color: rgba(0, 113, 227, 0.25);
}
.report-top-btn {
  position: fixed;
  right: 22px;
  bottom: 28px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text-2);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  z-index: 21;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease, background 0.15s ease;
}
.report-top-btn svg { width: 18px; height: 18px; }
.report-top-btn:hover {
  color: var(--accent);
  background: var(--surface);
}
.report-top-btn.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.report-top-btn[hidden] { display: grid; }
@media (max-width: 1180px) {
  .report-toc { display: none; }
}
.skill-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.skill-table th, .skill-table td { padding: 10px 10px; border-bottom: 1px solid var(--hairline); text-align: left; }
.skill-table tr:last-child td { border-bottom: none; }
.skill-table th { color: var(--text-2); font-weight: 500; font-size: 0.8rem; }
.mini-bar {
  width: 110px;
  height: 4px;
  background: var(--fill);
  border-radius: 2px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 10px;
  overflow: hidden;
}
.mini-bar > div { height: 100%; background: var(--accent); border-radius: 2px; }
.best-score {
  font-weight: 600;
  color: var(--amber);
  background: var(--amber-bg);
  padding: 2px 11px;
  border-radius: var(--pill);
  font-size: 0.85rem;
}
.heat {
  display: inline-block;
  min-width: 52px;
  text-align: center;
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 0.83rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- teacher ---------- */
.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--fill);
  padding: 4px;
  border-radius: var(--r-md);
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 12px;
  border-radius: var(--r-md);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.tab-panel { min-height: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--hairline);
  flex-wrap: wrap;
}
.list-row:last-child { border-bottom: none; }
.pill {
  display: inline-flex;
  align-items: center;
  background: var(--fill-2);
  border-radius: var(--pill);
  padding: 4px 12px;
  font-size: 0.8rem;
  line-height: 1.2;
  font-weight: 500;
  color: var(--text-2);
}
.grade-counter {
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  margin-bottom: 10px;
}
.grade-nav {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.grade-item {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 14px;
}
.criteria-row { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.criteria-row label { width: 130px; font-size: 0.88rem; color: var(--text-2); }
.criteria-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.criteria-val { width: 54px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(29, 29, 31, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
  padding: 11px 24px;
  border-radius: var(--pill);
  font-size: 0.92rem;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- modal (join-a-class prompt, etc.) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(29, 29, 31, 0.4);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: modal-fade 0.15s ease;
}
.modal-card {
  width: 400px;
  max-width: 100%;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.25);
  padding: 26px 26px 20px;
  animation: modal-pop 0.16s ease;
}
.modal-title { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 8px; }
.modal-body { color: var(--text-2); font-size: 0.94rem; line-height: 1.55; margin: 0 0 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
@keyframes modal-fade { from { opacity: 0; } }
@keyframes modal-pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .modal-card { animation: none; }
}

@media (min-width: 900px) {
  .q-image,
  .readpanel img,
  .md img {
    max-width: min(100%, 840px);
    max-height: clamp(280px, 36vh, 560px);
  }
}

@media (max-width: 640px) {
  .main { padding: 20px 14px 120px; }
  .main:has(.player-shell) { padding: 0 14px; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .mini-bar { width: 64px; }
  .page-host > .readpanel, .question-block { padding: 18px 16px; }
  .rc-ref { font-size: 1.25rem; }

  .player-topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 20px 10px 14px;
    margin: 0 -14px;
  }
  .player-topbar h1 {
    font-size: 1.15rem;
    order: 1;
  }
  .player-topbar .pageinfo {
    order: 2;
    text-align: center;
  }
  .player-topbar .btn.ghost {
    align-self: flex-start;
    order: 0;
    padding-left: 0;
  }
  .player-progress-line { margin: 0 -14px; }
  .player-footer {
    padding: 10px 20px 10px 14px;
    margin: 0 -14px;
  }
  .player-footer-actions { width: 100%; }
  .player-footer-actions .btn { flex: 1; justify-content: center; }

  .q-image,
  .readpanel img,
  .md img {
    max-width: 100%;
    max-height: clamp(160px, 56vw, 340px);
  }
  .q-image-wrap { margin: 8px 0 14px; }

  .qtext { font-size: 1rem; }
  .opt-btn { padding: 12px 14px; font-size: 0.94rem; }
  .aplayer { max-width: 100%; }
  .rc-media .aplayer { width: 100%; }

  .pager {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .pager .btn {
    width: 100%;
    justify-content: center;
  }
  .checkrow {
    flex-direction: column;
    align-items: stretch;
  }
  .checkrow .btn { width: 100%; }
  .page-checkrow .btn { width: 100%; }
  .match-columns { grid-template-columns: 1fr; }
  .match-left, .match-right { min-width: 0; }
}
