@media screen {
  :root {
    --ink: #172033;
    --muted: #657089;
    --accent: #5b5ce2;
    --accent-dark: #4647c7;
    --line: #e3e8f2;
    --surface: #f5f7fb;
    --green: #087f5b;
    --red: #c83b59;
  }

  body {
    min-width: 320px;
    background:
      radial-gradient(circle at 72% -10%, rgba(112, 110, 240, .12), transparent 34rem),
      linear-gradient(180deg, #f8faff 0, #f4f7fb 42rem, #f1f4f9 100%);
    color: var(--ink);
  }

  .layout {
    grid-template-columns: 258px minmax(0, 1fr);
  }

  .sidebar {
    padding: 1.55rem 1rem 1rem;
    border: 0;
    color: #e8ebff;
    background:
      radial-gradient(circle at 20% 5%, rgba(118, 112, 255, .35), transparent 13rem),
      linear-gradient(165deg, #171b39 0%, #11172e 56%, #0f1830 100%);
    box-shadow: 12px 0 36px rgba(27, 32, 68, .08);
  }

  .brand {
    margin: 0 0 2.2rem;
    padding: .35rem .45rem;
    color: #fff;
    letter-spacing: -.025em;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 13px;
    background: linear-gradient(145deg, #7c73ff, #5b5ce2);
    box-shadow: 0 10px 26px rgba(91, 92, 226, .35), inset 0 1px rgba(255,255,255,.3);
  }

  .brand small { color: #aeb7d7; letter-spacing: .08em; }
  .nav-label { color: #7f8ab0; font-weight: 700; }

  .subject-button {
    min-height: 48px;
    margin-bottom: .45rem;
    padding: .62rem .68rem;
    border: 1px solid transparent;
    border-radius: 12px;
    color: #bbc3df;
    transition: transform .16s ease, background .16s ease, border-color .16s ease, color .16s ease;
  }

  .subject-button:hover {
    color: #fff;
    border-color: rgba(255,255,255,.08);
    background: rgba(255,255,255,.07);
    transform: translateX(2px);
  }

  .subject-button.active {
    color: #fff;
    border-color: rgba(166, 162, 255, .28);
    background: linear-gradient(135deg, rgba(116, 106, 245, .92), rgba(81, 82, 207, .9));
    box-shadow: 0 12px 24px rgba(29, 27, 98, .32);
  }

  .subject-symbol {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 9px;
    background: rgba(255,255,255,.1);
  }

  .subject-button.active .subject-symbol { background: rgba(255,255,255,.18); }
  .subject-button .count { color: inherit; opacity: .72; }
  .sidebar-bottom { margin-top: auto; color: #7582a8; }
  .mobile-nav-row { display: block; }
  .mobile-nav-panel { display: contents; }
  .menu-toggle, .mobile-account { display: none; }

  .topbar {
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 6;
    padding: 0 2.25rem;
    border-bottom: 1px solid rgba(219, 225, 238, .82);
    background: rgba(249, 251, 255, .83);
    backdrop-filter: blur(18px);
    box-shadow: 0 6px 22px rgba(50, 62, 93, .04);
  }

  .topbar #account a {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: .35rem .7rem;
    border: 1px solid #d9def0;
    border-radius: 9px;
    color: #4d50bd;
    background: rgba(255,255,255,.8);
    text-decoration: none;
  }

  .account-action {
    min-height: 34px;
    padding: .35rem .72rem;
    border: 1px solid #d9def0;
    border-radius: 9px;
    color: #4d50bd;
    background: rgba(255,255,255,.86);
    font-weight: 700;
  }

  .auth-dialog { max-width: 460px; padding: 1.65rem; border: 0; border-radius: 18px; box-shadow: 0 28px 90px rgba(17,23,46,.3); }
  .auth-dialog .dialog-head { align-items: flex-start; gap: 1rem; }
  .auth-dialog h2 { margin: .28rem 0 0; font-size: 1.4rem; letter-spacing: -.03em; }
  .auth-kicker { color: #5b5ce2; font-size: .72rem; font-weight: 800; letter-spacing: .12em; }
  .auth-intro { margin: .85rem 0 1.1rem; line-height: 1.6; }
  .google-auth { display: flex; align-items: center; justify-content: center; gap: .72rem; width: 100%; min-height: 46px; border: 1px solid #dbe0eb; border-radius: 11px; color: #273149; background: #fff; font-weight: 700; }
  .google-auth:hover { border-color: #b9c1d3; background: #fafbfe; }
  .google-auth span { display: grid; place-items: center; width: 24px; height: 24px; border: 1px solid #d9deea; border-radius: 50%; color: #4285f4; font-size: .88rem; }
  .auth-divider { display: flex; align-items: center; gap: .8rem; margin: 1.15rem 0; color: #8a93a6; font-size: .78rem; }
  .auth-divider::before,.auth-divider::after { content: ''; flex: 1; height: 1px; background: #e4e7ef; }
  #email-auth-form { display: grid; gap: .5rem; }
  #email-auth-form label { margin-top: .28rem; color: #394158; font-size: .84rem; font-weight: 700; }
  #email-auth-form input { width: 100%; min-height: 44px; padding: .7rem .8rem; border: 1px solid #dce2ee; border-radius: 10px; color: var(--ink); background: #fff; }
  .auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-top: .7rem; }
  .auth-message { min-height: 1.4rem; margin: .85rem 0 0!important; color: #c83b59!important; }

  main {
    max-width: 1480px;
    padding: 2.1rem 2.25rem 1.5rem;
  }

  .heading-row { margin-bottom: 1.35rem; }
  .heading-row h1 { margin: .32rem 0 .35rem; font-size: 2rem; letter-spacing: -.04em; }
  .heading-row p { color: #737d93; }
  .eyebrow { color: #5b5ce2; font-weight: 800; letter-spacing: .13em; }
  .sample-badge { border-radius: 999px; padding: .38rem .7rem; }

  .builder {
    position: relative;
    margin: 0 0 1.15rem;
    padding: 1.25rem 1.35rem;
    overflow: hidden;
    border: 1px solid #dde2f1;
    border-radius: 16px;
    background:
      linear-gradient(135deg, rgba(255,255,255,.98), rgba(249,249,255,.95)),
      #fff;
    box-shadow: 0 18px 45px rgba(44, 51, 91, .07);
  }

  .builder::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: linear-gradient(#6d63ef, #50a7de);
  }

  .builder-heading h2 { font-size: 1.22rem; letter-spacing: -.025em; }
  .builder-heading .muted {
    padding: .25rem .58rem;
    border-radius: 999px;
    color: #5558bd;
    background: #efefff;
    font-weight: 700;
  }

  .builder-grid {
    grid-template-columns: minmax(150px,.8fr) minmax(220px,1.35fr) minmax(170px,1fr) minmax(110px,.46fr);
    gap: 1rem;
    margin: 1rem 0;
    align-items: start;
  }

  .field-label, .unit-picker legend { color: #394158; font-weight: 700; }
  select, .builder-grid input[type=number] {
    min-height: 44px;
    border-color: #dce2ee;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(24, 32, 51, .03);
  }

  select:hover, .builder-grid input[type=number]:hover { border-color: #bfc7dc; }
  .unit-picker label { min-height: 42px; margin: 0; padding: .62rem .72rem; border: 1px solid #e1e5ef; border-radius: 10px; background: #f9faff; }
  .unit-picker input { width: 17px; height: 17px; }
  .builder-actions { justify-content: space-between; }
  .builder-actions span { max-width: 46rem; }

  .primary {
    min-height: 42px;
    padding: .7rem 1.15rem;
    border-radius: 10px;
    background: linear-gradient(135deg, #6761e8, #5253d0);
    box-shadow: 0 8px 18px rgba(82, 83, 208, .22);
    transition: transform .15s ease, box-shadow .15s ease;
  }

  .primary:hover { background: linear-gradient(135deg, #5e58df, #4647c4); transform: translateY(-1px); box-shadow: 0 11px 23px rgba(82, 83, 208, .28); }
  .secondary { min-height: 40px; border-radius: 10px; border-color: #d9dfeb; }

  .view-tabs {
    width: fit-content;
    margin: .25rem 0 0;
    padding: .28rem;
    border: 1px solid #e0e5ef;
    border-radius: 12px;
    background: rgba(255,255,255,.7);
  }

  .view-tabs button { padding: .58rem .82rem; border: 0; border-radius: 9px; background: transparent; }
  .view-tabs button[aria-pressed=true] { color: #4e50c4; background: #fff; box-shadow: 0 4px 13px rgba(44, 51, 91, .1); }
  #save-status { min-height: 1.4rem; margin: .72rem 0 .4rem; }

  .flashcard-view { margin-top: 1rem; padding: 1.35rem; border: 1px solid #dde2f1; border-radius: 18px; background: rgba(255,255,255,.78); box-shadow: 0 18px 45px rgba(44,51,91,.07); }
  .flashcard-toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
  .flashcard-toolbar h2 { margin: .3rem 0 .2rem; font-size: 1.35rem; }
  .flashcard-toolbar p { margin: 0; color: var(--muted); }
  .flashcard-stage { width: min(760px,100%); margin: 1.35rem auto 1rem; perspective: 1200px; }
  .flashcard { position: relative; display: grid; align-content: center; justify-items: center; width: 100%; min-height: 390px; padding: 2.4rem; border: 1px solid #dadff0; border-radius: 22px; color: var(--ink); background: linear-gradient(145deg,#fff 0%,#f7f7ff 100%); box-shadow: 0 22px 52px rgba(47,51,106,.13); text-align: center; touch-action: pan-y; user-select: none; -webkit-user-select: none; transition: transform .2s ease, box-shadow .2s ease; }
  .flashcard:hover { transform: translateY(-2px); box-shadow: 0 27px 60px rgba(47,51,106,.17); }
  .flashcard.flipped { border-color: #c7c4f5; background: linear-gradient(145deg,#f8f7ff,#efefff); }
  .flashcard-position { position: absolute; align-self: start; justify-self: start; color: #7b84a0; font-size: .72rem; font-weight: 800; letter-spacing: .12em; }
  .flashcard-topic { margin-bottom: 1.15rem; padding: .28rem .65rem; border-radius: 999px; color: #5658c8; background: #ededff; font-size: .78rem; font-weight: 700; }
  .flashcard-question { max-width: 620px; font-size: 1.45rem; font-weight: 750; line-height: 1.55; white-space: pre-line; }
  .flashcard-options { max-width: 560px; margin-top: 1.15rem; color: #59637a; line-height: 1.85; white-space: pre-line; text-align: left; }
  #flashcard-diagram { width: min(100%,520px); }
  #flashcard-diagram .music-diagram { margin: 1rem auto 0; background: rgba(255,255,255,.78); text-align: left; }
  .flashcard-answer { display: grid; gap: .9rem; max-width: 620px; }
  .flashcard-answer strong { color: #494bc0; font-size: 1.5rem; line-height: 1.45; }
  .flashcard-answer span { color: #46516a; line-height: 1.75; }
  .flashcard-answer small { color: #778198; }
  .flashcard-hint { margin-top: 1.6rem; color: #8a93a6; font-size: .8rem; }
  .flashcard-actions { display: flex; justify-content: center; gap: .7rem; flex-wrap: wrap; }
  .flashcard-actions button { min-height: 42px; padding: .65rem 1rem; border-radius: 10px; font-weight: 700; }
  .review-again { color: #a23a55; border: 1px solid #efcad3; background: #fff5f7; }
  .got-it { color: #fff; background: #16805e; }
  .flashcard-progress { width: min(760px,100%); margin: 1rem auto 0; color: var(--muted); font-size: .8rem; }
  .flashcard-track { height: 7px; margin-top: .45rem; overflow: hidden; border-radius: 999px; background: #e7e9f2; }
  .flashcard-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,#5b5ce2,#16805e); transition: width .2s ease; }

  .study-grid { grid-template-columns: minmax(0,1fr) 290px; gap: 1.2rem; }
  .exercise-panel, .scope-card, .progress-card, .record-card, .empty-state {
    border-color: #e0e5ef;
    box-shadow: 0 14px 38px rgba(45, 54, 88, .055);
  }

  .exercise-panel { border-radius: 16px; }
  .exercise-header { padding: 1.15rem 1.35rem; background: linear-gradient(180deg,#fff,#fbfcff); }
  .exercise-header h2 { font-size: 1.16rem; letter-spacing: -.02em; }
  .exercise-number { color: #d8dcf2; font-size: 2.25rem; font-weight: 700; }
  .print-controls { padding: .82rem 1.35rem; background: #fafbfe; }

  .question { padding: 1.4rem; }
  .question:hover { background: #fdfdff; }
  .question-index { display: inline-grid; place-items: center; min-width: 26px; height: 26px; margin: 0; border-radius: 8px; color: #fff; background: #5b5ce2; }
  .type-chip, .subject-chip { padding: .16rem .5rem; border-radius: 999px; }
  .type-chip { background: #eef0f8; }
  .subject-chip { color: #667089; background: #f7f8fb; }
  .question-title { font-size: 1.04rem; font-weight: 700; color: #222b3f; }
  .options { gap: .7rem; }
  .option { min-height: 50px; border-color: #e0e4ed; border-radius: 11px; transition: border-color .15s ease, background .15s ease, transform .15s ease; }
  .option:hover { border-color: #9d99ed; background: #f9f8ff; transform: translateY(-1px); }
  .option:has(input:checked) { border-color: #6661df; background: #f0efff; box-shadow: 0 0 0 2px rgba(91,92,226,.08); }
  .answer-input { min-height: 44px; border-radius: 10px; }
  .feedback { border-radius: 10px; }
  .submit-bar { padding: 1rem 1.35rem; background: #f8f9fd; }

  .review-column { gap: .9rem; position: sticky; top: 80px; }
  .scope-card, .progress-card { padding: 1.2rem; border-radius: 14px; }
  .small-label { color: #7b84a0; font-weight: 800; }
  .unit-label { color: #5b5ce2; font-weight: 700; }
  .scope-card li { margin: .5rem 0; }
  .progress-value { color: #262e43; }
  .progress-track { height: 8px; background: #e8eaf3; }
  .progress-track > div { background: linear-gradient(90deg,#5b5ce2,#51a5df); }
  .review-tip { padding: .75rem .85rem; border: 1px dashed #d8dced; border-radius: 12px; background: rgba(255,255,255,.45); }
  .review-tip > span { color: #625fd9; }
  .page-footer { padding: .8rem .25rem 0; }
  .sources { padding: .35rem .25rem; }

  button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
    outline: 3px solid rgba(91,92,226,.35);
    outline-offset: 2px;
  }

  @media (max-width: 1180px) {
    .builder-grid { grid-template-columns: 1fr 1.35fr; }
    .study-grid { grid-template-columns: minmax(0,1fr) 250px; }
  }

  @media (max-width: 940px) {
    .layout { grid-template-columns: 220px minmax(0,1fr); }
    main { padding: 1.6rem 1.35rem 1.2rem; }
    .topbar { padding: 0 1.35rem; }
    .study-grid { grid-template-columns: 1fr; }
    .review-column { position: static; grid-template-columns: 1fr 1fr; }
    .review-tip { grid-column: 1 / -1; }
  }

  @media (max-width: 680px) {
    .layout { display: block; }
    .sidebar {
      height: auto;
      position: sticky;
      top: 0;
      z-index: 20;
      padding: .7rem 1rem;
      overflow: visible;
      border: 0;
      box-shadow: 0 8px 28px rgba(13, 18, 45, .18);
      background: linear-gradient(135deg,#171b39,#1a2450);
    }
    .mobile-nav-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
    .brand { margin: 0; padding: 0; font-size: 1.08rem; }
    .brand-mark { width: 36px; height: 36px; border-radius: 10px; font-size: 1.45rem; }
    .brand small { margin-top: .05rem; font-size: .66rem; }
    .menu-toggle { display: block; position: relative; width: 44px; height: 44px; flex: 0 0 44px; padding: 0; border: 1px solid rgba(255,255,255,.17); border-radius: 12px; background: rgba(255,255,255,.08); }
    .menu-toggle span { position: absolute; top: 20px; left: 11px; width: 21px; height: 2px; border-radius: 2px; background: #fff; transition: transform .18s ease, opacity .18s ease; }
    .menu-toggle span:nth-child(1) { transform: translateY(-7px); }
    .menu-toggle span:nth-child(3) { transform: translateY(7px); }
    .menu-open .menu-toggle span:nth-child(1) { transform: rotate(45deg); }
    .menu-open .menu-toggle span:nth-child(2) { opacity: 0; }
    .menu-open .menu-toggle span:nth-child(3) { transform: rotate(-45deg); }
    .mobile-nav-panel {
      display: block;
      position: absolute;
      top: calc(100% + .55rem);
      left: .75rem;
      right: .75rem;
      max-height: calc(100vh - 6rem);
      margin: 0;
      padding: .95rem;
      overflow: auto;
      border: 1px solid rgba(255,255,255,.13);
      border-radius: 16px;
      z-index: 30;
      background: #151a39;
      box-shadow: 0 24px 60px rgba(8,12,34,.38), 0 4px 14px rgba(8,12,34,.22);
      opacity: 0;
      visibility: hidden;
      transform: translateY(-8px) scale(.985);
      transform-origin: top right;
      pointer-events: none;
      transition: opacity .18s ease, transform .18s ease, visibility .18s ease;
    }
    .menu-open .mobile-nav-panel { opacity: 1; visibility: visible; transform: translateY(0) scale(1); pointer-events: auto; }
    .nav-label { display: block; margin: 0 0 .55rem; padding: 0; }
    #subjects { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .55rem; overflow: visible; padding: 0; }
    .subject-button { width: 100%; min-height: 46px; margin: 0; color: #c5cce2; border-color: rgba(255,255,255,.08); background: rgba(255,255,255,.045); }
    .subject-button.active { background: linear-gradient(135deg,#7168ee,#5557d0); }
    .mobile-account { display: flex; align-items: center; justify-content: space-between; gap: .9rem; margin-top: .85rem; padding: .8rem; border: 1px solid rgba(255,255,255,.1); border-radius: 12px; background: rgba(7,11,31,.24); }
    .account-copy { display: grid; min-width: 0; color: #fff; line-height: 1.35; }
    .account-copy strong, .account-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .account-copy small { margin-top: .12rem; color: #aeb7d7; font-size: .72rem; }
    .account-label { margin-bottom: .18rem; color: #858fb6; font-size: .63rem; font-weight: 800; letter-spacing: .12em; }
    .mobile-account .account-action { flex: 0 0 auto; color: #fff; border-color: rgba(255,255,255,.18); background: rgba(255,255,255,.1); }
    .sidebar-bottom { display: block; padding: .8rem .1rem 0; text-align: center; }
    .topbar { display: none; }
    main { padding: 1.25rem 1rem 1rem; }
    .heading-row { margin-bottom: 1rem; }
    .heading-row h1 { font-size: 1.7rem; }
    .builder { padding: 1.05rem; border-radius: 14px; }
    .builder-grid { grid-template-columns: 1fr; gap: .8rem; }
    .builder-actions { align-items: stretch; flex-direction: column; }
    .builder-actions .primary { width: 100%; }
    .view-tabs { width: 100%; display: grid; grid-template-columns: repeat(2,1fr); }
    .view-tabs button { padding: .55rem .35rem; }
    .review-column { grid-template-columns: 1fr; }
    .review-tip { grid-column: auto; }
    .question, .exercise-header { padding: 1.08rem; }
    .options { grid-template-columns: 1fr; }
    .auth-dialog { width: calc(100% - 1.25rem); padding: 1.25rem; }
    .auth-actions { grid-template-columns: 1fr; }
    #save-status { margin: .62rem 0 .35rem; line-height: 1.45; }
    .flashcard-view { padding: 1rem; border-radius: 14px; }
    .flashcard-toolbar { align-items: stretch; flex-direction: column; }
    .flashcard-toolbar .secondary { width: 100%; }
    .flashcard { min-height: 360px; padding: 2rem 1.15rem 1.5rem; border-radius: 17px; }
    .flashcard-question { font-size: 1.2rem; }
    .flashcard-answer strong { font-size: 1.25rem; }
    .flashcard-actions { display: grid; grid-template-columns: 1fr 1fr; }
  }
}
