/* css/style.css */
:root {
  --primary: #1e3a5f;
  --accent: #f97316;
  --accent-light: #fb923c;
  --bg-a: #f0f7ff;
  --bg-b: #e6f2ff;
  --card: #ffffff;
  --text: #1e3a5f;
  --muted: #6b7280;
  --green: #2ecc71;
  --red: #e74c3c;
  --sidebar-bg: #1e3a5f;
  --sidebar-hover: rgba(255, 255, 255, 0.10);
  --progress-track: #e5e7eb;
  --progress-fill-start: #67e8f9;
  --progress-fill-end: #22d3ee;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 8px 32px rgba(0, 59, 92, 0.10);
  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-orange: 0 4px 12px rgba(249, 115, 22, 0.30);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--bg-a) 0%, var(--bg-b) 100%);
  color: var(--text);
}
.screen { display: none; }
.screen.active { display: block; }
#screen-onboarding.active { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.break-screen.active { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 2rem;
  animation: cardIn 0.5s ease;
}
.hidden { display: none !important; }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
.demo-badge {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: #fff3df; color: #7a4a00; text-align: center;
  padding: 0.4rem; font-size: 0.85rem; border-bottom: 1px solid #ffd9a8;
}
.demo-badge.hidden { display: none; }

/* Onboarding */
.onboarding-card { max-width: 520px; width: 90%; }
.onboarding-card h1 { color: var(--primary); margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); margin-bottom: 1.5rem; }
.info-block { background: #eef2f5; border-radius: 8px; padding: 1rem; text-align: left; font-size: 0.92rem; margin-bottom: 1.5rem; }
.info-block ul { margin: 0.4rem 0 0.4rem 1.3rem; }
.howto { margin-top: 0.7rem; color: var(--primary); }
.input-group { margin-bottom: 1.25rem; text-align: left; }
.input-group label { display: block; font-weight: 600; margin-bottom: 0.4rem; }
.input-group input {
  width: 100%; padding: 0.75rem; font-size: 1rem;
  border: 2px solid #dde3e8; border-radius: 8px;
}
.input-group input:focus { outline: none; border-color: var(--primary); }

.btn {
  padding: 0.8rem 1.6rem; border: none; border-radius: 10px;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.3s ease;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #162b47; transform: translateY(-2px); box-shadow: 0 6px 18px rgba(30, 58, 95, 0.25); }
.btn-primary:disabled { background: #9fb4c2; cursor: not-allowed; }
.btn-ghost { background: #ffffff; color: var(--primary); border: 1px solid rgba(30, 58, 95, 0.15); }
.btn-ghost:hover { background: #eef4ff; transform: translateY(-2px); }

/* Exam header */
.exam-header {
  background: transparent; padding: 1.1rem 1.5rem 0.3rem;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 100;
}
.paper-title { font-weight: 700; color: var(--primary); font-size: 1.15rem; }
.part-label { margin-left: 0.8rem; color: var(--muted); }
.header-right { display: flex; gap: 1.2rem; align-items: center; }
.flag-status {
  display: flex; align-items: center; gap: 0.45rem;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: #fff; font-weight: 500; font-size: 15px; line-height: 1;
  padding: 0.6rem 1.15rem; border-radius: 10px;
  box-shadow: var(--shadow-orange); white-space: nowrap;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.flag-status i { font-size: 0.95rem; }
.timer {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px; padding: 0.4rem 1.1rem 0.5rem;
  box-shadow: var(--shadow-soft);
  min-width: 130px; text-align: center;
}
.timer > span { font-size: 36px; font-weight: 700; color: var(--text-primary, inherit); line-height: 1.05; }
.timer .timer-label { font-size: 12px; font-weight: 500; color: var(--muted); line-height: 1.2; }
.timer.warning { color: var(--red); background: #fdecea; animation: pulse 1s infinite; }
.timer.warning span { color: var(--red); }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.55; } 100% { opacity: 1; } }

.exam-body { display: flex; height: calc(100vh - 90px); gap: 1.25rem; padding: 1.25rem; }
.sidebar {
  width: 260px; min-width: 260px; background: var(--sidebar-bg);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  padding: 1.3rem 1rem; color: #fff;
  display: flex; flex-direction: column; gap: 1rem;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 0.6rem; color: #fff;
  font-weight: 700; font-size: 1.02rem;
  padding: 0.2rem 0.6rem 0.8rem; border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.sidebar-logo i { color: var(--progress-fill-start); font-size: 1.3rem; }
.parts-nav { display: flex; flex-direction: column; gap: 0.4rem; }
.parts-nav.small { flex-direction: row; flex-wrap: wrap; }
.nav-btn {
  padding: 0.62rem 0.9rem; text-align: left; background: transparent;
  color: rgba(255, 255, 255, 0.9); border: none; border-left: 3px solid transparent;
  border-radius: 10px; cursor: pointer; font-weight: 500; font-size: 0.95rem;
  font-family: inherit; transition: all 0.3s ease;
}
.nav-btn:hover { background: var(--sidebar-hover); color: #fff; }
.nav-btn.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--progress-fill-end); }
.nav-btn .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.35); margin-right: 0.4rem; }
.nav-btn .dot.answered { background: var(--green); }
.nav-btn .dot.flagged { background: var(--accent); }

.content-area { flex: 1; padding: 0.3rem 0.6rem 1rem; overflow-y: auto; }
.content-area h2 { color: var(--primary); margin-bottom: 0.5rem; }
.instruction { color: var(--muted); margin-bottom: 1.2rem; line-height: 1.5; }

/* Reading */
.reading-text {
  line-height: 1.9; font-size: 1.05rem; background: #fff;
  padding: 1.4rem 1.6rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-soft);
  margin-bottom: 1.5rem; animation: cardIn 0.5s ease;
}
.reading-text .gap { font-weight: 700; color: var(--primary); white-space: nowrap; }
.example-block {
  background: var(--bg-alt, #f3f6fb); border: 1px dashed var(--primary);
  padding: 0.8rem 1rem; border-radius: var(--radius); margin-bottom: 1.2rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; font-size: 0.95rem;
}
.example-block .keyword { margin: 0; }
.example-answer { font-weight: 700; color: #1a7f37; letter-spacing: 0.05em; }
.reading-text .example-answer { margin-left: 0.3rem; }
.passage { column-count: 2; column-gap: 2rem; }
@media (max-width: 900px) { .passage { column-count: 1; } }
.question-item {
  background: #fff; padding: 1.3rem 1.4rem; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft); margin-bottom: 1rem; position: relative;
  animation: cardIn 0.5s ease;
}
.question-item.flagged { border-left: 4px solid var(--accent); }
.question-item h4 { margin-bottom: 0.7rem; color: var(--primary); }
.question-item .prompt { margin-bottom: 0.8rem; line-height: 1.5; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.options.single-col { grid-template-columns: 1fr; }
.option-label {
  display: flex; align-items: center; padding: 0.72rem 0.85rem;
  border: 2px solid #e5e7eb; border-radius: 10px; cursor: pointer;
  transition: all 0.15s ease; font-size: 0.95rem;
}
.option-label:hover { border-color: var(--progress-fill-end); background: #f0f7ff; }
.option-label input { display: none; }
.option-label.selected { border-color: var(--primary); background: var(--primary); color: #fff; font-weight: 600; }
.option-label.selected .letter { color: var(--progress-fill-start); }
.option-label .letter { font-weight: 700; margin-right: 0.5rem; color: var(--primary); }
.btn-flag {
  position: absolute; top: 0.7rem; right: 0.7rem; background: none;
  border: none; color: #cbd5e1; font-size: 1.1rem; cursor: pointer; transition: all 0.15s ease;
}
.btn-flag:hover { color: var(--accent); transform: translateY(-1px); }
.btn-flag.flagged { color: var(--accent); }
.text-answer {
  width: 60%; padding: 0.5rem; font-size: 1rem;
  border: 2px solid #dde3e8; border-radius: 6px;
}
.text-answer:focus { outline: none; border-color: var(--primary); }
.answer-line { font-size: 1.02rem; line-height: 2; }
.answer-line input { width: 220px; }
.people-blocks { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.people-block { background: #fff; padding: 1rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); font-size: 0.92rem; line-height: 1.55; }
.people-block b { color: var(--primary); }
@media (max-width: 900px) { .people-blocks { grid-template-columns: 1fr; } }

/* Writing */
.writing-main { padding: 1.6rem 2rem; max-width: 1120px; margin: 0 auto; }
.writing-pane { margin-bottom: 1.8rem; border-radius: var(--radius-lg); }
.writing-pane h3 { color: var(--primary); margin-bottom: 0.6rem; }
.task-prompt { background: #fff; padding: 1rem 1.2rem; border-radius: 12px; box-shadow: var(--shadow-soft); line-height: 1.55; margin-bottom: 0.7rem; animation: cardIn 0.5s ease; }
.task-choices { display: flex; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.7rem; }
.task-choice {
  flex: 1; min-width: 220px; padding: 0.9rem; border: 2px solid #e5e7eb;
  border-radius: 12px; cursor: pointer; background: #fff; text-align: left; font-family: inherit;
  transition: all 0.3s ease;
}
.task-choice:hover { border-color: var(--progress-fill-end); background: #f0f7ff; }
.task-choice.selected { border-color: var(--primary); background: #eef4ff; }
.task-choice h5 { color: var(--primary); margin-bottom: 0.3rem; }
.task-choice p { font-size: 0.85rem; color: var(--muted); }
.writing-pane textarea {
  width: 100%; padding: 0.9rem; font-size: 1.02rem; line-height: 1.6;
  border: 2px solid #e5e7eb; border-radius: 12px; resize: vertical;
  font-family: inherit;
}
.writing-pane textarea:focus, .input-group input:focus { outline: none; border-color: var(--primary); }
.words { margin-top: 0.4rem; font-size: 0.9rem; color: var(--muted); }
.words .target { color: #999; }
.words.ok { color: var(--green); font-weight: 600; }
.words.warn { color: var(--red); font-weight: 600; }
.writing-footer { display: flex; align-items: center; gap: 1rem; }
.save-status { font-size: 0.85rem; color: var(--muted); }

/* Listening */
.audio-box { padding: 0.4rem 0; }
audio { width: 100%; }

/* Breaks */
.break-card { max-width: 460px; text-align: center; }
.break-icon { font-size: 2.6rem; color: var(--accent); margin-bottom: 0.8rem; }
.break-timer { font-size: 3rem; font-weight: 700; color: var(--primary); margin: 1rem 0 1.4rem; }

/* Results */
.results-main { padding: 1.6rem 2rem; max-width: 860px; margin: 0 auto; }
.result-card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); padding: 1.2rem 1.4rem; margin-bottom: 1rem; animation: cardIn 0.5s ease; }
.result-card h3 { color: var(--primary); margin-bottom: 0.6rem; }
.result-row { display: flex; justify-content: space-between; padding: 0.25rem 0; border-bottom: 1px dashed #eaeef1; }
.result-row:last-child { border-bottom: none; }
.result-score { font-weight: 700; color: var(--primary); }
.grand-total { font-size: 1.4rem; font-weight: 700; color: var(--primary); text-align: center; padding: 1rem 0; }
.results-footer { display: flex; gap: 1rem; margin-top: 1.2rem; }
.results-main .howto { color: var(--muted); font-size: 0.95rem; }

/* Option lists, pills, keywords */
.options-legend { margin-bottom: 1.2rem; }
.options-legend h4 { color: var(--primary); margin-bottom: 0.5rem; }
.option-pill {
  display: block; padding: 0.7rem 0.9rem; margin-bottom: 0.5rem;
  background: #fff; border-radius: 12px; box-shadow: var(--shadow-soft);
  font-size: 0.95rem; line-height: 1.45;
}
.option-pill .letter, .option-pill .pill-letter {
  font-weight: 700; color: var(--primary); margin-right: 0.4rem;
}
.pills { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.pill {
  min-width: 42px; height: 42px; padding: 0 0.6rem;
  border: 2px solid #dde3e8; border-radius: 24px; background: #fff;
  font-weight: 700; font-size: 0.95rem; color: var(--primary);
  cursor: pointer; font-family: inherit; transition: 0.15s;
}
.pill:hover { border-color: var(--primary); background: #f8f9fa; }
.pill.selected { border-color: var(--primary); background: var(--primary); color: #fff; }
.progress-bar {
  position: sticky; bottom: 0; height: 8px; background: var(--progress-track);
  border-radius: 5px; overflow: hidden; margin-top: 0.4rem;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--progress-fill-start), var(--progress-fill-end));
  border-radius: 5px; transition: width 0.5s ease;
}
.keyword { margin-bottom: 0.7rem; font-size: 0.95rem; color: var(--muted); }
.keyword strong { color: var(--accent); }
.gap-inline { display: inline-block; }
.gap-inline input.text-answer { width: 170px; max-width: 100%; }

/* Speaking organizer page */
.speaking-main { padding: 1.6rem 2rem; max-width: 980px; margin: 0 auto; }
.speaking-stage { display: flex; gap: 1.4rem; flex-wrap: wrap; margin-top: 1.2rem; }
.speaking-pane { flex: 1; min-width: 320px; background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); padding: 1.2rem 1.4rem; animation: cardIn 0.5s ease; }
.speaking-pane h3 { color: var(--primary); margin-bottom: 0.6rem; }
.speaking-script { line-height: 1.7; font-size: 1.02rem; }
.speaking-script p { margin-bottom: 0.6rem; }
.speaking-script .cue { color: var(--accent); font-weight: 700; }
.speaking-prompts { line-height: 1.6; }
.speaking-prompts p { margin: 0.55rem 0; font-size: 0.98rem; }
.speaking-timer { font-size: 3.4rem; font-weight: 700; color: var(--primary); text-align: center; padding: 0.5rem 0; }
.speaking-timer.warning { color: var(--red); animation: pulse 1s infinite; }
.controls { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.controls .btn { font-size: 0.95rem; padding: 0.6rem 1.1rem; }
.speaking-notes { font-size: 0.9rem; color: var(--muted); line-height: 1.5; }

/* Teacher Dashboard */
.teacher-main .exam-header .btn-ghost.active { background: var(--primary); color: #fff; }
.teacher-body { max-width: 1200px; margin: 0 auto; padding: 1.5rem 2rem; }
.teacher-tab { display: none; }
.teacher-tab.active { display: block; }
.teacher-panels { display: grid; grid-template-columns: 320px 1fr; gap: 1.2rem; }
@media (max-width: 900px) { .teacher-panels { grid-template-columns: 1fr; } }
.teacher-side { background: #fff; padding: 1.2rem 1.4rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); }
.teacher-main-pane { background: #fff; padding: 1.4rem 1.6rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); }
.teacher-side h3 { color: var(--primary); margin: 0.4rem 0 0.7rem; }
.teacher-main-pane h3 { color: var(--primary); margin-bottom: 0.6rem; }
#tw-works-list .work-item { padding: 0.6rem 0.8rem; border: 2px solid #eee; border-radius: 8px; margin-bottom: 0.5rem; cursor: pointer; }
#tw-works-list .work-item.selected { border-color: var(--progress-fill-end); background: #f0f7ff; }
.manual-form { margin: 0.7rem 0; padding: 0.7rem 0.9rem; border: 1px dashed var(--primary); border-radius: 8px; }
.manual-form input, .manual-form textarea { margin-top: 0.4rem; }
.muted { color: var(--muted); font-style: italic; }
.task-block { margin-bottom: 1.1rem; }
.task-block h4 { color: var(--primary); margin-bottom: 0.6rem; }
.slider-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin-bottom: 0.7rem; }
.slider-row label { flex: 1; }
.slider-row input[type=range] { flex: 2; }
.slider-row .slider-val { width: 2.2rem; text-align: right; font-weight: 700; }
.score-summary { margin: 1rem 0; padding: 0.9rem 1rem; background: var(--bg-alt, #f3f6fb); border-radius: 8px; line-height: 1.5; }
.sp-slider-grid .slider-row input[type=range] { accent-color: var(--accent); }
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin: 1rem 0; }
.photos .speaking-photo { width: 100%; border-radius: 8px; box-shadow: var(--shadow); cursor: zoom-in; }
.photos-row { display: flex; gap: 0.6rem; margin-bottom: 0.8rem; }
.cand-btn { font-size: 0.85rem; }
.img-missing { color: var(--muted); font-style: italic; }
.speaking-lightbox { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1000; background: rgba(0, 0, 0, 0.92); display: none; align-items: center; justify-content: center; padding: 1rem; box-sizing: border-box; }
.speaking-lightbox.open { display: flex; }
.speaking-lightbox-inner { position: relative; max-width: 100%; max-height: 100%; }
.speaking-lightbox .speaking-lightbox-img { max-width: 95vw; max-height: 95vh; object-fit: contain; border-radius: 4px; }
.speaking-lightbox-close { position: absolute; top: -2.4rem; right: 0; background: none; border: none; color: #fff; font-size: 2.4rem; line-height: 1; cursor: pointer; padding: 0.2rem 0.4rem; }
.speaking-lightbox:not(.open) .speaking-lightbox-close { display: none; }
body.lightbox-lock { overflow: hidden; }
.teacher-side textarea, .teacher-main-pane textarea { width: 100%; min-height: 90px; margin-top: 0.8rem; border: 2px solid #eee; border-radius: 8px; padding: 0.6rem; font-family: inherit; box-sizing: border-box; }
.teacher-side input[type=text] { width: 100%; margin-top: 0.8rem; border: 2px solid #eee; border-radius: 8px; padding: 0.6rem; font-family: inherit; box-sizing: border-box; }

/* Tablet */
@media (max-width: 1024px) {
  .sidebar { width: 200px; min-width: 200px; }
  .exam-body { padding: 1rem; gap: 1rem; }
  .timer > span { font-size: 30px; }
}

/* Mobile */
@media (max-width: 768px) {
  .exam-body { flex-direction: column; height: auto; }
  .sidebar { width: 100%; min-width: 0; border-radius: 16px; padding: 0.8rem; }
  .sidebar-logo { display: none; }
  .parts-nav, .parts-nav.small { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 0.5rem; }
  .nav-btn { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  .nav-btn.active { border-bottom-color: var(--progress-fill-end); }
  .content-area { padding: 0.3rem 0.2rem 1rem; overflow: visible; }
  .exam-header { padding: 0.9rem 1rem 0.3rem; }
  .header-right { flex-wrap: wrap; gap: 0.7rem; }
  .timer > span { font-size: 28px; }
  .timer { padding: 0.3rem 0.8rem; min-width: 100px; }
  .card { padding: 1.25rem; }
  .options, .people-blocks { grid-template-columns: 1fr; }
}