:root {
  --bg: #e7eef5;
  --panel: #ffffff;
  --ink: #152033;
  --muted: #5b6b7c;
  --line: #c9d5e2;
  --brand: #0b4f74;
  --brand-2: #1378a8;
  --accent: #ef9f1a;
  --ok: #1b7f4a;
  --ok-bg: #e6f6ec;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --chip: #d7ebf7;
  --drop: #f7fafc;
  --shadow: 0 14px 40px rgba(15, 40, 70, 0.1);
  --radius: 16px;
  --font: "Segoe UI", "Trebuchet MS", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 8% -8%, #d3e8f7 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #f6e5c0 0%, transparent 48%),
    linear-gradient(180deg, #edf3f8 0%, var(--bg) 40%, #e4ecf4 100%);
}

button, .choice, .drag-item { font: inherit; }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
  direction: rtl;
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  text-align: right;
}
.brand strong {
  font-size: 1.05rem;
  letter-spacing: .02em;
}
.brand span {
  font-size: .8rem;
  opacity: .88;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  direction: ltr;
}
.timer, .progress-pill {
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  padding: 6px 12px;
  font-variant-numeric: tabular-nums;
  font-size: .9rem;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 15px;
  cursor: pointer;
  background: #fff;
  color: var(--brand);
  font-weight: 700;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
.btn:hover { filter: brightness(1.04); transform: translateY(-1px); }
.btn.secondary {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,.45);
}
.btn.primary {
  background: var(--accent);
  color: #1a1400;
  box-shadow: 0 6px 16px rgba(239, 159, 26, .28);
}
.btn.ghost {
  background: #eef3f7;
  color: var(--brand);
  border: 1px solid var(--line);
}
.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

/* ===== Home ===== */
.home {
  max-width: 1080px;
  margin: 28px auto 48px;
  padding: 0 18px 24px;
}
.home-hero {
  background:
    linear-gradient(135deg, rgba(11,79,116,.96), rgba(19,120,168,.92)),
    radial-gradient(600px 240px at 90% 10%, rgba(239,159,26,.35), transparent 60%);
  color: #fff;
  border-radius: 22px;
  padding: 28px 28px 24px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.home-hero::after {
  content: "";
  position: absolute;
  inset: auto -40px -60px auto;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  pointer-events: none;
}
.home-kicker {
  display: inline-block;
  font-size: .78rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .85;
  margin-bottom: 8px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 4px 10px;
}
.home-hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.55rem, 3vw, 2.1rem);
  line-height: 1.2;
}
.home-sub {
  margin: 0;
  max-width: 62ch;
  line-height: 1.55;
  color: rgba(255,255,255,.9);
  font-size: .98rem;
}
.home-total {
  margin-top: 18px;
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  background: rgba(0,0,0,.16);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 14px;
  padding: 10px 14px;
}
.home-total-num {
  font-size: 1.8rem;
  font-weight: 800;
  color: #ffd27a;
  font-variant-numeric: tabular-nums;
}
.home-total-label {
  font-size: .9rem;
  opacity: .92;
}

.count-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0 8px;
}
.count-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 8px 22px rgba(15,40,70,.05);
}
.count-chip b {
  display: block;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.count-chip span:last-child {
  color: var(--muted);
  font-size: .86rem;
}
.chip-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.chip-icon svg { width: 22px; height: 22px; }
.chip-image .chip-icon { background: #e7f3fb; color: #0f6f9c; }
.chip-drag .chip-icon { background: #f3e9ff; color: #6b3fa0; }
.chip-normal .chip-icon { background: #e9f7ef; color: #1f7a4d; }

.section-title {
  margin: 22px 0 12px;
  font-size: 1.05rem;
  color: var(--brand);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.mode-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
.mode-card {
  position: relative;
  text-align: right;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 18px;
  padding: 18px 18px 16px;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(15,40,70,.06);
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-areas:
    "icon title"
    "icon desc"
    "count count";
  column-gap: 14px;
  row-gap: 4px;
  transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease;
}
.mode-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--accent);
  color: #1a1400;
  font-size: .72rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 3px 9px;
}
.mode-card.featured {
  border-color: #f0c46a;
  background: linear-gradient(180deg, #fffaf0 0%, #fff 55%);
  box-shadow: 0 14px 34px rgba(239, 159, 26, .16);
}
.mode-timed .mode-icon { background: #fff1d6; color: #a86600; }
.mode-weak .mode-icon { background: #ffe8e5; color: #b42318; }
.mode-timed:hover { border-color: #e0a93a; }
.mode-weak:hover { border-color: #e08a82; }
.mode-card.is-empty {
  opacity: .55;
  cursor: not-allowed;
}
.mode-weak-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.weak-reset {
  align-self: flex-start;
  border: 0;
  background: transparent;
  color: #8a5a5a;
  font-size: .8rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0 4px;
}
.weak-reset:hover { color: #b42318; }
.mode-card:hover {
  transform: translateY(-3px);
  border-color: #9dbbd0;
  box-shadow: 0 16px 34px rgba(15,40,70,.1);
}
.mode-icon {
  grid-area: icon;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  align-self: start;
}
.mode-icon svg { width: 26px; height: 26px; }
.mode-title {
  grid-area: title;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--ink);
}
.mode-desc {
  grid-area: desc;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.45;
}
.mode-count {
  grid-area: count;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: .9rem;
}
.mode-count b {
  color: var(--brand);
  font-size: 1.15rem;
  margin-left: 4px;
}

.mode-all .mode-icon { background: #e8f1f8; color: var(--brand); }
.mode-images .mode-icon { background: #e7f3fb; color: #0f6f9c; }
.mode-drag .mode-icon { background: #f3e9ff; color: #6b3fa0; }
.mode-normal .mode-icon { background: #e9f7ef; color: #1f7a4d; }

.mode-all:hover { border-color: #7eb0d0; }
.mode-images:hover { border-color: #7eb8d8; }
.mode-drag:hover { border-color: #b792e0; }
.mode-normal:hover { border-color: #7bc49a; }

.home-options {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  justify-content: center;
  background: rgba(255,255,255,.72);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--ink);
  font-size: .92rem;
}
.home-options label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* ===== Exam layout ===== */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  max-width: 1280px;
  margin: 16px auto 40px;
  padding: 0 16px;
}

.sidebar, .main {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 14px;
  height: calc(100vh - 110px);
  position: sticky;
  top: 78px;
  overflow: auto;
}
.sidebar h2 {
  margin: 0 0 10px;
  font-size: .95rem;
  color: var(--brand);
}
.q-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.q-dot {
  appearance: none;
  border: 1px solid var(--line);
  background: #f4f7fa;
  border-radius: 6px;
  height: 34px;
  cursor: pointer;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
}
.q-dot.answered { background: #d9eef9; border-color: #8ec5e3; color: var(--brand); }
.q-dot.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.q-dot.marked { box-shadow: inset 0 -3px 0 var(--accent); }
.q-dot.correct { background: var(--ok-bg); border-color: #8fd0a8; color: var(--ok); }
.q-dot.wrong { background: var(--bad-bg); border-color: #f0b4ae; color: var(--bad); }
.q-dot.weak {
  position: relative;
}
.q-dot.weak::after {
  content: "!";
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #d92d20;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
}
.legend-weak {
  background: #d92d20 !important;
  border: 0 !important;
  border-radius: 50% !important;
  position: relative;
}
.weak-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ffe8e5;
  color: #b42318;
  border: 1px solid #f0b4ae;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: .78rem;
  font-weight: 700;
}
.timer.countdown {
  font-weight: 700;
}
.timer.countdown.warn {
  background: rgba(217, 45, 32, .22);
  border-color: rgba(255, 180, 170, .55);
  animation: pulseWarn 1s ease infinite;
}
@keyframes pulseWarn {
  50% { filter: brightness(1.15); }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  font-size: .75rem;
  color: var(--muted);
}
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

.main { padding: 22px 24px 28px; min-height: 70vh; }
.q-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: .9rem;
}
.q-meta-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #eef4f8;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: .78rem;
  color: var(--brand);
  font-weight: 700;
}
.site-num {
  background: #fff6e5;
  color: #8a5a00;
  border: 1px solid #f0d59a;
  border-radius: 999px;
  padding: 5px 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.question-text {
  font-size: 1.08rem;
  line-height: 1.5;
  margin: 0 0 16px;
  font-weight: 650;
}
.question-text .site-ref {
  color: #8a5a00;
  font-weight: 800;
  white-space: nowrap;
}
.exhibit {
  margin: 0 0 18px;
  text-align: center;
}
.exhibit img {
  max-width: min(100%, 860px);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.choice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.choice:hover { border-color: #8eb9d6; }
.choice.selected {
  border-color: var(--brand-2);
  background: #eef7fc;
}
.choice.reveal-correct {
  border-color: var(--ok);
  background: var(--ok-bg);
}
.choice.reveal-wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
}
.choice .marker {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #9aadc0;
  display: grid;
  place-items: center;
  margin-top: 1px;
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
}
.choice.selected .marker {
  border-color: var(--brand-2);
  background: var(--brand-2);
  color: #fff;
}
.choice.multi .marker { border-radius: 6px; }
.choice .label { flex: 1; line-height: 1.4; }

.drag-hint {
  grid-column: 1 / -1;
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #eef6fb;
  border: 1px solid #c5dced;
  color: var(--brand);
  font-size: .85rem;
  line-height: 1.4;
}
.drag-wrap {
  display: block;
}
.drag-board {
  display: grid;
  grid-template-columns: minmax(180px, 280px) 1fr;
  gap: 18px;
  align-items: start;
}
.drag-item.selected-drag {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: #ffe7b0;
  border-color: #e0a93a;
}
.drop-slot.awaiting {
  border-color: var(--accent);
  background: #fff8ea;
}
.pool, .targets {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pool-title, .targets-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 700;
}
.drag-item {
  background: var(--chip);
  border: 1px solid #9fc4dc;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
  user-select: none;
  text-align: center;
  line-height: 1.35;
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset;
}
.drag-item:active { cursor: grabbing; }
.drag-item.dragging { opacity: .45; }

.target-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--drop);
  padding: 10px;
}
.target-card .t-label {
  font-size: .92rem;
  margin-bottom: 8px;
  line-height: 1.35;
  font-weight: 600;
}
.drop-slot {
  min-height: 44px;
  border: 2px dashed #b7c6d4;
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: border-color .15s, background .15s;
}
.drop-slot.over {
  border-color: var(--brand-2);
  background: #eaf6fd;
}
.drop-slot .drag-item {
  width: 100%;
  margin: 0;
}
.category-bin {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.category-bin h4 {
  margin: 0;
  padding: 10px 12px;
  background: #edf2f6;
  border-bottom: 1px solid var(--line);
  font-size: .95rem;
}
.category-slots {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
}

.feedback {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f8fafc;
  white-space: pre-wrap;
}
.feedback.ok { background: var(--ok-bg); border-color: #9ad0b1; }
.feedback.bad { background: var(--bad-bg); border-color: #f0b4ae; }
.feedback h3 { margin: 0 0 6px; font-size: 1rem; }
.feedback p { margin: 0; color: var(--muted); line-height: 1.45; font-size: .92rem; }

.nav-bar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.nav-bar .right { display: flex; gap: 8px; flex-wrap: wrap; }

.screen {
  max-width: 760px;
  margin: 48px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  text-align: center;
  direction: rtl;
}
.screen h1 {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 1.7rem;
}
.screen p { color: var(--muted); line-height: 1.5; }
.screen .stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 22px 0;
}
.stat {
  background: #f3f7fa;
  border-radius: 12px;
  padding: 14px 8px;
}
.stat b { display: block; font-size: 1.4rem; color: var(--brand); }
.stat span { font-size: .8rem; color: var(--muted); }
.options-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 18px 0 8px;
}

.hidden { display: none !important; }

@media (max-width: 1100px) {
  .mode-grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    margin: 10px auto 28px;
    padding: 0 10px;
    gap: 10px;
  }
  .sidebar {
    position: static;
    height: auto;
    max-height: 160px;
    padding: 10px;
  }
  .sidebar h2 { font-size: .85rem; }
  .q-grid { grid-template-columns: repeat(8, 1fr); gap: 5px; }
  .q-dot { height: 30px; font-size: .7rem; }
  .main { padding: 14px 12px 18px; min-height: 0; }
  .question-text { font-size: 1rem; }
  .exhibit img { max-width: 100%; }
  .choice { padding: 12px; min-height: 48px; }
  .drag-board { grid-template-columns: 1fr; }
  .mode-grid, .mode-grid-3, .count-strip, .screen .stats { grid-template-columns: 1fr; }
  .home { margin: 12px auto 28px; padding: 0 12px 18px; }
  .home-hero { padding: 18px 16px; border-radius: 16px; }
  .home-hero h1 { font-size: 1.35rem; }
  .home-sub { font-size: .9rem; }
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 12px;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
  .brand strong { font-size: .95rem; }
  .timer, .progress-pill { font-size: .8rem; padding: 5px 9px; }
  .btn { padding: 10px 12px; min-height: 42px; }
  .nav-bar { gap: 8px; }
  .nav-bar .right { width: 100%; }
  .nav-bar .right .btn { flex: 1; }
  .screen { margin: 20px 12px; padding: 22px 16px; }
  .site-num { font-size: .8rem; }
  .weak-pill { font-size: .72rem; }
}
@media (max-width: 480px) {
  .q-grid { grid-template-columns: repeat(6, 1fr); }
  .count-chip { padding: 12px; }
  .mode-card { padding: 14px; }
  .header-actions .btn.secondary { display: none; }
}
