/* More Life Chinese — surfaces follow the hub shell (--dx-*) */

:root {
  /* Status colours. AA on --dx-card-solid in light. */
  --vermillion: #9a4e12;
  --vermillion-bright: #7c3e0e;
  --vermillion-soft: rgba(154, 78, 18, 0.14);
  --vermillion-line: rgba(154, 78, 18, 0.45);
  --teal: #0f7a4a;
  --teal-bright: #0b5f39;
  --teal-dim: #0b5f39;
  --teal-soft: #e5f6ee;
  --teal-line: rgba(15, 122, 74, 0.45);
  --danger: #b91c1c;
}

html.dark {
  --vermillion: #ffc58a;
  --vermillion-bright: #ffd7ad;
  --vermillion-soft: rgba(255, 197, 138, 0.18);
  --vermillion-line: rgba(255, 197, 138, 0.5);
  --teal: #7dE8b0;
  --teal-bright: #b6f5d2;
  --teal-dim: #5dcca0;
  --teal-soft: rgba(125, 232, 176, 0.16);
  --teal-line: rgba(125, 232, 176, 0.45);
  --danger: #ffb4b0;
}

:root,
html.dark {
  --ink: transparent;
  --ink-elevated: var(--dx-card, hsl(0 0% 100% / 0.94));
  --ink-soft: var(--dx-card-solid, #ffffff);
  --ink-line: var(--dx-border, hsl(44 14% 80%));
  --ink-line-soft: var(--dx-border, hsl(44 14% 80%));
  --ink-wash: var(--dx-card, hsl(0 0% 100% / 0.94));

  --paper: var(--dx-text, var(--dx-text, #0d0b08));
  --paper-muted: var(--dx-muted, #5c574f);
  --paper-faint: var(--dx-muted, #5c574f);

  --peach: var(--dx-accent, var(--dx-accent, #1d4ed8));
  --peach-soft: var(--dx-accent-soft, hsl(224 76% 48% / 0.12));
  --accent: var(--dx-accent, var(--dx-accent, #1d4ed8));
  --accent-soft: var(--dx-accent-soft, hsl(224 76% 48% / 0.12));

  /* Semantic */
  --known: var(--teal);
  --learning: var(--vermillion);

  /* Radius */
  --radius-xs: 8px;
  --radius-sm: var(--dx-radius-sm, 10px);
  --radius: var(--dx-radius, 16px);
  --radius-lg: calc(var(--dx-radius, 16px) + 2px);
  --radius-pill: 999px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  /* Type scale */
  --text-xs: 0.6875rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-hanzi-list: clamp(1.35rem, 2.8vw, 1.7rem);
  --text-hanzi-detail: clamp(2.6rem, 9vw, 3.25rem);

  /* Elevation — hub card shadow */
  --shadow-sm: var(--dx-shadow, 0 8px 24px hsl(0 0% 0% / 0.08));
  --shadow: var(--dx-shadow, 0 8px 24px hsl(0 0% 0% / 0.08));
  --dash-shadow: var(--dx-shadow, 0 8px 24px hsl(0 0% 0% / 0.08));
  --focus-ring: 0 0 0 3px var(--dx-accent-soft, hsl(224 76% 48% / 0.12));

  /* Layout */
  --tap: 44px;
  --tab-h: 44px;
  --rail-w: 0px;
  --page-pad: clamp(12px, 2vw, 28px);
  --shell-max: 100%;
  --font-ui: var(--dx-font, var(--font-sans));
  --font-zh: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --chrome-top: env(safe-area-inset-top, 0px);
  --chrome-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: transparent;
  color: var(--paper);
  font-family: var(--dx-font, var(--font-ui));
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

html {
  background-color: var(--dx-bg, transparent);
}

body {
  background: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 100;
  transform: translateY(-160%);
  border-radius: 8px;
  background: var(--dx-card-solid, #fff);
  color: var(--paper);
  padding: 0.65rem 0.85rem;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

#topbar {
  flex-shrink: 0;
}

#sync-label {
  flex: 0 1 auto;
  width: auto;
  max-width: 5.5rem;
  height: 1.2em;
  text-align: right;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--dx-muted, var(--paper-muted));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#connect {
  flex-shrink: 0;
  padding: 0.55rem 0.85rem 0.15rem;
}

#connect[hidden] {
  display: none !important;
}

#btn-connect {
  width: 100%;
  min-height: 44px;
  border-radius: var(--dx-radius-sm, 10px);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

#topbar .dong-theme-toggle {
  position: static;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

#topbar .dong-theme-toggle__track {
  width: 44px;
  height: 28px;
  border: 1px solid var(--dx-border, var(--ink-line));
  border-radius: 999px;
  background: var(--dx-card, transparent);
  box-shadow: none;
}

.app {
  /* Fixed viewport height so Library list can flex-scroll without max-height hacks */
  height: 100dvh;
  height: 100svh;
  max-height: 100dvh;
  max-height: 100svh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--shell-max);
  margin: 0 auto;
  overflow: hidden;
  background: transparent;
}

.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.app-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding-bottom: var(--chrome-bottom);
  overflow: hidden;
}

/* Main */
.main {
  flex: 1;
  padding: 14px var(--page-pad) 20px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view[hidden] {
  display: none !important;
}

.view-library:not([hidden]) {
  display: flex;
}

.view-study:not([hidden]) {
  display: flex;
}

.view-progress:not([hidden]) {
  display: block !important;
  visibility: visible;
  opacity: 1;
}

.view-library {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
  animation: rise-in 0.35s var(--ease-out) both;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ink-reveal {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes tab-indicator-in {
  from {
    opacity: 0;
    transform: scaleX(0.4);
  }
  to {
    opacity: 1;
    transform: scaleX(1);
  }
}

@keyframes face-settle {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Toolbar — outside the list scrollport (sticky as belt-and-suspenders) */
.library-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 2;
  padding-bottom: 2px;
  background: transparent;
}

/* Library hero — Insights learning-hero language */
.library-masthead {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 1.2rem;
  margin-bottom: 0.25rem;
  border: 1px solid var(--ink-line);
  border-radius: calc(var(--radius) + 4px);
  background:
    radial-gradient(circle at 92% 5%, var(--peach-soft), transparent 36%),
    var(--ink-elevated);
  box-shadow: var(--shadow);
  animation: ink-reveal 0.55s var(--ease-out) both;
}

.library-eyebrow,
.eyebrow {
  display: block;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--paper-faint);
  line-height: 1.2;
}

.library-title {
  margin: 0.35rem 0 0.5rem;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 12px;
  line-height: 1.15;
  letter-spacing: -0.025em;
}

.library-title-zh {
  font-family: var(--font-zh);
  font-size: clamp(1.25rem, 4.5vw, 1.75rem);
  font-weight: 600;
  color: var(--paper);
  letter-spacing: 0.08em;
}

.library-title-en {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.search-field {
  position: relative;
  display: block;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--paper-muted);
  pointer-events: none;
  display: flex;
  transition: color 0.2s var(--ease-out);
}

.search-field:focus-within .search-icon {
  color: var(--accent);
}

.search-field input,
.select-field select {
  width: 100%;
  min-height: var(--tap);
  padding: 0.7rem 1rem;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius-sm);
  background: var(--ink-soft);
  color: var(--paper);
  font: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s var(--ease-out), box-shadow 0.22s var(--ease-out), background 0.2s;
}

.search-field input {
  padding-left: 2.5rem;
  border-radius: 999px;
}

.search-field input::placeholder {
  color: var(--paper-faint);
}

.search-field input:focus,
.select-field select:focus {
  border-color: var(--peach);
  box-shadow: var(--focus-ring);
  background: var(--ink-elevated);
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-filters {
  display: flex;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.chip,
.filter-chip {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--ink-line);
  background: var(--ink-soft);
  color: var(--paper-muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 650;
  cursor: pointer;
  transition:
    background 0.18s var(--ease-out),
    border-color 0.18s var(--ease-out),
    color 0.18s var(--ease-out),
    transform 0.14s var(--ease-out),
    box-shadow 0.18s var(--ease-out);
}

.chip:hover {
  border-color: color-mix(in srgb, var(--peach) 50%, var(--ink-line));
  color: var(--paper);
}

.chip:active {
  transform: scale(0.96);
}

.chip:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.chip-status {
  flex: 1;
  padding: 0.45rem 0.5rem;
  text-align: center;
}

.chip.is-active,
.filter-chip.active,
.filter-chip.is-active {
  border-color: var(--dx-accent, var(--accent));
  background: var(--dx-accent, var(--accent));
  color: var(--dx-accent-fg, #fff);
}

.btn-filters {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--ink-line);
  background: var(--ink-soft);
  color: var(--paper-muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 650;
  cursor: pointer;
  transition:
    background 0.18s var(--ease-out),
    border-color 0.18s var(--ease-out),
    color 0.18s var(--ease-out);
}

.btn-filters:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn-filters[aria-expanded="true"],
.btn-filters.is-open {
  border-color: var(--teal-dim);
  color: var(--teal-bright);
  background: var(--teal-soft);
}

.filters-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform 0.2s var(--ease-out);
}

.btn-filters[aria-expanded="true"] .filters-caret {
  transform: rotate(180deg);
}

.filters-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--ink-line);
  background: var(--ink-wash);
  animation: rise-in 0.25s var(--ease-out) both;
}

.filters-panel[hidden] {
  display: none !important;
}

.keyword-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keyword-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip-keyword {
  min-height: 44px;
  padding: 0.4rem 0.65rem;
  font-size: 0.72rem;
  background: var(--ink-soft);
}

.chip-keyword.is-active {
  background: var(--dx-accent, var(--accent));
  border-color: var(--dx-accent, var(--accent));
  color: var(--dx-accent-fg, #fff);
}

.stats-line {
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--paper-faint);
  border-top: none;
}

/* Card list — raised Insights cards */
.card-list {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0 12px;
  mask-image: linear-gradient(180deg, #000 92%, transparent);
}

.list-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  width: 100%;
  flex: 0 0 auto;
  align-self: start;
  margin-bottom: 0.55rem;
  min-height: var(--tap);
  height: auto;
  padding: 0.85rem 0.75rem 0.9rem 1rem;
  border: 1px solid var(--ink-line);
  border-radius: 14px;
  background: var(--ink-elevated);
  color: inherit;
  font: inherit;
  text-align: left;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.14s linear;
  content-visibility: auto;
  contain-intrinsic-size: auto 120px;
}

.list-row.is-status-changed {
  animation: list-row-ack 0.38s ease;
}

@keyframes list-row-ack {
  0% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach) 70%, transparent); }
  100% { box-shadow: var(--shadow); }
}

.list-open {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.list-row:last-child {
  border-bottom: 1px solid var(--ink-line);
}

.list-open:active {
  background: var(--accent-soft);
}

.list-open:focus-visible,
.list-status:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--peach) 80%, var(--paper));
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .list-row:hover {
    border-color: color-mix(in srgb, var(--peach) 60%, var(--ink-line));
    box-shadow: var(--shadow);
    background: var(--ink-elevated);
  }
}

.list-hanzi {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  z-index: 1;
  pointer-events: none;
  min-width: 0;
  font-family: var(--font-zh);
  font-size: var(--text-hanzi-list);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--paper);
}

.list-audio-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
  flex-shrink: 0;
}

.list-pinyin {
  grid-column: 1 / -1;
  grid-row: 2;
  position: relative;
  z-index: 1;
  pointer-events: none;
  min-width: 0;
  font-family: "Noto Sans", var(--font-ui);
  font-size: var(--text-sm);
  line-height: 1.65;
  padding-block: 0.14em;
  color: var(--teal-bright);
  font-weight: 500;
  letter-spacing: 0.01em;
  overflow: visible;
}

.list-gloss {
  grid-column: 1 / -1;
  grid-row: 3;
  position: relative;
  z-index: 1;
  pointer-events: none;
  min-width: 0;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--paper-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: end;
  align-self: start;
  margin-top: 2px;
  min-height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.list-status {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  z-index: 2;
  top: auto;
  right: auto;
  justify-self: end;
  align-self: center;
  min-height: var(--tap);
  min-width: 6.5rem;
  margin-top: 0;
  padding: 0 14px;
  cursor: pointer;
  touch-action: manipulation;
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.list-status:active {
  transform: scale(0.94);
  filter: brightness(1.12);
}

.list-status.is-flash {
  animation: list-pill-pop 0.28s ease;
}

@keyframes list-pill-pop {
  0% { transform: scale(0.9); }
  55% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.badge-learning {
  background: var(--vermillion-soft);
  border-color: rgba(224, 106, 46, 0.28);
  color: var(--vermillion);
}

.badge-known {
  background: var(--teal-soft);
  border-color: rgba(47, 181, 165, 0.28);
  color: var(--teal);
}

.list-empty,
.list-error {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 56px 20px;
  text-align: center;
  color: var(--paper-muted);
}

.list-empty-title {
  font-family: var(--font-zh);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--paper);
  letter-spacing: 0.06em;
}

.list-empty-hint {
  font-size: 0.9rem;
  max-width: 22em;
  line-height: 1.45;
}

/* Detail sheet */
.card-detail {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.card-detail[hidden] {
  display: none !important;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  animation: fade-in 0.2s ease both;
}

.detail-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  max-width: 560px;
  max-height: min(90dvh, 760px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 20px calc(28px + env(safe-area-inset-bottom, 0px));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background:
    linear-gradient(180deg, var(--ink-soft) 0%, var(--ink-elevated) 32%);
  border: 1px solid var(--ink-line);
  border-bottom: none;
  box-shadow: var(--shadow);
  animation: sheet-up 0.32s var(--ease-out);
}

@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.detail-handle {
  width: 40px;
  height: 4px;
  margin: 4px auto 16px;
  border-radius: 999px;
  background: var(--ink-line);
}

.detail-close {
  position: absolute;
  top: 14px;
  right: 12px;
  width: var(--tap);
  height: var(--tap);
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--paper-muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

.detail-close:hover {
  color: var(--paper);
  background: rgba(255, 255, 255, 0.06);
}

.detail-hanzi {
  margin: 0 40px 6px 0;
  font-family: var(--font-zh);
  font-size: var(--text-hanzi-detail);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0.04em;
  color: var(--paper);
}

.detail-pinyin {
  margin: 0 0 10px;
  font-family: "Noto Sans", var(--font-ui);
  font-size: var(--text-lg);
  line-height: 1.55;
  padding-block: 0.06em;
  color: var(--teal-bright);
  font-weight: 500;
  letter-spacing: 0.02em;
  overflow: visible;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.btn-audio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(47, 181, 165, 0.45);
  background: var(--teal-soft);
  color: var(--teal-bright);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.btn-audio:hover,
.btn-audio:focus-visible {
  border-color: var(--teal);
  background: rgba(47, 181, 165, 0.28);
  outline: none;
}

.btn-audio:active {
  transform: scale(0.97);
}

.btn-audio-card {
  margin-top: 4px;
}

.detail-status-actions {
  margin: 12px 0 4px;
}

.btn-mark-known {
  margin-top: 12px;
  width: auto;
  min-width: 160px;
  align-self: center;
}

.detail-pos {
  font-size: 0.85rem;
  color: var(--paper-muted);
}

.detail-gloss {
  margin: 0 0 8px;
  font-size: 1.12rem;
  font-weight: 500;
  line-height: 1.4;
}

.detail-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--ink-line);
}

.detail-section h3 {
  margin: 0 0 10px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

.detail-example {
  font-family: var(--font-zh);
  font-size: 1.15rem;
  margin: 0 0 6px;
  line-height: 1.45;
}

.detail-example-pinyin,
.detail-example-en {
  margin: 0 0 4px;
  font-size: 0.9rem;
  color: var(--paper-muted);
}

.detail-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-details {
  font-size: 0.9rem;
  color: var(--paper-muted);
  max-height: 220px;
  overflow-y: auto;
  line-height: 1.55;
}


.detail-hanzi-glyphs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.char-glyph {
  appearance: none;
  margin: 0;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-family: var(--font-zh);
  font-size: inherit;
  font-weight: 700;
  line-height: 1.1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.char-glyph:hover,
.char-glyph:focus-visible {
  border-color: rgba(47, 181, 165, 0.45);
  background: var(--teal-soft);
  outline: none;
}

.char-glyph.is-active {
  border-color: var(--teal);
  background: rgba(47, 181, 165, 0.22);
  color: var(--paper);
}

.char-glyph:active {
  transform: scale(0.96);
}

.char-glyph-sep {
  opacity: 0.7;
}

.detail-origin-empty {
  margin: 0;
  color: var(--paper-muted);
  font-size: 0.95rem;
}

.origin-head {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}

.origin-char {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--ink-line);
  background: rgba(255, 255, 255, 0.03);
  font-family: var(--font-zh);
  font-size: 2rem;
  font-weight: 700;
}

.origin-head-text {
  min-width: 0;
}

.detail-example-pinyin,
.origin-pinyin,
.flashcard-origin-meta,
.flashcard-origin-formula {
  font-family: "Noto Sans", var(--font-ui);
}

.origin-pinyin {
  margin: 0 0 4px;
  color: var(--teal);
  font-weight: 600;
}

.origin-meaning {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.35;
}

.origin-type-wrap {
  margin: 6px 0 0;
}

.origin-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(47, 181, 165, 0.35);
  background: rgba(47, 181, 165, 0.12);
  color: var(--teal-bright);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.origin-formula {
  margin: 0 0 10px;
  font-family: var(--font-zh);
  font-size: 1.05rem;
  color: var(--paper);
}

.origin-parts {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.origin-parts li {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
  align-items: baseline;
  font-size: 0.9rem;
}

.origin-part-char {
  font-family: var(--font-zh);
  font-size: 1.15rem;
  font-weight: 700;
}

.origin-part-role {
  color: var(--teal);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.origin-part-note {
  color: var(--paper-muted);
}

.origin-block {
  margin-top: 12px;
}

.origin-block h4 {
  margin: 0 0 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

.origin-block p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--paper-muted);
}

/* Dashboard language (Wiki Insights) — Study + Progress only */
.eyebrow {
  display: block;
  color: var(--paper-muted);
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.learning-hero,
.level-card {
  border: 1px solid var(--ink-line);
  border-radius: calc(var(--radius) + 4px);
  background:
    radial-gradient(circle at 92% 5%, var(--vermillion-soft), transparent 36%),
    var(--ink-elevated);
  box-shadow: var(--dash-shadow);
}

.learning-hero {
  padding: 1.2rem;
  margin-bottom: 0.75rem;
}

.hero-topline,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.hero-xp {
  color: var(--vermillion);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 800;
}

.learning-hero h2,
.learning-hero .study-title,
.section-heading h2,
.level-card h2 {
  margin: 0;
  color: var(--paper);
  letter-spacing: -0.025em;
}

.learning-hero h2,
.learning-hero .study-title {
  margin: 0.35rem 0 0.45rem;
  font-size: clamp(1.25rem, 4.5vw, 1.75rem);
}

.learning-hero .study-lead {
  margin: 0;
  font-size: 0.92rem;
  color: var(--paper-muted);
  line-height: 1.45;
}

.progress-track,
.study-progress-bar {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink-line) 75%, var(--ink-soft));
}

.progress-fill,
.study-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--vermillion), var(--teal));
  transform-origin: left center;
  animation: progress-draw 0.45s var(--ease-out) both;
}

@keyframes progress-draw {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

.status-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-top: 1rem;
}

.status-stats > * {
  min-width: 0;
  min-height: 62px;
  border: 1px solid var(--dx-border, var(--ink-line));
  border-radius: 12px;
  background: var(--dx-card-solid, var(--ink-soft));
  color: var(--paper);
  font: inherit;
  font-family: var(--font-ui);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.25rem;
}

.status-stats strong {
  display: block;
  font-size: 1.2rem;
  line-height: 1.1;
}

.status-stats span {
  display: block;
  margin-top: 0.25rem;
  color: var(--paper-muted);
  font-size: 0.68rem;
  font-weight: 600;
}

.primary-action,
#study-start {
  display: flex;
  width: 100%;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 0.9rem 1rem;
  border: 0;
  border-radius: var(--dx-radius, var(--radius));
  background: var(--dx-accent, var(--accent));
  box-shadow: var(--dx-shadow, none);
  color: var(--dx-accent-fg, #fff);
  font: inherit;
  font-family: var(--dx-font, var(--font-ui));
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

#study-start.btn-primary {
  background: var(--dx-accent, var(--accent));
  color: var(--dx-accent-fg, #fff);
  box-shadow: var(--dx-shadow, none);
}

.primary-action:hover,
#study-start:hover {
  filter: brightness(1.04);
}

.primary-action small,
#study-start small {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.72rem;
  font-weight: 650;
  opacity: 0.85;
}

.primary-action strong,
#study-start strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.95rem;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.primary-arrow {
  flex-shrink: 0;
  font-size: 1.4rem;
}

.section-heading {
  margin: 0 0 0.7rem;
}

.section-heading h2 {
  margin-top: 0.15rem;
  font-size: 1.08rem;
}

.level-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.level-orb {
  display: grid;
  width: 58px;
  height: 58px;
  flex-shrink: 0;
  place-items: center;
  border: 5px solid var(--vermillion);
  border-radius: 50%;
  background: var(--ink-elevated);
  color: var(--vermillion);
  font-family: var(--font-ui);
  font-size: 1.05rem;
  font-weight: 850;
}

.level-main {
  min-width: 0;
  flex: 1;
}

.level-main h2 {
  margin-top: 0.1rem;
  font-size: 1.1rem;
}

.level-main p {
  margin: 0.2rem 0 0.55rem;
  color: var(--paper-muted);
  font-size: 0.7rem;
}

.level-card > strong {
  align-self: flex-start;
  color: var(--vermillion);
  font-size: 0.75rem;
  white-space: nowrap;
}

.progress-root > .status-stats {
  margin-top: 0;
  margin-bottom: 1.25rem;
}

/* Study */
.view-study {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: rise-in 0.35s var(--ease-out) both;
}

.study-idle {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.study-idle[hidden] {
  display: none !important;
}

.study-hero:not(.learning-hero) {
  display: grid;
  place-items: center;
  height: 120px;
  margin: 4px 0 4px;
  border-radius: calc(var(--radius) + 4px);
  background:
    radial-gradient(circle at 92% 5%, var(--vermillion-soft), transparent 36%),
    var(--ink-elevated);
  border: 1px solid var(--ink-line);
  box-shadow: var(--dash-shadow);
  overflow: hidden;
}

.study-hero.learning-hero {
  display: block;
  height: auto;
  text-align: left;
  overflow: visible;
}

.study-hero-glyph {
  font-family: var(--font-zh);
  font-size: 3.6rem;
  font-weight: 700;
  color: var(--paper);
  text-shadow: 0 8px 28px var(--vermillion-soft);
  animation: float-glyph 4s ease-in-out infinite;
}

.study-hero.learning-hero .study-hero-glyph {
  display: block;
  margin: 0.2rem 0 0.1rem;
  font-size: 2.4rem;
  text-align: center;
  animation: none;
}

@keyframes float-glyph {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.study-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.study-lead {
  margin: -6px 0 0;
  font-size: 0.92rem;
  color: var(--paper-muted);
  line-height: 1.45;
}

.study-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.practice-goal {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.15rem;
  margin-top: 0.85rem;
}

.goal-ring {
  position: relative;
  width: 148px;
  height: 148px;
  margin-bottom: 0.35rem;
}

.goal-ring svg {
  display: block;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.goal-ring-track,
.goal-ring-value {
  fill: none;
  stroke-width: 8;
}

.goal-ring-track {
  stroke: var(--ink-line);
}

.goal-ring-value {
  stroke: var(--vermillion);
  stroke-linecap: round;
  stroke-dasharray: 289.027;
  stroke-dashoffset: 289.027;
  transition: stroke-dashoffset 0.45s var(--ease-out);
}

.goal-ring.is-complete .goal-ring-value {
  stroke: var(--teal);
}

.goal-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
}

.goal-ring-label strong {
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 1.7rem;
  font-weight: 750;
  letter-spacing: -0.04em;
  line-height: 1;
}

.goal-ring-label span {
  color: var(--paper-muted);
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.practice-streak {
  margin: 0.35rem 0 0;
  color: var(--vermillion);
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 750;
}

.practice-goal .study-lead {
  margin-top: 0.2rem;
}

.practice-session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
}

.practice-session-row .study-progress {
  text-align: left;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--paper);
}

.practice-combo {
  flex: 0 0 auto;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--vermillion-soft);
  color: var(--vermillion);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.practice-combo[hidden],
#study-start[hidden],
#study-empty[hidden],
#practice-done[hidden],
.practice-celebrate[hidden] {
  display: none !important;
}

.practice-celebrate {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(var(--chrome-bottom) + 14px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  min-width: 168px;
  padding: 0.85rem 1.15rem 0.95rem;
  border: 1px solid var(--ink-line);
  border-radius: calc(var(--radius) + 4px);
  background:
    radial-gradient(circle at 50% 0%, var(--vermillion-soft), transparent 70%),
    var(--ink-elevated);
  box-shadow: var(--dash-shadow);
  color: var(--paper);
  text-align: center;
  pointer-events: none;
  transform: translateX(-50%);
}

.practice-celebrate strong {
  font-family: var(--font-ui);
  font-size: 1.45rem;
  letter-spacing: -0.04em;
}

.practice-celebrate span {
  color: var(--paper-muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.practice-celebrate.is-on {
  animation: practice-pop 2.6s var(--ease-out) both;
}

@keyframes practice-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(10px) scale(0.96);
  }
  12% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  78% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(6px) scale(0.98);
  }
}

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s, filter 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--dx-accent, var(--accent));
  color: var(--dx-accent-fg, #fff);
  box-shadow: var(--dx-shadow, none);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--dx-card, transparent);
  border-color: var(--dx-border, var(--ink-line));
  color: var(--dx-text, var(--paper));
}

.btn-secondary:hover {
  border-color: var(--teal-dim);
  color: var(--teal-bright);
}

.study-empty {
  margin: 0;
  padding: 20px 16px;
  text-align: center;
  color: var(--paper-muted);
  border: 1px dashed var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-soft);
}

.study-session {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.study-session[hidden] {
  display: none !important;
}

.study-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.study-progress-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--ink-line);
  overflow: hidden;
}

.study-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--vermillion), var(--teal));
  transition: width 0.28s var(--ease-out);
}

.study-progress {
  margin: 0;
  font-size: 0.85rem;
  color: var(--paper-muted);
  text-align: center;
}

.flashcard {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: clamp(220px, 42dvh, 380px);
  padding: clamp(22px, 3vw, 40px);
  border: 1px solid var(--dx-border, var(--ink-line));
  border-radius: var(--dx-radius, 16px);
  background: var(--dx-card, var(--ink-elevated));
  color: var(--dx-text, var(--paper));
  font: inherit;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--dx-shadow, none);
  transition:
    border-color 0.28s var(--ease-out),
    box-shadow 0.28s var(--ease-out),
    transform 0.28s var(--ease-out),
    background 0.28s var(--ease-out);
  user-select: none;
}

.flashcard .btn-audio {
  position: relative;
  z-index: 2;
  pointer-events: auto;
  margin: 10px auto 0;
}

.flashcard:hover,
.flashcard:focus-visible {
  border-color: rgba(47, 181, 165, 0.55);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35), 0 0 0 3px var(--teal-soft);
  outline: none;
  transform: translateY(-2px);
}

.flashcard:active {
  transform: translateY(0) scale(0.995);
}

.flashcard.is-flipped {
  border-color: var(--dx-accent, var(--accent));
  background: var(--dx-card, var(--ink-elevated));
  box-shadow: var(--dx-shadow, none);
}

.flashcard-face {
  width: 100%;
}

.flashcard-front {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: clamp(180px, 34dvh, 300px);
  gap: 14px;
}

.flashcard-hanzi {
  font-family: var(--font-zh);
  font-size: clamp(2.6rem, 8vw, 4.4rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.04em;
}

.flashcard-hint {
  font-size: 0.82rem;
  color: var(--paper-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.flashcard-back {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: clamp(180px, 34dvh, 300px);
  justify-content: center;
  animation: face-settle 0.32s var(--ease-out) both;
}

.flashcard.is-flipped .flashcard-hanzi {
  letter-spacing: 0.06em;
}

.flashcard-back[hidden] {
  display: none !important;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.flashcard-pinyin {
  font-family: "Noto Sans", var(--font-ui);
  font-size: 1.2rem;
  line-height: 1.6;
  padding-block: 0.12em;
  color: var(--teal);
  font-weight: 500;
  overflow: visible;
}

.flashcard-pos {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--paper-muted);
}

.flashcard-gloss {
  font-size: 1.2rem;
  font-weight: 600;
  max-width: 20em;
}

.flashcard-example {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--ink-line);
  width: 100%;
  max-width: 22em;
}

.flashcard-example > div:first-child {
  font-family: var(--font-zh);
  font-size: 1.05rem;
  line-height: 1.45;
}

.flashcard-example-en {
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--paper-muted);
}


.flashcard-origins {
  width: 100%;
  max-width: 22em;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--ink-line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  max-height: min(42vh, 320px);
  overflow-y: auto;
}

.flashcard-origins-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

.flashcard-char-item {
  border: 1px solid var(--ink-line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  overflow: visible;
}

.flashcard-char-row {
  appearance: none;
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 0;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.flashcard-char-row:hover,
.flashcard-char-row:focus-visible {
  background: rgba(47, 181, 165, 0.12);
  outline: none;
}

.flashcard-char-row.is-open {
  background: rgba(47, 181, 165, 0.16);
}

.flashcard-char-glyph {
  font-family: var(--font-zh);
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
}

.flashcard-char-meta {
  font-size: 0.85rem;
  line-height: 1.55;
  padding-block: 0.12em;
  color: var(--paper-muted);
  min-width: 0;
  overflow: visible;
  white-space: normal;
}

.flashcard-char-caret {
  color: var(--teal);
  transition: transform 0.15s ease;
}


.flashcard-char-panel {
  padding: 0 12px 12px;
  border-top: 1px solid var(--ink-line);
}

.flashcard-char-panel[hidden] {
  display: none !important;
}

.flashcard-origin-meta {
  margin: 10px 0 6px;
  color: var(--teal);
  font-weight: 600;
  font-size: 0.92rem;
}

.flashcard-origin-type {
  margin: 0 0 6px;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(47, 181, 165, 0.35);
  background: rgba(47, 181, 165, 0.12);
  color: var(--teal-bright);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.flashcard-origin-formula {
  margin: 0 0 8px;
  font-family: var(--font-zh);
  font-size: 1rem;
}

.flashcard-origin-block {
  margin-top: 8px;
}

.flashcard-origin-block h4 {
  margin: 0 0 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

.flashcard-origin-block p,
.flashcard-origin-empty {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--paper-muted);
}

.study-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  position: sticky;
  bottom: 0;
  z-index: 4;
  margin-top: auto;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  background: var(--dx-bg, #f6f4ef);
  border-top: 1px solid var(--dx-border, var(--ink-line));
}

.study-actions[hidden] {
  display: none !important;
}

.btn-rate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: 8px 4px;
  font-size: 0.82rem;
  border: 1px solid var(--ink-line);
  background: var(--ink-elevated);
  color: var(--paper);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    transform 0.14s var(--ease-out),
    background 0.18s var(--ease-out),
    border-color 0.18s var(--ease-out),
    box-shadow 0.18s var(--ease-out),
    filter 0.18s var(--ease-out);
}

.btn-rate:hover {
  filter: brightness(1.08);
}

.btn-rate:active {
  transform: translateY(1px) scale(0.97);
}

.btn-rate:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.rate-key {
  font-size: 0.65rem;
  font-weight: 700;
  opacity: 0.45;
  letter-spacing: 0.04em;
}

.btn-again {
  border-color: rgba(210, 85, 85, 0.45);
  color: var(--danger);
}

.btn-again:active {
  background: rgba(210, 85, 85, 0.16);
}

.btn-hard {
  border-color: rgba(212, 100, 44, 0.45);
  color: var(--vermillion);
}

.btn-hard:active {
  background: var(--vermillion-soft);
}

.btn-good {
  border-color: rgba(47, 181, 165, 0.45);
  color: var(--teal);
}

.btn-good:active {
  background: var(--teal-soft);
}

.btn-easy {
  border-color: rgba(47, 181, 165, 0.75);
  background: var(--teal-soft);
  color: var(--teal-bright);
}

.btn-easy:active {
  background: rgba(47, 181, 165, 0.28);
}

/* Tabs use the hub pill bar (.dx-tabs). Keep them in the column, not a fixed dock. */
.tab-bar {
  flex-shrink: 0;
  position: relative;
  z-index: 30;
}

.tab-icon {
  width: 16px;
  height: 16px;
  flex: none;
}

.dx-tabs > .dx-tab {
  gap: 6px;
}

.dx-tab[aria-current="page"] {
  background: var(--dx-accent-soft, transparent);
  color: var(--dx-accent, var(--accent));
}

/* Progress visualizations */
.view-progress {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
  width: 100%;
}

.progress-root {
  width: 100%;
  min-height: 200px;
}

.progress-card-journey {
  grid-column: 1 / -1;
}

.journey-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--paper-muted);
}

.journey-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.journey-legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.swatch-total {
  background: rgba(196, 205, 216, 0.55);
}

.journey-curve-wrap {
  width: 100%;
  margin: 0 0 8px;
}

.journey-curve {
  width: 100%;
  height: auto;
  display: block;
}

.journey-grid {
  stroke: var(--ink-line);
  stroke-width: 1;
}

.journey-axis {
  fill: var(--paper-muted);
  font-size: 9px;
  font-family: var(--font-ui);
}

.journey-line {
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.journey-line-total {
  stroke: rgba(196, 205, 216, 0.45);
  stroke-width: 1.5;
}

.journey-line-learning {
  stroke: var(--vermillion);
  stroke-dasharray: 5 4;
}

.journey-line-known {
  stroke: var(--teal);
}

.journey-dot {
  fill: var(--teal);
  stroke: rgba(15, 20, 25, 0.9);
  stroke-width: 1;
}

.journey-summary {
  margin: 4px 0 14px;
  font-size: 0.85rem;
  color: var(--paper-muted);
}

.journey-summary strong {
  color: var(--paper);
}

.journey-delta {
  color: var(--teal);
}

.journey-subhead {
  margin: 14px 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

.journey-recent {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.journey-chip {
  appearance: none;
  border: 1px solid var(--dx-border, var(--ink-line));
  background: var(--dx-card-solid, var(--ink-soft));
  color: var(--paper);
  font-family: var(--font-hanzi, "Noto Serif SC", serif);
  font-size: 1.05rem;
  line-height: 1.2;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.journey-chip:hover,
.journey-chip:focus-visible {
  border-color: var(--teal);
  outline: none;
}

.journey-recent-empty {
  margin: 0 0 4px;
}

.journey-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  border-left: 2px solid var(--ink-line);
  margin-left: 4px;
}

.journey-timeline-item {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  padding: 0 0 14px 14px;
  position: relative;
}

.journey-timeline-item::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-line);
}

.journey-timeline-item.journey-milestone::before {
  background: var(--teal);
}

.journey-timeline-item.journey-local::before {
  background: var(--vermillion);
}

.journey-time {
  font-size: 0.72rem;
  color: var(--paper-muted);
  padding-top: 2px;
}

.journey-timeline-title {
  margin: 0;
  font-size: 0.9rem;
  color: var(--paper);
  font-weight: 600;
}

.journey-timeline-detail {
  margin: 3px 0 0;
  font-size: 0.78rem;
  color: var(--paper-muted);
}

.journey-link {
  appearance: none;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(94, 184, 166, 0.45);
  text-underline-offset: 2px;
}

.journey-link:hover,
.journey-link:focus-visible {
  color: var(--teal);
  outline: none;
}

.progress-loading,
.progress-empty {
  margin: 24px 0;
  text-align: center;
  color: var(--paper-muted);
}

.progress-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.progress-card {
  padding: 16px;
  border-radius: calc(var(--radius) + 4px);
  border: 1px solid var(--ink-line);
  background: var(--ink-elevated);
  box-shadow: var(--dash-shadow);
}

.progress-card h2 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.progress-card > .section-heading h2 {
  margin: 0.15rem 0 0;
}

.progress-hint {
  margin: -6px 0 12px;
  font-size: 0.78rem;
  color: var(--paper-muted);
}

.mastery-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.progress-donut {
  width: 132px;
  height: 132px;
  flex-shrink: 0;
}

.donut-track {
  stroke: var(--ink-line);
}

.donut-known {
  stroke: var(--teal);
}

.donut-learning {
  stroke: var(--vermillion);
}

.donut-pct {
  fill: var(--paper);
  font-size: 18px;
  font-weight: 700;
  font-family: var(--font-ui);
}

.donut-sub {
  fill: var(--paper-muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--font-ui);
}

.mastery-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--paper-muted);
}

.mastery-legend strong {
  color: var(--paper);
  font-weight: 700;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
}

.swatch-known {
  background: var(--teal);
}

.swatch-learning {
  background: var(--vermillion);
}

.mastery-total {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--ink-line);
}

.srs-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.srs-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  background: var(--ink-elevated);
  border: 1px solid var(--ink-line);
  text-align: center;
}

.srs-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--paper);
  line-height: 1.1;
}

.srs-label {
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

.srs-mini-track {
  display: block;
  height: 3px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--ink-line);
  overflow: hidden;
}

.srs-mini-track > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.srs-due .srs-value {
  color: var(--vermillion);
}

.srs-due .srs-mini-track > span {
  background: var(--vermillion);
}

.srs-new .srs-mini-track > span {
  background: #8ab4f8;
}

.srs-learning .srs-mini-track > span {
  background: var(--vermillion);
}

.srs-review .srs-mini-track > span {
  background: var(--teal);
}

.audio-meter {
  height: 12px;
  border-radius: 999px;
  background: var(--ink-line);
  overflow: hidden;
  margin-bottom: 10px;
}

.audio-meter-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal-dim), var(--teal));
  transition: width 0.35s var(--ease-out);
}

.audio-meter-caption {
  margin: 0;
  font-size: 0.85rem;
  color: var(--paper-muted);
}

.audio-meter-caption strong {
  color: var(--paper);
}

.progress-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-bar-row {
  display: grid;
  grid-template-columns: minmax(72px, 0.9fr) 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 6px 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.progress-bar-row:hover,
.progress-bar-row:focus-visible {
  background: rgba(47, 181, 165, 0.1);
  outline: none;
}

.progress-bar-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--paper);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-bar-track {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: var(--ink-line);
  overflow: hidden;
}

.progress-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--vermillion), var(--teal));
  min-width: 2px;
  transition: width 0.35s var(--ease-out);
}

.progress-card-pos .progress-bar-fill {
  background: linear-gradient(90deg, var(--teal-dim), #8ab4f8);
}

.progress-bar-value {
  font-size: 0.75rem;
  color: var(--paper-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Banners */
.banner {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.banner[hidden] {
  display: none !important;
}

.banner-loading {
  background: var(--dx-card-solid, #fff);
  color: var(--teal-bright);
  border: 1px solid var(--teal-line);
}

.banner-error {
  background: var(--dx-card-solid, #fff);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* —— Responsive breakpoints —— */

@media (max-width: 379px) {
  .chip-status {
    font-size: 0.78rem;
  }

  .status-stats {
    gap: 0.3rem;
  }

  .status-stats span {
    font-size: 0.61rem;
  }

  .btn-rate {
    font-size: 0.75rem;
  }

  .goal-ring {
    width: 124px;
    height: 124px;
  }

  .goal-ring-label strong {
    font-size: 1.45rem;
  }

  .srs-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .level-card {
    align-items: flex-start;
  }

  .level-orb {
    width: 50px;
    height: 50px;
    font-size: 0.92rem;
  }

  .level-card > strong {
    display: none;
  }
}

@media (min-width: 480px) {
  .detail-panel {
    border-radius: 24px;
    margin-bottom: calc(var(--chrome-bottom) + 16px);
  }

  .card-detail {
    align-items: center;
    padding: clamp(12px, 3vw, 28px);
  }

  .rate-key {
    display: inline;
  }
}

/* Tablet: widen shell; list still flex-scrolls (no max-height hack) */
@media (min-width: 640px) {
  :root {
    --shell-max: min(100%, 720px);
  }

  .study-idle {
    max-width: 520px;
    margin: 0 auto;
    width: 100%;
  }

  .study-session {
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
  }

  .progress-grid {
    grid-template-columns: 1fr 1fr;
  }

  .progress-card-journey,
  .progress-card-topics,
  .progress-card-pos {
    grid-column: 1 / -1;
  }
}

/* Large tablet / small laptop: split library, pill tabs stay on top */
@media (min-width: 900px) {
  :root {
    --shell-max: 100%;
    --chrome-bottom: 0px;
    --page-pad: clamp(20px, 2.5vw, 36px);
  }

  .app {
    flex-direction: column;
    align-items: stretch;
    max-width: none;
  }

  .app-body {
    flex-direction: column;
  }

  .library-masthead {
    padding: 1.25rem;
    margin-bottom: 0.25rem;
  }

  .library-title-zh {
    font-size: 1.75rem;
  }

  .app-shell {
    flex: 1;
    min-width: 0;
    padding-bottom: 0;
    /* Full-bleed beside the rail — no unused void on wide desktops */
    max-width: none;
    width: 100%;
    margin-inline: 0;
  }

  .main {
    height: 100%;
    min-height: 0;
  }

  .view-library {
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 16px 20px;
    height: 100%;
    align-items: stretch;
  }

  .library-toolbar {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: calc(var(--chrome-top) + 8px);
    align-self: stretch;
    max-height: none;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
    padding-bottom: 8px;
    gap: 12px;
    background: transparent;
  }

  .filters-panel {
    display: flex !important;
  }

  .filters-panel[hidden] {
    display: flex !important;
  }

  .btn-filters {
    display: none;
  }

  .card-list {
    grid-column: 2;
    grid-row: 1;
    height: 100%;
    min-height: 0;
    mask-image: none;
    padding: 8px;
    border: none;
    background: transparent;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
    align-content: start;
  }

  .list-row {
    margin-bottom: 0;
    border-radius: 14px;
    border: 1px solid var(--ink-line);
    background: var(--ink-elevated);
    box-shadow: var(--shadow);
  }

  .list-row:nth-child(odd) {
    border-right: 1px solid var(--ink-line);
  }

  .view-study {
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
    padding-top: 8px;
  }

  .view-progress {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    height: 100%;
  }

  .study-hero:not(.learning-hero) {
    height: clamp(120px, 18vh, 180px);
  }

  .study-hero.learning-hero {
    height: auto;
    padding: 1.25rem;
  }

  .study-hero:not(.learning-hero) .study-hero-glyph {
    font-size: clamp(3.2rem, 6vw, 4.5rem);
  }

  .learning-hero,
  .level-card {
    padding: 1.25rem;
  }
}

/* Desktop wide: three-column library with side detail */
@media (min-width: 1100px) {
  .progress-grid {
    grid-template-columns: 1.1fr 1fr 1fr;
  }

  .progress-card-journey {
    grid-column: 1 / -1;
  }

  .progress-card-mastery {
    grid-column: 1;
  }

  .progress-card-srs {
    grid-column: 2;
  }

  .progress-card-audio {
    grid-column: 3;
  }

  .progress-card-topics {
    grid-column: 1 / 3;
  }

  .progress-card-pos {
    grid-column: 3;
  }

  /* Three-column when detail open; two-column (filters + dense list) when closed */
  .view-library {
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  }

  body.detail-open .view-library,
  .view-library:has(#card-detail:not([hidden])) {
    grid-template-columns: minmax(220px, 280px) minmax(260px, 1fr) minmax(320px, 1.1fr);
  }

  body.detail-open .card-list,
  .view-library:has(#card-detail:not([hidden])) .card-list {
    grid-template-columns: 1fr;
  }

  body.detail-open .list-row:nth-child(odd),
  .view-library:has(#card-detail:not([hidden])) .list-row:nth-child(odd) {
    border-right: none;
  }

  .card-detail:not([hidden]) {
    position: relative;
    inset: auto;
    z-index: 1;
    grid-column: 3;
    grid-row: 1;
    display: block;
    align-items: stretch;
    justify-content: stretch;
    height: 100%;
    min-height: 0;
  }

  .card-detail:not([hidden]) .detail-backdrop {
    display: none;
  }

  .card-detail:not([hidden]) .detail-panel {
    position: relative;
    width: 100%;
    max-width: none;
    max-height: none;
    height: 100%;
    margin: 0;
    border-radius: var(--radius);
    border: 1px solid var(--ink-line);
    border-bottom: 1px solid var(--ink-line);
    animation: rise-in 0.25s var(--ease-out);
    box-shadow: none;
  }

  .card-detail:not([hidden]) .detail-handle {
    display: none;
  }

  .study-session,
  .study-idle {
    max-width: 680px;
  }

  .flashcard {
    min-height: clamp(280px, 40vh, 420px);
  }
}

@media (min-width: 1400px) {
  .view-library {
    gap: 20px 28px;
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  }

  body.detail-open .view-library,
  .view-library:has(#card-detail:not([hidden])) {
    grid-template-columns: minmax(240px, 300px) minmax(280px, 1fr) minmax(340px, 1.05fr);
  }

  .list-hanzi {
    font-size: 1.75rem;
  }

  .card-list {
    background: transparent;
  }
}

/* Prefer reduced motion — keep feedback colors, drop motion hierarchy */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .library-masthead,
  .view-library,
  .flashcard-back,
  .filters-panel,
  .tab.is-active::before {
    animation: none !important;
  }

  .list-row:hover,
  .list-row:active,
  .flashcard:hover,
  .flashcard:focus-visible,
  .flashcard:active,
  .chip:active,
  .btn-rate:active,
  .tab.is-active .tab-icon {
    transform: none !important;
  }
}


/* Full-screen character origin */
.char-origin-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  background: rgba(6, 10, 14, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  pointer-events: auto;
}

.char-origin-overlay.is-open {
  display: flex;
}

.char-origin-overlay[hidden] {
  display: none !important;
}

.char-origin-sheet {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: var(--dx-card-solid, #fff);
  color: var(--paper);
  box-shadow: var(--dx-shadow, none);
}

.char-origin-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ink-line);
  flex: 0 0 auto;
}

.char-origin-close {
  appearance: none;
  position: relative;
  z-index: 2;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--ink-line);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.char-origin-close:hover,
.char-origin-close:focus-visible {
  border-color: var(--teal);
  outline: none;
}

.char-origin-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.char-origin-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 18px 32px;
  -webkit-overflow-scrolling: touch;
}

.origin-head-lg {
  margin-bottom: 18px;
}

.origin-char-lg {
  width: 88px;
  height: 88px;
  font-size: 2.6rem;
  border-radius: 18px;
}

.char-origin-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--ink-line);
}

.char-origin-section h3 {
  margin: 0 0 10px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

.char-origin-section p {
  margin: 0;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--paper-muted);
}

.char-origin-empty-wrap {
  text-align: center;
  padding-top: 24px;
}

.btn-open-char-origin {
  margin-top: 14px;
}

.char-origin-footer {
  flex: 0 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--ink-line);
  background: var(--dx-card-solid, #fff);
}

body.char-origin-open {
  overflow: hidden;
}

@media (min-width: 900px) {
  .char-origin-overlay {
    padding: 24px;
  }

  .char-origin-sheet {
    border-radius: 18px;
    overflow: hidden;
    max-height: calc(100vh - 48px);
  }
}
