:root {
  --bg: #f4f7f7;
  --card: #ffffff;
  --text: #132228;
  --text-muted: #5e7179;
  --line: #e3eaec;
  --brand: #0f766e;
  --brand-light: #e6f6f4;
  --brand-hover: #115e59;
  --brand-dark: #0a4641;
  --accent: #d97706;
  --accent-light: #fef3c7;
  --ok: #15803d;
  --ok-light: #ecfdf3;
  --ok-border: #86efac;
  --bad: #b91c1c;
  --bad-light: #fef2f2;
  --bad-border: #fca5a5;
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 10px 25px rgba(15, 118, 110, 0.12);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  font-size: 15px;
  min-height: 100vh;
}

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

/* Shell Layout */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(76px + var(--safe-bottom));
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.topinner {
  max-width: 920px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  color: var(--brand);
  letter-spacing: -0.02em;
  cursor: pointer;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: white;
  font-size: 14px;
  font-weight: 900;
}

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

.badge {
  font-size: 12px;
  font-weight: 600;
  background: var(--brand-light);
  color: var(--brand);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.2);
}

/* Main Container */
.main {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 18px 16px;
  flex: 1;
}

/* Hero Section */
.hero {
  background: linear-gradient(135deg, #0d9488 0%, #0f766e 50%, #115e59 100%);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0;
  opacity: 0.92;
  font-size: 14px;
  max-width: 600px;
}

.progress-wrap {
  margin-top: 18px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.progress-bar {
  height: 10px;
  background: rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  background: #ffffff;
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 18px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 12px 10px;
  border-radius: var(--radius-md);
  text-align: center;
  backdrop-filter: blur(8px);
}

.stat-box b {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}

.stat-box span {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.9;
}

/* Cards & Actions Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.action-card {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.action-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #99d5ce;
}

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

.action-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.action-card h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.action-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
}

.card-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--brand-light);
  color: var(--brand);
}

.card-tag.accent {
  background: var(--accent-light);
  color: var(--accent);
}

/* Question Practice View */
.q-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.q-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.q-num {
  font-size: 18px;
  font-weight: 800;
  color: var(--brand);
}

.q-meta {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 3px 8px;
  border-radius: 6px;
}

.q-actions {
  display: flex;
  gap: 6px;
}

/* Question Visual Image */
.visual-container {
  margin: 16px auto;
  max-width: 680px;
  text-align: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.visual-img {
  max-width: 100%;
  max-height: 280px;
  height: auto;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s ease;
  object-fit: contain;
  display: inline-block;
}

.visual-img:hover {
  transform: scale(1.02);
}

.visual-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Question Text */
.q-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin: 14px 0 16px;
  line-height: 1.5;
}

/* Options */
.options-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: #ffffff;
  border: 1.5px solid #dbe2e6;
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 48px;
}

.option-btn:hover:not(:disabled) {
  border-color: #93c5c0;
  background: #fbfdfd;
}

.option-letter {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1.5px solid #cbd5e1;
  font-size: 13px;
  font-weight: 700;
  color: #475569;
  background: #f8fafc;
  margin-top: 1px;
}

.option-text {
  flex: 1;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
}

.option-icon {
  flex: 0 0 22px;
  font-size: 16px;
  font-weight: bold;
  display: none;
}

/* Option States */
.option-btn.selected {
  border-color: var(--brand);
  background: var(--brand-light);
}

.option-btn.selected .option-letter {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.option-btn.correct {
  border-color: var(--ok-border) !important;
  background: var(--ok-light) !important;
}

.option-btn.correct .option-letter {
  border-color: var(--ok);
  background: var(--ok);
  color: white;
}

.option-btn.correct .option-icon {
  display: block;
  color: var(--ok);
}

.option-btn.wrong {
  border-color: var(--bad-border) !important;
  background: var(--bad-light) !important;
}

.option-btn.wrong .option-letter {
  border-color: var(--bad);
  background: var(--bad);
  color: white;
}

.option-btn.wrong .option-icon {
  display: block;
  color: var(--bad);
}

/* Feedback Box */
.feedback-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  animation: fadeIn 0.2s ease;
}

.feedback-box.ok {
  background: var(--ok-light);
  border: 1px solid var(--ok-border);
  color: #14532d;
}

.feedback-box.bad {
  background: var(--bad-light);
  border: 1px solid var(--bad-border);
  color: #7f1d1d;
}

.feedback-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}

.feedback-explanation {
  font-size: 13.5px;
  margin-top: 6px;
  line-height: 1.45;
  opacity: 0.95;
}

/* Source Question Toggle */
.source-toggle-wrap {
  margin-top: 14px;
}

.source-toggle-btn {
  background: none;
  border: none;
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.source-toggle-btn:hover {
  text-decoration: underline;
}

.source-drawer {
  margin-top: 10px;
  padding: 10px;
  background: #f8fafb;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  text-align: center;
}

.source-drawer img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
}

/* Navigation Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 14px;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn-secondary {
  background: #e7eff1;
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #d8e4e7;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-ghost:hover:not(:disabled) {
  background: #f0f4f5;
}

.btn-danger {
  background: var(--bad);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #991b1b;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  min-height: 36px;
}

/* Question Jump Selector */
.jump-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.jump-input {
  width: 70px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
}

/* Exam Mode UI */
.exam-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 14px;
}

.exam-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
}

.exam-palette {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 14px 0;
}

.palette-chip {
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.palette-chip.current {
  outline: 2px solid var(--brand);
}

.palette-chip.answered {
  background: #e2f4f1;
  border-color: #99d5ce;
  color: var(--brand);
}

/* Exam Result Card */
.result-card {
  text-align: center;
  padding: 28px 20px;
}

.result-badge {
  display: inline-block;
  font-size: 40px;
  margin-bottom: 12px;
}

.result-score {
  font-size: 32px;
  font-weight: 900;
  color: var(--brand);
  margin-bottom: 4px;
}

.result-verdict {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 16px;
}

.result-verdict.pass {
  color: var(--ok);
}

.result-verdict.fail {
  color: var(--bad);
}

/* 600 Review Chips & Filters */
.filter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.tab-pill {
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-pill.active {
  background: var(--brand-light);
  border-color: #99d5ce;
  color: var(--brand);
  font-weight: 700;
}

.search-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  background: #ffffff;
  font-size: 14px;
  margin-bottom: 14px;
}

.search-input:focus {
  outline: none;
  border-color: var(--brand);
}

.chips-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.qchip {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s ease;
}

.qchip:hover {
  transform: translateY(-1px);
  border-color: #99d5ce;
}

.qchip.done {
  background: var(--ok-light);
  border-color: var(--ok-border);
  color: #166534;
}

.qchip.bad {
  background: var(--bad-light);
  border-color: var(--bad-border);
  color: #991b1b;
}

.qchip.book {
  box-shadow: inset 0 0 0 2px #f59e0b;
}

/* Bottom Navigation */
.nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}

.nav-inner {
  max-width: 920px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 2px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease;
}

.nav-item-icon {
  font-size: 18px;
  margin-bottom: 2px;
}

.nav-item-label {
  font-size: 11px;
  font-weight: 600;
}

.nav-item.active {
  color: var(--brand);
}

.nav-item.active .nav-item-label {
  font-weight: 800;
}

/* Lightbox Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  animation: slideUp 0.2s ease;
}

.lightbox-content {
  max-width: 90vw;
  max-height: 85vh;
  text-align: center;
  position: relative;
}

.lightbox-img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 12px;
  background: white;
}

.lightbox-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  border: none;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
}

/* Notice box */
.notice-box {
  font-size: 13px;
  color: var(--text-muted);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 20px;
  line-height: 1.5;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* Responsive queries */
@media (max-width: 768px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .chips-grid {
    grid-template-columns: repeat(5, 1fr);
  }
  .exam-palette {
    grid-template-columns: repeat(5, 1fr);
  }
  .hero {
    padding: 18px;
  }
  .hero h1 {
    font-size: 22px;
  }
  .main {
    padding: 12px 10px;
  }
  .q-card {
    padding: 16px 14px;
  }
}

@media (max-width: 400px) {
  .chips-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .exam-palette {
    grid-template-columns: repeat(4, 1fr);
  }
}