:root {
  --ink: #0b1220;
  --muted: #6b7a90;
  --line: rgba(15, 28, 48, 0.1);
  --ok: #149a6a;
  --danger: #d64545;
  --card: rgba(255, 255, 255, 0.92);
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --opts: 4;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  font-family: Manrope, system-ui, sans-serif;
  color: var(--ink);
  background: #071018;
  position: fixed;
  inset: 0;
  width: 100%;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 8% -8%, #1a3a4a 0%, transparent 55%),
    radial-gradient(700px 480px at 100% 0%, #2a4d3a 0%, transparent 50%),
    linear-gradient(160deg, #071018 0%, #0d1b24 45%, #102018 100%);
}
.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.5;
}
.bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(55px);
  opacity: 0.35;
}
.bg-glow-a { width: 200px; height: 200px; left: -50px; bottom: 8%; background: #0f8b6c; }
.bg-glow-b { width: 170px; height: 170px; right: -40px; top: 12%; background: #e8a317; }

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: calc(8px + var(--safe-t)) 10px calc(8px + var(--safe-b));
  gap: 8px;
  overflow: hidden;
  min-height: 0;
}

.top {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #eef5f1;
  min-width: 0;
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-family: Sora, sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  background: linear-gradient(145deg, #12a57d, #0b6e56);
  flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand strong {
  display: block;
  font-family: Sora, sans-serif;
  font-size: 0.88rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand small {
  display: block;
  color: rgba(238, 245, 241, 0.65);
  font-size: 0.68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.progress-wrap { display: grid; gap: 4px; min-width: 0; }
.progress-meta {
  display: flex;
  justify-content: space-between;
  color: rgba(238, 245, 241, 0.85);
  font-size: 0.72rem;
  font-weight: 700;
}
.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
}
.progress-bar i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #12a57d, #e8a317);
  transition: width 0.3s ease;
}

.card {
  background: var(--card);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: var(--radius);
  box-shadow: 0 12px 36px rgba(8, 18, 36, 0.18);
  padding: 10px;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
}

.card.no-image {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.img-box {
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  min-height: 0;
  max-height: 28vh;
  display: grid;
  place-items: center;
}
.img-box img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 28vh;
  object-fit: contain;
}

.question {
  font-family: Sora, sans-serif;
  font-size: clamp(0.82rem, 2.7vh, 1.05rem);
  line-height: 1.28;
  letter-spacing: -0.02em;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}

.answers {
  display: grid;
  grid-template-rows: repeat(var(--opts), minmax(0, 1fr));
  gap: 6px;
  min-height: 0;
  overflow: hidden;
}

.answer {
  width: 100%;
  height: 100%;
  min-height: 0;
  text-align: left;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 650;
  font-size: clamp(0.75rem, 2.1vh, 0.92rem);
  line-height: 1.25;
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.answer span:last-child {
  min-width: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
.answer:active { transform: none; }
.answer .idx {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
  background: #eef3f8;
  color: var(--muted);
}
.answer.selected { border-color: rgba(15, 139, 108, 0.45); background: #edfaf5; }
.answer.correct {
  border-color: rgba(20, 154, 106, 0.7);
  background: #e8f8f1;
}
.answer.correct .idx { background: var(--ok); color: #fff; }
.answer.wrong {
  border-color: rgba(214, 69, 69, 0.65);
  background: #fdf0f0;
}
.answer.wrong .idx { background: var(--danger); color: #fff; }
.answer:disabled { cursor: default; }

.feedback {
  padding: 6px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feedback.ok { background: #e8f8f1; color: #0b6e56; }
.feedback.bad { background: #fdf0f0; color: #9b2c2c; }

.bottom {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 8px;
  flex-shrink: 0;
}
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 10px;
  font: inherit;
  font-weight: 750;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost {
  background: rgba(255,255,255,0.12);
  color: #eef5f1;
  border: 1px solid rgba(255,255,255,0.18);
}
.btn-primary {
  background: linear-gradient(145deg, #14b386, #0d7a5d);
  color: #fff;
  box-shadow: 0 8px 20px rgba(15, 139, 108, 0.3);
}

.loader {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  gap: 12px;
  background: #071018;
  color: #eef5f1;
  text-align: center;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.loader.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-ring {
  width: 42px; height: 42px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #14b386;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Short phones */
@media (max-height: 680px) {
  .img-box, .img-box img { max-height: 22vh; }
  .question { -webkit-line-clamp: 3; font-size: clamp(0.78rem, 2.4vh, 0.95rem); }
  .answer { padding: 6px 8px; }
  .btn { padding: 10px 8px; }
  .card { padding: 8px; gap: 6px; }
}

@media (max-height: 560px) {
  .img-box, .img-box img { max-height: 18vh; }
  .brand-mark { width: 28px; height: 28px; }
  .question { -webkit-line-clamp: 2; }
}
