:root {
  --bg-deep:     #e8eef6;
  --bg-surface:  #ffffff;
  --bg-card:     #ffffff;
  --bg-card-alt: #f4f7fc;
  --bg-hover:    #eaf0f8;
  --border:      #d0dbea;
  --border-light:#e2e9f4;
  --text:        #1f2a3f;
  --text-muted:  #5a6f8a;
  --text-dim:    #8a9db3;
  --accent:      #3e6b9e;
  --accent-dim:  #89b0da;
  --green:       #3aab7a;
  --green-bg:    rgba(58,171,122,0.08);
  --red:         #d96574;
  --red-bg:      rgba(217,101,116,0.08);
  --radius-sm:   8px;
  --radius-md:   14px;
  --radius-lg:   20px;
  --shadow-card: 0 4px 24px rgba(62,107,158,0.08);
  --transition:  0.25s cubic-bezier(0.22,1,0.36,1);
}

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

html { -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Sora', sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(62,107,158,0.05) 0%, transparent 70%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(62,107,158,0.04) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 28px 60px;
}

#unit-view { display: block; }
#test-view { display: none; }

/* ===== UNIT SELECTION HEADER ===== */
.unit-header {
  padding: 52px 0 36px;
  margin-bottom: 40px;
  position: relative;
}

.unit-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-light) 15%, var(--border-light) 85%, transparent);
}

.unit-header-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.unit-logo {
  font-family: 'Epilogue', sans-serif;
  font-weight: 800;
  font-size: 36px;
  letter-spacing: -1.2px;
  background: linear-gradient(135deg, #1f2a3f 0%, #3e6b9e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}

.unit-version {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.unit-sub {
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 300;
  letter-spacing: 0.3px;
}

/* waveform bars */
.waveform {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 24px;
  margin-top: 16px;
}
.waveform span {
  display: block;
  width: 3px;
  background: var(--accent);
  opacity: 0.3;
  border-radius: 2px;
  animation: wave 1.6s ease-in-out infinite;
}
.waveform span:nth-child(1)  { height: 8px;  animation-delay: 0.0s; }
.waveform span:nth-child(2)  { height: 14px; animation-delay: 0.1s; }
.waveform span:nth-child(3)  { height: 20px; animation-delay: 0.2s; }
.waveform span:nth-child(4)  { height: 24px; animation-delay: 0.3s; }
.waveform span:nth-child(5)  { height: 18px; animation-delay: 0.15s; }
.waveform span:nth-child(6)  { height: 22px; animation-delay: 0.25s; }
.waveform span:nth-child(7)  { height: 16px; animation-delay: 0.35s; }
.waveform span:nth-child(8)  { height: 10px; animation-delay: 0.2s; }
.waveform span:nth-child(9)  { height: 20px; animation-delay: 0.4s; }
.waveform span:nth-child(10) { height: 12px; animation-delay: 0.1s; }
.waveform span:nth-child(11) { height: 18px; animation-delay: 0.3s; }
.waveform span:nth-child(12) { height: 8px;  animation-delay: 0.05s; }
.waveform span:nth-child(13) { height: 22px; animation-delay: 0.35s; }
.waveform span:nth-child(14) { height: 14px; animation-delay: 0.15s; }
.waveform span:nth-child(15) { height: 16px; animation-delay: 0.25s; }

@keyframes wave {
  0%, 100% { opacity: 0.2; transform: scaleY(0.6); }
  50% { opacity: 0.6; transform: scaleY(1); }
}

/* ===== UNIT GRID ===== */
.unit-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 640px) { .unit-grid { grid-template-columns: repeat(2,1fr); } }
@media (min-width: 900px) { .unit-grid { grid-template-columns: repeat(4,1fr); } }

.unit-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px 20px 20px;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
  animation: cardIn 0.5s ease both;
  animation-delay: calc(0.06s * var(--i, 0));
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.unit-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 32px rgba(62,107,158,0.10), var(--shadow-card);
}

.unit-card:active { transform: translateY(0); }

.unit-card-num {
  font-family: 'Epilogue', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.unit-checkmark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-12deg);
  width: 120px;
  height: 120px;
  border: 3px dashed rgba(58,171,122,0.20);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 60px;
  color: rgba(58,171,122,0.22);
  font-weight: 700;
  pointer-events: none;
  line-height: 1;
  user-select: none;
  box-shadow:
    0 0 0 6px rgba(58,171,122,0.04),
    0 0 20px rgba(58,171,122,0.06),
    inset 0 0 20px rgba(58,171,122,0.03);
  text-shadow: 0 1px 3px rgba(58,171,122,0.10);
}

.unit-card.is-done {
  border-color: rgba(58,171,122,0.20);
}

.unit-card-title {
  font-family: 'Epilogue', sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 6px;
}

.unit-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 300;
  margin-bottom: 16px;
  line-height: 1.4;
  flex: 1;
}

.unit-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.unit-card-count {
  color: var(--text-dim);
  font-weight: 400;
}

.unit-card-go {
  color: var(--accent);
  font-weight: 500;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity var(--transition);
}
.unit-card:hover .unit-card-go { opacity: 1; }
.unit-card-go::after {
  content: '';
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--accent);
  border-top: 1.5px solid var(--accent);
  transform: rotate(45deg);
  margin-top: -1px;
}

/* ===== TEST TOP BAR ===== */
.test-top {
  display: flex;
  align-items: center;
  padding: 24px 0 14px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  margin-right: 12px;
}
.btn-back:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.btn-back svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.8; fill: none; }

.test-top-title {
  font-family: 'Epilogue', sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  letter-spacing: -0.2px;
}

.test-progress {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0.5px;
}

/* ===== AUDIO PLAYER ===== */
.audio-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px 16px;
  margin-bottom: 32px;
}

.audio-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.audio-label .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.audio-section audio {
  width: 100%;
  display: block;
  border-radius: var(--radius-sm);
  outline: none;
}

audio::-webkit-media-controls-panel { background: var(--bg-card-alt); }
audio::-webkit-media-controls-current-time-display,
audio::-webkit-media-controls-time-remaining-display { color: var(--text-muted); }
audio { filter: brightness(1); }

/* ===== QUESTION LIST ===== */
.questions-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px 24px 18px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.question-card.is-correct {
  border-color: rgba(58,171,122,0.25);
  box-shadow: 0 0 0 1px rgba(58,171,122,0.08);
}
.question-card.is-wrong {
  border-color: rgba(217,101,116,0.25);
  box-shadow: 0 0 0 1px rgba(217,101,116,0.08);
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.question-text {
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.6;
  flex: 1;
}

.question-number {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.3px;
  padding-top: 2px;
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.status-badge.correct {
  background: var(--green-bg);
  color: var(--green);
}
.status-badge.wrong {
  background: var(--red-bg);
  color: var(--red);
}

/* ===== OPTIONS ===== */
.options-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
@media (min-width: 640px) {
  .options-list { grid-template-columns: 1fr 1fr; }
}

.option-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
  -webkit-user-select: none;
}

.option-item:hover {
  border-color: var(--accent-dim);
  background: var(--bg-hover);
  color: var(--text);
}

.option-item.selected {
  border-color: var(--accent);
  background: rgba(62,107,158,0.08);
  color: var(--text);
}

.option-item .opt-letter {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: all var(--transition);
}
.option-item.selected .opt-letter {
  background: var(--accent);
  color: #fff;
}
.option-item .opt-label { flex: 1; }

.option-item.is-right {
  border-color: rgba(58,171,122,0.30);
  background: rgba(58,171,122,0.06);
  color: var(--green);
}
.option-item.is-right .opt-letter {
  background: var(--green);
  color: #ffffff;
}
.option-item.is-wrong {
  border-color: rgba(217,101,116,0.30);
  background: rgba(217,101,116,0.06);
  color: var(--red);
}
.option-item.is-wrong .opt-letter {
  background: var(--red);
  color: #ffffff;
}

/* ===== RELISTEN ===== */
.relisten-wrap {
  margin-top: 14px;
  display: flex;
  align-items: center;
}

.btn-relisten {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px 6px 12px;
  font-family: 'Sora', sans-serif;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
  letter-spacing: 0.3px;
}
.btn-relisten:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
  background: rgba(62,107,158,0.06);
}
.btn-relisten svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.6;
  fill: none;
}

/* ===== TRANSCRIPT ===== */
.transcript-wrap {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-muted);
}

.transcript-head {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.transcript-line {
  padding: 2px 0;
  word-break: break-word;
}

.transcript-line + .transcript-line {
  border-top: 1px solid transparent;
}

/* ===== EXPLANATION ===== */
.explanation-wrapper {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.btn-explanation {
  background: none;
  border: none;
  font-family: 'Sora', sans-serif;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color var(--transition);
}
.btn-explanation:hover { color: var(--accent); }

.btn-explanation .arrow-icon {
  display: inline-flex;
  transition: transform 0.3s ease;
  color: var(--text-dim);
  font-size: 10px;
}
.btn-explanation .arrow-icon.open { transform: rotate(90deg); }

.explanation-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, padding 0.4s ease, opacity 0.3s ease;
  opacity: 0;
  padding-top: 0;
}
.explanation-body.open {
  max-height: 240px;
  opacity: 1;
  padding-top: 12px;
}
.explanation-body .inner {
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
  border-left: 2px solid var(--accent-dim);
}

/* ===== SUBMIT ===== */
.submit-area {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.btn-submit {
  background: linear-gradient(135deg, var(--accent) 0%, #3a5f8a 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 48px;
  font-family: 'Epilogue', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
  max-width: 340px;
  letter-spacing: 0.3px;
}
.btn-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(62,107,158,0.25);
}
.btn-submit:active { transform: translateY(0); }

.submit-error {
  color: var(--red);
  font-size: 13px;
  font-weight: 400;
  min-height: 22px;
  text-align: center;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #ffffff;
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 12px 28px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 400;
  box-shadow: 0 4px 24px rgba(62,107,158,0.12);
  opacity: 0;
  transition: transform 0.4s ease, opacity 0.4s ease;
  pointer-events: none;
  z-index: 999;
  max-width: 90vw;
  text-align: center;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 40px 0 10px;
  letter-spacing: 0.5px;
  font-weight: 300;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  #app { padding: 0 16px 40px; }
  .unit-header { padding: 32px 0 28px; margin-bottom: 28px; }
  .unit-logo { font-size: 28px; }
  .unit-sub { font-size: 13px; }
  .unit-card { padding: 18px 16px 16px; }
  .unit-card-title { font-size: 15px; }
  .test-top { padding: 18px 0 12px; margin-bottom: 20px; }
  .test-top-title { font-size: 15px; }
  .question-card { padding: 18px 16px 14px; }
  .question-text { font-size: 13px; }
  .option-item { padding: 10px 12px; font-size: 12px; }
  .audio-section { padding: 14px 14px 12px; }
  .btn-submit { padding: 13px 32px; font-size: 14px; }
  .unit-grid { gap: 12px; }
}

@media (max-width: 400px) {
  .unit-logo { font-size: 24px; }
  .unit-card-title { font-size: 14px; }
}
