:root {
  --navy: #071a37;
  --blue: #1261d8;
  --blue-dark: #0a47aa;
  --cyan: #35b9ff;
  --red: #e5343a;
  --green: #169b62;
  --amber: #d98a00;
  --ink: #17233b;
  --muted: #65738c;
  --line: #dce4f0;
  --surface: #ffffff;
  --canvas: #f3f6fb;
  --shadow: 0 18px 45px rgba(18, 45, 84, 0.1);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 5%, rgba(53, 185, 255, 0.12), transparent 27rem),
    var(--canvas);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px clamp(18px, 4vw, 64px);
  color: #fff;
  background: rgba(7, 26, 55, 0.96);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(145deg, var(--red), #b31324);
  box-shadow: 0 8px 22px rgba(229, 52, 58, 0.3);
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.05rem; }
.brand small { color: #9eb3d2; margin-top: 2px; }

.header-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  color: #c9d9ed;
  font-size: 0.86rem;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2fd487;
  box-shadow: 0 0 0 5px rgba(47, 212, 135, 0.12);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100vh - 150px);
  margin: 34px auto 48px;
}

footer {
  padding: 24px;
  text-align: center;
  color: #8592a8;
  border-top: 1px solid var(--line);
  font-weight: 600;
}

.loading-card, .panel, .hero, .exam-card, .result-hero {
  background: var(--surface);
  border: 1px solid rgba(204, 215, 231, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.loading-card {
  width: min(430px, 100%);
  margin: 120px auto;
  padding: 48px;
  text-align: center;
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 18px;
  border: 4px solid #dbe7f7;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hero {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  gap: 28px;
  padding: clamp(28px, 5vw, 56px);
  color: #fff;
  background: linear-gradient(135deg, #071a37, #0b3d82);
}

.hero::after {
  content: "";
  position: absolute;
  inset: auto -100px -180px auto;
  width: 420px;
  height: 420px;
  border: 70px solid rgba(53, 185, 255, 0.09);
  border-radius: 50%;
}

.eyebrow {
  margin: 0 0 12px;
  color: #67caff;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.hero h1 {
  margin: 0;
  max-width: 720px;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.12;
}

.hero-copy {
  max-width: 680px;
  margin: 18px 0 0;
  color: #c4d4e9;
  line-height: 1.85;
}

.hero-stats {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  align-content: center;
}

.hero-stat {
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
}

.hero-stat strong { display: block; font-size: 1.8rem; }
.hero-stat span { color: #aebfd6; font-size: 0.88rem; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
  gap: 22px;
  margin-top: 22px;
}

.panel { padding: 26px; }
.panel-title-row, .exam-topbar, .result-heading, .history-row, .question-meta, .exam-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel h2, .panel h3 { margin: 0; }
.muted { color: var(--muted); }

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.field { display: grid; gap: 8px; }
.field > span { color: #4d5c74; font-size: 0.9rem; font-weight: 700; }

.field input, .field select, .visual-select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  color: var(--ink);
  background: #f8faff;
  border: 1px solid #ccd8e8;
  border-radius: 12px;
  outline: none;
}

.field input:focus, .field select:focus, .visual-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(18, 97, 216, 0.1);
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 12px;
  align-items: center;
}

input[type="range"] { accent-color: var(--blue); }

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: #f7f9fd;
}

.check-row input { width: 19px; height: 19px; accent-color: var(--blue); }

.btn {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  font-weight: 800;
  transition: 0.18s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: linear-gradient(135deg, var(--blue), var(--blue-dark)); box-shadow: 0 9px 20px rgba(18, 97, 216, 0.22); }
.btn-danger { color: #fff; background: var(--red); }
.btn-soft { color: var(--blue-dark); background: #eaf2ff; }
.btn-ghost { color: #4b5970; background: #f1f4f9; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.86rem; }

.tip-box {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #d9e8fb;
  border-radius: 13px;
  color: #315274;
  background: #f2f8ff;
  line-height: 1.65;
}

.tip-icon {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: #fff;
  background: var(--blue);
  font-weight: 900;
}

.history-list { display: grid; gap: 12px; margin-top: 20px; }

.history-row {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfe;
}

.history-score {
  flex: 0 0 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--blue-dark);
  background: #e9f2ff;
  font-weight: 900;
}

.history-info { flex: 1; }
.history-info strong, .history-info small { display: block; }
.history-info small { margin-top: 5px; color: var(--muted); }
.empty-state { padding: 36px 18px; text-align: center; color: var(--muted); }

.exam-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 20px;
}

.exam-main { min-width: 0; }

.exam-topbar {
  position: sticky;
  top: 92px;
  z-index: 20;
  margin-bottom: 18px;
  padding: 14px 18px;
  color: #fff;
  border-radius: 16px;
  background: var(--navy);
  box-shadow: 0 12px 30px rgba(7, 26, 55, 0.18);
}

.timer {
  direction: ltr;
  min-width: 128px;
  padding: 9px 13px;
  text-align: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 1.2rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.timer.warning { color: #ffd483; background: rgba(217, 138, 0, 0.18); }
.timer.danger { color: #ff9b9e; background: rgba(229, 52, 58, 0.2); }

.progress-track {
  flex: 1;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), #79e1ff);
  transition: width 0.25s ease;
}

.exam-card { padding: clamp(22px, 4vw, 40px); }
.question-meta { color: var(--muted); font-size: 0.9rem; }
.question-number { color: var(--blue); font-weight: 900; }

.question-text {
  direction: ltr;
  margin: 22px 0;
  text-align: left;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.3rem, 2.5vw, 1.75rem);
  line-height: 1.55;
}

.question-image-wrap {
  margin: 12px 0 24px;
  text-align: center;
}

.question-image {
  max-height: 390px;
  width: auto;
  border-radius: 10px;
  image-rendering: auto;
}

.options { display: grid; gap: 12px; direction: ltr; }

.option {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  transition: 0.16s ease;
}

.option:hover { border-color: #9ab9e7; background: #f8fbff; }
.option.selected { border-color: var(--blue); background: #edf5ff; box-shadow: inset 4px 0 0 var(--blue); }
.option input { margin-top: 4px; accent-color: var(--blue); }
.option-letter {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--blue-dark);
  background: #eaf2ff;
  font-weight: 900;
}

.fill-answer {
  direction: ltr;
  width: 100%;
  min-height: 56px;
  padding: 0 16px;
  border: 1px solid #bccbe0;
  border-radius: 13px;
  outline: none;
  font-size: 1.08rem;
}

.fill-answer:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(18, 97, 216, 0.1); }

.visual-source {
  display: grid;
  place-items: center;
  margin: 12px 0 22px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #f8faff;
}

.visual-source img { max-height: 310px; width: auto; }
.visual-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; direction: ltr; }

.visual-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.visual-card img { width: 100%; height: 190px; object-fit: contain; }
.visual-label { color: var(--muted); font-weight: 800; }

.exam-actions {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.palette-panel {
  position: sticky;
  top: 92px;
  align-self: start;
  padding: 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 16px 0 20px;
  max-height: 430px;
  overflow: auto;
}

.palette button {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #65738c;
  background: #f7f9fc;
  font-size: 0.78rem;
  font-weight: 800;
}

.palette button.answered { color: #fff; border-color: var(--green); background: var(--green); }
.palette button.current { color: #fff; border-color: var(--blue); background: var(--blue); box-shadow: 0 0 0 3px rgba(18, 97, 216, 0.15); }

.legend { display: grid; gap: 8px; color: var(--muted); font-size: 0.82rem; }
.legend span { display: flex; align-items: center; gap: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: #e6ebf3; }
.legend .done { background: var(--green); }
.legend .now { background: var(--blue); }

.result-hero {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 28px;
  align-items: center;
  padding: 30px;
}

.score-ring {
  --score: 0;
  width: 160px;
  height: 160px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--blue) calc(var(--score) * 1%), #e5ebf3 0);
}

.score-ring::before {
  content: "";
  grid-area: 1 / 1;
  width: 126px;
  height: 126px;
  border-radius: 50%;
  background: #fff;
}

.score-ring strong { position: relative; grid-area: 1 / 1; font-size: 2rem; }
.result-heading h1 { margin: 0 0 8px; }

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.result-stat { padding: 14px; border-radius: 12px; background: #f6f8fc; }
.result-stat strong, .result-stat span { display: block; }
.result-stat strong { font-size: 1.25rem; }
.result-stat span { margin-top: 4px; color: var(--muted); font-size: 0.82rem; }

.review-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 14px;
}

.review-list { display: grid; gap: 14px; }
.review-item { padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.review-item.wrong { border-right: 5px solid var(--red); }
.review-item.correct { border-right: 5px solid var(--green); }
.review-item.unanswered { border-right: 5px solid var(--amber); }
.review-item h3 { direction: ltr; margin: 8px 0 14px; text-align: left; font-family: Georgia, serif; line-height: 1.5; }
.review-answer { direction: ltr; display: grid; gap: 7px; padding: 12px; text-align: left; border-radius: 10px; background: #f7f9fc; }
.review-answer .good { color: var(--green); font-weight: 800; }
.review-answer .bad { color: var(--red); font-weight: 800; }
.review-thumb { display: block; max-height: 250px; width: auto; margin: 12px auto; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 18, 39, 0.65);
  backdrop-filter: blur(5px);
}

.modal {
  width: min(440px, 100%);
  padding: 26px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.modal h2 { margin-top: 0; }
.modal p { color: var(--muted); line-height: 1.7; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }

@media (max-width: 900px) {
  .hero, .dashboard-grid, .exam-layout, .result-hero { grid-template-columns: 1fr; }
  .palette-panel { position: static; order: -1; }
  .palette { grid-template-columns: repeat(10, 1fr); max-height: 180px; }
  .exam-topbar { top: 82px; }
}

@media (max-width: 640px) {
  .site-header { padding: 10px 14px; }
  .header-badge { display: none; }
  .app-shell { width: min(100% - 20px, 1180px); margin-top: 18px; }
  .hero { padding: 28px 22px; }
  .hero-stats, .setup-grid, .result-stats { grid-template-columns: 1fr 1fr; }
  .panel { padding: 20px; }
  .visual-grid { grid-template-columns: 1fr; }
  .exam-topbar { flex-wrap: wrap; top: 76px; }
  .progress-track { order: 3; flex-basis: 100%; }
  .exam-actions { flex-wrap: wrap; }
  .exam-actions .btn { flex: 1; }
  .palette { grid-template-columns: repeat(7, 1fr); }
  .result-hero { padding: 22px; text-align: center; }
  .score-ring { margin: auto; }
  .result-heading { display: block; }
  .review-toolbar { align-items: stretch; flex-direction: column; }
}

/* Offline & Network status styling */
.live-dot.offline {
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(217, 138, 0, 0.18);
}

/* Bookmarking/Flagging button in question header */
.btn-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid #ccd8e8;
  border-radius: 20px;
  background: #f8faff;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  transition: all 0.2s ease;
  cursor: pointer;
  outline: none;
}

.btn-flag:hover {
  border-color: var(--amber);
  color: #b27300;
  background: #fffdf6;
}

.btn-flag.active {
  border-color: var(--amber);
  background: #fff8db;
  color: #b27300;
}

.btn-flag.active .flag-icon {
  fill: var(--amber);
}

/* Question Palette Flag styling */
.palette button {
  position: relative;
}

.palette button.flagged::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  border: 1px solid #fff;
}

/* Review Page flag badge and button container styling */
.review-flag-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  background: #fff8db;
  color: #b27300;
  font-size: 0.78rem;
  font-weight: 700;
}

.review-toolbar-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

