:root {
  color-scheme: light;
  :root {
    color-scheme: light;
    --bg-top: #f4efe4;
    --bg-bottom: #d6e5f2;
    --panel: rgba(255, 255, 255, 0.82);
    --panel-border: rgba(34, 59, 87, 0.14);
    --text: #1f2a36;
    --muted: #5a6a79;
    --accent: #1f6aa5;
    --accent-strong: #0d4f83;
    --ok: #1a7f4b;
    --wrong: #b0413e;
    --shadow: 0 24px 60px rgba(31, 42, 54, 0.16);
  }

  * {
    box-sizing: border-box;
  }

  [x-cloak] {
    display: none !important;
  }

  body {
    margin: 0;
    min-height: 100vh;
    font-family: Georgia, "Times New Roman", serif;
    color: var(--text);
    background:
      radial-gradient(
        circle at top left,
        rgba(255, 255, 255, 0.7),
        transparent 30%
      ),
      linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
  }

  .app-shell {
    width: min(920px, calc(100% - 32px));
    margin: 0 auto;
    padding: 48px 0 64px;
  }

  .stack {
    display: grid;
    gap: 22px;
  }

  .hero {
    margin-bottom: 24px;
  }

  .eyebrow {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.75rem;
    color: var(--accent-strong);
  }

  h1 {
    margin: 0;
    font-size: clamp(2.4rem, 5vw, 4.4rem);
    line-height: 0.96;
  }

  .subtitle {
    margin: 16px 0 0;
    max-width: 42rem;
    color: var(--muted);
    font-size: 1.05rem;
  }

  .hero-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
  }

  .card {
    padding: 28px;
    border: 1px solid var(--panel-border);
    border-radius: 28px;
    background: var(--panel);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
  }

  .panel-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 20px;
  }

  .panel-head.compact {
    align-items: center;
  }

  .section-kicker {
    margin: 0 0 6px;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--accent-strong);
  }

  h2,
  .panel-head h2 {
    margin: 0;
    font-size: clamp(1.45rem, 3vw, 2rem);
    line-height: 1.3;
  }

  .metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }

  .password-gate {
    display: grid;
    gap: 18px;
  }

  .password-field {
    display: grid;
    gap: 8px;
    font-weight: 700;
  }

  .password-field input {
    width: min(420px, 100%);
    border: 1px solid rgba(31, 106, 165, 0.18);
    border-radius: 14px;
    padding: 14px 16px;
    font: inherit;
    background: rgba(255, 255, 255, 0.92);
  }

  .metric {
    padding: 18px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(31, 106, 165, 0.1);
  }

  .metric-label,
  .muted-text,
  .quiz-path-preview,
  .quiz-link {
    color: var(--muted);
  }

  .metric strong {
    display: block;
    margin-top: 8px;
    font-size: 2rem;
  }

  .tests-list {
    display: grid;
    gap: 14px;
  }

  .test-card {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    border-radius: 20px;
    border: 1px solid rgba(31, 106, 165, 0.12);
    background: rgba(255, 255, 255, 0.74);
  }

  .test-card-copy h3 {
    margin: 0;
  }

  .test-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
  }

  .test-card-actions,
  .toolbar,
  .actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }

  .pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 0.78rem;
    background: rgba(31, 106, 165, 0.12);
    color: var(--accent-strong);
  }

  .pill-complete {
    background: rgba(26, 127, 75, 0.12);
    color: var(--ok);
  }

  .quiz-path-preview,
  .quiz-link {
    margin: 10px 0 0;
    font-size: 0.9rem;
    word-break: break-all;
  }

  .quiz-link-anchor {
    color: var(--accent-strong);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
  }

  .empty-state {
    margin: 0;
    padding: 20px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.68);
    color: var(--muted);
  }

  .status-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    color: var(--muted);
    font-size: 0.95rem;
  }

  .answers {
    display: grid;
    gap: 14px;
  }

  .answer {
    display: grid;
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border: 1px solid rgba(31, 106, 165, 0.16);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.7);
    transition:
      transform 120ms ease,
      border-color 120ms ease,
      background 120ms ease;
  }

  .answer:hover {
    transform: translateY(-1px);
    border-color: rgba(31, 106, 165, 0.4);
    background: rgba(255, 255, 255, 0.92);
  }

  .answer.is-selected {
    border-color: rgba(31, 106, 165, 0.42);
    background: rgba(230, 241, 250, 0.92);
  }

  .answer.is-locked {
    cursor: default;
  }

  .answer input {
    margin: 0;
  }

  .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    background: rgba(31, 106, 165, 0.1);
    color: var(--accent-strong);
    font-weight: 700;
  }

  .feedback {
    padding: 14px 16px;
    border-radius: 16px;
    font-size: 0.98rem;
  }

  .feedback.ok {
    background: rgba(26, 127, 75, 0.12);
    color: var(--ok);
  }

  .feedback.wrong {
    background: rgba(176, 65, 62, 0.12);
    color: var(--wrong);
  }

  button {
    border: 0;
    border-radius: 999px;
    padding: 13px 20px;
    font: inherit;
    cursor: pointer;
    background: var(--accent);
    color: white;
  }

  button.primary-cta {
    background: linear-gradient(135deg, #c85512, #e3872d);
    color: #fff9f2;
    font-weight: 700;
    font-size: 1rem;
    padding: 15px 24px;
    box-shadow: 0 14px 28px rgba(200, 85, 18, 0.28);
  }

  button.primary-cta:hover {
    transform: translateY(-1px);
  }

  .generate-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
  }

  .unanswered-info {
    background: rgba(31, 106, 165, 0.06);
    border: 1px solid rgba(31, 106, 165, 0.15);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 8px;
  }

  .unanswered-info details {
    margin-top: 8px;
  }

  .unanswered-info .question-ids {
    margin-top: 6px;
    word-break: break-all;
    font-size: 0.85rem;
    line-height: 1.5;
  }

  button.secondary {
    background: rgba(31, 106, 165, 0.12);
    color: var(--accent-strong);
  }

  button.danger {
    background: rgba(176, 65, 62, 0.12);
    color: var(--wrong);
  }

  button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
  }

  /* Wrong Answers Modal */
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    padding: 40px 16px;
    overflow-y: auto;
  }

  .modal-content {
    background: var(--surface, #fff);
    border-radius: 18px;
    width: min(100%, 680px);
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.12);
  }

  .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 2px solid rgba(176, 65, 62, 0.25);
  }

  .modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 800;
  }

  .modal-close {
    background: rgba(0, 0, 0, 0.08);
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: #333;
    padding: 4px 10px;
    border-radius: 8px;
    line-height: 1;
    font-weight: 700;
  }

  .modal-close:hover {
    background: rgba(176, 65, 62, 0.15);
    color: var(--wrong, #b0413e);
  }

  .modal-body {
    padding: 20px 24px;
    overflow-y: auto;
  }

  .modal-search {
    width: 100%;
    padding: 12px 16px;
    border-radius: 10px;
    border: 2px solid rgba(0, 0, 0, 0.12);
    background: rgba(0, 0, 0, 0.03);
    font-size: 1rem;
    margin-bottom: 16px;
    outline: none;
    transition:
      border-color 0.15s,
      background 0.15s;
    box-sizing: border-box;
  }

  .modal-search:focus {
    border-color: var(--accent-strong, #1f6aa5);
    background: #fff;
  }

  .modal-search::placeholder {
    color: #999;
  }

  .search-empty {
    text-align: center;
    color: #888;
    padding: 24px 0;
  }

  .modal-back {
    margin-bottom: 16px;
  }

  .wrong-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .wrong-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    text-align: left;
    padding: 14px 16px;
    border-radius: 12px;
    border: 2px solid rgba(176, 65, 62, 0.3);
    background: rgba(176, 65, 62, 0.08);
    cursor: pointer;
    transition:
      background 0.15s,
      border-color 0.15s;
    font-weight: 500;
  }

  .wrong-item:hover {
    background: rgba(176, 65, 62, 0.16);
    border-color: rgba(176, 65, 62, 0.5);
  }

  .wrong-count-badge {
    flex-shrink: 0;
    background: var(--wrong, #b0413e);
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
    min-width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(176, 65, 62, 0.4);
  }

  .wrong-item-text {
    flex: 1;
    line-height: 1.5;
    color: #1a1a1a;
  }

  /* All Questions Modal — neutral blue variant */
  .all-item {
    border-color: rgba(31, 106, 165, 0.25);
    background: rgba(31, 106, 165, 0.06);
  }

  .all-item:hover {
    background: rgba(31, 106, 165, 0.14);
    border-color: rgba(31, 106, 165, 0.45);
  }

  .all-id-badge {
    background: var(--accent-strong, #1f6aa5);
    box-shadow: 0 2px 6px rgba(31, 106, 165, 0.35);
  }

  .wrong-detail-count {
    color: var(--wrong, #b0413e);
    font-size: 0.9rem;
    margin-bottom: 8px;
  }

  .wrong-detail-prompt {
    font-size: 1.15rem;
    line-height: 1.5;
    margin-bottom: 16px;
    font-weight: 600;
    color: #1a1a1a;
  }

  .wrong-detail-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .wrong-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: rgba(0, 0, 0, 0.04);
    color: #333;
  }

  .wrong-option-correct {
    border: 2px solid var(--ok, #2d8a4e);
    background: rgba(45, 138, 78, 0.14);
  }

  .wrong-option-mark {
    margin-left: auto;
    font-weight: 800;
    color: var(--ok, #2d8a4e);
    font-size: 0.85rem;
    white-space: nowrap;
  }

  @media (max-width: 640px) {
    .app-shell {
      width: min(100%, calc(100% - 20px));
      padding-top: 24px;
    }

    .card {
      padding: 20px;
      border-radius: 22px;
    }

    .metrics,
    .test-card {
      display: grid;
      grid-template-columns: 1fr;
    }

    .panel-head,
    .status-row,
    .hero-actions,
    .actions,
    .toolbar,
    .test-card-actions {
      flex-direction: column;
    }

    .answer {
      grid-template-columns: auto 1fr;
    }

    .answer input {
      grid-row: 1 / span 2;
    }
  }

  .answer input {
    grid-row: 1 / span 2;
  }
}
