    :root {
      --bg: #fafafa;
      --surface: #ffffff;
      --border: #e9e9e9;
      --line: #f0efea;
      --text: #14171e;
      --muted: #7c7a72;
      --accent: #6366f1;
      --accent-soft: #eef2ff;
      --success: #10b981;
      --success-soft: #ecfdf5;
      --error: #f43f5e;
      --error-soft: #fef2f4;
      --shadow: 0 2px 8px rgba(0,0,0,0.04);
      --shadow-lg: 0 4px 16px -2px rgba(0,0,0,0.06);
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
      background: var(--bg);
      color: var(--text);
      line-height: 1.5;
      min-height: 100dvh;
      -webkit-font-smoothing: antialiased;
    }

    .container {
      max-width: 720px;
      margin: 0 auto;
      padding: 40px 24px 80px;
    }

    h1 {
      font-size: 32px;
      font-weight: 600;
      letter-spacing: -0.02em;
      margin-bottom: 8px;
    }

    .subtitle {
      color: var(--muted);
      font-size: 14px;
      margin-bottom: 28px;
    }

    .subtitle strong { color: var(--text); font-weight: 600; }

    .filter-label {
      font-size: 12px;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--muted);
      margin-bottom: 10px;
      font-weight: 500;
    }

    .filter-row {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin-bottom: 28px;
    }

    .chip {
      padding: 7px 14px;
      border: 1px solid var(--border);
      border-radius: 999px;
      font-size: 13px;
      cursor: pointer;
      background: var(--surface);
      font-family: inherit;
      color: var(--text);
      transition: all 0.2s;
      font-weight: 500;
    }

    .chip:hover { border-color: var(--accent); color: var(--accent); }
    .chip.active {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
    }

    .mode-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
      gap: 12px;
      margin-bottom: 24px;
    }

    .mode-btn {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 20px;
      cursor: pointer;
      transition: all 0.2s;
      text-align: left;
      font-family: inherit;
    }

    .mode-btn:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-lg);
      border-color: var(--accent);
    }

    .mode-btn h3 {
      font-size: 16px;
      font-weight: 600;
      margin-bottom: 6px;
      letter-spacing: -0.01em;
    }

    .mode-btn p {
      color: var(--muted);
      font-size: 13px;
      line-height: 1.4;
    }

    .progress-bar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 12px;
      font-size: 14px;
      color: var(--muted);
    }

    .progress-bar strong { color: var(--text); font-weight: 600; }

    .progress-track {
      height: 4px;
      background: var(--line);
      border-radius: 2px;
      overflow: hidden;
      margin-bottom: 24px;
    }

    .progress-fill {
      height: 100%;
      background: var(--accent);
      transition: width 0.4s ease;
      border-radius: 2px;
    }

    .question-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 20px;
      padding: 32px;
      box-shadow: var(--shadow);
    }

    .question-label {
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      color: var(--muted);
      margin-bottom: 14px;
      font-weight: 500;
    }

    .question-prompt {
      font-size: 28px;
      font-weight: 600;
      letter-spacing: -0.02em;
      margin-bottom: 8px;
      line-height: 1.3;
      word-break: break-word;
    }

    .question-hint {
      color: var(--muted);
      font-size: 14px;
      font-family: 'JetBrains Mono', monospace;
      margin-bottom: 8px;
    }

    .family-tag {
      display: inline-block;
      padding: 4px 10px;
      background: var(--accent-soft);
      color: var(--accent);
      border-radius: 6px;
      font-size: 12px;
      font-weight: 500;
    }

    .input-area { margin-top: 28px; }

    .text-input {
      width: 100%;
      font-family: 'JetBrains Mono', monospace;
      font-size: 18px;
      padding: 14px 16px;
      border: 1.5px solid var(--border);
      border-radius: 12px;
      background: var(--surface);
      transition: all 0.2s;
      color: var(--text);
    }

    .text-input:focus {
      outline: none;
      border-color: var(--accent);
      box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
    }

    .text-input.correct { border-color: var(--success); background: var(--success-soft); }
    .text-input.wrong { border-color: var(--error); background: var(--error-soft); }

    .options {
      display: grid;
      gap: 10px;
    }

    .option-btn {
      text-align: left;
      padding: 14px 16px;
      border: 1.5px solid var(--border);
      border-radius: 12px;
      background: var(--surface);
      cursor: pointer;
      font-family: inherit;
      font-size: 15px;
      color: var(--text);
      transition: all 0.15s;
      line-height: 1.4;
    }

    .option-btn:hover:not(:disabled) {
      border-color: var(--accent);
      background: var(--accent-soft);
    }

    .option-btn:disabled { cursor: default; }

    .option-btn.correct {
      border-color: var(--success);
      background: var(--success-soft);
      color: var(--success);
      font-weight: 500;
    }

    .option-btn.wrong {
      border-color: var(--error);
      background: var(--error-soft);
      color: var(--error);
    }

    .actions {
      display: flex;
      gap: 10px;
      margin-top: 24px;
    }

    button.primary {
      background: var(--accent);
      color: white;
      border: none;
      padding: 12px 22px;
      border-radius: 10px;
      font-family: inherit;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s;
    }

    button.primary:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }
    button.primary:disabled { opacity: 0.4; cursor: not-allowed; }

    button.secondary {
      background: transparent;
      color: var(--text);
      border: 1px solid var(--border);
      padding: 12px 22px;
      border-radius: 10px;
      font-family: inherit;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s;
    }

    button.secondary:hover { background: var(--bg); border-color: var(--text); }

    button.ghost {
      background: transparent;
      color: var(--muted);
      border: none;
      padding: 12px 22px;
      border-radius: 10px;
      font-family: inherit;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s;
    }

    button.ghost:hover { color: var(--text); }

    .feedback {
      margin-top: 20px;
      padding: 14px 16px;
      border-radius: 12px;
      font-size: 14px;
      line-height: 1.5;
    }

    .feedback.correct {
      background: var(--success-soft);
      color: #047857;
      border: 1px solid #a7f3d0;
    }

    .feedback.wrong {
      background: var(--error-soft);
      color: #be123c;
      border: 1px solid #fecdd3;
    }

    .feedback strong { font-weight: 600; font-family: 'JetBrains Mono', monospace; font-size: 13px; }

    .result {
      text-align: center;
      padding: 24px 0;
    }

    .result h1 { margin-bottom: 20px; }

    .result-score {
      font-size: 72px;
      font-weight: 700;
      color: var(--accent);
      letter-spacing: -0.04em;
      line-height: 1;
      margin-bottom: 8px;
    }

    .result-detail {
      color: var(--muted);
      font-size: 15px;
      margin-bottom: 28px;
    }

    .result-detail strong { color: var(--text); font-weight: 600; }

    .review-list {
      text-align: left;
      margin-top: 40px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 20px;
    }

    .review-list h3 {
      font-size: 13px;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--muted);
      font-weight: 600;
      margin-bottom: 12px;
    }

    .review-item {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      padding: 10px 0;
      border-bottom: 1px dashed var(--line);
      font-size: 14px;
      gap: 12px;
    }

    .review-item:last-child { border-bottom: none; }

    .review-word {
      font-weight: 600;
      font-family: 'JetBrains Mono', monospace;
      font-size: 13px;
    }

    .review-meaning { color: var(--muted); margin-left: 8px; flex: 1; }

    .review-family {
      font-size: 11px;
      color: var(--accent);
      background: var(--accent-soft);
      padding: 3px 8px;
      border-radius: 5px;
      font-weight: 500;
      white-space: nowrap;
    }

    .review-empty {
      text-align: center;
      color: var(--success);
      padding: 20px;
      font-weight: 500;
    }

    /* ============ Learn Module ============ */
    .learn-back-btn {
      background: transparent;
      border: none;
      color: var(--muted);
      font-family: inherit;
      font-size: 14px;
      cursor: pointer;
      padding: 0;
      margin-bottom: 20px;
      display: inline-flex;
      align-items: center;
      gap: 4px;
      transition: color 0.2s;
    }
    .learn-back-btn:hover { color: var(--accent); }

    #learn-screen h2 {
      font-size: 28px;
      font-weight: 600;
      letter-spacing: -0.02em;
      margin-bottom: 6px;
      font-family: 'JetBrains Mono', monospace;
      color: var(--accent);
    }

    .learn-family-subtitle {
      color: var(--muted);
      font-size: 14px;
      margin-bottom: 24px;
    }

    .learn-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 12px;
      margin-top: 8px;
    }

    .family-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 20px;
      cursor: pointer;
      text-align: left;
      font-family: inherit;
      transition: all 0.2s;
      display: flex;
      flex-direction: column;
      gap: 6px;
    }
    .family-card:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-lg);
      border-color: var(--accent);
    }
    .family-card-name {
      font-family: 'JetBrains Mono', monospace;
      font-size: 18px;
      font-weight: 600;
      color: var(--accent);
      letter-spacing: -0.01em;
    }
    .family-card-count {
      font-size: 11px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.05em;
      font-weight: 500;
    }
    .family-card-meaning {
      font-size: 14px;
      color: var(--text);
      line-height: 1.4;
      margin-top: 4px;
    }

    .affix-flow {
      display: flex;
      flex-wrap: wrap;
      align-items: stretch;
      gap: 6px;
      padding: 20px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      margin-bottom: 16px;
    }
    .affix-piece {
      padding: 12px 14px;
      border-radius: 10px;
      border: 1.5px solid var(--border);
      background: var(--bg);
      text-align: center;
      flex: 1;
      min-width: 90px;
    }
    .affix-piece.root {
      background: var(--accent-soft);
      border-color: var(--accent);
    }
    .affix-piece.prefix {
      background: #f0f9ff;
      border-color: #93c5fd;
    }
    .affix-piece.suffix {
      background: #fdf4ff;
      border-color: #d8b4fe;
    }
    .affix-piece-form {
      font-family: 'JetBrains Mono', monospace;
      font-size: 15px;
      font-weight: 600;
      color: var(--text);
      margin-bottom: 4px;
      word-break: break-all;
    }
    .affix-piece.root .affix-piece-form { color: var(--accent); }
    .affix-piece-type {
      font-size: 10px;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--muted);
      margin-bottom: 6px;
      font-weight: 500;
    }
    .affix-piece-meaning {
      font-size: 12px;
      color: var(--text);
      line-height: 1.4;
    }
    .affix-plus {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 18px;
      color: var(--muted);
      font-weight: 300;
      padding: 0 2px;
    }

    .story-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 24px;
      line-height: 1.75;
      color: var(--text);
      margin-bottom: 28px;
      font-size: 15px;
      white-space: pre-line;
    }

    .section-title {
      font-size: 12px;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      color: var(--muted);
      font-weight: 600;
      margin-bottom: 12px;
    }

    .words-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
      gap: 10px;
      margin-bottom: 28px;
    }
    .learn-word-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 14px;
      transition: all 0.2s;
    }
    .learn-word-card:hover {
      border-color: var(--accent);
      transform: translateY(-1px);
      box-shadow: var(--shadow);
    }
    .learn-word-text {
      font-family: 'JetBrains Mono', monospace;
      font-size: 16px;
      font-weight: 600;
      color: var(--text);
      margin-bottom: 4px;
      letter-spacing: -0.01em;
    }
    .learn-word-pos {
      font-size: 11px;
      color: var(--muted);
      font-family: 'JetBrains Mono', monospace;
      margin-bottom: 6px;
    }
    .learn-word-meaning {
      font-size: 13px;
      color: var(--text);
      line-height: 1.4;
    }

    .phrases-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 20px;
      margin-bottom: 24px;
    }
    .learn-phrase {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      padding: 10px 0;
      border-bottom: 1px dashed var(--line);
      font-size: 14px;
      gap: 12px;
    }
    .learn-phrase:last-child { border-bottom: none; padding-bottom: 0; }
    .learn-phrase:first-child { padding-top: 0; }
    .phrase-text {
      font-family: 'JetBrains Mono', monospace;
      font-weight: 600;
      color: var(--accent);
    }
    .phrase-meaning { color: var(--muted); text-align: right; }

    .learn-actions {
      display: flex;
      gap: 10px;
      margin-top: 8px;
      padding-top: 24px;
      border-top: 1px solid var(--line);
    }

    /* ============ Import Screen ============ */
    .import-tabs {
      display: flex;
      gap: 4px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 4px;
      margin-bottom: 20px;
      width: fit-content;
    }
    .import-tab {
      background: transparent;
      border: none;
      padding: 8px 16px;
      border-radius: 7px;
      cursor: pointer;
      font-family: inherit;
      font-size: 13px;
      font-weight: 500;
      color: var(--muted);
      transition: all 0.15s;
    }
    .import-tab:hover { color: var(--text); }
    .import-tab.active {
      background: var(--surface);
      color: var(--text);
      box-shadow: var(--shadow);
    }

    .import-form {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 24px;
      margin-bottom: 24px;
    }
    .import-field {
      display: flex;
      flex-direction: column;
      gap: 6px;
      margin-bottom: 14px;
    }
    .import-field label {
      font-size: 12px;
      font-weight: 500;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }
    .import-field input,
    .import-field textarea {
      font-family: inherit;
      font-size: 15px;
      padding: 10px 12px;
      border: 1.5px solid var(--border);
      border-radius: 8px;
      background: var(--bg);
      color: var(--text);
      transition: border-color 0.15s;
    }
    .import-field input:focus,
    .import-field textarea:focus {
      outline: none;
      border-color: var(--accent);
    }
    .import-field textarea {
      font-family: 'JetBrains Mono', monospace;
      font-size: 13px;
      line-height: 1.5;
      resize: vertical;
      min-height: 120px;
    }
    .import-row {
      display: flex;
      gap: 12px;
    }
    .import-row .import-field { flex: 1; }
    .import-hint {
      font-size: 11px;
      font-weight: 400;
      color: var(--accent);
      text-transform: none;
      letter-spacing: 0;
      margin-left: 8px;
    }
    .import-hint code {
      background: var(--bg);
      padding: 1px 5px;
      border-radius: 4px;
      font-size: 11px;
    }

    .import-preview-table {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 12px 16px;
      margin-bottom: 16px;
      max-height: 400px;
      overflow-y: auto;
    }
    .import-preview-header,
    .import-preview-row {
      display: grid;
      grid-template-columns: 1.5fr 0.7fr 2fr 1.5fr 0.7fr 40px;
      gap: 8px;
      align-items: center;
      padding: 8px 0;
      border-bottom: 1px dashed var(--line);
      font-size: 13px;
    }
    .import-preview-header {
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--muted);
      font-weight: 600;
      border-bottom: 1px solid var(--border);
    }
    .import-preview-row:last-child { border-bottom: none; }
    .import-preview-row .word {
      font-family: 'JetBrains Mono', monospace;
      font-weight: 600;
      color: var(--text);
    }
    .import-preview-row .pos {
      font-family: 'JetBrains Mono', monospace;
      color: var(--muted);
      font-size: 11px;
    }
    .import-preview-row .meaning { color: var(--text); }
    .import-preview-row .family-input {
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      padding: 4px 6px;
      border: 1px solid transparent;
      border-radius: 4px;
      background: transparent;
      width: 100%;
      color: var(--text);
    }
    .import-preview-row .family-input:hover { border-color: var(--border); }
    .import-preview-row .family-input:focus {
      outline: none;
      border-color: var(--accent);
      background: var(--bg);
    }
    .import-preview-row .source {
      font-size: 10px;
      padding: 2px 6px;
      border-radius: 4px;
      font-weight: 600;
      text-align: center;
    }
    .import-preview-row .source.auto {
      background: var(--success-soft);
      color: var(--success);
    }
    .import-preview-row .source.manual {
      background: #fff7ed;
      color: #c2410c;
    }
    .import-preview-row .source.newfamily {
      background: var(--accent-soft);
      color: var(--accent);
    }
    .import-preview-row .remove-btn {
      background: transparent;
      border: none;
      color: var(--muted);
      cursor: pointer;
      padding: 4px;
      border-radius: 4px;
      font-size: 16px;
      line-height: 1;
    }
    .import-preview-row .remove-btn:hover {
      background: var(--error-soft);
      color: var(--error);
    }

    .import-summary {
      font-size: 13px;
      color: var(--muted);
      padding: 8px 0;
      margin-bottom: 8px;
    }
    .import-summary strong { color: var(--text); font-weight: 600; }

    .import-success-banner {
      display: flex;
      align-items: center;
      gap: 10px;
      background: var(--success-soft);
      color: var(--success);
      border: 1px solid #a7f3d0;
      border-radius: 12px;
      padding: 12px 16px;
      font-size: 14px;
      font-weight: 500;
      margin-bottom: 24px;
    }

    @media (max-width: 640px) {
      .import-preview-header,
      .import-preview-row {
        grid-template-columns: 1fr 0.7fr 1.5fr 40px;
        font-size: 12px;
      }
      .import-preview-header > :nth-child(2),
      .import-preview-header > :nth-child(5),
      .import-preview-row > :nth-child(2),
      .import-preview-row > :nth-child(5) {
        display: none;
      }
    }

    /* ============ Wrong Words Screen ============ */
    .empty-state {
      text-align: center;
      padding: 60px 20px;
      color: var(--muted);
    }
    .empty-icon {
      display: inline-flex;
      color: var(--border);
      margin-bottom: 16px;
    }
    .empty-title {
      font-size: 18px;
      font-weight: 600;
      color: var(--text);
      margin-bottom: 8px;
    }
    .empty-hint {
      font-size: 14px;
      color: var(--muted);
    }

    .wrong-stats-row {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 10px;
      margin-bottom: 24px;
    }
    .wrong-stat {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 16px 12px;
      text-align: center;
    }
    .wrong-stat-num {
      font-size: 24px;
      font-weight: 700;
      color: var(--accent);
      font-family: 'JetBrains Mono', monospace;
      letter-spacing: -0.02em;
      margin-bottom: 4px;
    }
    .wrong-stat-label {
      font-size: 11px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }

    .wrong-list {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 12px 20px;
      margin-bottom: 24px;
      max-height: 400px;
      overflow-y: auto;
    }
    .wrong-row {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 0;
      border-bottom: 1px dashed var(--line);
      font-size: 14px;
    }
    .wrong-row:last-child { border-bottom: none; }
    .wrong-row-rank {
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      color: var(--muted);
      min-width: 22px;
      text-align: right;
    }
    .wrong-row-word {
      font-family: 'JetBrains Mono', monospace;
      font-weight: 600;
      color: var(--text);
      min-width: 90px;
    }
    .wrong-row-meaning {
      flex: 1;
      color: var(--muted);
      font-size: 13px;
    }
    .wrong-row-stats {
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 11px;
      font-family: 'JetBrains Mono', monospace;
    }
    .wrong-row-wrong {
      color: var(--error);
      font-weight: 600;
    }
    .wrong-row-right {
      color: var(--success);
    }
    .wrong-row-rate {
      background: var(--error-soft);
      color: var(--error);
      padding: 2px 6px;
      border-radius: 4px;
      font-weight: 600;
      min-width: 36px;
      text-align: center;
    }
    .wrong-row-rate.low {
      background: var(--success-soft);
      color: var(--success);
    }
    .wrong-row-rate.mid {
      background: #fff7ed;
      color: #c2410c;
    }

    @media (max-width: 480px) {
      .wrong-stats-row { grid-template-columns: 1fr 1fr; }
      .wrong-stats-row .wrong-stat:nth-child(3) { grid-column: 1 / -1; }
      .wrong-row-meaning { display: none; }
    }

    /* ============ Speaker & IPA ============ */
    .speaker-btn {
      background: var(--surface);
      border: 1px solid var(--border);
      color: var(--muted);
      cursor: pointer;
      padding: 6px;
      border-radius: 8px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: all 0.15s;
      vertical-align: middle;
      flex-shrink: 0;
    }
    .speaker-btn:hover {
      background: var(--accent-soft);
      border-color: var(--accent);
      color: var(--accent);
    }
    .speaker-btn:active {
      transform: scale(0.94);
    }
    .speaker-btn.speaking {
      background: var(--accent);
      border-color: var(--accent);
      color: white;
      animation: pulse 0.9s ease-in-out infinite;
    }
    .speaker-btn svg { display: block; }
    .speaker-btn.sm { padding: 4px; border-radius: 6px; }
    .speaker-btn.sm svg { width: 12px; height: 12px; }

    @keyframes pulse {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.55; }
    }

    .ipa {
      font-family: 'JetBrains Mono', monospace;
      font-size: 14px;
      color: var(--muted);
      letter-spacing: 0.02em;
      margin-top: 6px;
    }
    .ipa-sm {
      font-size: 11px;
      color: var(--muted);
      font-family: 'JetBrains Mono', monospace;
      letter-spacing: 0.02em;
    }

    .prompt-row {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }
    .prompt-row .question-prompt { margin-bottom: 0; }

    .learn-word-row {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 6px;
    }
    .learn-word-row .learn-word-text { margin-bottom: 0; }
    .learn-word-ipa {
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      color: var(--muted);
      margin-top: 2px;
      letter-spacing: 0.02em;
    }

    .hidden { display: none !important; }

    @media (max-width: 480px) {
      .container { padding: 24px 16px 60px; }
      h1 { font-size: 26px; }
      .question-card { padding: 24px; }
      .question-prompt { font-size: 22px; }
      .mode-grid { grid-template-columns: 1fr; }
    }

/* ============================================================
   Mobile / Touch optimizations
   Added: 2026-07-16 — see project README for change rationale.
   ============================================================ */

/* Touch target base — all interactive elements should be ≥ 44px tall on touch */
button, .chip, .option-btn, .speaker-btn, .text-input, .learn-back-btn {
  -webkit-tap-highlight-color: rgba(99, 102, 241, 0.12);
  touch-action: manipulation;
}

/* Prevent iOS auto-zoom on input focus (font-size ≥ 16px) */
.text-input { font-size: 16px; }

/* Smooth scrolling on iOS */
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }

/* ============ Tablet / phone (≤ 768px) ============ */
@media (max-width: 768px) {
  .container {
    padding: 28px 18px 60px;
  }

  h1 {
    font-size: 28px;
  }

  /* Filter row: horizontal scroll if chips overflow (better than wrapping to many rows) */
  .filter-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    margin-left: -18px;
    margin-right: -18px;
    padding-left: 18px;
    padding-right: 18px;
    scrollbar-width: none;
  }
  .filter-row::-webkit-scrollbar { display: none; }
  .chip {
    flex-shrink: 0;
    padding: 9px 16px;
    min-height: 36px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* Mode grid: 2 columns on small tablets, 1 on phones */
  .mode-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Affix flow: scroll horizontally on narrow screens instead of cramming */
  .affix-flow {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px;
    gap: 4px;
    scrollbar-width: none;
  }
  .affix-flow::-webkit-scrollbar { display: none; }
  .affix-piece {
    flex-shrink: 0;
    min-width: 100px;
  }
  .affix-plus {
    flex-shrink: 0;
  }

  /* Learn family grid: 2 columns on small tablets */
  .learn-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
  }

  /* Question card: slightly tighter */
  .question-card {
    padding: 24px 20px;
  }
  .question-prompt {
    font-size: 24px;
    word-break: break-word;
  }

  /* Option buttons: bigger touch target, more padding */
  .option-btn {
    padding: 16px 18px;
    min-height: 56px;
    font-size: 15px;
  }

  /* Text input: bigger on touch */
  .text-input {
    padding: 16px 18px;
    min-height: 52px;
    font-size: 16px;
  }

  /* Action buttons row: full-width stacked on small screens */
  .actions {
    flex-direction: column;
    gap: 10px;
  }
  .actions button {
    width: 100%;
  }

  button.primary, button.secondary {
    padding: 14px 20px;
    min-height: 48px;
    font-size: 15px;
  }

  /* Wrong words list: card-style on tablet (was already list, but tighten) */
  .wrong-list {
    gap: 10px;
  }

  /* Quiz meta row: stack on small screens */
  .quiz-meta {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .quiz-meta .quit-btn {
    width: 100%;
  }
}

/* ============ Phone (≤ 480px) ============ */
@media (max-width: 480px) {
  .container {
    padding: 20px 14px 50px;
  }

  h1 {
    font-size: 24px;
    letter-spacing: -0.01em;
  }
  .subtitle {
    font-size: 13px;
  }

  /* Mode grid: 1 column on phones */
  .mode-grid {
    grid-template-columns: 1fr;
  }

  /* Question card */
  .question-card {
    padding: 20px 16px;
  }
  .question-prompt {
    font-size: 22px;
  }
  .q-hint {
    font-size: 12px;
  }

  /* Affix pieces: smaller on phones */
  .affix-piece {
    min-width: 88px;
    padding: 10px 12px;
  }
  .affix-piece-form {
    font-size: 14px;
  }
  .affix-piece-meaning {
    font-size: 11px;
  }

  /* Learn grid: 1 column on phones */
  .learn-grid {
    grid-template-columns: 1fr;
  }

  /* Learn family card: tighter */
  .family-card {
    padding: 16px;
  }
  .family-card-name {
    font-size: 16px;
  }

  /* Wrong stats: 2 columns + full-width last */
  .wrong-stats-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .wrong-stats-row .wrong-stat:nth-child(3) {
    grid-column: 1 / -1;
  }
  .wrong-row-meaning {
    display: none;
  }

  /* Learn screen title */
  #learn-screen h2 {
    font-size: 24px;
  }

  /* Phrase items: stack */
  .learn-phrase {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .phrase-meaning {
    margin-left: 0;
  }

  /* Hide "FAMILIES" count label on small screens to save space */
  .filter-label {
    font-size: 11px;
  }

  /* Stat blocks (mode screen): stack vertically */
  .mode-stats {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
}

/* ============ iOS-specific tweaks ============ */
@supports (-webkit-touch-callout: none) {
  /* iOS only: prevent input zoom on focus by ensuring 16px+ */
  .text-input, .option-btn { font-size: 16px; }

  /* iOS Safari sometimes renders sticky/fixed oddly — defensive */
  body { min-height: -webkit-fill-available; }
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ Print (future-proof, doesn't affect screen) ============ */
@media print {
  .no-print, .actions, .filter-row { display: none !important; }
  body { background: white; color: black; }
}

/* ============ A4: Listening prompt ============ */
.listening-prompt {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
  font-size: 20px;
  animation: pulse-soft 1.6s ease-in-out infinite;
}

@keyframes pulse-soft {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* ============ A2/A3: Explanation block in feedback ============ */
.explain-examples {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.explain-example {
  font-size: 14px;
  line-height: 1.5;
}
.ex-en {
  color: var(--text);
  font-weight: 500;
}
.ex-zh {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.explain-family {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 12px 14px;
  border-top: 1px solid rgba(99, 102, 241, 0.2);
}
.explain-family-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 8px;
}
.explain-affix {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}
.mini-affix {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  background: var(--surface);
  border: 1px solid var(--border);
}
.mini-affix.root {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.mini-affix.prefix {
  background: #f0f9ff;
  border-color: #bae6fd;
  color: #0369a1;
}
.mini-affix.suffix {
  background: #fef3c7;
  border-color: #fde68a;
  color: #92400e;
}
.mini-affix-plus {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.explain-family-story {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  opacity: 0.85;
}

/* ============ S1: Spaced repetition progress strip ============ */
.sr-progress {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.sr-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.sr-num {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.1;
}
.sr-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sr-stat-accent { margin-left: auto; }
.sr-go-btn {
  font-size: 13px;
  padding: 8px 14px;
  min-height: 36px;
}

/* Highlight when there are due words */
.sr-progress.has-due {
  background: linear-gradient(135deg, var(--accent-soft) 0%, var(--surface) 100%);
  border-color: var(--accent);
}
.sr-progress.has-due .sr-stat:first-child .sr-num {
  color: var(--accent);
  animation: pulse-soft 1.6s ease-in-out infinite;
}

/* ============ PWA: install button ============ */
.pwa-install-row {
  display: flex;
  justify-content: flex-end;
  margin-top: -16px;
  margin-bottom: 16px;
}
.pwa-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 32px;
}
.pwa-install-btn:hover {
  background: var(--accent);
  color: white;
}
.pwa-install-btn svg { display: block; }

/* ============ PWA: update toast ============ */
.pwa-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: white;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
}
.pwa-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.pwa-toast button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.pwa-toast button:hover {
  background: #4f46e5;
}

/* ============ PWA: offline banner ============ */
.pwa-offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #f59e0b;
  color: white;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  z-index: 9998;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.pwa-offline-banner.show {
  display: flex;
}
.pwa-offline-dot {
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  animation: pulse-soft 1.4s ease-in-out infinite;
}

/* Safe area for iOS notch (when status bar is overlaying) */
@supports (padding: max(0px)) {
  .pwa-offline-banner {
    padding-top: max(8px, env(safe-area-inset-top));
  }
}

/* ============ Family filter: learned / unlearned / count / "新" tag ============ */
.filter-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.filter-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}
.filter-link {
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}
.filter-link:hover {
  background: var(--accent-soft);
}
.filter-link:active {
  transform: scale(0.95);
}
.filter-divider {
  color: var(--border);
  user-select: none;
}

.chip-count {
  display: inline-block;
  margin-left: 4px;
  font-size: 11px;
  color: inherit;
  opacity: 0.7;
  font-family: 'JetBrains Mono', monospace;
}
.chip-new {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  font-size: 10px;
  background: var(--bg);
  color: var(--muted);
  border-radius: 4px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-family: 'JetBrains Mono', monospace;
}
.chip.learned {
  /* Visually emphasize "learned" families (subtly, when active) */
  border-color: rgba(99, 102, 241, 0.3);
}
.chip.unlearned {
  /* Mute unlearned families so the eye is drawn to active/learned ones */
  opacity: 0.7;
}
.chip.unlearned.active {
  /* But if user manually enabled an unlearned family, show that intent */
  opacity: 1;
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.chip.unlearned.active .chip-new {
  background: white;
  color: var(--accent);
}

/* ============ Keyboard shortcuts: visual hints ============ */
.option-btn {
  /* Allow flex layout for key + text */
  display: flex !important;
  align-items: center;
  gap: 12px;
}
.option-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
  transition: all 0.15s;
}
.option-btn:hover .option-key,
.option-btn:focus-visible .option-key {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.option-btn.correct .option-key {
  background: var(--success);
  border-color: var(--success);
  color: white;
}
.option-btn.wrong .option-key {
  background: var(--error);
  border-color: var(--error);
  color: white;
}
.option-text {
  flex: 1;
  text-align: left;
}

/* kbd hint chip (inline in button labels) */
.kbd-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 18px;
  padding: 0 5px;
  margin-left: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  color: inherit;
  vertical-align: middle;
  line-height: 1;
}
button.primary .kbd-hint,
button.secondary .kbd-hint,
button.ghost .kbd-hint {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
  color: inherit;
}
button.ghost .kbd-hint {
  background: var(--bg);
  border-color: var(--border);
  color: var(--muted);
}

/* On mobile, hide kbd hints (no keyboard anyway) */
@media (hover: none) and (pointer: coarse) {
  .kbd-hint { display: none; }
  .option-key { display: none; }
}
