:root {
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --paper: #fff;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --accent: #f59e0b;
  --accent-soft: #fff7ed;
  --success: #059669;
  --danger: #dc2626;
  --shadow: 0 10px 40px rgba(79, 70, 229, 0.12);
  --radius: 16px;
  --ui: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--ui);
  background: linear-gradient(160deg, #eef2ff 0%, #fdf4ff 45%, #fff7ed 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

.exam-head {
  background: linear-gradient(135deg, #4338ca 0%, #6366f1 55%, #818cf8 100%);
  color: #fff;
  padding: 1rem 1.1rem 1.1rem;
  box-shadow: 0 4px 24px rgba(67, 56, 202, 0.35);
}

.exam-head-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.exam-badge {
  display: inline-block;
  margin: 0 0 0.2rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}

.exam-level {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.92;
}

.exam-title {
  margin: 0.1rem 0 0;
  font-size: 1.45rem;
  font-weight: 800;
}

.exam-sub, .exam-name {
  margin: 0.25rem 0 0;
  font-size: 0.88rem;
  opacity: 0.9;
}

.timer-wrap {
  text-align: right;
  min-width: 6.5rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.5rem 0.65rem;
  border-radius: 12px;
  backdrop-filter: blur(4px);
}

.timer-phase-label {
  margin: 0 0 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.9;
}

.timer-value {
  display: block;
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 0.25rem 0.4rem;
  text-align: center;
}

.timer-total-line {
  margin: 0.3rem 0 0;
  font-size: 0.72rem;
  opacity: 0.85;
}

.timer-total-value {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.timer-wrap.is-warn .timer-value { color: #fde68a; }
.timer-wrap.is-danger .timer-value { color: #fecaca; }

.exam-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.sheet {
  background: var(--paper);
  border: none;
  border-radius: var(--radius);
  padding: 1.35rem 1.2rem 1.6rem;
  min-height: 55vh;
  box-shadow: var(--shadow);
}

.gate-form { text-align: center; padding: 2rem 0.5rem; }
.gate-title {
  margin: 0 0 1rem;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.cover {
  text-align: center;
  padding: 1.5rem 0.5rem 2rem;
}

.cover-line {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.cover-steps {
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.careful-box {
  margin: 0 auto 1.5rem;
  max-width: 440px;
  padding: 1rem 1.1rem;
  border: 2px solid #c7d2fe;
  border-radius: 14px;
  background: linear-gradient(180deg, #fafbff 0%, #f5f3ff 100%);
  text-align: left;
  font-size: 0.92rem;
  line-height: 1.5;
}

.careful-label {
  margin: 0 0 0.5rem;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--primary);
}

.careful-focus {
  margin: 0 0 0.35rem;
  font-weight: 700;
  color: var(--text);
}

.careful-reminder {
  margin: 0 0 0.65rem;
  color: var(--muted);
}

.careful-list {
  margin: 0;
  padding-left: 1.15rem;
  color: #475569;
  font-size: 0.88rem;
}

.careful-list li { margin: 0.25rem 0; }

.exam-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.exam-step {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  background: #f1f5f9;
  border: 2px solid transparent;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 800;
  background: #cbd5e1;
  color: #fff;
}

.exam-step.is-current {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 800;
}

.exam-step.is-current .step-num {
  background: var(--primary);
}

.exam-step.is-done {
  background: #ecfdf5;
  color: var(--success);
}

.exam-step.is-done .step-num {
  background: var(--success);
}

.exam-step[data-step="speaking"].is-current {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #b45309;
}

.exam-step[data-step="speaking"].is-current .step-num {
  background: var(--accent);
}

.phase-notice {
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 2px dashed #fcd34d;
  background: #fffbeb;
  font-size: 0.86rem;
  line-height: 1.45;
  color: #92400e;
}

.part-block {
  margin-top: 1.35rem;
  padding-top: 1.1rem;
  border-top: 2px solid var(--border);
}

.part-block:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.part-label {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 0.45rem;
  color: var(--primary-dark);
}

.part-intro {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  color: #475569;
}

.passage {
  margin: 0.5rem 0 0.75rem;
  line-height: 1.65;
  white-space: pre-wrap;
  font-family: Georgia, "Times New Roman", serif;
  background: #f8fafc;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.word-box {
  margin: 0.5rem 0 0.75rem;
  font-size: 0.92rem;
  line-height: 1.8;
  padding: 0.5rem 0.65rem;
  background: var(--primary-light);
  border-radius: 10px;
}

.dialogue-options {
  margin: 0.5rem 0 0.75rem;
  font-size: 0.92rem;
}

.dialogue-options p { margin: 0.15rem 0; }

.q {
  margin: 0.9rem 0;
  padding: 0.65rem 0.75rem;
  background: #fafafa;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.q-num {
  font-weight: 800;
  margin-right: 0.25rem;
  color: var(--primary);
}

.prompt { margin: 0 0 0.4rem; font-weight: 600; }

.options label {
  display: block;
  margin: 0.35rem 0;
  padding: 0.4rem 0.55rem;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}

.options label:hover { background: var(--primary-light); }

.field, .gap-input {
  width: 100%;
  max-width: 320px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  transition: border-color 0.15s;
}

.field:focus, .gap-input:focus {
  outline: none;
  border-color: var(--primary);
}

textarea.story {
  width: 100%;
  min-height: 120px;
  padding: 0.65rem;
  font: inherit;
  border: 2px solid var(--border);
  border-radius: 10px;
  resize: vertical;
}

.finish-row {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 2px solid var(--border);
}

.btn {
  font-family: var(--ui);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.6rem 1.35rem;
  border: none;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.45);
}

.btn-secondary {
  background: #fff;
  color: var(--muted);
  border: 2px solid var(--border);
}

.btn-wide {
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
}

.btn-begin {
  font-size: 1.05rem;
  padding: 0.85rem 1.25rem;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-play {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.35);
}

.btn-rec {
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  color: #fff;
  min-width: 6.5rem;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
}

.btn-stop {
  background: #fff;
  color: var(--danger);
  border: 2px solid var(--danger);
}

.paper.is-locked { opacity: 0.45; pointer-events: none; }

.result {
  margin-top: 1.25rem;
  padding: 1.5rem 1rem;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fafbff 0%, #fff 100%);
  border: 2px solid #c7d2fe;
  text-align: center;
}

.result h3 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.result-emoji {
  font-size: 2.5rem;
  line-height: 1;
  margin-bottom: 0.35rem;
}

.result-note {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.hidden { display: none !important; }

.listen-audio-box {
  margin-bottom: 1.25rem;
  padding: 1rem;
  border-radius: 14px;
  background: linear-gradient(135deg, #ecfeff 0%, #e0f2fe 100%);
  border: 2px solid #7dd3fc;
}

.listen-note {
  margin-top: 0.5rem !important;
  font-size: 0.82rem !important;
  color: #0369a1 !important;
}

.play-count {
  font-size: 0.88rem;
  color: var(--muted);
  margin-left: 0.5rem;
}

.gap-letter { max-width: 3.5rem; text-transform: uppercase; text-align: center; }

.speak-intro { font-weight: 600; }

.speak-prompt {
  margin: 0.35rem 0 0.65rem;
  line-height: 1.6;
}

.speak-task {
  padding: 0.85rem;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 2px solid #fed7aa;
}

.rec-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.25rem;
}

.rec-status {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.sheet.is-loading { opacity: 0.5; pointer-events: none; }

/* Custom modal */
.flyers-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.flyers-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 27, 75, 0.55);
  backdrop-filter: blur(4px);
  animation: modalFadeIn 0.2s ease;
}

.flyers-modal-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem 1.35rem 1.35rem;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(67, 56, 202, 0.35);
  animation: modalPopIn 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.flyers-modal-icon {
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  border-radius: 50%;
  background: var(--primary-light);
}

.flyers-modal-icon.is-warn { background: #fff7ed; }
.flyers-modal-icon.is-success { background: #ecfdf5; }
.flyers-modal-icon.is-mic { background: #fff7ed; }
.flyers-modal-icon.is-error { background: #fef2f2; }

.flyers-modal-title {
  margin: 0 0 0.65rem;
  font-size: 1.2rem;
  font-weight: 800;
  text-align: center;
  color: var(--primary-dark);
  line-height: 1.3;
}

.flyers-modal-body {
  font-size: 0.92rem;
  line-height: 1.55;
  color: #475569;
  margin-bottom: 1.25rem;
}

.flyers-modal-body p { margin: 0.4rem 0; }

.modal-highlight {
  margin: 0.65rem 0;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  font-weight: 600;
  color: var(--text);
}

.modal-warn-box {
  margin: 0.65rem 0;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: #fff7ed;
  border: 2px solid #fed7aa;
  color: #9a3412;
  font-weight: 600;
}

.modal-checklist {
  margin: 0.5rem 0 0;
  padding-left: 0;
  list-style: none;
}

.modal-checklist li {
  position: relative;
  padding: 0.35rem 0 0.35rem 1.5rem;
  margin: 0.15rem 0;
}

.modal-checklist li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 800;
}

.flyers-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.flyers-modal-actions .btn { width: 100%; text-align: center; }

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalPopIn {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (max-width: 480px) {
  .exam-head-inner { flex-direction: column; align-items: flex-start; }
  .timer-wrap { align-self: stretch; text-align: left; }
  .flyers-modal-card { padding: 1.25rem 1rem; }
}
