@layer reset, base, components, responsive, print;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, dl, dd, ul { margin: 0; }
  fieldset { min-width: 0; border: 0; padding: 0; margin: 0; }
  button, input { font: inherit; }
  img { max-width: 100%; }
}
@layer base {
  :root {
    color-scheme: light;
    --canvas: #f8fafc;
    --paper: #fff;
    --ink: #182238;
    --muted: #526179;
    --edge: #e2e8f0;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --tint: #eef2ff;
    --shadow: 0 2px 4px #26355b06, 0 10px 26px #26355b06;
    --nav-height: 68px;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 400;
    line-height: 1.5;
    background: var(--canvas);
    color: var(--ink);
  }
  body { min-width: 280px; }
  h1, h2, h3 { line-height: 1.2; letter-spacing: -.025em; }
  h1 { font-size: clamp(1.95rem, 4vw, 2.8rem); font-weight: 790; }
  h2 { font-size: 1.2rem; font-weight: 750; }
  h3 { font-size: 1.12rem; }
  a { color: var(--primary-dark); }
  button:not(:disabled), label:has(input:not(:disabled)) { cursor: pointer; }
  button:disabled { cursor: not-allowed; opacity: .6; }
  input[type=radio], input[type=checkbox] { accent-color: var(--primary); width: 1.05rem; height: 1.05rem; flex: none; margin: 0; }
  :focus-visible { outline: 3px solid #6a5eea; outline-offset: 3px; }
  progress { height: 8px; width: 100%; border: 0; border-radius: 10px; overflow: hidden; display: block; background: #e9edf7; }
  progress::-webkit-progress-bar { background: #e9edf7; }
  progress::-webkit-progress-value { background: var(--primary); border-radius: 10px; }
  progress::-moz-progress-bar { background: var(--primary); border-radius: 10px; }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .skip-link { position: fixed; z-index: 30; left: 1rem; top: -8rem; background: var(--paper); padding: .75rem; }
  .skip-link:focus { top: .75rem; }
  .muted { color: var(--muted); }
  .print-only { display: none; }
}
@layer components {
  .site-header { position: sticky; top: 0; z-index: 10; background: var(--paper); border-bottom: 1px solid var(--edge); }
  .site-bar { max-width: 1200px; min-height: var(--nav-height); margin: auto; padding: 0 26px; display: flex; align-items: center; gap: 28px; }
  .brand { display: inline-flex; align-items: center; gap: 10px; font-size: .98rem; color: var(--ink); text-decoration: none; font-weight: 780; line-height: 1.15; white-space: nowrap; }
  .brand small { display: block; color: var(--muted); font-size: .76rem; margin-top: 4px; font-weight: 500; }
  .site-bar nav { display: flex; gap: 6px; align-items: center; margin-left: auto; }
  .site-bar nav a, .auth-switch a { color: var(--muted); text-decoration: none; font-size: .875rem; font-weight: 680; border-radius: 8px; padding: 9px 12px; white-space: nowrap; }
  .site-bar nav a:hover, .site-bar nav a.active { background: var(--tint); color: var(--primary-dark); }
  .account { display: flex; align-items: center; gap: 9px; }
  .avatar { border-radius: 50%; width: 32px; height: 32px; flex: none; display: grid; place-items: center; background: var(--tint); color: var(--primary-dark); font-weight: 750; }
  .account-name { max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .875rem; font-weight: 650; }

  .page { max-width: 1200px; margin: auto; padding: 32px 26px 64px; display: grid; gap: 20px; }
  .card { background: var(--paper); border: 1px solid var(--edge); border-radius: 12px; box-shadow: var(--shadow); }
  .hero { position: relative; isolation: isolate; overflow: hidden; padding: 31px 34px; border-radius: 14px; color: #fff; background: linear-gradient(110deg, #252260, #402dad 66%, #5141cc); }
  .hero::after { content: ""; position: absolute; z-index: -1; pointer-events: none; width: 405px; aspect-ratio: 1; right: -55px; top: -125px; border-radius: 50%; background: repeating-radial-gradient(circle, #ffffff22 0 1px, transparent 1px 23px); mask-image: linear-gradient(100deg, transparent, #000 48%); }
  .hero-label { color: #e2ddff; font-size: .77rem; font-weight: 750; letter-spacing: .11em; display: inline-block; margin-bottom: 7px; }
  .hero p { color: #eeebff; margin-top: 8px; }
  .page-heading { display: flex; justify-content: space-between; align-items: end; gap: 15px; }
  .page-heading p, .section-head p { color: var(--muted); margin-top: 5px; }
  .button { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: 9px 15px; min-height: 42px; border: 1px solid transparent; border-radius: 8px; text-decoration: none; color: var(--ink); font-weight: 720; font-size: .89rem; white-space: nowrap; width: fit-content; }
  .button.primary { color: #fff; background: var(--primary); box-shadow: 0 2px 3px #3328af25; }
  .button.primary:hover:not(:disabled) { background: var(--primary-dark); }
  .button.secondary { background: var(--paper); border-color: #d6deea; }
  .button.ghost { background: transparent; color: var(--muted); }
  .button.secondary:hover:not(:disabled), .button.ghost:hover:not(:disabled) { background: var(--tint); border-color: #c7c8f5; color: var(--primary-dark); }
  .button.small { font-size: .85rem; min-height: 35px; padding: 6px 10px; }
  .alert { color: #a21d3a; background: #fff1f3; border: 1px solid #fecdd3; border-radius: 8px; padding: 10px 13px; }
  .state { padding: 28px; text-align: center; color: var(--muted); }
  .state .button { margin-top: 12px; }
  .empty-inline { background: #f8fafc; border-radius: 9px; padding: 15px; margin-top: 12px; color: var(--muted); }
  .empty-inline .button { margin-top: 8px; }

  .auth-shell { min-height: calc(100dvh - var(--nav-height)); padding: 46px 16px; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 20%, #edeaff 0%, transparent 57%); }
  .auth-card { width: min(100%, 440px); padding: clamp(20px, 5vw, 32px); }
  .auth-intro { text-align: center; }
  .auth-intro h1 { font-size: 1.65rem; margin-top: 12px; }
  .auth-intro p { color: var(--muted); margin-top: 8px; font-size: .95rem; }
  .auth-switch { display: grid; grid-template-columns: 1fr 1fr; background: #f1f3f9; padding: 4px; border-radius: 10px; text-align: center; margin: 24px 0 18px; }
  .auth-switch a.active { color: var(--primary-dark); background: #fff; box-shadow: 0 1px 4px #26355b15; }
  .auth-card form { display: grid; gap: 7px; }
  .auth-card label { margin-top: 7px; font-size: .9rem; font-weight: 680; }
  .auth-card input, .custom-count { width: 100%; min-width: 0; border: 1px solid #cfd9e7; border-radius: 8px; background: #fff; color: var(--ink); padding: 9px 12px; }
  .auth-card .button { margin-top: 13px; width: 100%; }
  .field-error { color: #a21d3a; font-size: .84rem; }

  .setup-section, .question-card, .report-card { padding: clamp(16px, 3vw, 24px); min-width: 0; }
  .section-head { display: flex; align-items: flex-start; gap: 11px; }
  .section-head p { font-size: .9rem; }
  .section-heading-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  .step { width: 30px; height: 30px; display: grid; place-items: center; flex: none; border-radius: 8px; color: var(--primary-dark); background: var(--tint); font-weight: 770; font-size: .91rem; }
  .subject-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-top: 17px; }
  .subject-card { text-align: left; border: 1px solid var(--edge); background: var(--paper); color: var(--ink); border-radius: 10px; padding: 13px; display: grid; justify-items: start; gap: 7px; }
  .subject-card:hover, .chapter:hover, .mode:hover { border-color: #a7a3f6; }
  .subject-card.selected, .chapter.selected, .mode.selected { border-color: #837aee; background: #f6f5ff; }
  .subject-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; font-size: 1.27rem; font-weight: 700; color: #3548a8; background: #e6eaff; }
  .subject-icon[data-subject=BIO] { background: #def6e9; color: #176441; }
  .subject-icon[data-subject=CHEM] { background: #f1e8ff; color: #6839ad; }
  .subject-icon[data-subject=PHY] { background: #fff0d0; color: #8a5100; }
  .subject-icon[data-subject=CS] { background: #dff6fa; color: #086678; }
  .chapter-grid, .mode-grid, .configuration, .diagnostics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .chapter-grid, .configuration, .mode-field { margin-top: 17px; }
  .chapter, .mode { display: flex; align-items: center; gap: 10px; border: 1px solid var(--edge); border-radius: 9px; padding: 10px 12px; min-width: 0; }
  .chapter strong, .mode strong, .chapter small, .mode small { display: block; }
  .chapter small, .mode small { color: var(--muted); font-size: .84rem; }
  legend { font-weight: 720; font-size: .92rem; margin-bottom: 8px; padding: 0; }
  .pills { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .pill { border: 1px solid #dbe2ec; border-radius: 100px; color: var(--muted); background: #fff; font-weight: 650; font-size: .84rem; padding: 7px 10px; }
  .pill:hover, .pill.active { background: var(--tint); color: var(--primary-dark); border-color: #b4adfa; }
  .custom-count { width: 80px; font-size: .9rem; padding: 6px 8px; }
  .diagrams-toggle { display: flex; align-items: center; gap: 8px; margin: 17px 0; font-size: .92rem; }
  .setup-actions { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding-top: 16px; border-top: 1px solid var(--edge); }
  .setup-actions span { color: var(--muted); }
  .setup-actions .button { min-width: 160px; margin-left: auto; }

  .exam-toolbar { position: sticky; top: calc(var(--nav-height) + 9px); z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 22px; align-items: center; padding: 13px 19px; }
  .exam-toolbar h1 { font-size: 1.2rem; margin-bottom: 4px; }
  .exam-clock { min-width: 132px; text-align: center; padding: 5px 12px; border-radius: 8px; background: var(--tint); color: var(--primary-dark); font-variant-numeric: tabular-nums; }
  .exam-clock strong { display: block; line-height: 1.2; font-size: 1.38rem; }
  .exam-clock small { font-size: .76rem; }
  .exam-clock.warning { background: #ffe4e9; color: #a21d3a; }
  .exam-progress span { display: block; margin-bottom: 6px; font-size: .88rem; font-weight: 650; }
  .exam-layout { display: grid; grid-template-columns: minmax(0, 2.35fr) minmax(245px, 1fr); align-items: start; gap: 20px; }
  .question-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .question-top :is(h2,h3) { margin-right: 4px; scroll-margin-top: 160px; }
  .badge { display: inline-flex; align-items: center; font-size: .79rem; font-weight: 730; border-radius: 100px; padding: 3px 8px; background: var(--tint); color: var(--primary-dark); }
  .badge.slate { background: #edf1f7; color: #465571; }
  .badge.success { background: #d8f7e9; color: #126048; }
  .badge.danger { background: #ffe4e9; color: #a21d3a; }
  .question-text { font-size: 1rem; line-height: 1.6; margin: 19px 0; overflow-wrap: anywhere; }
  .diagram { display: block; max-height: 380px; object-fit: contain; margin: 0 auto 18px; border: 1px solid var(--edge); border-radius: 8px; background: #fff; }
  .option-list { display: grid; gap: 9px; }
  .option { display: flex; align-items: center; gap: 10px; border: 1px solid #dbe2ec; border-radius: 9px; padding: 10px 12px; min-height: 49px; overflow-wrap: anywhere; }
  label.option:hover { border-color: #a7a3f6; }
  .option.selected { color: #302298; background: #f4f2ff; border-color: #837aee; }
  label.option input { position: absolute; margin: 0; opacity: 0; }
  label.option:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
  .letter { min-width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: #ebeff6; color: #43516b; font-size: .85rem; font-weight: 780; }
  .selected .letter { background: var(--primary); color: #fff; }
  .question-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--edge); margin-top: 18px; padding-top: 16px; }
  .mark-button.marked { background: #fff3cf; border-color: #edca72; color: #794600; }
  .navigator { padding: 17px; }
  .exam-sidebar { min-width: 0; }
  .exam-sidebar > .ad-container, .setup-page > .ad-container { margin-top: 32px; }
  .ad-container { min-width: 0; text-align: center; }
  .ad-label { color: var(--muted); font-size: .75rem; margin-bottom: 4px; }
  .ad-unit, .ad-container .adsbygoogle, .ad-placeholder { min-height: var(--ad-min-height); width: 100%; }
  .ad-container .adsbygoogle { display: block; }
  .ad-placeholder {
    border: 1px dashed #97a5be;
    border-radius: 9px;
    background: var(--paper);
    color: var(--muted);
    display: grid;
    gap: 4px;
    align-content: center;
    padding: 8px;
    font-size: .85rem;
    overflow-wrap: anywhere;
  }
  .navigator h2 { font-size: 1.02rem; }
  .question-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(37px, 1fr)); max-height: 326px; overflow: auto; gap: 7px; margin: 14px -3px; padding: 4px; }
  .question-palette button, .legend i { border: 1px solid #dce4ef; border-radius: 7px; background: #eef2f8; color: #374760; font-weight: 720; }
  .question-palette button { min-height: 36px; padding: 3px; font-size: .84rem; }
  .question-palette .answered, .legend .answered { color: #126048; background: #d8f7e9; border-color: #97d9bd; }
  .question-palette .marked, .legend .marked { color: #794600; background: #fff3cf; border-color: #edca72; }
  .question-palette .current, .legend .current { outline: 2px solid var(--primary); outline-offset: 1px; }
  .legend { display: grid; grid-template-columns: 1fr 1fr; padding: 0; list-style: none; gap: 7px; color: var(--muted); font-size: .83rem; }
  .legend li { display: flex; align-items: center; gap: 6px; }
  .legend i { width: 12px; height: 12px; border-radius: 3px; }
  .keyboard-hint { font-size: .8rem; color: var(--muted); border-top: 1px solid var(--edge); margin-top: 13px; padding-top: 11px; }
  kbd { background: #edf1f7; border-radius: 3px; padding: 1px 3px; }
  dialog { border: 1px solid var(--edge); border-radius: 12px; max-width: min(440px, calc(100% - 26px)); padding: 24px; color: var(--ink); box-shadow: var(--shadow); }
  dialog::backdrop { background: #17203377; }
  dialog p { margin-top: 8px; color: var(--muted); }
  .dialog-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 8px; margin-top: 18px; }

  .result-hero { display: flex; align-items: center; gap: 22px; }
  .score-circle { border: 3px solid #d8d2ff; width: 105px; aspect-ratio: 1; border-radius: 50%; display: grid; place-content: center; text-align: center; flex: none; }
  .score-circle strong { font-size: 1.6rem; line-height: 1.1; }
  .score-circle small { color: #eeebff; }
  .result-metadata h2 { font-size: 1.65rem; }
  .result-hero dl { display: flex; gap: clamp(16px, 5vw, 52px); margin-left: auto; }
  .result-hero dt { color: #e2ddff; font-size: .85rem; }
  .result-hero dd { font-size: 1.25rem; font-weight: 750; margin-top: 4px; }
  .report-card .muted { margin-top: 4px; font-size: .89rem; }
  .bloom-list { display: grid; gap: 13px; margin-top: 16px; }
  .bloom-item div { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .9rem; margin-bottom: 5px; }
  .bloom-item span { color: var(--muted); }
  .review-section { display: grid; gap: 12px; }
  .review-heading { flex-wrap: wrap; }
  .answer-status { margin-left: auto; }
  .correct-option { border-color: #91d6b7; background: #eefbf5; color: #126048; }
  .wrong-option { border-color: #ef9eb0; background: #fff1f3; color: #a21d3a; }
  .option-label { margin-left: auto; font-size: .82rem; }
  .kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .kpi { padding: 16px; display: grid; align-content: start; gap: 6px; }
  .kpi span, .kpi small { color: var(--muted); font-size: .86rem; }
  .kpi strong { font-size: clamp(1.13rem, 2vw, 1.65rem); overflow-wrap: anywhere; color: #322883; }
  .chart { position: relative; height: 260px; margin-top: 16px; }
  .table-scroll { overflow: auto; margin-top: 12px; }
  table { border-collapse: collapse; width: 100%; font-size: .88rem; text-align: left; }
  th, td { white-space: nowrap; padding: 9px 10px; border-bottom: 1px solid var(--edge); }
  th { color: var(--muted); background: #f1f4fa; font-weight: 730; }
  .diagnostics > * { min-width: 0; }
  .diagnostics .report-card { height: 100%; }
  .diagnostic-list { padding: 0; list-style: none; margin-top: 12px; }
  .diagnostic-list li { display: flex; gap: 10px; justify-content: space-between; padding: 8px 0; }
  .diagnostic-list li + li { border-top: 1px solid var(--edge); }
  .diagnostic-list small { display: block; color: var(--muted); }
}
@layer responsive {
  @media (max-width: 850px) {
    .ad-container.hide-mobile { display: none !important; }
    .site-bar { gap: 12px; }
    .account-name { display: none; }
    .subject-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .exam-layout { grid-template-columns: minmax(0, 1fr); }
  }
  @media (width > 850px) {
    .ad-container.hide-desktop { display: none !important; }
  }
  @media (max-width: 600px) {
    :root { --nav-height: 103px; }
    .site-bar { flex-wrap: wrap; padding: 8px 13px 6px; gap: 3px 9px; }
    .site-bar:not(:has(nav:not([hidden]))) { min-height: 58px; }
    .site-bar nav { order: 3; margin-left: 0; width: 100%; }
    .site-bar nav a { padding: 6px 9px; }
    .account { margin-left: auto; gap: 3px; }
    .avatar { display: none; }
    .page { padding: 17px 12px 35px; gap: 13px; }
    .hero { padding: 23px 17px; }
    .page-heading { align-items: start; flex-direction: column; }
    .subject-grid, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
    .chapter-grid, .configuration, .mode-grid, .diagnostics { grid-template-columns: minmax(0, 1fr); }
    .setup-actions { align-items: stretch; flex-direction: column; }
    .setup-actions .button { width: 100%; }
    .exam-toolbar { grid-template-columns: minmax(0, 1fr) auto auto; gap: 7px; padding: 8px; top: calc(var(--nav-height) + 3px); }
    .exam-toolbar .button { padding-inline: 7px; font-size: .77rem; }
    .exam-clock { min-width: auto; padding: 4px 6px; }
    .exam-clock strong { font-size: 1rem; }
    .exam-clock small { display: none; }
    .exam-progress { grid-column: 1 / -1; grid-row: 2; }
    .exam-progress span { margin-bottom: 2px; }
    .question-footer .button { min-height: 37px; padding-inline: 7px; font-size: .8rem; }
    .keyboard-hint { display: none; }
    .result-hero { flex-wrap: wrap; gap: 10px; }
    .score-circle { width: 75px; }
    .result-hero dl { margin-left: 0; width: 100%; }
    .option-label { font-size: .74rem; }
    .chart { height: 200px; }
  }
}
@layer print {
  @media print {
    @page { size: A4; margin: 14mm; }
    :root, body { background: #fff; color: #000; font-size: 11pt; print-color-adjust: exact; }
    .print-only { display: block; }
    .site-header, .skip-link, .screen-only, .ad-container, .adsbygoogle, .google-auto-placed, button { display: none !important; }
    .page { max-width: none; padding: 0; gap: 10px; }
    .print-heading { border-bottom: 2px solid #222; padding-bottom: 10px; }
    .print-heading h1 { font-size: 20pt; }
    .print-heading p { margin-top: 4px; }
    .card { box-shadow: none; border-radius: 4px; padding: 10px; }
    .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .report-card, .kpi-grid, tr { break-inside: avoid; }
    .report-card.history-table { break-inside: auto; }
    .table-scroll { overflow: visible; }
    th, td { padding: 5px; font-size: 9pt; white-space: normal; }
    thead { display: table-header-group; }
    .chart { height: 155px; }
    .diagnostics { display: block; }
    .diagnostics > * { display: block; margin-bottom: 10px; }
  }
}

[hidden], .redirecting body { display: none !important; }
