* {
  box-sizing: border-box;
}

:root {
  --bg-deep: #0f172a;
  --bg-mid: #1e1b4b;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-soft: #a5b4fc;
  --cyan: #22d3ee;
  --violet: #8b5cf6;
  --card: rgba(255, 255, 255, 0.92);
  --card-border: rgba(129, 140, 248, 0.35);
  --text: #1e1b4b;
  --text-muted: #64748b;
  --success: #10b981;
  --danger: #f43f5e;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 12px 40px rgba(79, 70, 229, 0.18);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(145deg, var(--bg-deep) 0%, var(--bg-mid) 45%, #312e81 100%);
  color: var(--text);
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
}

.bg-glow--1 {
  width: 320px;
  height: 320px;
  top: -80px;
  right: -60px;
  background: rgba(99, 102, 241, 0.45);
}

.bg-glow--2 {
  width: 280px;
  height: 280px;
  bottom: 10%;
  left: -80px;
  background: rgba(139, 92, 246, 0.35);
}

#app {
  position: relative;
  z-index: 1;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.visible {
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: calc(env(safe-area-inset-top) + 16px) 20px 16px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--violet) 100%);
  color: #fff;
  box-shadow: 0 4px 24px rgba(99, 102, 241, 0.4);
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.topbar-logo {
  height: 44px;
  width: auto;
  display: block;
  border-radius: 10px;
  flex-shrink: 0;
}

.topbar-logo--compact {
  height: 36px;
}

.exam-topbar {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 8px;
}

.review-topbar {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
}

.review-topbar .brand {
  justify-content: flex-start;
}

.review-topbar h1 {
  font-size: 1.1rem;
}

.timer-wrap {
  text-align: center;
}

.timer-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
}

#timer {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.counter-badge {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
}

.content {
  flex: 1;
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.start-content {
  padding-bottom: 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.start-content .card {
  margin-bottom: 0;
}

.start-content .btn-primary {
  margin-top: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.hero-card h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-card p {
  margin: 0 0 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.exam-rules {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.exam-rules strong {
  color: var(--text);
}

.question-card {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.45;
}

.question-card p,
.review-item .question {
  white-space: pre-line;
  margin: 0;
}

.question-image {
  display: block;
  margin: 16px auto 0;
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 2px solid var(--card-border);
  background: #fff;
  padding: 8px;
}

.answers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.answer-btn {
  width: 100%;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 16px 18px;
  text-align: left;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.1);
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    color 0.15s,
    transform 0.15s,
    box-shadow 0.15s;
}

.answer-btn:hover:not(:disabled) {
  border-color: var(--accent-soft);
  background: #f8faff;
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.2);
}

.answer-btn.selected {
  border-color: #c7d2fe;
  background: linear-gradient(135deg, var(--accent) 0%, var(--violet) 100%);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 8px 28px rgba(99, 102, 241, 0.45);
}

.answer-btn.selected:hover:not(:disabled) {
  color: #ffffff;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  transform: translateY(-1px);
}

.answer-btn.correct {
  border-color: var(--success);
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  color: #065f46;
  font-weight: 600;
}

.answer-btn.wrong {
  border-color: var(--danger);
  background: linear-gradient(135deg, #ffe4e6, #fecdd3);
  color: #9f1239;
  font-weight: 600;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--card-border);
}

.nav-btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.nav-btn--ghost {
  background: rgba(99, 102, 241, 0.1);
  color: var(--accent);
}

.nav-btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--violet));
  color: #fff;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

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

.icon-btn {
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.5;
}

.btn {
  width: 100%;
  border: none;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--violet) 100%);
  box-shadow: 0 10px 32px rgba(99, 102, 241, 0.45);
  margin-top: 4px;
}

.btn-secondary {
  color: var(--accent);
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--accent-soft);
}

.card label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.inline-form input {
  flex: 1;
  min-width: 0;
  width: auto;
}

.inline-form .btn {
  width: auto;
  flex-shrink: 0;
  margin-top: 0;
  padding: 12px 18px;
  white-space: nowrap;
}

.card input[type="number"] {
  border: 2px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
}

.card input:focus {
  outline: none;
  border-color: var(--accent);
}

.hidden {
  display: none !important;
}

.load-error {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #9f1239;
  font-size: 0.92rem;
  line-height: 1.45;
}

.result-card h2 {
  margin: 0 0 16px;
  text-align: center;
  font-size: 1.25rem;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  text-align: center;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(139, 92, 246, 0.08));
}

.stat span {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat strong {
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.elapsed-label {
  text-align: center;
  color: var(--text-muted);
  margin: 0 0 4px;
  font-size: 0.9rem;
}

.elapsed-time {
  display: block;
  text-align: center;
  font-size: 1.75rem;
  margin-bottom: 16px;
}

.status-pill {
  margin: 0 -20px -20px;
  padding: 14px;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  border-radius: 0 0 var(--radius) var(--radius);
}

.status-pass {
  background: linear-gradient(135deg, #059669, #10b981);
}

.status-fail {
  background: linear-gradient(135deg, #e11d48, #f43f5e);
}

.review-item {
  margin-bottom: 12px;
}

.review-item .question {
  margin-bottom: 10px;
}

.review-item .question-image {
  max-height: 160px;
  margin-bottom: 10px;
}

.review-list .answer-btn {
  cursor: default;
  margin-bottom: 8px;
}

.review-list .answer-btn:hover {
  transform: none;
}

@media (max-width: 480px) {
  #timer {
    font-size: 1.45rem;
  }

  .answer-btn {
    font-size: 0.95rem;
    padding: 14px;
  }
}
