  :root {
    --paper: #efe8d8;
    --paper-raised: #f7f2e6;
    --ink: #241f19;
    --ink-soft: #5a5044;
    --ink-faint: #8c8172;
    --seal: #a33b2c;
    --seal-deep: #832c20;
    --jade: #4c7a6e;
    --jade-deep: #3a5e54;
    --gold: #b98f4a;
    --rate-1: #b8623f;
    --rate-2: #71a189;
    --blue-fill: #4472a8;
    --blue-fill-deep: #345f8c;
    --red-fill: #c0483a;
    --yellow-fill: #d1a53a;
    --green-fill: #5b9574;
    --hairline: rgba(36,31,25,0.14);
    --shadow: rgba(36,31,25,0.18);
    --hanzi-font: 'Noto Sans CJK SC', 'Noto Sans SC', 'Source Han Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --hanzi-size: clamp(56px, 16vw, 84px);
    --example-size: 16px;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  :root:not([data-theme="light"]) {
    @media (prefers-color-scheme: dark) {
      --paper: #1c1915;
      --paper-raised: #262220;
      --ink: #ece5d6;
      --ink-soft: #b9ae9a;
      --ink-faint: #83786a;
      --seal: #d1685a;
      --seal-deep: #e08172;
      --jade: #7fb0a1;
      --jade-deep: #97c4b6;
      --gold: #d3ac6f;
      --rate-1: #d99569;
      --rate-2: #a3c9b8;
      --hairline: rgba(236,229,214,0.14);
      --shadow: rgba(0,0,0,0.4);
    }
  }
  :root[data-theme="dark"] {
    --paper: #1c1915;
    --paper-raised: #262220;
    --ink: #ece5d6;
    --ink-soft: #b9ae9a;
    --ink-faint: #83786a;
    --seal: #d1685a;
    --seal-deep: #e08172;
    --jade: #7fb0a1;
    --jade-deep: #97c4b6;
    --gold: #d3ac6f;
    --rate-1: #d99569;
    --rate-2: #a3c9b8;
    --hairline: rgba(236,229,214,0.14);
    --shadow: rgba(0,0,0,0.4);
  }
  html, body {
    height: 100%;
  }
  * { box-sizing: border-box; }
  html { scroll-padding-top: env(safe-area-inset-top, 0px); }
  body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    min-height: 100%;
    display: flex;
    flex-direction: column;
  }
  .app {
    max-width: 1040px;
    margin: 0 auto;
    width: 100%;
    padding: 0 20px 32px;
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  .learn-area {
    display: flex;
    gap: 14px;
    flex: 1;
    min-height: 0;
    margin-top: 14px;
  }
  .content-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
  }
  #cardsView {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .pool-panel {
    flex: 0 0 348px;
    width: 348px;
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: calc(100vh - 220px);
  }
  .pool-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    flex: 0 0 auto;
  }
  .legend-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--hairline);
    background: none;
    color: var(--ink-soft);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 20px;
    cursor: pointer;
  }
  .legend-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
  }
  .legend-chip.off {
    color: var(--ink-faint);
    opacity: 0.55;
  }
  .legend-chip.off .dot {
    opacity: 0.4;
  }
  .pool-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-auto-rows: 48px;
    gap: 6px;
    align-content: start;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    padding: 3px 3px 3px 1px;
  }
  .pool-cell {
    position: relative;
    width: 100%;
    height: 48px;
    border-radius: 9px;
    border: 1.5px solid var(--hairline);
    background: var(--paper);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    font-family: var(--hanzi-font);
    color: #fdf8ee;
    white-space: nowrap;
    overflow: hidden;
  }
  .pool-cell.learned {
    border-color: transparent;
  }
  .pool-cell .lvl-badge {
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 8.5px;
    line-height: 1;
    font-family: system-ui, sans-serif;
    font-weight: 700;
    color: #000;
  }
  .pool-cell { cursor: pointer; }
  .pool-cell.in-pool::before {
    content: '✓';
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 9px;
    line-height: 1;
    font-family: system-ui, sans-serif;
    font-weight: 700;
    color: var(--jade);
    opacity: .75;
  }
  .pool-cell.learned.in-pool::before { color: #1f5a3c; opacity: .8; }
  .island-hsk-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; font-size: 12.5px; color: var(--ink-soft); }
  .island-hsk-select { padding: 5px 8px; border: 1px solid var(--hairline); border-radius: 7px; background: var(--paper-raised); color: var(--ink); font: inherit; font-size: 12.5px; }
  #inpNewIslandHsk { width: 100%; }
  .backup-all-row .export-row-label { font-weight: 600; }
  .demo-badge { display: inline-block; font-size: 10.5px; font-weight: 600; color: var(--jade-deep); border: 1px solid var(--jade); border-radius: 10px; padding: 1px 7px; margin-top: 4px; white-space: nowrap; }
  .session-pause { padding: 4px 10px; font-size: 11.5px; margin: 0 8px; white-space: nowrap; flex: 0 0 auto; }
  @media (max-width: 600px) {
    /* narrow screens: text + pause on one line, the dots in their own row */
    .session-bar { flex-wrap: wrap; row-gap: 8px; }
    .session-bar > span:first-child { flex: 1; min-width: 0; }
    .session-pause { margin-right: 0; }
    .session-bar .dots { flex-basis: 100%; justify-content: center; }
  }
  .grid-search { flex: 0 0 auto; display: flex; gap: 8px; align-items: center; }
  .grid-search input { flex: 1; min-width: 0; }
  .grid-filter-btn { flex: 0 0 auto; padding: 7px 12px; font-size: 12px; }
  .grid-filter-btn.active { border-color: var(--ink-faint); color: var(--ink); }
  .grid-filter-panel { display: none; flex-basis: 100%; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--hairline); border-radius: 12px; }
  .grid-filter-panel.open { display: flex; }
  .gf-row { display: flex; gap: 8px; align-items: flex-start; }
  .gf-label { flex: 0 0 78px; font-size: 11px; color: var(--ink-faint); padding-top: 5px; }
  .gf-items { display: flex; flex-wrap: wrap; gap: 5px; }
  .seg { display: inline-flex; border: 1px solid var(--hairline); border-radius: 20px; overflow: hidden; }
  .seg-btn { background: none; border: none; color: var(--ink-faint); font: inherit; font-size: 11.5px; font-weight: 600; padding: 5px 11px; cursor: pointer; }
  .seg-btn + .seg-btn { border-left: 1px solid var(--hairline); }
  .seg-btn.active { background: var(--hairline); color: var(--jade-deep); }
  .gf-reset { align-self: flex-end; font-size: 11.5px; padding: 4px 10px; }
  .pool-cell .peek { color: var(--ink-soft); opacity: .75; }
  .grid-search input { width: 100%; box-sizing: border-box; padding: 7px 12px; border-radius: 20px; border: 1px solid var(--hairline); background: var(--paper); color: var(--ink); font: inherit; font-size: 13px; }
  .grid-search input:focus { outline: none; border-color: var(--ink-faint); }
  .pool-cell.in-streak::after {
    content: '🔥';
    position: absolute;
    left: 3px;
    bottom: 2px;
    font-size: 8px;
    line-height: 1;
    opacity: .8;
  }
  .pool-edit-hint { flex-basis: 100%; font-size: 11.5px; color: var(--jade-deep); margin-top: 2px; }
  .sent-word { border-radius: 4px; transition: background-color .12s; }
  .sent-word:hover { background-color: var(--hairline); }
  .sent-word[style] {
    border-radius: 0;
    background-image: linear-gradient(var(--lc), var(--lc));
    background-size: calc(100% - 1px) 4px;
    background-position: left bottom;
    background-repeat: no-repeat;
  }
  .grid-info-toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%) translateY(8px);
    background: var(--ink);
    color: var(--paper);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-family: var(--hanzi-font), system-ui, sans-serif;
    max-width: min(90vw, 380px);
    text-align: center;
    z-index: 40;
    box-shadow: 0 6px 20px var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s, transform .15s;
  }
  .grid-info-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  main#main {
    min-width: 0;
  }
  /* ---- mobile: 6-page swipe carousel (Vokabeln | Karten | Geschichten | Satzinseln | Statistiken | Audio) ---- */
  @media (max-width: 820px) {
    /* Move .app's own horizontal padding onto the header/tabs/dots individually,
       so the carousel track's clip boundary sits exactly at the viewport edge —
       otherwise a sliver of the neighboring page bleeds into that padding zone. */
    .app { padding-left: 0; padding-right: 0; overflow-x: hidden; touch-action: pan-y; }
    .app > header.top,
    .app > .view-tabs,
    .app > .swipe-dots {
      padding-left: 20px;
      padding-right: 20px;
    }
    .learn-area.carousel {
      flex-wrap: nowrap;
      width: 600%;
      transition: transform 0.28s cubic-bezier(.2,.7,.3,1);
      gap: 0;
      touch-action: pan-y;
    }
    /* content-col itself must not take a carousel slot — it only exists for the
       desktop layout. In carousel mode its children (cardsView/storiesView/
       islandsView/statsPageView/audioView) are promoted to act as direct flex
       items of .learn-area, each its own page. */
    .learn-area.carousel > .content-col {
      display: contents;
    }
    .learn-area.carousel > .pool-panel,
    .learn-area.carousel #cardsView,
    .learn-area.carousel #storiesView,
    .learn-area.carousel #islandsView,
    .learn-area.carousel #statsPageView,
    .learn-area.carousel #audioView {
      flex: 0 0 16.6667%;
      width: 16.6667%;
      max-width: 16.6667%;
      min-width: 0;
      box-sizing: border-box;
      padding: 0 8px;
    }
    .learn-area.carousel .pool-panel {
      max-height: none;
      height: 100%;
    }
    .learn-area.carousel #cardsView,
    .learn-area.carousel #storiesView,
    .learn-area.carousel #islandsView,
    .learn-area.carousel #statsPageView,
    .learn-area.carousel #audioView {
      display: block !important;
    }
    .swipe-dots {
      display: flex;
      justify-content: center;
      gap: 7px;
      padding: 10px 0 2px;
    }
    .swipe-dots .sdot {
      width: 7px; height: 7px; border-radius: 50%;
      background: var(--hairline);
      transition: background .2s, transform .2s;
    }
    .swipe-dots .sdot.on {
      background: var(--seal);
      transform: scale(1.25);
    }
  }
  @media (min-width: 821px) {
    .swipe-dots { display: none; }
    #tabGrid { display: none; }
  }
  .view-tabs {
    display: flex;
    gap: 6px;
    padding: 12px 0 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .view-tabs::-webkit-scrollbar { display: none; }
  .tab-btn {
    background: none;
    border: none;
    color: var(--ink-faint);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    padding: 8px 4px 10px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    flex: 0 0 auto;
  }
  .tab-btn.active {
    color: var(--seal);
    border-bottom-color: var(--seal);
  }
  .stories-wrap {
    max-width: 620px;
    margin: 18px auto 0;
  }
  .story-form .field { margin-bottom: 18px; }
  .story-form textarea {
    width: 100%;
    min-height: 70px;
    padding: 10px 11px;
    border-radius: 8px;
    border: 1px solid var(--hairline);
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
  }
  .story-form select, .story-form input[type="number"] {
    width: 100%;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--hairline);
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
  }
  .story-card {
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: 10px;
    padding: 9px 13px;
    margin-bottom: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .story-card-toprow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
  }
  .story-card:hover { border-color: var(--ink-faint); }
  .audio-rec-playing { border-color: var(--seal); }
  .audio-rec-check { width: 16px; height: 16px; margin-top: 1px; flex: 0 0 auto; cursor: pointer; }
  .story-card .story-title {
    font-family: var(--hanzi-font);
    font-size: 15.5px;
    margin-bottom: 1px;
  }
  .story-card .story-title-en {
    font-size: 11.5px;
    font-style: italic;
    color: var(--ink-soft);
    margin-bottom: 2px;
  }
  .story-card .story-meta {
    font-size: 11px;
    color: var(--ink-faint);
    line-height: 1.35;
  }
  .story-audio-row {
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px dashed var(--hairline);
    padding-top: 6px;
    cursor: default;
  }
  .story-audio-bar {
    flex: 1;
    height: 5px;
    border-radius: 4px;
    background: var(--hairline);
    overflow: hidden;
  }
  .story-audio-fill {
    height: 100%;
    background: var(--seal);
    border-radius: 4px;
    transition: width .3s;
  }
  .story-audio-label {
    font-size: 10.5px;
    color: var(--ink-faint);
    min-width: 40px;
    text-align: right;
  }
  .audio-mini-btn {
    padding: 3px 7px;
    font-size: 12.5px;
    min-width: auto;
    flex: 0 0 auto;
  }
  .audio-mini-note {
    font-size: 11px;
    color: var(--ink-faint);
    flex: 0 0 auto;
  }
  .audio-mini-done { color: var(--seal); font-weight: 700; font-size: 14px; }
  .audio-mini-success { font-size: 11px; color: var(--jade); flex: 0 0 auto; }
  .story-audio-params {
    font-size: 10px;
    color: var(--ink-faint);
    opacity: .65;
    padding: 0 2px;
    margin-top: 1px;
  }
  .audio-picker {
    background: var(--paper);
    border: 1px solid var(--hairline);
    border-radius: 10px;
    padding: 12px;
    cursor: default;
  }
  .audio-picker-label {
    font-size: 11.5px;
    color: var(--ink-faint);
    margin: 8px 0 6px;
  }
  .audio-picker-label:first-child { margin-top: 0; }
  .audio-picker-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .audio-opt {
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: 7px;
    padding: 7px 12px;
    font-size: 12.5px;
    font-family: inherit;
    color: var(--ink);
    cursor: pointer;
  }
  .audio-opt.selected {
    border-color: var(--seal);
    background: var(--seal);
    color: #fff;
    font-weight: 600;
  }
  .audio-picker-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
  }
  .story-toprow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
  }
  .story-sentence {
    margin-bottom: 18px;
    padding-bottom: 16px;
    border-bottom: 1px dashed var(--hairline);
  }
  .story-sentence:last-child { border-bottom: none; }
  .story-sentence .s-h {
    font-family: var(--hanzi-font);
    font-size: 22px;
    line-height: 1.6;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .story-sentence .s-p { color: var(--seal); font-size: 14px; margin-top: 4px; }
  .story-sentence .s-e { color: var(--ink-soft); font-size: 13.5px; margin-top: 4px; }
  .story-title-block {
    text-align: center;
    margin-bottom: 24px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--hairline);
  }
  .story-title-block .t-h { font-family: var(--hanzi-font); font-size: 28px; margin-bottom: 6px; }
  .story-title-block .t-p { color: var(--seal); font-size: 15px; }
  .story-title-block .t-e { color: var(--ink-faint); font-size: 13px; margin-top: 3px; }
  .story-btn-row { display: flex; gap: 10px; margin-top: 24px; }
  .empty-note { color: var(--ink-faint); font-size: 13.5px; text-align: center; padding: 30px 0; }

  .stats-wrap {
    max-width: 620px;
    margin: 18px auto 0;
  }
  .stat-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 22px;
  }
  .stat-card {
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: 12px;
    padding: 14px 16px;
  }
  .stat-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.15;
  }
  .stat-card .stat-value .unit {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-faint);
    margin-left: 3px;
  }
  .stat-card .stat-label {
    font-size: 12px;
    color: var(--ink-faint);
    margin-top: 3px;
  }
  .stat-card.streak .stat-value { color: var(--seal); }
  .stats-section-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink-soft);
    margin: 22px 0 10px;
  }
  .level-dist-bar {
    display: flex;
    height: 22px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--hairline);
    margin-bottom: 8px;
  }
  .level-dist-bar .seg {
    height: 100%;
  }
  .level-dist-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 11.5px;
    color: var(--ink-faint);
    margin-bottom: 4px;
  }
  .level-dist-legend .lg-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
  }
  .cal-widget {
    border: 1px solid var(--hairline);
    border-radius: 10px;
    padding: 10px 10px 12px;
    margin-bottom: 6px;
    background: var(--paper-raised);
  }
  .cal-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
  }
  .cal-title {
    flex: 1;
    text-align: center;
    font-size: 13.5px;
    font-weight: 600;
    text-transform: capitalize;
  }
  .cal-nav-btn {
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 1px solid var(--hairline);
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    flex: none;
  }
  .cal-detail-icons {
    display: flex;
    gap: 2px;
    flex: none;
  }
  .cal-icon-btn {
    width: 26px; height: 26px;
    border-radius: 6px;
    border: none;
    background: transparent;
    font-size: 13px;
    line-height: 1;
    cursor: default;
    opacity: 0.55;
  }
  .cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    margin-bottom: 4px;
  }
  .cal-weekday {
    text-align: center;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--ink-faint);
  }
  .cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
    touch-action: pan-y;
  }
  .cal-day {
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    background: var(--paper);
    border: 1px solid transparent;
    position: relative;
  }
  .cal-day-empty { background: transparent; }
  .cal-day-num { font-size: 10.5px; }
  .cal-day-count {
    font-size: 8px;
    font-weight: 700;
    opacity: 0.85;
  }
  .cal-today { border-color: var(--seal); }
  .cal-heat-0 { background: var(--paper); color: var(--ink-faint); }
  .cal-heat-1 { background: color-mix(in srgb, var(--seal) 22%, var(--paper)); }
  .cal-heat-2 { background: color-mix(in srgb, var(--seal) 45%, var(--paper)); }
  .cal-heat-3 { background: color-mix(in srgb, var(--seal) 68%, var(--paper)); color: #fff; }
  .cal-heat-4 { background: var(--seal); color: #fff; }
  .cal-icon-btn.active { opacity: 1; background: var(--hairline); }
  .cal-detail-panel {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--hairline);
  }
  .cal-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
  }
  .cal-detail-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-soft);
  }
  .cal-detail-close {
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 1px solid var(--hairline);
    background: var(--paper);
    color: var(--ink-faint);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
  }
  .cal-gran-row {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
  }
  .cal-gran-btn {
    flex: 1;
    padding: 6px 0;
    border-radius: 7px;
    border: 1px solid var(--hairline);
    background: var(--paper);
    color: var(--ink);
    font-size: 12px;
    cursor: pointer;
  }
  .cal-gran-btn.selected {
    background: var(--seal);
    border-color: var(--seal);
    color: #fff;
  }
  .cal-bars-row {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 120px;
    overflow-x: auto;
  }
  .cal-bar-col {
    flex: 1;
    min-width: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
  }
  .cal-bar-value {
    font-size: 9px;
    color: var(--ink-soft);
    font-weight: 700;
    margin-bottom: 2px;
    white-space: nowrap;
  }
  .cal-bar-track {
    width: 70%;
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: var(--hairline);
    border-radius: 3px 3px 0 0;
    overflow: hidden;
  }
  .cal-bar-fill {
    width: 100%;
    background: var(--seal);
    border-radius: 3px 3px 0 0;
  }
  .cal-bar-label {
    font-size: 8px;
    color: var(--ink-faint);
    margin-top: 3px;
    white-space: nowrap;
  }
  .cal-curve-svg {
    width: 100%;
    height: 130px;
    display: block;
  }
  .cal-curve-ceiling {
    font-size: 10.5px;
    color: var(--ink-faint);
    text-align: right;
    margin-bottom: 2px;
  }
  .cal-curve-axis {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--ink-faint);
    margin-top: 2px;
  }
  .hsk-progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 9px;
    font-size: 12.5px;
  }
  .hsk-progress-row .hsk-name {
    width: 68px;
    flex: 0 0 68px;
    color: var(--ink-soft);
    font-weight: 600;
  }
  .hsk-progress-row .hsk-bar-track {
    flex: 1;
    height: 9px;
    border-radius: 5px;
    background: var(--hairline);
    overflow: hidden;
    display: flex;
  }
  .hsk-progress-row .hsk-bar-seg {
    display: block;
    height: 100%;
  }
  .hsk-progress-row .hsk-bar-fill {
    display: block;
    height: 100%;
    border-radius: 5px;
  }
  .hsk-progress-row .hsk-count {
    width: 64px;
    flex: 0 0 64px;
    text-align: right;
    color: var(--ink-faint);
    font-size: 11.5px;
  }
  .stats-motivation {
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-left: 3px solid var(--seal);
    border-radius: 8px;
    padding: 12px 15px;
    font-size: 13px;
    color: var(--ink-soft);
    margin-bottom: 20px;
  }
  .freq-word-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--hairline);
  }
  .freq-word-row:last-child { border-bottom: none; }
  .freq-word-h {
    font-family: var(--hanzi-font);
    font-size: 17px;
    flex: 0 0 auto;
    min-width: 46px;
  }
  .freq-word-p {
    color: var(--seal);
    font-size: 12px;
    flex: 0 0 auto;
    min-width: 76px;
  }
  .freq-word-e {
    color: var(--ink-faint);
    font-size: 12px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .export-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }
  .export-row-label {
    flex: 1;
    font-size: 13px;
    color: var(--ink-soft);
  }
  .export-row .btn-secondary {
    padding: 7px 14px;
    font-size: 14px;
    min-width: 40px;
  }
  header.top {
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
    padding-bottom: 14px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--hairline);
  }
  .brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
    white-space: nowrap;
  }
  .brand .mark {
    font-family: var(--hanzi-font);
    font-size: 26px;
    color: var(--seal);
    line-height: 1;
  }
  .brand h1 {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
    letter-spacing: 0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .top-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
  }
  .icon-btn {
    background: none;
    border: 1px solid var(--hairline);
    color: var(--ink-soft);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: border-color .15s, color .15s;
  }
  .icon-btn:hover { border-color: var(--ink-faint); color: var(--ink); }

  .lang-popover {
    position: fixed;
    top: calc(58px + env(safe-area-inset-top, 0px));
    right: 20px;
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: 10px;
    box-shadow: 0 4px 16px var(--shadow);
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 30;
    min-width: 150px;
  }
  .lang-popover.show { display: flex; }
  .lang-option {
    background: none;
    border: none;
    text-align: left;
    padding: 9px 10px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--ink);
    cursor: pointer;
  }
  .lang-option:hover { background: var(--paper); }
  .lang-option.active { font-weight: 700; color: var(--seal); }

  .stats-strip {
    display: flex;
    gap: 18px;
    padding: 12px 2px;
    font-size: 12.5px;
    color: var(--ink-faint);
    flex-wrap: wrap;
  }
  .stats-strip b { color: var(--ink-soft); font-weight: 600; }

  main {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  /* --- Session intro / empty states --- */
  .panel {
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: 14px;
    padding: 28px 24px;
    margin-top: 18px;
    text-align: center;
  }
  .panel h2 {
    font-size: 18px;
    margin: 0 0 8px;
  }
  .panel p {
    color: var(--ink-soft);
    font-size: 14px;
    line-height: 1.55;
    margin: 0 0 20px;
  }
  .btn-primary {
    background: var(--seal);
    color: #fdf8ee;
    border: none;
    padding: 13px 26px;
    border-radius: 9px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s;
  }
  .btn-primary:hover { background: var(--seal-deep); }
  .btn-secondary {
    background: none;
    border: 1px solid var(--hairline);
    color: var(--ink-soft);
    padding: 11px 22px;
    border-radius: 9px;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
  }
  .btn-secondary:hover { border-color: var(--ink-faint); color: var(--ink); }

  /* --- Welcome dialog (js/welcome.js) --- */
  .info-btn { font-family: Georgia, 'Times New Roman', serif; font-style: italic; font-weight: 700; font-size: 17px; }
  .welcome-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
  .welcome-box { background: var(--paper-raised); color: var(--ink); border: 1px solid var(--hairline); border-radius: 14px; max-width: 480px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 22px 20px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
  .welcome-box h2 { margin: 0 0 8px; font-size: 20px; }
  .welcome-box h3 { margin: 16px 0 4px; font-size: 14.5px; color: var(--seal); }
  .welcome-box p, .welcome-box li { font-size: 14px; line-height: 1.5; color: var(--ink-soft); margin: 0 0 6px; }
  .welcome-tabs { margin: 0; padding-left: 18px; }
  .welcome-tabs strong { color: var(--ink); }
  .welcome-key { margin-top: 14px !important; padding: 10px 12px; border: 1px dashed var(--hairline); border-radius: 10px; }
  .welcome-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
  .welcome-check { font-size: 13.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; cursor: pointer; }

  /* --- Mode cards on the cards start screen (free practice + Power-Streak) --- */
  .mode-card .mode-head { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
  .mode-card .mode-icon { font-size: 30px; }
  .mode-card .mode-title { font-size: 26px; font-weight: 700; color: var(--seal); line-height: 1; }
  .mode-card .mode-num { font-size: 40px; font-weight: 700; color: var(--seal); line-height: 1; }
  .mode-card .mode-unit { font-size: 14px; color: var(--ink-soft); }
  .mode-card .mode-motto { font-size: 15px; font-weight: 600; margin: 10px 0 6px; }
  .mode-card .mode-grid { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; margin: 0 0 6px; }
  .mode-card .mode-cell { border: 1px solid var(--hairline); border-radius: 8px; padding: 6px 2px; }
  .mode-card .mode-cell .n { font-size: 18px; font-weight: 700; }
  .mode-card .mode-cell .l { font-size: 11px; color: var(--ink-faint); }
  .mode-card .mode-cell.due .n { color: var(--seal); }
  .mode-card .mode-note { font-size: 12px; color: var(--ink-faint); margin-bottom: 18px; }
  .mode-card .mode-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
  .mode-card .mode-info { margin-top: 16px; font-size: 13px; color: var(--ink-soft); }
  .mode-card .mode-info summary { cursor: pointer; color: var(--ink-faint); }
  .mode-card .mode-info p { text-align: left; font-size: 13px; margin: 8px 0 0; }
  .mode-card .mode-reset { margin: 14px auto 0; }

  /* --- Flashcard --- */
  .session-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 18px;
    font-size: 12.5px;
    color: var(--ink-faint);
  }
  .dots {
    display: flex;
    gap: 5px;
  }
  .dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--hairline);
    cursor: pointer;
  }
  .dot.done { background: var(--jade); }
  .dot.active { box-shadow: 0 0 0 2px var(--seal); }

  .card {
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: 18px;
    margin-top: 12px;
    padding: 40px 28px 28px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 2px 0 var(--hairline);
    min-height: 340px;
    position: relative;
  }
  .hsk-badge {
    position: absolute;
    top: 18px;
    left: 20px;
    font-size: 11px;
    font-weight: 600;
    color: var(--gold);
    border: 1px solid var(--gold);
    border-radius: 20px;
    padding: 3px 10px;
    letter-spacing: 0.02em;
  }
  .rank-note {
    position: absolute;
    top: 18px;
    right: 20px;
    font-size: 11px;
    color: var(--ink-faint);
  }
  .hanzi {
    font-family: var(--hanzi-font);
    font-size: var(--hanzi-size);
    line-height: 1.1;
    margin-top: 20px;
    font-weight: 600;
    cursor: pointer;
  }
  .pinyin-line {
    min-height: 30px;
    margin-top: 14px;
    font-size: 19px;
    color: var(--seal);
    font-weight: 500;
    letter-spacing: 0.01em;
  }
  .hint-row {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .hint-btn {
    background: none;
    border: 1px solid var(--hairline);
    color: var(--ink-soft);
    padding: 7px 14px;
    border-radius: 20px;
    font-size: 12.5px;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  a.hint-btn { text-decoration: none; }
  .imprint-link { margin-top: 28px; text-align: center; }
  .imprint-link a { color: var(--ink-faint); }
  .get-key-btn { display: inline-flex; margin-top: 8px; }
  .key-free-check { width: 100%; justify-content: flex-start; margin-top: 8px; }
  .hint-btn:hover { border-color: var(--ink-faint); color: var(--ink); }
  .hint-btn.on {
    border-color: var(--jade);
    color: var(--jade-deep);
  }
  .solution-line {
    min-height: 22px;
    margin-top: 12px;
    font-size: 15px;
    color: var(--ink-soft);
    font-style: italic;
  }
  .try-box {
    margin-top: 14px;
    padding: 10px 14px;
    border: 1px dashed var(--hairline);
    border-radius: 10px;
  }
  .try-box .try-label { font-size: 12px; color: var(--ink-faint); }
  .try-box .try-h { font-family: var(--hanzi-font); font-size: 22px; line-height: 1.5; margin-top: 2px; min-height: 33px; }
  .try-box .try-p { color: var(--seal); font-size: 14px; margin-top: 2px; }
  .try-box .try-e { color: var(--ink-soft); font-size: 13.5px; font-style: italic; margin-top: 2px; }
  .try-box .try-msg { color: var(--ink-faint); font-size: 12.5px; margin-top: 4px; }
  .examples-box {
    margin-top: 18px;
    text-align: left;
    width: 100%;
    font-size: 13.5px;
    color: var(--ink-soft);
    line-height: 1.7;
    border-top: 1px dashed var(--hairline);
    padding-top: 14px;
    display: none;
  }
  .examples-box.show { display: block; }
  .examples-box .ex-h { font-family: var(--hanzi-font); color: var(--ink); font-size: var(--example-size); }
  .examples-box .ex-p { color: var(--seal); font-size: 12.5px; }
  .examples-box .ex-e { color: var(--ink-faint); font-size: 12.5px; }
  .examples-box .ex-row { margin-bottom: 10px; }
  .ex-speak-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 0;
    vertical-align: middle;
    opacity: 0.75;
  }
  .ex-speak-btn:hover { opacity: 1; }

  .feedback-toast {
    margin-top: 14px;
    font-size: 12.5px;
    color: var(--jade-deep);
    min-height: 18px;
  }

  .rate-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 22px;
  }
  .rate-btn {
    border: none;
    border-radius: 10px;
    padding: 13px 4px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    color: #fdf8ee;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: filter .15s, transform .1s;
  }
  .rate-btn:active { transform: scale(0.97); }
  .rate-btn .val { font-size: 10.5px; opacity: 0.75; font-weight: 500; }
  /* rate-btn colors are set inline via levelToColor() to match the pool overview gradient */
  .rate-btn:hover { filter: brightness(1.06); }
  .rate-btn.disabled, .rate-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(0.4);
  }
  .rate-btn.disabled:hover, .rate-btn:disabled:hover { filter: grayscale(0.4); }
  /* rate-btn text stays cream in both themes since its background colors (from levelToColor) are fixed, not theme-adaptive */
  .nav-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 4px;
  }
  .nav-row .hint-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
  }

  /* --- Settings drawer --- */
  .overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: none;
    z-index: 20;
  }
  .overlay.show { display: block; }
  .drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(380px, 92vw);
    background: var(--paper-raised);
    z-index: 21;
    transform: translateX(100%);
    transition: transform .22s ease;
    padding: calc(24px + env(safe-area-inset-top, 0px)) 22px 24px;
    overflow-y: auto;
    border-left: 1px solid var(--hairline);
  }
  .drawer.show { transform: translateX(0); }
  .drawer h2 {
    font-size: 16px;
    margin: 0 0 18px;
  }
  .field {
    margin-bottom: 20px;
  }
  .field label {
    display: block;
    font-size: 12.5px;
    color: var(--ink-soft);
    margin-bottom: 8px;
    font-weight: 500;
  }
  .field input[type="number"] {
    width: 100%;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--hairline);
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
  }
  .field select {
    width: 100%;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--hairline);
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
  }
  .field input[type="range"] {
    width: 100%;
    accent-color: var(--seal);
    margin-top: 4px;
  }
  .size-val {
    color: var(--ink-faint);
    font-weight: 400;
  }
  .hsk-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .hsk-check {
    display: flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--hairline);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    cursor: pointer;
  }
  .hsk-check input { accent-color: var(--seal); }
  .drawer-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 26px;
    padding-top: 20px;
    border-top: 1px solid var(--hairline);
  }
  .danger-btn {
    background: none;
    border: 1px solid var(--hairline);
    color: var(--seal);
    padding: 10px 16px;
    border-radius: 9px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
  }
  .drawer-note {
    font-size: 11.5px;
    color: var(--ink-faint);
    line-height: 1.5;
    margin-top: 10px;
  }

  @media (max-width: 420px) {
    .brand { gap: 7px; }
    .brand .mark { font-size: 22px; }
    .brand h1 { font-size: 15px; }
    .top-actions { gap: 6px; }
    .card { padding: 32px 18px 22px; }
    .rate-btn { font-size: 11.5px; padding: 12px 2px; }
  }
