:root {
      --bg: #f6f8ff;
      --panel: rgba(255, 255, 255, 0.88);
      --panel-strong: #ffffff;
      --text: #162033;
      --muted: #667085;
      --primary: #5b7cfa;
      --primary-2: #10b981;
      --accent: #f97316;
      --accent-dark: #c2410c;
      --ok: #16a34a;
      --bad: #dc2626;
      --line: rgba(91, 124, 250, 0.18);
      --shadow: 0 24px 70px rgba(22, 32, 51, 0.14);
      --shadow-soft: 0 14px 34px rgba(22, 32, 51, 0.10);
      --radius: 28px;
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      min-height: 100vh;
      font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      color: var(--text);
      background:
        radial-gradient(circle at 8% 8%, rgba(91, 124, 250, 0.22), transparent 28rem),
        radial-gradient(circle at 92% 18%, rgba(16, 185, 129, 0.18), transparent 26rem),
        radial-gradient(circle at 50% 100%, rgba(249, 115, 22, 0.16), transparent 30rem),
        linear-gradient(135deg, #f7faff 0%, #eef4ff 45%, #f8fbff 100%);
      display: grid;
      place-items: center;
      padding: clamp(14px, 3vw, 28px);
    }

    body::before {
      content: "";
      position: fixed;
      inset: 0;
      pointer-events: none;
      background-image: linear-gradient(rgba(91, 124, 250, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(91, 124, 250, 0.06) 1px, transparent 1px);
      background-size: 34px 34px;
      mask-image: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent 72%);
    }

    .app {
      width: min(1120px, 100%);
      background: var(--panel);
      backdrop-filter: blur(18px);
      border: 1px solid rgba(255, 255, 255, 0.72);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      overflow: hidden;
      position: relative;
    }

    header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 20px;
      padding: clamp(20px, 4vw, 34px);
      background:
        linear-gradient(135deg, rgba(91, 124, 250, 0.95), rgba(16, 185, 129, 0.82)),
        #5b7cfa;
      color: #fff;
    }

    .brand { display: flex; align-items: center; gap: 16px; }

    .logo {
      width: 68px;
      aspect-ratio: 1;
      border-radius: 22px;
      display: grid;
      place-items: center;
      background: rgba(255, 255, 255, 0.18);
      border: 1px solid rgba(255, 255, 255, 0.36);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.32);
      flex: 0 0 auto;
    }

    .logo svg { width: 46px; height: 46px; filter: drop-shadow(0 8px 14px rgba(0,0,0,0.15)); }
    .logo polygon { fill: #ffffff; }
    h1 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.45rem); line-height: 1.02; letter-spacing: -0.04em; }
    .subtitle { margin: 7px 0 0; color: rgba(255,255,255,0.84); font-weight: 650; font-size: clamp(0.92rem, 1.8vw, 1.03rem); }

    .scorebar { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
    .pill { background: rgba(255, 255, 255, 0.18); border: 1px solid rgba(255,255,255,0.26); border-radius: 999px; padding: 10px 14px; font-weight: 850; white-space: nowrap; backdrop-filter: blur(8px); }

    main { padding: clamp(18px, 4vw, 38px); }
    .screen { display: none; }
    .screen.active { display: block; animation: fade 240ms ease; }
    @keyframes fade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

    .intro, .result-card, .question-card {
      background: var(--panel-strong);
      border-radius: var(--radius);
      padding: clamp(20px, 4vw, 36px);
      border: 1px solid rgba(91, 124, 250, 0.12);
      box-shadow: var(--shadow-soft);
    }

    .intro h2, .result-card h2 { margin: 0 0 8px; font-size: clamp(1.55rem, 3vw, 2.35rem); letter-spacing: -0.035em; }
    .intro p, .result-card p { color: var(--muted); font-size: 1.07rem; line-height: 1.6; margin-top: 0; }

    .settings { display: grid; gap: 24px; margin: 26px 0; align-items: start; }
    .field { display: grid; gap: 10px; }
    .count-field { justify-items: center; text-align: center; }
    .topics-field { width: 100%; }
    .competition-field { width: 100%; margin-top: 4px; justify-items: center; text-align: center; }
    .competition-field .field-title { color: var(--accent-dark); }
    label, .field-title { font-weight: 900; color: #24304a; }
    select { display: none; }
    button { font: inherit; }

    .topic-tiles {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
      gap: 12px;
      width: 100%;
    }

    .competition-tiles {
      display: grid;
      grid-template-columns: repeat(2, minmax(230px, 340px));
      justify-content: center;
      gap: 14px;
      width: 100%;
    }

    .topic-tile {
      min-height: 96px;
      border: 1px solid var(--line);
      border-radius: 20px;
      background:
        linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,255,0.98));
      color: var(--text);
      text-align: left;
      padding: 15px;
      cursor: pointer;
      display: grid;
      gap: 6px;
      transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
    }

    .topic-tile:hover { transform: translateY(-2px); border-color: rgba(91, 124, 250, 0.45); box-shadow: 0 16px 28px rgba(91, 124, 250, 0.14); }
    .topic-tile.active { background: linear-gradient(135deg, rgba(91,124,250,0.98), rgba(16,185,129,0.92)); color: #fff; border-color: transparent; box-shadow: 0 18px 34px rgba(91, 124, 250, 0.28); }
    .topic-tile.competition-tile {
      min-height: 112px;
      border-color: rgba(249, 115, 22, 0.34);
      background: linear-gradient(135deg, #fff7ed, #ffffff 52%, #fff1e6);
      box-shadow: 0 12px 26px rgba(249, 115, 22, 0.10);
    }
    .topic-tile.competition-tile:hover { border-color: rgba(249, 115, 22, 0.70); box-shadow: 0 18px 34px rgba(249, 115, 22, 0.18); }
    .topic-tile.competition-tile.active {
      background: linear-gradient(135deg, var(--accent), #f59e0b);
      color: #fff;
      box-shadow: 0 20px 38px rgba(249, 115, 22, 0.32);
    }
    .topic-tile strong { font-size: 1rem; line-height: 1.18; }
    .topic-tile span { color: var(--muted); font-size: 0.9rem; font-weight: 650; line-height: 1.35; }
    .topic-tile.active span { color: rgba(255,255,255,0.84); }

    .count-options { display: grid; grid-template-columns: repeat(4, minmax(78px, 1fr)); gap: 10px; width: min(460px, 100%); }
    .count-options input { position: absolute; opacity: 0; pointer-events: none; }
    .count-options span { display: grid; place-items: center; min-height: 54px; border-radius: 17px; border: 1px solid var(--line); background: #fff; font-weight: 950; cursor: pointer; transition: 140ms ease; }
    .count-options span:hover { transform: translateY(-1px); border-color: rgba(91, 124, 250, 0.45); }
    .count-options input:checked + span { background: #162033; color: #fff; border-color: #162033; box-shadow: 0 14px 24px rgba(22, 32, 51, 0.18); }

    .topic-preview { margin-top: 12px; padding: 14px 16px; border-radius: 18px; background: #f4f7ff; border: 1px solid var(--line); color: #3b4964; font-weight: 750; }

    .btn { border: 0; border-radius: 17px; padding: 14px 19px; cursor: pointer; font-weight: 900; transition: transform 130ms ease, filter 130ms ease, box-shadow 130ms ease; }
    .btn:hover { transform: translateY(-1px); filter: brightness(1.02); }
    .btn:active { transform: translateY(1px); }
    .btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; box-shadow: 0 16px 30px rgba(91, 124, 250, 0.26); }
    .btn-secondary { background: #eef3ff; color: #24304a; box-shadow: none; }

    .topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; color: var(--muted); font-weight: 850; }
    .progress { height: 12px; background: #e9eefb; border-radius: 999px; overflow: hidden; margin: 0 0 24px; }
    .progress > div { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: inherit; transition: width 260ms ease; }
    .question { font-size: clamp(1.28rem, 3vw, 2.05rem); margin: 0 0 22px; line-height: 1.25; letter-spacing: -0.025em; }
    .answers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
    .answer { min-height: 78px; text-align: left; border: 1px solid rgba(22, 32, 51, 0.10); border-radius: 20px; background: #fff; padding: 16px; cursor: pointer; font-weight: 800; color: var(--text); transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease; }
    .answer:hover:not(:disabled) { transform: translateY(-2px); border-color: rgba(91, 124, 250, 0.55); background: #f8fbff; box-shadow: 0 14px 25px rgba(91, 124, 250, 0.10); }
    .answer:disabled { cursor: not-allowed; }
    .answer.correct { border-color: rgba(22,163,74,0.58); background: #ecfdf3; }
    .answer.wrong { border-color: rgba(220,38,38,0.58); background: #fef2f2; }

    .image-answers {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      align-items: stretch;
    }

    .image-answer {
      min-height: auto;
      padding: 12px;
      display: grid;
      gap: 10px;
      text-align: center;
    }

    .image-answer img {
      width: 100%;
      max-height: 300px;
      object-fit: contain;
      border-radius: 16px;
      background: #f8fafc;
      border: 1px solid rgba(22, 32, 51, 0.08);
      padding: 8px;
    }

    .image-answer span {
      font-weight: 950;
      color: #3b4964;
    }

    .prompt-image-wrap {
      display: grid;
      place-items: center;
      margin: 0 0 22px;
      padding: 14px;
      border-radius: 22px;
      background: #f8fafc;
      border: 1px solid rgba(22, 32, 51, 0.10);
    }

    .prompt-image-wrap img {
      width: min(100%, 430px);
      max-height: 310px;
      object-fit: contain;
      border-radius: 16px;
      background: #fff;
      padding: 8px;
      border: 1px solid rgba(22, 32, 51, 0.08);
    }

    .review-prompt-image {
      margin: 10px 0;
    }

    .review-prompt-image img {
      width: min(100%, 180px);
      max-height: 150px;
      object-fit: contain;
      border-radius: 12px;
      background: #fff;
      border: 1px solid rgba(22, 32, 51, 0.10);
      padding: 6px;
    }

    .review-images {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 150px));
      gap: 12px;
      margin-top: 10px;
    }

    .review-images img {
      width: 100%;
      max-height: 130px;
      object-fit: contain;
      border-radius: 12px;
      background: #fff;
      border: 1px solid rgba(22, 32, 51, 0.10);
      padding: 6px;
    }

    .feedback { margin-top: 18px; padding: 14px 16px; border-radius: 17px; background: #f5f7fb; display: none; line-height: 1.5; font-weight: 650; border: 1px solid rgba(22,32,51,0.07); }
    .feedback.show { display: block; }
    .actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

    .result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 24px 0; }
    .stat { background: #f4f7ff; border: 1px solid var(--line); border-radius: 22px; padding: 22px; text-align: center; }
    .stat strong { display: block; font-size: clamp(2.2rem, 6vw, 4rem); color: var(--primary); line-height: 1; letter-spacing: -0.05em; }
    .stat span { display: block; margin-top: 8px; color: #3b4964; font-weight: 900; }
    .review { display: grid; gap: 10px; margin-top: 18px; }
    .review-item { border-left: 6px solid #d0d5dd; background: #f8fafc; border-radius: 14px; padding: 13px 14px; line-height: 1.4; }
    .review-item.good { border-left-color: var(--ok); }
    .review-item.bad { border-left-color: var(--bad); }
    .small { color: var(--muted); font-size: 0.93rem; margin-top: 6px; }

    @media (max-width: 760px) {
      header { align-items: flex-start; flex-direction: column; }
      .scorebar { justify-content: flex-start; }
      .answers, .result-grid { grid-template-columns: 1fr; }
      .answer { min-height: auto; }
      .topic-tiles, .competition-tiles { grid-template-columns: 1fr; }
    }
