:root {
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #d7dde5;
  --paper: #ffffff;
  --soft: #f4f7fb;
  --accent: #2563eb;
  --accent-dark: #1746a2;
  --danger: #b42318;
  --ok: #087443;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
}

.navlinks {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

a { color: var(--accent); }

.navlinks a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.student-hero {
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 44px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0;
}

h1, h2 { margin: 0 0 16px; }
h1 { font-size: 36px; }
h2 { font-size: 22px; }

.lead {
  max-width: 560px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}

button, .primary {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

button:hover, .primary:hover { background: var(--accent-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }

.secondary {
  background: white;
  color: var(--accent);
}

.secondary:hover {
  background: #e8f0ff;
  color: var(--accent-dark);
}

.danger-button {
  border-color: var(--danger);
  color: var(--danger);
}

.danger-button:hover {
  background: #fff1f0;
  color: var(--danger);
}

.status-ungraded {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  background: #fff1f0;
  color: var(--danger);
  font-weight: 900;
}

.status-graded {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  background: #ecfdf3;
  color: var(--ok);
  font-weight: 750;
}

.status-aborted {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  background: #fff1f0;
  color: var(--danger);
  font-weight: 900;
}

.status-closed {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  background: #f1f5f9;
  color: var(--muted);
  font-weight: 800;
}

.quiz {
  margin-top: 22px;
}

.quiz-choice-list {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.compact-picker {
  gap: 8px;
}

.quiz-select-label {
  color: var(--muted);
  font-weight: 800;
}

.quiz-select {
  width: 100%;
  min-height: 54px;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  padding: 0 14px;
}

.quiz-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.quiz-choice:hover,
.quiz-choice.selected {
  border-color: var(--accent);
  background: #f6f9ff;
}

.quiz-choice h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.quiz-choice p {
  margin: 0;
  color: var(--muted);
}

.selected-quiz {
  display: grid;
  gap: 4px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 6px;
  background: #e8f0ff;
  color: var(--accent-dark);
  font-weight: 700;
}

.selected-quiz span {
  color: var(--muted);
  font-size: 16px;
}

.start-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.start-mode.mode-disabled {
  background: #e5e7eb;
  border-color: #d1d5db;
  color: #8a94a6;
}

.start-mode[data-mode="dictation"]:not(:disabled) {
  background: var(--ok);
  border-color: var(--ok);
  color: white;
}

.start-mode[data-mode="dictation"]:not(:disabled):hover {
  background: #065f35;
  border-color: #065f35;
}

.practice-button {
  border-color: #f97316;
  color: white;
  background: #f97316;
}

.practice-button:not(:disabled):hover {
  background: #ea580c;
  border-color: #ea580c;
}

.quiz-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
}

.practice-notice {
  margin: 14px 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
  font-weight: 800;
}

.code {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 2px;
}

.code-suffix {
  color: var(--danger);
}

.timer {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent-dark);
}

.audio-list {
  display: grid;
  gap: 12px;
}

.audio-card, .answer-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.answer-result {
  margin-top: 16px;
}

.answer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  margin-bottom: 12px;
}

.answer-list {
  display: grid;
  gap: 12px;
}

.sentence-search-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.sentence-search-heading h1 {
  margin: 0;
}

.sentence-result-summary {
  margin: -4px 0 16px;
  color: var(--muted);
}

.sentence-result-card {
  align-items: start;
}

.abort-notice {
  padding: 18px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--danger);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.5;
}

.quiz-abort-actions {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.quiz-abort-actions button {
  width: 100%;
}

.quiz-abort-actions p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.jp {
  margin: 12px 0 4px;
  font-weight: 750;
  line-height: 1.6;
}

.cn {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.num {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e8f0ff;
  color: var(--accent-dark);
  font-weight: 800;
}

audio { width: 100%; }

.hidden { display: none; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.success { color: var(--ok); font-weight: 700; }

.login-panel, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login-panel {
  max-width: 420px;
  margin: 60px auto;
}

.stack {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  background: white;
}

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

select {
  min-height: 42px;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel { margin-bottom: 16px; }

.stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.stats span {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--soft);
}

.stats b { font-size: 24px; margin-right: 4px; }

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.small-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 12px;
  box-sizing: border-box;
  text-decoration: none;
  white-space: nowrap;
}

.code-input-group {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: stretch;
}

.code-input-group span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 6px 0 0 6px;
  background: #f8fafc;
  color: var(--ink);
  font-weight: 900;
}

.code-input-group input {
  border-radius: 0 6px 6px 0;
}

.quick-answer-panel {
  max-width: 560px;
  margin: 0 auto;
}

.quick-toast {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 50;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 32px));
  box-sizing: border-box;
  padding: 18px 22px;
  border: 0;
  border-radius: 8px;
  color: white;
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
  transition: opacity .3s ease, transform .3s ease;
}

.quick-toast-open {
  background: rgba(37, 99, 235, .86);
}

.quick-toast-close {
  background: rgba(180, 35, 24, .88);
}

.quick-toast-neutral {
  background: rgba(75, 85, 99, .86);
}

.quick-toast.toast-hiding {
  opacity: 0;
  transform: translate(-50%, calc(-50% - 8px));
}

.quick-answer-form {
  display: grid;
  gap: 16px;
}

.quick-code-input input {
  text-align: center;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.number-pad button {
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
}

.number-pad button:active {
  background: #e8f0ff;
  border-color: var(--accent);
}

.compact-number-pad {
  margin-top: 12px;
  gap: 8px;
}

.compact-number-pad button {
  min-height: 44px;
  font-size: 18px;
}

.compact-number-pad .pad-submit {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.compact-number-pad .pad-submit:hover,
.compact-number-pad .pad-submit:active {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.quick-answer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.quick-answer-actions .danger-button {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.quick-answer-actions .danger-button:hover {
  background: #8f1d14;
  border-color: #8f1d14;
  color: white;
}

.checkbox-line {
  display: flex;
  gap: 18px;
  align-items: center;
  min-height: 42px;
  padding: 8px 0;
}

.checkbox-line label {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  font-weight: 800;
}

.checkbox-line input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.compact-form {
  max-width: 460px;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.upload-grid button { align-self: end; }

.upload-grid .wide {
  grid-column: 1 / -1;
}

.hint {
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  line-height: 1.6;
}

select[multiple] {
  min-height: 168px;
  padding: 8px;
}

select[multiple] option {
  padding: 7px 8px;
}

.publish-form {
  display: grid;
  grid-template-columns: 1fr 150px 180px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
}

.ui-copy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.ui-copy-grid .wide {
  grid-column: 1 / -1;
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.aborted-grading-warning {
  display: inline-block;
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--danger);
  font-size: 20px;
  font-weight: 900;
}

.bulk-delete-form {
  margin: 0;
}

.session-delete-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.date-delete-form {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.date-delete-form input {
  width: 132px;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 14px;
}

.session-delete-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 14px;
}

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

.row-actions form {
  margin: 0;
}

.row-actions button {
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
  color: var(--muted);
  font-weight: 700;
  flex-wrap: wrap;
}

.pager-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
}

.pager-button.disabled {
  opacity: .45;
  cursor: not-allowed;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.compact-section-head {
  align-items: center;
  margin-bottom: 14px;
}

.section-head p {
  margin: 0;
  color: var(--muted);
}

.range-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr)) repeat(3, auto);
  gap: 10px;
  align-items: end;
  margin: 18px 0;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

.sessions-table {
  table-layout: fixed;
}

.sessions-table th:nth-child(1),
.sessions-table td:nth-child(1) {
  width: 56px;
}

.sessions-table th:nth-child(2),
.sessions-table td:nth-child(2) {
  width: 120px;
}

.sessions-table th:nth-child(3),
.sessions-table td:nth-child(3) {
  width: 100px;
}

.sessions-table th:nth-child(4),
.sessions-table td:nth-child(4) {
  width: 76px;
}

.sessions-table th:nth-child(5),
.sessions-table td:nth-child(5) {
  width: 92px;
}

.sessions-table .row-actions {
  justify-content: center;
}

.sessions-table a {
  text-decoration: none;
}

.sessions-table .row-actions button {
  min-height: 0;
  min-width: 0;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  line-height: 1.2;
}

.audio-delete-check,
#checkAllAudios {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  cursor: pointer;
}

th:first-child,
td:first-child {
  min-width: 56px;
  text-align: center;
}

.lesson-cell {
  min-width: 128px;
  white-space: normal;
  word-break: keep-all;
}

.tag-cell {
  min-width: 112px;
  white-space: normal;
  word-break: keep-all;
}

th, td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  font-size: 15px;
  color: var(--muted);
  background: #f8fafc;
}

td small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
}

td audio { min-width: 220px; }

.grading-table {
  table-layout: fixed;
}

.grading-table th:first-child,
.grading-table td:first-child {
  width: 56px;
  min-width: 56px;
}

.grading-table .grading-answer {
  width: 100%;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.grading-table .grading-answer strong {
  display: block;
  font-size: 24px;
  line-height: 1.45;
}

.grading-table .grading-answer small {
  font-size: 17px;
  line-height: 1.55;
}

.filtered-out {
  display: none;
}

.edit-row td {
  background: #f8fafc;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px;
}

@media (max-width: 760px) {
  html, body {
    max-width: 100%;
    overflow-x: hidden;
  }
  .topbar { align-items: flex-start; flex-direction: column; min-height: 54px; padding: 12px 16px; }
  .navlinks { justify-content: flex-start; gap: 12px; }
  .shell { width: min(100% - 28px, 1120px); padding: 20px 0 40px; }
  .panel {
    box-sizing: border-box;
    max-width: 100%;
    overflow: hidden;
    padding: 22px;
  }
  .student-hero {
    min-height: 0;
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
  }
  .student-hero .eyebrow { margin-bottom: 8px; }
  .student-hero h1 { margin-bottom: 12px; }
  .student-hero .lead { margin: 0; font-size: 17px; line-height: 1.65; }
  .quiz-head, .answer-head { align-items: stretch; flex-direction: column; padding: 24px; }
  .sentence-search-heading { align-items: flex-start; }
  .quiz-choice { align-items: stretch; flex-direction: column; }
  h1 { font-size: 30px; }
  .admin-grid, .upload-grid, .edit-grid, .range-tools, .inline-form, .publish-form, .ui-copy-grid { grid-template-columns: 1fr; }
  .section-head {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }
  .section-head h2 {
    margin-bottom: 0;
  }
  .session-delete-actions {
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    width: 100%;
    gap: 6px;
    flex-wrap: nowrap;
  }
  .date-delete-form {
    display: flex;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
    width: auto;
    min-width: 0;
  }
  .date-delete-form input {
    box-sizing: border-box;
    width: 118px;
    min-width: 0;
    min-height: 32px;
    padding: 4px 6px;
    font-size: 13px;
  }
  .date-delete-form button {
    box-sizing: border-box;
    width: auto;
    min-height: 32px;
    padding: 0 8px;
    font-size: 13px;
  }
  .bulk-delete-form {
    flex: 0 0 auto;
  }
  .bulk-delete-form button {
    width: auto;
    min-height: 32px;
    padding: 0 8px;
    font-size: 13px;
  }
  .upload-grid .wide { grid-column: auto; }
  .ui-copy-grid .wide { grid-column: auto; }
  .audio-card, .answer-card { grid-template-columns: 46px 1fr; }
  .audio-delete-check,
  #checkAllAudios {
    width: 26px;
    height: 26px;
  }
  .grading-table .grading-answer { min-width: 0; }
  .grading-table .grading-answer strong { font-size: 21px; }
  .grading-table .grading-answer small { font-size: 16px; }
  .row-actions {
    gap: 6px;
  }
  .row-actions button {
    min-height: 36px;
    min-width: 56px;
    padding: 0 10px;
    font-size: 17px;
  }
  .sessions-table {
    display: block;
    width: 100%;
    border-collapse: collapse;
  }
  .sessions-table thead {
    display: none;
  }
  .sessions-table tbody {
    display: block;
    width: 100%;
  }
  .sessions-table tr {
    display: grid;
    grid-template-columns: minmax(44px, .5fr) minmax(92px, 1fr) minmax(74px, .85fr);
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
  }
  .sessions-table.has-select tr {
    grid-template-columns: 30px minmax(44px, .5fr) minmax(86px, 1fr) minmax(72px, .8fr);
  }
  .sessions-table td {
    display: block;
    box-sizing: border-box;
    min-width: 0;
    padding: 0;
    border: 0;
    font-size: 16px;
    overflow: visible;
    white-space: nowrap;
  }
  .sessions-table th {
    display: none;
  }
  .sessions-table:not(.has-select) td:nth-child(1) { order: 2; }
  .sessions-table:not(.has-select) td:nth-child(2) { order: 3; }
  .sessions-table:not(.has-select) td:nth-child(3) { order: 1; }
  .sessions-table:not(.has-select) td:nth-child(4) { display: none; }
  .sessions-table.has-select td:nth-child(1) { order: 1; }
  .sessions-table.has-select td:nth-child(2) { order: 3; }
  .sessions-table.has-select td:nth-child(3) { order: 4; }
  .sessions-table.has-select td:nth-child(4) { order: 2; }
  .sessions-table.has-select td:nth-child(5) { display: none; }
  .sessions-table td.empty {
    grid-column: 1 / -1;
    white-space: normal;
    text-align: center;
    color: var(--muted);
  }
  .sessions-table a {
    display: inline-block;
    max-width: 100%;
    font-size: 18px;
    font-weight: 800;
    white-space: nowrap;
  }
  .sessions-table .code-suffix {
    margin-left: 1px;
  }
  .sessions-table:not(.has-select) td:nth-child(2),
  .sessions-table.has-select td:nth-child(3) {
    color: var(--muted);
    font-size: 16px;
  }
  .sessions-table:not(.has-select) td:nth-child(3),
  .sessions-table.has-select td:nth-child(4) {
    justify-self: start;
  }
  .sessions-table:not(.has-select) td:nth-child(4),
  .sessions-table.has-select td:nth-child(5) {
    justify-self: end;
  }
  .sessions-table .row-actions {
    justify-content: center;
  }
  .sessions-table .row-actions button {
    min-height: 30px;
    min-width: 0;
    padding: 0 10px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
  }
  .sessions-table .status-graded,
  .sessions-table .status-aborted,
  .sessions-table .status-closed {
    padding: 4px 6px;
    font-size: 14px;
    line-height: 1.2;
    white-space: nowrap;
  }
  th:first-child,
  td:first-child {
    min-width: 0;
  }
  .sessions-table th:first-child,
  .sessions-table td:first-child {
    min-width: 0;
  }
  .lesson-cell {
    min-width: 140px;
  }
  .tag-cell {
    min-width: 120px;
  }
}
