  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  button, input, textarea, select { font-family: inherit; font-size: inherit; }

  :root { color-scheme: light dark; }

  body {
    font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #fafafa;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
  }

  /* ── Auth / Verify / Reset screens ── */
  #auth-screen, #verify-screen, #reset-screen {
    display: none;
    width: 100%;
    height: 100dvh;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
  }

  .auth-card {
    background: #fff;
    border-radius: 20px;
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0,0,0,.1);
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin: 20px;
  }

  .auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
  }
  .auth-brand span { font-size: 1.8rem; }
  .auth-brand h1 { font-size: 1.5rem; font-weight: 700; color: #4f46e5; }
  .auth-tagline { text-align: center; color: #778; font-size: .85rem; margin-top: -10px; }

  .auth-tabs {
    display: flex;
    border-radius: 10px;
    background: #fafafa;
    padding: 4px;
    gap: 4px;
  }
  .auth-tab {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 8px;
    background: none;
    color: #778;
    font-size: .88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
  }
  .auth-tab.active {
    background: #fff;
    color: #4f46e5;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
  }

  .auth-form { display: flex; flex-direction: column; gap: 14px; }
  .auth-form-desc { font-size: .85rem; color: #667; line-height: 1.5; }

  .auth-field { display: flex; flex-direction: column; gap: 5px; }
  .auth-field label { font-size: .78rem; font-weight: 600; color: #445; }
  .auth-field input {
    padding: 10px 14px;
    border: 1.5px solid #c8d0e0;
    border-radius: 10px;
    font-size: .92rem;
    outline: none;
    transition: border-color .15s;
    font-family: inherit;
  }
  .auth-field input:focus { border-color: #f97316; }

  .auth-submit {
    padding: 12px;
    background: #f97316;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    font-family: inherit;
  }
  .auth-submit:hover { background: #ea6c00; }
  .auth-submit:disabled { background: #fed7aa; cursor: default; }

  .auth-link {
    background: none;
    border: none;
    color: #f97316;
    font-size: .83rem;
    cursor: pointer;
    text-align: center;
    padding: 0;
    font-family: inherit;
  }
  .auth-link:hover { text-decoration: underline; }

  .auth-error {
    padding: 9px 13px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: .83rem;
    line-height: 1.4;
  }
  .auth-info {
    padding: 9px 13px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    color: #16a34a;
    font-size: .83rem;
    line-height: 1.4;
  }

  .verify-emoji { font-size: 3rem; text-align: center; }
  .verify-title { font-size: 1.2rem; font-weight: 700; color: #4f46e5; text-align: center; }
  .verify-sub { font-size: .88rem; color: #667; text-align: center; line-height: 1.5; }

  /* ── App screen ── */
  #app-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
  }

  /* ── Header ── */
  header {
    width: 100%;
    background: #4f46e5;
    color: #fff;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
  }
  header h1 { font-size: 1.1rem; font-weight: 600; letter-spacing: .02em; }
  header .flag { font-size: 1.4rem; }
  header .subtitle { font-size: .78rem; color: #aab; }
  .home-btn { display: flex; align-items: center; gap: 10px; background: none; border: none; color: inherit; cursor: pointer; padding: 0; border-radius: 6px; }
  .home-btn:hover { opacity: .85; }

  .gear-wrap {
    position: relative;
    margin-left: 10px;
    flex-shrink: 0;
  }
  .gear-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,.6);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 8px;
    line-height: 1;
    transition: color .15s, background .15s;
    display: flex;
    align-items: center;
  }
  .gear-btn:hover { color: #fff; background: rgba(255,255,255,.1); }
  .gear-btn.open  { color: #fff; background: rgba(255,255,255,.15); }

  .gear-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #3730a3;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 10px;
    padding: 6px;
    min-width: 140px;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
    flex-direction: column;
    gap: 2px;
    z-index: 500;
  }
  .gear-menu.open { display: flex; }

  .gear-menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    border-radius: 7px;
    border: none;
    background: none;
    color: #ccd;
    font-size: .85rem;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background .12s, color .12s;
    width: 100%;
  }
  .gear-menu-item:hover { background: rgba(255,255,255,.08); color: #fff; }
  .gear-menu-item.active { color: #4ade80; }
  .gear-menu-item .mi-icon { font-size: 1rem; line-height: 1; width: 18px; text-align: center; }

  /* ── Streak widget ── */
  .streak-wrap {
    position: relative;
    margin-left: auto;
    flex-shrink: 0;
  }
  .streak-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background .15s;
    font-family: inherit;
  }
  .streak-btn:hover { background: rgba(255,255,255,.1); }
  .streak-btn.open  { background: rgba(255,255,255,.15); }

  .streak-flame { font-size: 1.2rem; line-height: 1; transition: filter .3s, opacity .3s; }
  .streak-flame.dim { filter: grayscale(1); opacity: .35; }
  .streak-num {
    font-size: 1.1rem;
    font-weight: 700;
    color: #ccc;
    min-width: 1.6ch;
    text-align: left;
    transition: color .2s;
  }
  .streak-num.alive { color: #fff; }

  @keyframes streak-pop {
    0%   { transform: scale(1);    filter: none;                              color: #fff; }
    20%  { transform: scale(1.7);  filter: drop-shadow(0 0 10px #fbbf24);    color: #fbbf24; }
    50%  { transform: scale(1.45); filter: drop-shadow(0 0 16px #f97316);    color: #fb923c; }
    80%  { transform: scale(1.1);  filter: drop-shadow(0 0 6px #fbbf24);     color: #fde68a; }
    100% { transform: scale(1);    filter: none;                              color: #fff; }
  }
  .streak-num.popping {
    animation: streak-pop .65s cubic-bezier(.36,.07,.19,.97) forwards;
  }

  .streak-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #3730a3;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 10px;
    padding: 14px;
    min-width: 210px;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
    flex-direction: column;
    gap: 10px;
    z-index: 500;
  }
  .streak-menu.open { display: flex; }

  .sm-streak-row { display: flex; align-items: center; gap: 10px; }
  .sm-streak-flame { font-size: 1.6rem; line-height: 1; }
  .sm-streak-count { font-size: 1.5rem; font-weight: 700; color: #fff; line-height: 1.1; }
  .sm-streak-label { font-size: .72rem; color: #aab; margin-top: 1px; }

  .sm-divider { height: 1px; background: rgba(255,255,255,.1); }

  .sm-freeze-heading { font-size: .72rem; font-weight: 600; color: #aab; text-transform: uppercase; letter-spacing: .05em; }
  .sm-freeze-desc { font-size: .75rem; color: #778; line-height: 1.45; margin-top: -4px; }

  .freeze-slot { display: flex; align-items: center; gap: 8px; }
  .freeze-icon { font-size: .85rem; line-height: 1; }
  .freeze-slot-label { font-size: .75rem; color: #ccd; flex: 1; line-height: 1.3; }
  .freeze-slot-status { font-size: .7rem; margin-top: 1px; }
  .freeze-slot.charged .freeze-slot-status { color: #38bdf8; }
  .freeze-slot:not(.charged) .freeze-slot-status { color: #667; }
  .freeze-track {
    width: 52px;
    height: 4px;
    background: rgba(255,255,255,.15);
    border-radius: 999px;
    overflow: hidden;
    flex-shrink: 0;
  }
  .freeze-fill {
    height: 100%;
    width: 0%;
    background: #7dd3fc;
    border-radius: 999px;
    transition: width .5s ease;
  }
  .freeze-slot.charged .freeze-fill { background: #38bdf8; }

  /* ── Main container ── */
  .container {
    width: 100%;
    max-width: 720px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  /* ── Level screen ── */
  #level-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 32px 24px;
    gap: 20px;
  }
  #level-screen h2 { font-size: 1.25rem; color: #4f46e5; font-weight: 600; }
  #level-screen .screen-sub {
    color: #556;
    font-size: .85rem;
    margin-top: -12px;
    line-height: 1.5;
  }

  .level-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .level-card {
    padding: 14px 16px;
    border-radius: 14px;
    border: 2px solid #e2e8f0;
    background: #fff;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
  }
  .level-card:hover {
    border-color: var(--lc);
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
  }
  .level-card.selected { border-color: var(--lc); background: #fffbf5; }

  .level-badge {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: var(--lc);
    color: #fff;
    font-weight: 700;
    font-size: .82rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .level-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .level-card-head .lc-title { font-weight: 600; font-size: .9rem; color: #4f46e5; }
  .level-card-head .lc-vn { font-size: .72rem; color: #778; }
  .level-desc { font-size: .78rem; color: #556; line-height: 1.45; }

  /* ── Topic screen ── */
  #topic-screen {
    flex: 1;
    display: none;
    flex-direction: column;
    justify-content: center;
    padding: 32px 24px;
    gap: 20px;
  }
  #topic-screen h2 { font-size: 1.25rem; color: #4f46e5; font-weight: 600; }
  #topic-screen p { color: #556; font-size: .9rem; margin-top: -12px; }

  .back-btn {
    align-self: flex-start;
    background: none;
    border: none;
    font-size: .82rem;
    color: #778;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: -6px;
  }
  .back-btn:hover { color: #334; }

  .selected-level-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--lc, #f97316);
    color: #fff;
    border-radius: 999px;
    padding: 3px 10px 3px 4px;
    font-size: .75rem;
    font-weight: 600;
    width: fit-content;
    margin-bottom: -8px;
  }
  .selected-level-pill .pill-badge {
    background: rgba(255,255,255,.25);
    border-radius: 999px;
    padding: 1px 7px;
    font-size: .72rem;
  }

  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }
  .chip {
    padding: 8px 16px;
    border-radius: 999px;
    border: 1.5px solid #c8d0e0;
    background: #fff;
    color: #334;
    font-size: .875rem;
    cursor: pointer;
    transition: all .15s;
    user-select: none;
  }
  .chip:hover { border-color: #f97316; color: #f97316; background: #fff7ed; }
  .chip.selected { border-color: #f97316; background: #f97316; color: #fff; }



  .btn-start {
    align-self: flex-start;
    padding: 11px 28px;
    background: #f97316;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    display: none;
  }
  .btn-start:hover { background: #ea6c00; }
  .btn-start:disabled { background: #fed7aa; cursor: default; }

  /* ── Chat screen ── */
  #chat-screen {
    flex: 1;
    display: none;
    flex-direction: column;
    min-height: 0;
  }

  .topic-bar {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 20px;
    font-size: .82rem;
    color: #667;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }
  .topic-bar strong { color: #334; }
  .topic-bar .level-tag {
    background: var(--lc, #f97316);
    color: #fff;
    border-radius: 6px;
    padding: 1px 8px;
    font-size: .72rem;
    font-weight: 700;
  }
  .topic-bar button {
    margin-left: auto;
    background: none;
    border: 1px solid #dde;
    border-radius: 6px;
    padding: 3px 10px;
    font-size: .78rem;
    color: #778;
    cursor: pointer;
  }
  .topic-bar button:hover { border-color: #f97316; color: #f97316; }

  #messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scrollbar-width: thin;
    scrollbar-color: #d0d5dd transparent;
  }
  #messages::-webkit-scrollbar { width: 5px; }
  #messages::-webkit-scrollbar-thumb { background: #d0d5dd; border-radius: 999px; }

  .msg { display: flex; flex-direction: column; max-width: 82%; }
  .msg.user { align-self: flex-end; align-items: flex-end; }
  .msg.claude { align-self: flex-start; align-items: flex-start; }

  @keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .msg { animation: msg-in .18s ease; }

  .bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: .93rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
  }
  .msg.user .bubble {
    background: linear-gradient(135deg, #f97316, #fb923c);
    color: #fff;
    border-bottom-right-radius: 4px;
  }
  .msg.claude .bubble {
    background: #fff;
    color: #4f46e5;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
  }
  .msg.claude .bubble.streaming { opacity: .85; }

  /* ── Clickable words ── */
  .vn-word {
    cursor: pointer;
    border-radius: 3px;
    transition: background .1s;
  }
  .vn-word:hover { background: #ffedd5; }
  .vn-word.active  { background: #fed7aa; }
  .vn-word.new-word { background: #d1fae5; color: #065f46; font-weight: 600; }
  .vn-word.new-word:hover { background: #a7f3d0; }

  /* ── Word popover ── */
  #word-popover {
    display: none;
    position: fixed;
    z-index: 999;
    max-width: 280px;
    background: #4f46e5;
    color: #f0f0f8;
    border-radius: 12px;
    padding: 12px 15px;
    box-shadow: 0 6px 24px rgba(0,0,0,.25);
    font-size: .85rem;
    line-height: 1.5;
    pointer-events: none;
  }
  #word-popover .pop-word {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fb923c;
    margin-bottom: 5px;
  }
  #word-popover .pop-body { color: #dde; }
  #word-popover .pop-loading { color: #88a; font-style: italic; }
  #word-popover .pop-body strong { color: #fff; }
  #word-popover .pop-body em { color: #fed7aa; }
  #word-popover .pop-body p { margin: 0; }
  #word-popover .pop-body p + p { margin-top: 6px; }

  .bubble-row { display: flex; align-items: flex-start; gap: 6px; }

  .play-btn {
    flex-shrink: 0;
    margin-top: 10px;
    background: none;
    border: none;
    color: #aab;
    font-size: .8rem;
    cursor: pointer;
    padding: 2px 3px;
    border-radius: 5px;
    transition: color .15s;
    line-height: 1;
  }
  .play-btn:hover { color: #f97316; }

  .feedback-toggle {
    margin-top: 5px;
    font-size: .75rem;
    color: #889;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    user-select: none;
  }
  .feedback-toggle:hover { color: #f97316; }
  .feedback-toggle::before { content: "▸"; transition: transform .15s; }
  .feedback-toggle.open::before { transform: rotate(90deg); }

  .feedback-box {
    display: none;
    margin-top: 4px;
    padding: 8px 12px;
    background: #fff7ed;
    border-right: 3px solid #f0c040;
    border-radius: 8px 0 0 8px;
    font-size: .82rem;
    color: #554;
    line-height: 1.5;
    text-align: left;
  }
  .feedback-box.good { background: #f0fdf4; border-color: #4ade80; color: #166534; }

  .sender-label {
    font-size: .7rem;
    color: #99a;
    margin-bottom: 3px;
    padding: 0 4px;
  }

  /* ── Keyboard inset padding (VirtualKeyboard API) ── */
  #chat-screen {
    padding-bottom: env(keyboard-inset-height, 0px);
  }

  /* ── Input row ── */
  .input-row {
    display: flex;
    gap: 10px;
    padding: 14px 16px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
  }
  .input-row textarea {
    flex: 1;
    resize: none;
    border: 1.5px solid #c8d0e0;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: .9rem;
    font-family: inherit;
    line-height: 1.45;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color .15s;
  }
  .input-row textarea:focus { border-color: #f97316; }
  .input-row textarea::placeholder { color: #aab; }
  .send-btn {
    align-self: flex-end;
    width: 42px; height: 42px;
    border-radius: 12px;
    background: #f97316;
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, box-shadow .15s;
    flex-shrink: 0;
  }
  .send-btn:hover { background: #ea6c00; box-shadow: 0 2px 8px rgba(108,99,255,.4); }
  .send-btn:disabled { background: #fed7aa; cursor: default; box-shadow: none; }

  /* ── Quest bar ── */
  #quest-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    background: #fff7ed;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
  }
  #quest-bar .quest-label {
    font-size: .72rem;
    font-weight: 600;
    color: #778;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: .04em;
  }
  .quest-track {
    flex: 1;
    height: 7px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
  }
  .quest-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #f97316, #fb923c);
    border-radius: 999px;
    transition: width .4s ease;
  }
  #quest-bar .quest-pts {
    font-size: .72rem;
    color: #99a;
    white-space: nowrap;
    min-width: 52px;
    text-align: right;
  }
  #quest-bar.mastered .quest-fill { background: linear-gradient(90deg, #22c55e, #4ade80); }
  #quest-bar.mastered .quest-pts { color: #16a34a; font-weight: 600; }

  /* ── Quest complete overlay ── */
  #quest-complete {
    position: fixed;
    inset: 0;
    background: rgba(10,10,30,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn .2s ease;
  }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  .qc-card {
    background: #fff;
    border-radius: 20px;
    padding: 36px 32px;
    max-width: 320px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    animation: slideUp .25s ease;
  }
  @keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
  .qc-emoji { font-size: 3rem; }
  .qc-title { font-size: 1.25rem; font-weight: 700; color: #4f46e5; }
  .qc-sub { font-size: .88rem; color: #667; line-height: 1.5; }
  .qc-card button {
    margin-top: 8px;
    padding: 11px 28px;
    background: #f97316;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
  }
  .qc-card button:hover { background: #ea6c00; }

  /* ── Wikipedia image in bubble ── */
  .chat-img-wrap {
    margin-top: 8px;
    border-radius: 10px;
    overflow: hidden;
    max-width: 260px;
    box-shadow: 0 1px 4px rgba(0,0,0,.12);
    position: relative;
  }
  .chat-img-wrap img {
    display: block;
    width: 100%;
    height: auto;
  }
  .chat-img-caption {
    font-size: .68rem;
    color: #99a;
    margin-top: 3px;
    padding: 0 2px;
  }
  .chat-img-caption a {
    color: #99a;
    text-decoration: none;
  }
  .chat-img-caption a:hover { text-decoration: underline; }

  .typing-indicator {
    display: none;
    align-self: flex-start;
    background: #fff;
    border-radius: 16px;
    padding: 11px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
  }
  .typing-indicator span {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #aab;
    margin: 0 2px;
    animation: bounce .9s infinite;
  }
  .typing-indicator span:nth-child(2) { animation-delay: .15s; }
  .typing-indicator span:nth-child(3) { animation-delay: .3s; }
  @keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
  }

  /* ── Vocab review button ── */
  .vocab-btn {
    display: flex; align-items: center; gap: 4px;
    background: none; border: 1.5px solid #e2e8f0; border-radius: 20px;
    padding: 4px 10px; font-size: .8rem; font-weight: 600;
    color: #64748b; cursor: pointer; transition: all .15s;
  }
  .vocab-btn:hover { background: #f8fafc; border-color: #cbd5e1; color: #334155; }
  .vocab-btn .vb-count { background: #fb923c; color: #fff; border-radius: 10px; padding: 0 6px; font-size: .72rem; min-width: 18px; text-align: center; }
  .vocab-btn .vb-count.zero { display: none; }

  /* ── Vocab screen ── */
  #vocab-screen {
    display: none; flex-direction: column; flex: 1;
    padding: 0; gap: 0;
  }
  .vocab-header {
    display: flex; align-items: center; gap: 8px;
    padding: 14px 16px 10px; border-bottom: 1px solid #e2e8f0;
  }
  .vocab-header button { background: none; border: none; font-size: 1rem; cursor: pointer; color: #64748b; padding: 4px 8px; border-radius: 6px; }
  .vocab-header button:hover { background: #f1f5f9; }
  .vocab-header h2 { flex: 1; font-size: 1rem; font-weight: 700; color: #1e293b; margin: 0; }
  .vocab-progress-row { padding: 10px 16px 0; display: flex; align-items: center; gap: 10px; font-size: .82rem; color: #64748b; }
  .vocab-progress-track { flex: 1; height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; }
  .vocab-progress-fill { height: 100%; background: #fb923c; border-radius: 3px; transition: width .3s; }
  .vocab-card-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 16px; }
  .vocab-card {
    width: 100%; max-width: 420px;
    background: #fff; border-radius: 16px; box-shadow: 0 2px 12px rgba(0,0,0,.1);
    padding: 32px 28px; text-align: center;
    min-height: 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  }
  .vocab-card .vc-word { font-size: 2rem; font-weight: 700; color: #1e293b; }
  .vocab-card .vc-meta { display: flex; align-items: center; gap: 6px; }
  .vocab-card .vc-level { font-size: .75rem; font-weight: 600; color: #94a3b8; letter-spacing: .06em; text-transform: uppercase; }
  .vocab-card .vc-topic { font-size: .72rem; color: #a5b4fc; background: #eef2ff; border-radius: 4px; padding: 1px 6px; }
  .vocab-card .vc-context { font-size: .85rem; color: #64748b; font-style: italic; line-height: 1.5; max-width: 320px; }
  .vocab-card .vc-translation { font-size: 1.1rem; color: #3b82f6; font-weight: 600; }
  .vocab-card .vc-pos { font-size: .78rem; color: #94a3b8; }
  .vc-remove-btn {
    background: #f1f5f9; border: none; color: #94a3b8;
    font-size: 1rem; cursor: pointer; padding: 0 12px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
  }
  .vc-remove-btn:hover { color: #ef4444; background: #fee2e2; }
  .vocab-show-btn {
    background: #1e293b; color: #fff; border: none; border-radius: 10px;
    padding: 12px 28px; font-size: .95rem; font-weight: 600; cursor: pointer;
    transition: background .15s;
  }
  .vocab-show-btn:hover { background: #334155; }
  .vocab-rating-row { display: flex; gap: 8px; width: 100%; max-width: 420px; justify-content: center; flex-wrap: wrap; }
  .vocab-rating-btn {
    flex: 1; min-width: 70px; padding: 10px 6px;
    border: none; border-radius: 10px; font-size: .82rem; font-weight: 700;
    cursor: pointer; transition: filter .15s;
  }
  .vocab-rating-btn:hover { filter: brightness(1.1); }
  .vr-again  { background: #fee2e2; color: #dc2626; }
  .vr-hard   { background: #fef3c7; color: #d97706; }
  .vr-good   { background: #dcfce7; color: #16a34a; }
  .vr-easy   { background: #dbeafe; color: #2563eb; }
  .vocab-done { text-align: center; padding: 40px 20px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
  .vocab-done .vd-emoji { font-size: 2.5rem; }
  .vocab-done .vd-title { font-size: 1.2rem; font-weight: 700; color: #1e293b; }
  .vocab-done .vd-sub { font-size: .88rem; color: #64748b; }
  .vocab-done button { background: #1e293b; color: #fff; border: none; border-radius: 10px; padding: 12px 24px; font-size: .92rem; font-weight: 600; cursor: pointer; margin-top: 8px; }

  /* ── Vocab added badge in popover ── */
  .pop-vocab-badge { display: inline-block; margin-top: 6px; font-size: .72rem; color: #16a34a; font-weight: 600; }

  /* ── Vocab overview ── */
  .vocab-overview { width: 100%; max-width: 500px; display: flex; flex-direction: column; gap: 18px; padding: 8px 0 24px; }
  .vo-level-section { background: #fff; border-radius: 14px; box-shadow: 0 1px 6px rgba(0,0,0,.07); overflow: hidden; }
  .vo-level-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 18px; cursor: pointer; user-select: none;
    border-bottom: 1px solid #f1f5f9;
  }
  .vo-level-header:hover { background: #f8fafc; }
  .vo-level-title { font-size: .88rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
  .vo-level-summary { font-size: .78rem; color: #94a3b8; }
  .vo-level-chevron { font-size: .75rem; color: #94a3b8; transition: transform .2s; }
  .vo-level-body { display: none; flex-direction: column; gap: 0; }
  .vo-level-body.open { display: flex; }
  .vo-topic-row { display: flex; flex-direction: column; gap: 4px; padding: 10px 18px; border-bottom: 1px solid #f8fafc; }
  .vo-topic-row:last-child { border-bottom: none; }
  .vo-topic-label { display: flex; justify-content: space-between; align-items: baseline; }
  .vo-topic-name { font-size: .82rem; color: #334155; }
  .vo-topic-count { font-size: .75rem; color: #94a3b8; }
  .vt-bar-wrap { height: 6px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
  .vt-bar-fill { height: 100%; border-radius: 99px; background: #3b82f6; transition: width .3s; }
  .vo-start-btn {
    width: 100%; max-width: 500px; padding: 14px;
    background: #1e293b; color: #fff; border: none; border-radius: 12px;
    font-size: .95rem; font-weight: 700; cursor: pointer; margin-top: 4px;
  }
  .vo-start-btn:hover { background: #334155; }
  .vc-new-badge { font-size: .7rem; color: #16a34a; background: #dcfce7; border-radius: 4px; padding: 1px 6px; font-weight: 700; }
  .vo-topic-done { font-size: .68rem; color: #16a34a; font-weight: 600; margin-left: 4px; }

  /* ── Practice-type selector (on topic screen) ── */
  .mode-selector {
    display: none;
    gap: 12px;
  }
  .mode-selector.visible {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  .mode-card {
    padding: 18px 16px;
    border-radius: 14px;
    border: 2px solid #e2e8f0;
    background: #fff;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
  }
  .mode-card:hover {
    border-color: #f97316;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
  }
  .mode-card .mode-icon {
    font-size: 1.8rem;
  }
  .mode-card .mode-title {
    font-weight: 600;
    font-size: .92rem;
    color: #1e293b;
  }
  .mode-card .mode-desc {
    font-size: .76rem;
    color: #64748b;
    line-height: 1.4;
  }

  /* ── Listening screen ── */
  #listen-screen {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
  }
  #listen-screen .topic-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-size: .82rem;
    color: #556;
    flex-shrink: 0;
  }
  #listen-screen .topic-bar button {
    margin-left: auto;
    background: none;
    border: 1px solid #c8d0e0;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: .75rem;
    color: #556;
    cursor: pointer;
  }
  #listen-screen .topic-bar button:hover { border-color: #f97316; color: #f97316; }

  .listen-quest-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    background: #fff7ed;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
  }
  .listen-quest-bar .quest-label {
    font-size: .72rem;
    font-weight: 600;
    color: #778;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: .04em;
  }
  .listen-quest-bar .quest-track {
    flex: 1;
    height: 7px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
  }
  .listen-quest-bar .quest-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #f97316, #fb923c);
    border-radius: 999px;
    transition: width .4s ease;
  }
  .listen-quest-bar .quest-pts {
    font-size: .72rem;
    color: #99a;
    white-space: nowrap;
    min-width: 52px;
    text-align: right;
  }
  .listen-quest-bar.mastered .quest-fill { background: linear-gradient(90deg, #22c55e, #4ade80); }
  .listen-quest-bar.mastered .quest-pts { color: #16a34a; font-weight: 600; }

  .listen-body {
    flex: 1;
    overflow-y: auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
  }

  .listen-audio-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }
  .listen-play-btn {
    width: 64px; height: 64px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #f97316, #fb923c);
    color: #fff;
    font-size: 1.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s, box-shadow .15s;
    box-shadow: 0 4px 16px rgba(249,115,22,.3);
  }
  .listen-play-btn:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(249,115,22,.4); }
  .listen-play-btn:disabled { opacity: .5; cursor: default; transform: none; }
  .listen-play-hint {
    font-size: .78rem;
    color: #778;
  }

  .listen-question {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    text-align: center;
    max-width: 400px;
  }

  .listen-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 400px;
  }
  .listen-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    font-size: .9rem;
    color: #334;
  }
  .listen-option:hover { border-color: #f97316; background: #fff7ed; }
  .listen-option.selected { border-color: #f97316; background: #fff7ed; }
  .listen-option.correct { border-color: #22c55e; background: #dcfce7; }
  .listen-option.incorrect { border-color: #ef4444; background: #fee2e2; }
  .listen-option.disabled { pointer-events: none; opacity: .7; }
  .listen-option input[type="radio"] { accent-color: #f97316; }

  .listen-check-btn {
    padding: 12px 32px;
    background: #f97316;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
  }
  .listen-check-btn:hover { background: #ea6c00; }
  .listen-check-btn:disabled { background: #fed7aa; cursor: default; }

  .listen-feedback {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }
  .listen-feedback .lf-result {
    font-size: 1.1rem;
    font-weight: 700;
  }
  .listen-feedback .lf-result.correct { color: #16a34a; }
  .listen-feedback .lf-result.incorrect { color: #dc2626; }
  .listen-feedback .lf-points {
    font-size: .82rem;
    color: #64748b;
  }

  .listen-passage-reveal {
    width: 100%;
    max-width: 400px;
    padding: 14px 18px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    font-size: .88rem;
    color: #334;
    line-height: 1.6;
    display: none;
  }
  .listen-passage-reveal.visible { display: block; }

  .listen-actions {
    display: flex;
    gap: 12px;
    align-items: center;
  }
  .listen-actions button {
    padding: 10px 20px;
    border-radius: 10px;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    border: none;
  }
  .listen-show-text-btn {
    background: #f1f5f9;
    color: #475569;
  }
  .listen-show-text-btn:hover { background: #e2e8f0; }
  .listen-next-btn {
    background: #f97316;
    color: #fff;
  }
  .listen-next-btn:hover { background: #ea6c00; }

  .listen-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px;
    color: #778;
    font-size: .88rem;
  }
  .listen-spinner {
    width: 32px; height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: #f97316;
    border-radius: 50%;
    animation: spin .8s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ── Night mode (follows browser/OS preference) ── */
  @media (prefers-color-scheme: dark) {
    body { background: #0f172a; color: #cbd5e1; }

    .auth-card { background: #1e293b; box-shadow: 0 8px 32px rgba(0,0,0,.4); }
    .auth-brand h1, .verify-title, .qc-title, #level-screen h2, #topic-screen h2,
    .level-card-head .lc-title { color: #a5b4fc; }
    .auth-tagline, .auth-tab, .auth-form-desc, .auth-field label, .verify-sub, .qc-sub,
    #level-screen .screen-sub, #topic-screen p, .level-desc, .level-card-head .lc-vn,
    .back-btn, #quest-bar .quest-pts, .vocab-progress-row, .vocab-card .vc-context,
    .vocab-card .vc-pos, .vocab-card .vc-level, .vocab-done .vd-sub, .vo-level-summary,
    .vo-level-chevron, .vo-topic-count, .chat-img-caption, .chat-img-caption a,
    .sender-label, .feedback-toggle { color: #94a3b8; }
    .auth-tabs { background: #0f172a; }
    .auth-tab.active { background: #334155; color: #a5b4fc; box-shadow: none; }
    .auth-field input, .input-row textarea { background: #0f172a; border-color: #475569; color: #e2e8f0; }
    .auth-field input::placeholder, .input-row textarea::placeholder { color: #64748b; }
    .auth-error { background: rgba(220,38,38,.15); border-color: rgba(220,38,38,.4); color: #fca5a5; }
    .auth-info { background: rgba(34,197,94,.15); border-color: rgba(34,197,94,.4); color: #86efac; }

    .level-card { background: #1e293b; border-color: #334155; }
    .level-card.selected { background: #2a2418; }
    .back-btn:hover { color: #cbd5e1; }
    .chip { background: #1e293b; border-color: #475569; color: #cbd5e1; }
    .chip:hover { background: #2a2113; }

    .topic-bar { background: #1e293b; border-color: #334155; color: #94a3b8; }
    .topic-bar strong { color: #e2e8f0; }
    .topic-bar button { border-color: #475569; color: #94a3b8; }
    #messages::-webkit-scrollbar-thumb { background: #334155; }
    .msg.claude .bubble, .typing-indicator { background: #1e293b; color: #c7d2fe; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
    .typing-indicator span { background: #64748b; }
    .feedback-box { background: #2a2113; color: #cbd5e1; }
    .feedback-box.good { background: rgba(34,197,94,.12); color: #86efac; }

    .input-row { background: #1e293b; border-color: #334155; }

    #quest-bar { background: #2a2113; border-color: #334155; }
    .quest-track, .vocab-progress-track, .vt-bar-wrap { background: #334155; }

    .qc-card { background: #1e293b; }

    .vocab-btn { border-color: #334155; color: #94a3b8; }
    .vocab-btn:hover { background: #1e293b; border-color: #475569; color: #e2e8f0; }
    .vocab-header { border-color: #334155; }
    .vocab-header button { color: #94a3b8; }
    .vocab-header button:hover { background: #334155; }
    .vocab-header h2 { color: #e2e8f0; }
    .vocab-card { background: #1e293b; box-shadow: 0 2px 12px rgba(0,0,0,.35); }
    .vocab-card .vc-word, .vocab-done .vd-title { color: #e2e8f0; }
    .vocab-card .vc-topic { color: #a5b4fc; background: #312e81; }
    .vc-remove-btn { background: #334155; color: #94a3b8; }
    .vc-remove-btn:hover { background: rgba(239,68,68,.2); color: #fca5a5; }
    .vocab-show-btn, .vo-start-btn, .vocab-done button { background: #4f46e5; }
    .vocab-show-btn:hover, .vo-start-btn:hover, .vocab-done button:hover { background: #6366f1; }

    .vo-level-section { background: #1e293b; box-shadow: 0 1px 6px rgba(0,0,0,.25); }
    .vo-level-header { border-color: #334155; }
    .vo-level-header:hover { background: #243044; }
    .vo-topic-row { border-color: #243044; }
    .vo-topic-name { color: #cbd5e1; }
  }
