:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --correct: #16a34a;
  --incorrect: #ef4444;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --focus-bg: #d64f87;
  --focus-ring: #d64f87;
  --focus-text: #ffffff;
  --mark-bg: #7a2323;
  --mark-text: #ffffff;
  --selection-bg: #d64f87;
  --selection-text: #ffffff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

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

.loading-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-weight: 800;
  color: var(--muted);
}

.topbar {
  height: 58px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  box-shadow: var(--shadow);
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 420px;
}

.logo {
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #ef4444;
  user-select: none;
  white-space: nowrap;
}

.meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.2;
}

.meta-line {
  font-weight: 700;
  font-size: 14px;
  color: #111827;
}

.meta-red {
  color: #ef4444;
  font-weight: 900;
}

.timer {
  font-weight: 900;
  color: #ef4444;
  font-size: 18px;
  letter-spacing: 0.3px;
}

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

.audiobar {
  flex: 1;
  min-width: 300px;
  max-width: 520px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
}

.audio-icon-btn,
.audio-chip-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.audio-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.audio-chip-btn {
  min-width: 44px;
  height: 28px;
  border-radius: 999px;
  padding: 0 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.audio-time {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.audio-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: #065f46;
  font-size: 12px;
  font-weight: 900;
  flex: 0 0 auto;
}

.audio-status.is-waiting {
  color: var(--muted);
}

.audio-status.is-ended {
  color: #1d4ed8;
}

.audio-separator {
  opacity: 0.7;
}

.audio-volume {
  width: 82px;
  flex: 0 0 82px;
  accent-color: var(--accent);
}

#audioPlayer {
  display: none;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.btn:hover {
  border-color: #cbd5e1;
}

.btn.ghost {
  background: #fff;
}

.btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon:hover {
  border-color: #cbd5e1;
}

.main {
  margin: 12px 14px 0 14px;
  height: calc(100vh - 58px - 12px - 52px - 18px);
  display: flex;
  gap: 10px;
}

.main.single-layout {
  display: flex;
  flex-direction: column;
}

.attempt-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 10px;
  flex: 0 0 auto;
}

.attempt-panel-title {
  font-size: 13px;
  font-weight: 900;
  color: #111827;
  margin-bottom: 8px;
}

.attempt-current-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.attempt-stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 8px 10px;
}

.attempt-stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.attempt-stat-value {
  font-size: 14px;
  font-weight: 800;
  color: #111827;
  line-height: 1.35;
}

.attempt-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 124px;
  overflow: auto;
}

.attempt-history-item,
.attempt-history-empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
}

.attempt-history-item strong {
  display: inline-block;
  margin-right: 8px;
}

.attempt-history-empty {
  color: var(--muted);
}

.pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.single-pane {
  width: 100%;
  height: 100%;
}

.pane-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-weight: 900;
  font-size: 14px;
}

.pane-body {
  padding: 14px 16px;
  overflow: auto;
  height: 100%;
  font-size: 18px;
  line-height: 1.7;
  background: #fbfbff;
}

#questionsPane {
  position: relative;
}

#questionsPane .questions-section {
  max-width: 900px;
  margin: 0 auto;
}

#questionsPane h1,
#questionsPane h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

#questionsPane h3,
#questionsPane h4 {
  font-size: 18px;
  margin: 6px 0 8px;
}

#questionsPane p {
  margin-bottom: 10px;
}

#questionsPane ul,
#questionsPane ol {
  margin: 8px 0 12px 18px;
}

#questionsPane li {
  margin-bottom: 6px;
}

#questionsPane table {
  width: 100%;
}

#questionsPane .question-group {
  margin-bottom: 16px;
}

#questionsPane .question {
  border-radius: 8px;
}

#questionsPane .question.is-active-question {
  background: transparent;
  box-shadow: none;
  outline: none;
}

#questionsPane .question.is-correct {
  background: #f0fdf4;
}

#questionsPane .question.is-wrong {
  background: #fef2f2;
}

#questionsPane .question.is-unanswered {
  background: #fff7ed;
}

#questionsPane .question-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 17px;
}

#questionsPane .question-table th,
#questionsPane .question-table td {
  border: 1px solid var(--line);
  padding: 10px 8px;
  vertical-align: top;
  text-align: left;
}

#questionsPane .question-table th {
  background: #f8fafc;
}

#questionsPane .note-box,
#questionsPane .listening-match-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: #fff;
  margin: 10px 0 16px;
}

#questionsPane .listening-match-block {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(220px, 0.85fr);
  gap: 14px;
}

#questionsPane .listening-match-left,
#questionsPane .listening-match-right,
#questionsPane .feature-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#questionsPane .feature-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

#questionsPane .feature-row.is-active-question {
  background: #ffffff;
  border-color: var(--line);
  box-shadow: none;
}

#questionsPane .feature-row.is-drop-target {
  border-color: #93c5fd;
  background: #eff6ff;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

#questionsPane .feature-row.is-filled .feature-input {
  border-bottom-color: var(--accent);
}

#questionsPane .feature-qtext {
  flex: 1;
  font-size: 18px;
  line-height: 1.5;
}

#questionsPane .feature-opt,
#questionsPane [data-feature-value],
#questionsPane [data-option-value] {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  text-align: left;
}

#questionsPane .feature-opt.is-selected-option,
#questionsPane [data-feature-value].is-selected-option,
#questionsPane [data-option-value].is-selected-option {
  background: #e0e7ff;
  border-color: #93c5fd;
}

#questionsPane .feature-opt.is-dragging,
#questionsPane [data-feature-value].is-dragging,
#questionsPane [data-option-value].is-dragging {
  opacity: 0.55;
  transform: scale(0.98);
}

#questionsPane .feature-opt.is-used-option,
#questionsPane [data-feature-value].is-used-option,
#questionsPane [data-option-value].is-used-option {
  opacity: 0.45;
  cursor: not-allowed;
}

#questionsPane .choice-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 17px;
  padding: 2px 0;
}

#questionsPane input[type="radio"] {
  margin-top: 5px;
}

.blank,
.feature-input,
.answer-slot,
.drop-slot {
  min-width: 100px;
  min-height: 30px;
  font-size: 17px;
  padding: 2px 4px;
  border: none;
  border-bottom: 2px solid #9ca3af;
  background: transparent;
  outline: none;
  border-radius: 0;
  box-shadow: none;
  vertical-align: baseline;
}

.blank:focus,
.feature-input:focus,
.answer-slot:focus,
.drop-slot:focus {
  border-bottom-color: var(--accent);
  background: rgba(219, 234, 254, 0.35);
}

.feature-input {
  min-width: 140px;
  text-align: center;
  cursor: pointer;
}

.feature-input.is-drop-target {
  border-bottom-color: var(--accent);
  background: rgba(219, 234, 254, 0.45);
}

#questionsPane .hl,
#questionsPane .highlight,
#questionsPane .custom-highlight,
#questionsPane .text-highlight,
#questionsPane .user-highlight,
#questionsPane [data-highlight="true"] {
  background: var(--mark-bg);
  color: var(--mark-text);
  border-radius: 4px;
  padding: 0 2px;
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.18);
}

#questionsPane .user-highlight[data-highlight-state="double"],
#questionsPane [data-highlight="true"][data-highlight-state="double"] {
  background: var(--selection-bg);
  color: var(--selection-text);
}

#questionsPane ::selection {
  background: var(--selection-bg);
  color: var(--selection-text);
}

#questionsPane ::-moz-selection {
  background: var(--selection-bg);
  color: var(--selection-text);
}

#selbar {
  position: fixed;
  display: none;
  z-index: 9999;
  background: #111827;
  color: #fff;
  border-radius: 10px;
  padding: 6px 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  gap: 6px;
}

#selbar button {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: #fff;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-weight: 800;
}

.notes {
  position: fixed;
  right: 14px;
  bottom: 78px;
  width: 320px;
  height: 40vh;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
  display: none;
  z-index: 9000;
}

.notes .nh {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 900;
}

.notes textarea {
  width: 100%;
  height: calc(40vh - 46px);
  border: none;
  outline: none;
  padding: 10px 12px;
  resize: none;
  font-size: 14px;
  line-height: 1.5;
}

.settings-panel {
  position: fixed;
  top: 66px;
  right: 14px;
  width: 260px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
  padding: 14px;
  display: none;
  z-index: 9000;
}

.settings-head {
  font-weight: 900;
  margin-bottom: 12px;
}

.settings-item + .settings-item {
  margin-top: 14px;
}

.settings-label {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 8px;
}

.settings-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-choice {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.settings-choice.is-active {
  background: #e0e7ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 70px;
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
  display: none;
  z-index: 99999;
  font-weight: 800;
  font-size: 14px;
}

.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 52px;
  background: #fff;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.06);
  z-index: 8000;
}

.part-chip {
  font-weight: 900;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff;
  user-select: none;
}

.part-chip.done {
  background: var(--green-bg);
  border-color: var(--green);
  color: #065f46;
}

.qnums {
  display: flex;
  gap: 8px;
  align-items: center;
  overflow: auto;
}

.qbtn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 900;
  background: #f9fafb;
  cursor: pointer;
  user-select: none;
  flex: 0 0 auto;
}

.qbtn.done {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.qbtn.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.qbtn.incorrect {
  background: var(--incorrect);
  border-color: var(--incorrect);
  color: #fff;
}

.qbtn.active {
  outline: 2px solid var(--accent);
  background: #e0e7ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10000;
}

.confirm-overlay.is-open {
  display: flex;
}

.confirm-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

.confirm-card h3 {
  font-size: 18px;
  font-weight: 900;
  margin-bottom: 10px;
}

.confirm-card p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

body.theme-dark-white {
  --bg: #000000;
  --panel: #ffffff;
  --line: #111111;
  --text: #000000;
  --muted: #333333;
}

body.theme-dark-yellow {
  --bg: #000000;
  --panel: #fef3c7;
  --line: #111111;
  --text: #000000;
  --muted: #4b5563;
}

body.text-large .pane-body,
body.text-large #questionsPane .feature-qtext,
body.text-large #questionsPane .question-table {
  font-size: 21px;
}

body.text-large .blank,
body.text-large .feature-input {
  font-size: 20px;
}

body.text-extra-large .pane-body,
body.text-extra-large #questionsPane .feature-qtext,
body.text-extra-large #questionsPane .question-table {
  font-size: 24px;
}

body.text-extra-large .blank,
body.text-extra-large .feature-input {
  font-size: 23px;
}

@media (max-width: 960px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 10px 14px;
    gap: 10px;
  }

  .brand {
    min-width: 0;
  }

  .actions {
    flex-wrap: wrap;
  }

  .main {
    height: calc(100vh - 110px - 12px - 52px - 18px);
  }

  .attempt-panel {
    grid-template-columns: 1fr;
  }

  #questionsPane .listening-match-block {
    grid-template-columns: 1fr;
  }

  .audiobar {
    order: 3;
    width: 100%;
    max-width: none;
  }
}

body:not([data-mode="mock"]) #app .bottombar {
  position: fixed;
  inset: auto 0 0 0;
  top: auto;
  right: 0;
  bottom: 0;
  left: 0;
  height: auto;
  min-height: 0;
  max-height: 80px;
  flex: 0 0 auto;
  align-self: auto;
  box-sizing: border-box;
  align-items: center;
  padding: 8px 14px;
  overflow: hidden;
}

body:not([data-mode="mock"]) #app .bottombar .part-chip,
body:not([data-mode="mock"]) #app .bottombar .qbtn {
  flex: 0 0 auto;
}

body:not([data-mode="mock"]) #app .bottombar .qnums {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 44px;
  align-self: center;
  overflow-x: auto;
  overflow-y: hidden;
}
