/* Shared Just Voca design system: NGSL + HSK */
:root {
  color-scheme: light;
  --voca-scale: 1;
  --voca-ink: #172033;
  --voca-muted: #64748b;
  --voca-line: #e2e8f0;
  --voca-blue: #2563eb;
  --voca-blue-dark: #1d4ed8;
  --voca-green: #15803d;
  --voca-red: #dc2626;
  --voca-header-bg: rgba(255,255,255,.96);
  --voca-card: #ffffff;
}
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body.voca-page {
  margin: 0;
  padding: 0;
  color: var(--voca-ink);
  background: #f3f6fb;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  line-height: 1.48;
  -webkit-font-smoothing: antialiased;
}
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

/* Unified sticky header */
.top-panel {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  background: var(--voca-header-bg);
  border-bottom: 1px solid rgba(203,213,225,.8);
  box-shadow: 0 4px 18px rgba(15,23,42,.07);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.top-inner {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 12px 20px 11px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}
.title-group {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 13px;
  flex-wrap: wrap;
}
.brand-link {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  flex: 0 0 auto;
  padding: 3px 0;
  color: #334155;
  text-decoration: none !important;
  font-size: calc(15px * var(--voca-scale));
  font-weight: 750;
  letter-spacing: -.045em;
  white-space: nowrap;
  transition: color .15s ease, transform .15s ease;
}
.brand-link .brand-voca { color: #2563eb; font-weight: 900; }
.brand-link:hover { color: #0f172a; text-decoration: none !important; transform: translateY(-1px); }
.brand-link:hover .brand-voca { color: #1d4ed8; }
.page-title {
  min-width: 0;
  margin: 0;
  color: #172554;
  font-size: calc(clamp(19px, 2.4vw, 25px) * var(--voca-scale));
  font-weight: 850;
  letter-spacing: -.045em;
  line-height: 1.2;
}
.font-size-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  margin-left: 2px;
  padding: 3px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
}
.font-size-controls button {
  min-width: 34px;
  height: 30px;
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #334155;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.font-size-controls button:hover { background: #dbeafe; color: #1d4ed8; }
.font-size-controls button:disabled { opacity: .35; cursor: default; }
.font-size-controls #fontResetBtn { min-width: 47px; color: #64748b; font-size: 10px; }
.header-meta {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 12px;
  flex-wrap: wrap;
  color: #64748b;
  font-size: calc(12px * var(--voca-scale));
  font-weight: 650;
  text-align: right;
}
.stats, .rank-status { white-space: nowrap; }
.rank-status { color: #64748b; }
.rank-status.ready { color: #047857; }
.rank-status.error { color: #b45309; }

/* Common help details */
details.help {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  color: #475569;
  font-size: calc(12px * var(--voca-scale));
  overflow: hidden;
}
details.help summary {
  position: relative;
  padding: 7px 34px 7px 11px;
  color: #334155;
  font-weight: 750;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
details.help summary::-webkit-details-marker { display: none; }
details.help summary::after {
  content: "+";
  position: absolute;
  top: 50%; right: 12px;
  transform: translateY(-50%);
  color: #64748b;
  font-size: 16px;
  font-weight: 800;
}
details.help[open] summary::after { content: "−"; }
.help-content { padding: 0 11px 10px; line-height: 1.65; }
.help-content b { color: #0f172a; }

/* Unified controls */
.controls {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.controls input[type="search"], .controls input[type="text"] {
  flex: 1 1 250px;
  min-width: 170px;
  height: 39px;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: #fff;
  color: #172033;
  font-size: calc(14px * var(--voca-scale));
  outline: none;
}
.controls input:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px #dbeafe; }
.controls select {
  flex: 0 0 auto;
  min-width: 116px;
  height: 39px;
  padding: 7px 30px 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: #fff;
  color: #334155;
  font-size: calc(12px * var(--voca-scale));
  font-weight: 650;
}
.check-filter-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 5px;
  color: #334155;
  font-size: calc(12px * var(--voca-scale));
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.check-filter-label input { width: 17px; height: 17px; margin: 0; accent-color: #dc2626; }
.controls button, .loop-btn {
  min-height: 38px;
  padding: 7px 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: #fff;
  color: #334155;
  font-size: calc(12px * var(--voca-scale));
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .14s ease;
}
.controls button:hover { background: #f1f5f9; border-color: #94a3b8; }
.controls button:active, .loop-btn:active { transform: translateY(1px); }
#checkVisibleBtn { background: #fff; border-color: #fecaca; color: #b91c1c; }
#checkVisibleBtn:hover { background: #fef2f2; }
.loop-btn { background: #0f766e; border-color: #0f766e; color: #fff; }
.loop-btn:hover { background: #115e59; border-color: #115e59; }
.loop-btn.active { background: #dc2626; border-color: #dc2626; }

/* Frequency legend */
.frequency-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 7px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #fff;
  color: #475569;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; }
.swatch.tier-1 { background: #2563eb; }
.swatch.tier-2 { background: #059669; }
.swatch.tier-3 { background: #d97706; }
.swatch.tier-4 { background: #7c3aed; }
.swatch.tier-5 { background: #ea580c; }
.swatch.tier-6 { background: #db2777; }

/* Consistent word action buttons */
.action-group { display: inline-flex; align-items: center; justify-content: flex-start; gap: 6px; flex-wrap: nowrap; white-space: nowrap; }
.action-button, .audio-btn, .dict-link, .voca-art-trigger {
  box-sizing: border-box;
  min-width: 76px;
  min-height: 42px;
  padding: 7px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: calc(12px * var(--voca-scale));
  font-weight: 800;
  line-height: 1;
  text-decoration: none !important;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15,23,42,.08);
  transition: background-color .14s ease, border-color .14s ease, color .14s ease, transform .14s ease;
  touch-action: manipulation;
}
.action-button:active, .audio-btn:active, .dict-link:active, .voca-art-trigger:active { transform: translateY(1px); }
.action-icon { font-size: 17px; line-height: 1; }
.voca-art-trigger, .action-art { min-width: 86px; background: #2563eb; border-color: #1d4ed8; color: #fff; }
.voca-art-trigger:hover, .action-art:hover { background: #1d4ed8; border-color: #1e40af; }
.audio-btn, .action-audio { min-width: 80px; background: #15803d; border-color: #15803d; color: #fff; }
.audio-btn:hover, .action-audio:hover { background: #166534; border-color: #166534; }
.audio-btn.playing { background: #facc15 !important; border-color: #eab308 !important; color: #1e293b !important; outline: none !important; box-shadow: 0 0 0 2px #fde68a !important; }
.dict-link, .action-dict { min-width: 76px; background: #e0f2fe; border-color: #bae6fd; color: #075985; }
.dict-link:hover, .action-dict:hover { background: #bae6fd; border-color: #7dd3fc; }

/* Checkboxes / checked state */
.check-cell { width: 48px; text-align: center; }
.check-box, .check-btn {
  appearance: none; -webkit-appearance: none;
  width: 23px; height: 23px; margin: 0;
  display: inline-grid; place-content: center;
  border: 1.5px solid #94a3b8; border-radius: 6px;
  background: #fff; color: transparent; cursor: pointer;
  vertical-align: middle;
}
.check-box:checked, .check-btn.checked { background: #dc2626; border-color: #dc2626; color: #fff; }
.check-box:checked::after, .check-btn.checked::after { content: "✓"; color: #fff; font-size: 15px; font-weight: 900; line-height: 1; }
tr.checked-row { background: #fff1f2 !important; }
tr.checked-row td:first-child { border-left: 4px solid #dc2626; }
tr.checked-row .word-main, tr.checked-row .hanzi { color: #b91c1c; }

/* Checked list and fixed scroll-to-top button */
.checked-section {
  width: min(1500px, calc(100% - 32px));
  margin: 18px auto 0;
  padding: 14px;
  border: 1px solid #fecaca;
  border-radius: 13px;
  background: #fff7f7;
}
.checked-header { display: flex; align-items: center; justify-content: space-between; gap: 9px; flex-wrap: wrap; }
.checked-section h2 { margin: 0; color: #991b1b; font-size: calc(16px * var(--voca-scale)); }
.checked-list { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 10px; }
.checked-item { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid #fecaca; border-radius: 9px; background: #fff; }
.checked-item .word-mini { color: #7f1d1d; font-size: calc(14px * var(--voca-scale)); font-weight: 850; }
.checked-item .checked-sub { color: #64748b; font-size: calc(12px * var(--voca-scale)); }
.checked-item button { min-width: 30px; min-height: 30px; padding: 3px 7px; border: 1px solid #e2e8f0; border-radius: 7px; background: #fff; color: #334155; cursor: pointer; }
.checked-item button.remove { color: #dc2626; border-color: #fecaca; font-size: 16px; font-weight: 900; }
.empty { color: #94a3b8; font-size: calc(13px * var(--voca-scale)); }
.scroll-top-btn {
  position: fixed; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 500;
  width: 46px; height: 46px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #1d4ed8; border-radius: 50%;
  background: #2563eb; color: #fff; font-size: 22px; font-weight: 900;
  box-shadow: 0 5px 18px rgba(37,99,235,.28);
  opacity: 0; pointer-events: none; transform: translateY(9px);
  transition: opacity .18s ease, transform .18s ease, background .18s ease;
  cursor: pointer;
}
.scroll-top-btn.visible { opacity: .96; pointer-events: auto; transform: translateY(0); }
.scroll-top-btn:hover { background: #1d4ed8; }
.voca-toast {
  position: fixed; left: 50%; bottom: 22px; z-index: 12000;
  max-width: min(540px, calc(100vw - 32px));
  transform: translate(-50%, 14px); opacity: 0; pointer-events: none;
  padding: 10px 14px; border: 1px solid #334155; border-radius: 10px;
  background: #0f172a; color: #fff; font-size: 13px; font-weight: 650; line-height: 1.45;
  box-shadow: 0 8px 25px rgba(15,23,42,.25); transition: opacity .18s, transform .18s;
}
.voca-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .top-inner { padding: 10px 14px; }
  .top-header { align-items: flex-start; }
  .header-meta { justify-content: flex-end; }
  .controls input[type="search"], .controls input[type="text"] { flex: 1 1 100%; }
}
@media (max-width: 650px) {
  body.voca-page { padding-bottom: 0; }
  .top-panel { position: relative; }
  .top-inner { padding: 10px 11px 9px; gap: 8px; }
  .top-header { display: flex; flex-direction: column; align-items: stretch; gap: 5px; }
  .title-group { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
  .brand-link { font-size: calc(14px * var(--voca-scale)); }
  .page-title { font-size: calc(19px * var(--voca-scale)); }
  .font-size-controls { margin-left: auto; }
  .font-size-controls button { min-width: 30px; height: 28px; padding: 3px 6px; }
  .font-size-controls #fontResetBtn { min-width: 43px; }
  .header-meta { justify-content: flex-start; text-align: left; gap: 6px 10px; font-size: 11px; }
  .controls { gap: 6px; }
  .controls input[type="search"], .controls input[type="text"] { flex: 1 1 100%; width: 100%; height: 40px; }
  .controls select { flex: 1 1 130px; min-width: 0; height: 38px; }
  .controls button, .loop-btn { flex: 1 1 auto; min-height: 38px; }
  details.help summary { padding: 7px 32px 7px 9px; }
  .frequency-legend { gap: 4px; }
  .legend-item { font-size: 9px; padding: 3px 6px; }
  .action-group { display: flex; align-items: center; justify-content: flex-start; gap: 7px; width: max-content; max-width: 100%; }
  .action-button, .audio-btn, .dict-link, .voca-art-trigger { min-height: 42px; min-width: 72px; padding: 7px 9px; font-size: calc(12px * var(--voca-scale)); }
  .voca-art-trigger, .action-art { min-width: 80px; }
  .audio-btn, .action-audio { min-width: 76px; }
  .dict-link, .action-dict { min-width: 72px; }
  .checked-section { width: calc(100% - 20px); padding: 11px; }
  .scroll-top-btn { right: 13px; bottom: max(13px, env(safe-area-inset-bottom)); width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}


/* Keep filtered rows hidden even when mobile layouts set table rows to grid. */
.word-table tbody tr[hidden] { display: none !important; }

/* Initial and progressive word-list loading indicator. */
.page-loading:not([hidden]) {
  position: fixed; inset: 0; z-index: 13000; display: grid; place-items: center;
  padding: 22px; padding-bottom: max(22px, env(safe-area-inset-bottom));
  background: rgba(241, 245, 249, .91); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.page-loading[hidden] { display: none !important; }
.page-loading-card {
  width: min(100%, 360px); padding: 25px 22px 20px; border: 1px solid #dbe4ef; border-radius: 18px;
  background: #fff; box-shadow: 0 18px 54px rgba(15, 23, 42, .16); text-align: center;
}
.page-loading-spinner { width: 38px; height: 38px; margin: 0 auto 14px; border: 4px solid #dbeafe;
  border-top-color: #2563eb; border-radius: 50%; animation: voca-loading-spin .8s linear infinite; }
@keyframes voca-loading-spin { to { transform: rotate(360deg); } }
.page-loading-title { display: block; color: #0f172a; font-size: 17px; font-weight: 850; line-height: 1.4; }
.page-loading-message { margin: 8px 0 15px; color: #475569; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.page-loading-track { width: 100%; height: 8px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.page-loading-bar { width: 4%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #2563eb, #38bdf8); transition: width .12s linear; }
.page-loading-footer { display: flex; justify-content: flex-end; margin-top: 7px; color: #64748b; font-size: 11px; font-variant-numeric: tabular-nums; }
.page-loading-retry { margin-top: 15px; padding: 9px 15px; border: 1px solid #2563eb; border-radius: 9px; background: #2563eb; color: #fff; font-weight: 750; cursor: pointer; }
.page-loading-retry[hidden] { display: none !important; }
.page-loading.is-error .page-loading-spinner { display: none; }
.page-loading.is-error .page-loading-bar { background: #dc2626; }
@media (prefers-reduced-motion: reduce) { .page-loading-spinner { animation-duration: 2s; } }
