/* ===================================================
   JP Study App — Warm Paper Japanese Design
   iPhone 16e optimized · Safe area · Glassmorphism
   =================================================== */

:root {
  /* Colors — Warm Paper Japanese */
  --bg: #fdf8f0;
  --bg-soft: #fffef9;
  --bg-card: #fffef9;
  --primary: #c0392b;
  --primary-dark: #9b2335;
  --accent: #92400e;
  --accent-soft: rgba(220, 38, 38, 0.08);
  --success: #15803d;
  --danger: #9f1239;
  --text: #1c1917;
  --text-muted: #78716c;
  --border: rgba(160, 100, 60, 0.16);

  /* Shadows — warm sepia tints */
  --shadow-card: 0 4px 16px rgba(146, 64, 14, 0.08), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-hover: 0 8px 28px rgba(146, 64, 14, 0.15), 0 2px 8px rgba(0,0,0,0.05);
  --shadow-modal: 0 24px 64px rgba(28, 25, 23, 0.38);
  --shadow-soft: 0 18px 45px rgba(146, 64, 14, 0.10);

  /* Radii */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;

  /* Transitions */
  --transition-fast: 0.18s ease-out;
  --transition-med: 0.22s ease-out;

  /* Font */
  --font-jp: "Noto Serif JP", serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overflow-y: scroll;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px 8px;
  /* Gradient background blobs */
  background:
    radial-gradient(ellipse 80% 50% at 15% -5%, rgba(220, 38, 38, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 85% 105%, rgba(146, 64, 14, 0.07), transparent),
    radial-gradient(ellipse 40% 30% at 50% 50%, rgba(253, 248, 240, 0.5), transparent),
    var(--bg);
}

@media (max-width: 480px) {
  body {
    padding: 0;
  }
}

/* ===== APP SHELL ===== */
.app-shell {
  width: 100%;
  max-width: 900px;
  background: rgba(253, 248, 240, 0.92);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.8);
  overflow: hidden;
  height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
}

@media (max-width: 480px) {
  .app-shell {
    border-radius: 0;
    height: 100dvh;
    height: 100vh;
    border: none;
  }
}

/* ===== APP HEADER (Tab bar — top on desktop, bottom on mobile) ===== */
.app-header {
  display: none;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(253, 248, 240, 0.94);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  flex-shrink: 0;
}

.title-block {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.app-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-pill {
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.title-ja {
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.badge {
  padding: 3px 8px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.badge--accent {
  border-color: rgba(192, 57, 43, 0.45);
  color: var(--primary);
  background: rgba(192, 57, 43, 0.06);
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  margin: 0;
  width: 100%;
  padding: 3px;
  background: rgba(192, 57, 43, 0.06);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  flex: 1 1 auto;
}

.tab {
  flex: 1;
  position: relative;
  border: none;
  border-radius: var(--radius-full);
  padding: 7px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  transition: color var(--transition-fast), transform var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
}

.tab span.tab-label-main {
  font-size: 11px;
  line-height: 1;
}

.tab span.tab-label-sub {
  font-size: 8px;
  opacity: 0.65;
  line-height: 1;
}

.tab--active {
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.95);
  box-shadow:
    0 2px 12px rgba(146, 64, 14, 0.15),
    0 1px 3px rgba(0,0,0,0.06);
  transform: translateY(-1px);
}

.tab-indicator {
  position: absolute;
  bottom: 2px;
  height: 2px;
  width: 20px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary), var(--accent));
  opacity: 0;
  transform: scaleX(0.4);
  transition: opacity var(--transition-med), transform var(--transition-med);
}

.tab--active .tab-indicator {
  opacity: 1;
  transform: scaleX(1);
}

/* Shrink tab sub-label on small screens */
@media (max-width: 720px) {
  .tabs {
    padding: 2px;
  }
  .tab {
    padding: 6px 2px;
    min-height: 40px;
  }
  .tab span.tab-label-sub {
    display: none;
  }
  .app-header {
    flex-wrap: wrap;
  }
  .title-ja {
    font-size: 16px;
  }
}

/* ===== MOBILE BOTTOM NAV ===== */
@media (max-width: 768px) {
  .app-body {
    order: 1;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .app-header {
    order: 2;
    position: sticky;
    bottom: 0;
    top: auto;
    background: rgba(253, 248, 240, 0.92);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--border);
    border-bottom: none;
    padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    padding-top: 6px;
    z-index: 20;
  }
}

/* ===== APP BODY ===== */
.app-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 0;
}

/* ===== SECTION ===== */
.section {
  display: none;
  background: rgba(255, 254, 249, 0.80);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 10px;
  position: relative;
  overflow: hidden;
  min-height: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.section::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 0% 0%, rgba(192, 57, 43, 0.06), transparent);
  pointer-events: none;
}

.section-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 0;
}

.section--active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.section-header {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  flex-grow: 1;
  flex-shrink: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  gap: 6px;
}

.section-title-main {
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text);
}

.section-title-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Chip */
.chip {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: rgba(192, 57, 43, 0.07);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.vocab-count-chip {
  overflow: hidden;
  width: 30px;
  font-size: 11px;
  padding: 2px 2px;
  border-radius: var(--radius-full);
  background: rgba(192, 57, 43, 0.07);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.chip--active {
  background: rgba(160, 100, 60, 0.16);
  border-color: rgba(192, 57, 43, 0.35);
  color: var(--primary-dark);
  font-weight: 600;
}

/* ===== FILTERS ===== */
.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.field-group {
  flex: 1 1 130px;
  min-width: 0;
}

#section-kanji .field-group {
  flex: 0 0 auto;
  max-width: 100%;
}

#section-grammar .filters-row .field-group:first-child {
  flex: 0 0 auto;
  max-width: 130px;
}

#section-grammar .filters-row .field-group:last-child {
  flex: 1 1 auto;
  min-width: 0;
}

#section-grammar #grammar-lesson-filter {
  max-width: 110px;
}

#section-grammar #grammar-search-input {
  width: 100%;
}

.filters-toggle-row {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.filters-toggle {
  white-space: nowrap;
}

.note-doc-select {
  min-width: 0;
  flex: 1 1 0;
}

.section-header .btn-row {
  flex-wrap: nowrap;
  flex-shrink: 0;
  margin-top: 0;
  gap: 4px;
}

.filters-toggle-row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.kanji-count-jump-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.input-kanji-stt-jump {
  width: 64px;
  max-width: 76px;
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1.2;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
}

.input-kanji-stt-jump::placeholder {
  color: #9ca3af;
  font-size: 12px;
}

.input-kanji-stt-jump:focus {
  outline: none;
  border-color: rgba(192, 57, 43, 0.45);
  box-shadow: 0 0 0 3px rgba(146, 64, 14, 0.08);
}

.filters-toggle {
  border: none;
  background: none;
  padding: 0;
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline dotted;
}

.filters-row--hidden {
  display: none;
}

/* ===== INPUTS & SELECT ===== */
select, .btn, .btn-ghost, .input-text {
  font: inherit;
}

select {
  width: 100%;
  padding: 8px 32px 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  outline: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 12px,
    calc(100% - 9px) 12px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

select:focus {
  border-color: rgba(192, 57, 43, 0.45);
  box-shadow: 0 0 0 3px rgba(146, 64, 14, 0.08);
}

#kanji-filters-row .field-group {
  flex: 1 1 100%;
  max-width: 100%;
  width: 100%;
}

.radical-matrix {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 5px;
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.6);
  box-sizing: border-box;
}

.radical-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 2px 5px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(192, 57, 43, 0.05);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.radical-tile:hover {
  background: rgba(192, 57, 43, 0.12);
}

.radical-tile--active {
  background: rgba(160, 100, 60, 0.2);
  border-color: rgba(192, 57, 43, 0.5);
}

.radical-tile-char {
  font-size: 16px;
  line-height: 1.1;
  color: var(--text);
}

.radical-tile--active .radical-tile-char {
  color: var(--primary-dark);
  font-weight: 700;
}

.radical-tile-label {
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.radical-tile-count {
  position: absolute;
  top: -5px;
  right: -4px;
  font-size: 9px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-full);
  background: var(--primary-dark, #92400e);
  color: #fff;
  font-weight: 600;
}

.input-text {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-text:focus {
  border-color: rgba(192, 57, 43, 0.45);
  box-shadow: 0 0 0 3px rgba(146, 64, 14, 0.08);
}

#section-vocab .filters-row .field-group select,
#section-vocab .filters-row .field-group .input-text {
  font-size: 16px;
  padding: 6px 8px;
}

.field-label {
  font-size: 9px;
  color: var(--text-muted);
  margin-bottom: 3px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ===== SETTINGS PANEL ===== */
.settings-panel {
  margin-top: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 10px;
}

.settings-panel--hidden {
  display: none;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}

.settings-title {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.settings-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.settings-toggle {
  display: none;
}

.settings-toggle-icon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
}

.settings-toggle--open {
  border-color: rgba(192, 57, 43, 0.45);
  color: var(--primary);
  background: rgba(192, 57, 43, 0.06);
}

.settings-toggle--open .settings-toggle-icon {
  border-color: rgba(192, 57, 43, 0.45);
  color: var(--primary);
}

.settings-body {
  margin-top: 8px;
  display: none;
  gap: 6px;
  flex-wrap: wrap;
}

.settings-body--open {
  display: flex;
}

/* ===== CHECKBOX CHIPS ===== */
.checkbox-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  min-height: 32px;
  transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.checkbox-chip input {
  margin: 0;
  width: 13px;
  height: 13px;
  accent-color: var(--primary);
}

.checkbox-chip--active {
  border-color: rgba(192, 57, 43, 0.45);
  background: rgba(192, 57, 43, 0.08);
  color: var(--primary-dark);
  box-shadow: 0 0 0 2px rgba(146, 64, 14, 0.08);
}

/* ===== PILLS ===== */
.pill {
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-muted);
}

.pill--soft-accent {
  border-color: rgba(192, 57, 43, 0.35);
  font-weight: 600;
  color: var(--primary-dark);
  background: rgba(192, 57, 43, 0.06);
}

.pill--lesson {
  border-color: rgba(146, 64, 14, 0.35);
  color: var(--accent);
  background: rgba(146, 64, 14, 0.05);
}

.pill--type {
  border-color: rgba(5, 150, 105, 0.4);
  color: var(--success);
  background: rgba(5, 150, 105, 0.06);
}

/* ===== BUTTONS ===== */
.btn-row {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  border-radius: var(--radius-full);
  border: none;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #ffffff;
  box-shadow:
    0 4px 16px rgba(192, 57, 43, 0.35),
    0 1px 4px rgba(0,0,0,0.08);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  min-height: 44px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 8px 24px rgba(192, 57, 43, 0.40),
    0 2px 8px rgba(0,0,0,0.08);
}

.btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow:
    0 2px 8px rgba(146, 64, 14, 0.25),
    0 1px 3px rgba(0,0,0,0.06);
}

.btn-ghost {
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-muted);
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  min-height: 44px;
}

.btn-ghost:hover {
  background: rgba(192, 57, 43, 0.06);
  border-color: rgba(146, 64, 14, 0.25);
  color: var(--primary);
  box-shadow: var(--shadow-card);
}

.btn-ghost--danger {
  border-color: rgba(244, 63, 94, 0.4);
  color: var(--danger);
  background: rgba(244, 63, 94, 0.05);
}

.btn-ghost--danger:hover {
  background: rgba(244, 63, 94, 0.10);
  border-color: rgba(244, 63, 94, 0.6);
  color: var(--danger);
}

.btn-ghost:active {
  transform: translateY(1px);
}

/* ===== STAR BUTTONS ===== */
.star-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 20px;
  padding: 4px;
  line-height: 1;
  color: #d1d5db;
  transition: color var(--transition-fast), transform var(--transition-fast);
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.star-btn:hover {
  color: #fbbf24;
  transform: scale(1.15);
}

.star-btn--active {
  color: #eab308;
  -webkit-text-fill-color: #eab308;
}

.filter-icon-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(192, 57, 43, 0.06);
  color: var(--primary);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

#start-vocab-test-btn {
  font-size: 13px;
  font-weight: 700;
}

#reset-vocab-filter-btn {
  font-size: 16px;
}

.filter-icon-btn:hover {
  background: rgba(192, 57, 43, 0.12);
  border-color: rgba(192, 57, 43, 0.35);
}

.filter-icon-btn--active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Nav menu popup */
.nav-menu-popup {
  position: fixed;
  top: 60px;
  left: 8px;
  z-index: 200;
  min-width: 160px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  padding: 4px;
  display: none;
  flex-direction: column;
  gap: 2px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.nav-menu-popup--open {
  display: flex;
}

.nav-menu-item {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-menu-item:hover {
  background: rgba(192, 57, 43, 0.08);
  color: var(--primary-dark);
}

.nav-menu-item--active {
  background: rgba(192, 57, 43, 0.10);
  color: var(--primary-dark);
  font-weight: 600;
}

.star-filter-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  line-height: 1;
  color: #d1d5db;
  transition: color var(--transition-fast), transform var(--transition-fast);
  flex-shrink: 0;
  min-height: 32px;
}

.star-filter-btn:hover {
  color: #fbbf24;
  transform: scale(1.1);
}

.star-filter-btn--active {
  color: #f59e0b;
}

/* ===== MASTERED BUTTONS ===== */
.mastered-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px;
  line-height: 1.2;
  border-radius: var(--radius-sm);
  color: #9ca3af;
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
  flex-shrink: 0;
  min-height: 32px;
}

.mastered-btn:hover {
  color: var(--success);
  border-color: rgba(5, 150, 105, 0.4);
}

.mastered-btn--active {
  color: var(--success);
  border-color: rgba(5, 150, 105, 0.5);
  background: rgba(5, 150, 105, 0.07);
}

.test-mastered-row {
  margin: 10px 0 6px;
}

.test-mastered-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
  min-height: 44px;
}

.test-mastered-btn:hover {
  color: var(--success);
  border-color: rgba(5, 150, 105, 0.4);
}

.test-mastered-btn--active {
  color: var(--success);
  border-color: rgba(5, 150, 105, 0.5);
  background: rgba(5, 150, 105, 0.07);
}

/* ===== AUTO-PLAY & AUDIO BUTTONS ===== */
@keyframes audio-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.15); }
}

.autoplay-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-full);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
}

.autoplay-btn:hover {
  border-color: rgba(192, 57, 43, 0.35);
  color: var(--primary);
  background: rgba(192, 57, 43, 0.06);
}

.autoplay-btn--active {
  border-color: rgba(244, 63, 94, 0.5);
  color: var(--danger);
  background: rgba(244, 63, 94, 0.06);
}

.audio-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  line-height: 1;
  color: var(--primary);
  opacity: 0.65;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.audio-btn:hover {
  opacity: 1;
  transform: scale(1.1);
}

.audio-btn--playing {
  opacity: 1;
  animation: audio-pulse 0.6s ease-in-out infinite alternate;
}

/* ===== VOCAB ACTIONS BAR ===== */
.vocab-actions {
  display: flex;
  justify-content: flex-end;
  padding: 4px 0 2px;
}

.vocab-actions .btn-row {
  justify-content: flex-end;
  gap: 6px;
  margin-top: 0;
}

.vocab-actions .btn,
.vocab-actions .btn-ghost {
  font-size: 12px;
  padding: 4px 10px;
  min-height: 28px;
}

/* ===== VIEW TOGGLE ===== */
.view-toggle-row {
  display: flex;
  gap: 4px;
}

.view-toggle-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  min-height: 32px;
}

.view-toggle-btn--active {
  border-color: rgba(192, 57, 43, 0.45);
  color: var(--primary);
  background: rgba(192, 57, 43, 0.08);
}

/* ===== CONTENT GRID & CARDS ===== */
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1.1fr);
  gap: 10px;
  margin-top: 8px;
  min-height: 0;
}

@media (max-width: 720px) {
  .content-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  padding: 10px 12px;
  position: relative;
  overflow: hidden;
  min-height: 0;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 0% 0%, rgba(192, 57, 43, 0.04), transparent);
  pointer-events: none;
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
  position: relative;
  z-index: 1;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}

.card-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.card-body {
  position: relative;
  z-index: 1;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 2px;
}

.card-body--test {
  max-height: none;
}

/* Hide inline detail/test cards */
.card--vocab-detail-hidden,
.card--kanji-detail-hidden,
.card--grammar-detail-hidden,
.card--vocab-test-hidden {
  display: none;
}

/* Section-specific content grids */
#section-vocab .content-grid,
#section-kanji .content-grid,
#section-grammar .content-grid {
  grid-template-columns: minmax(0, 1fr);
}

#section-vocab .content-grid {
  flex: 1 1 auto;
  min-height: 0;
}

#section-vocab .content-grid > .card:first-child {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#vocab-list-container {
  max-height: none;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

#section-kanji .content-grid {
  flex: 1 1 auto;
  min-height: 0;
}

#section-kanji .content-grid > .card:first-child {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#kanji-list-container {
  max-height: none;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 200px;
}

#section-grammar .content-grid {
  flex: 1 1 auto;
  min-height: 0;
}

#section-grammar .content-grid > .card:first-child {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#grammar-list-container {
  max-height: none;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

/* Scrollbar */
.scroll-thin::-webkit-scrollbar {
  width: 4px;
}

.scroll-thin::-webkit-scrollbar-thumb {
  background: rgba(146, 64, 14, 0.18);
  border-radius: var(--radius-full);
}

.scroll-thin::-webkit-scrollbar-track {
  background: transparent;
}

/* ===== VOCAB LIST ===== */
.vocab-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 96px;
}

.vocab-item {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  padding: 6px 8px;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vocab-item:hover {
  border-color: rgba(146, 64, 14, 0.25);
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

.vocab-item--highlight {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 2px rgba(146, 64, 14, 0.18), var(--shadow-hover) !important;
  background: rgba(192, 57, 43, 0.04) !important;
}

.vocab-item-main {
  display: flex;
  align-items: baseline;
  gap: 4px;
  flex-wrap: wrap;
}

.vocab-kanji {
  font-family: var(--font-jp);
  font-size: 16px;
  font-weight: 500;
  color: #78350f;
}

.vocab-kanji b {
  font-weight: 700;
  font-size: 1.5em;
  color: #9b1c1c;
  padding: 0 2px;
}

.vocab-kanji b.vocab-kanji--linked {
  color: #1d4ed8;
  cursor: pointer;
}

.vocab-hira {
  font-family: var(--font-jp);
  font-size: 20px;
  font-weight: 700;
  color: #1c1917;
}

.vocab-romazi {
  font-size: 12px;
  font-weight: 500;
  color: #a8786a;
  font-style: italic;
}

.vocab-hanviet {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  letter-spacing: 0.03em;
  opacity: 0.85;
}

.vocab-meaning {
  padding-left: 4px;
  font-size: 15px;
  font-weight: 600;
  color: #292524;
}

.vocab-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 2px;
}

/* ===== VOCAB FLASHCARD ===== */
.vocab-flashcard-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 4px 32px;
  gap: 14px;
}

.vocab-flashcard-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

.vocab-flashcard-counter {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.vocab-flashcard-mode-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-full, 999px);
  overflow: hidden;
}

.vocab-flashcard-mode-btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.vocab-flashcard-mode-btn--active {
  background: var(--primary);
  color: #fff;
}

.vocab-flashcard-autonext-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-full, 999px);
  background: transparent;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.vocab-flashcard-autonext-btn--active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.vocab-flashcard-autonext-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.vocab-flashcard-autonext-seconds {
  width: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full, 999px);
  background: transparent;
  padding: 4px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.vocab-flashcard-autonext-unit {
  font-size: 11px;
  color: var(--text-muted);
}

.vocab-flashcard-view-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.vocab-flashcard-fullscreen-btn,
.vocab-flashcard-pip-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-full, 999px);
  background: transparent;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.vocab-flashcard-pip-btn {
  font-size: 11px;
}

.vocab-flashcard-fullscreen-btn--active,
.vocab-flashcard-pip-btn--active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.vocab-flashcard-wrap--fullscreen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg);
  justify-content: center;
  padding: 24px 16px 40px;
  overflow-y: auto;
}

.vocab-flashcard-wrap--fullscreen .vocab-flashcard-top-row,
.vocab-flashcard-wrap--fullscreen .vocab-flashcard-stage {
  max-width: 720px;
}

.vocab-flashcard-wrap--fullscreen .vocab-flashcard {
  min-height: 320px;
}

.vocab-flashcard-wrap--fullscreen .vocab-flashcard .vocab-hira {
  font-size: 48px;
}

.vocab-flashcard-wrap--fullscreen .vocab-flashcard .vocab-kanji {
  font-size: 32px;
}

.vocab-flashcard-wrap--fullscreen .vocab-flashcard .vocab-meaning {
  font-size: 28px;
}

.vocab-flashcard-stage {
  position: relative;
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vocab-flashcard {
  width: 100%;
  min-height: 200px;
  perspective: 1200px;
  cursor: pointer;
  position: relative;
}

.vocab-flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 18px;
  border-radius: var(--radius-lg, 16px);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-hover);
  backface-visibility: hidden;
  transition: transform 0.5s;
  transform-style: preserve-3d;
  text-align: center;
}

.vocab-flashcard-face--front {
  transform: rotateY(0deg);
}

.vocab-flashcard-face--back {
  transform: rotateY(180deg);
}

.vocab-flashcard--flipped .vocab-flashcard-face--front {
  transform: rotateY(-180deg);
}

.vocab-flashcard--flipped .vocab-flashcard-face--back {
  transform: rotateY(0deg);
}

/* Mode 1 mặt: hiện cả 2 phía cùng lúc, không cần lật */
.vocab-flashcard--single {
  cursor: default;
  min-height: 0;
  perspective: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 16px);
  background: var(--bg-card);
  box-shadow: var(--shadow-hover);
  display: flex;
  flex-direction: column;
}

.vocab-flashcard--single .vocab-flashcard-face {
  position: static;
  transform: none;
  backface-visibility: visible;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 14px 18px;
}

.vocab-flashcard-divider {
  width: 70%;
  border-top: 1px dashed var(--border);
  margin: 2px 0 6px;
}

.vocab-flashcard .vocab-hira {
  font-size: 30px;
}

.vocab-flashcard .vocab-kanji {
  font-size: 20px;
}

.vocab-flashcard .vocab-meaning {
  font-size: 20px;
  padding-left: 0;
}

.vocab-flashcard-hint {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
}

.vocab-flashcard-star,
.vocab-flashcard-mastered,
.vocab-flashcard-audio {
  position: absolute;
  z-index: 2;
}

.vocab-flashcard-star {
  top: 6px;
  right: 6px;
}

.vocab-flashcard-mastered {
  top: 6px;
  left: 6px;
}

.vocab-flashcard-audio {
  bottom: 6px;
  right: 6px;
}

.vocab-flashcard-nav {
  margin-top: 0;
}

.vocab-flashcard-nav .detail-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ===== DETAIL NAV ROW ===== */
.detail-nav-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.detail-nav-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-card);
}

.detail-nav-btn:hover {
  border-color: rgba(192, 57, 43, 0.35);
  color: var(--primary);
  box-shadow: var(--shadow-hover);
}

.detail-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.detail-actions-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

/* ===== KANJI GRID ===== */
.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  padding-bottom: 110px;
}

.kanji-grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
  position: relative;
  min-height: 44px;
}

.kanji-grid-item:hover {
  border-color: rgba(192, 57, 43, 0.35);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.kanji-grid-item--jump-focus {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
  border-color: rgba(244, 63, 94, 0.6) !important;
  box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.12);
}

.kanji-grid-item--jump-focus .kanji-grid-char {
  color: var(--danger);
}

.kanji-grid-char {
  font-family: var(--font-jp);
  font-size: 28px;
  font-weight: 300;
  line-height: 1.2;
  color: var(--text);
}

.kanji-grid-name {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary);
  text-align: center;
  margin-top: 2px;
}

.kanji-grid-num {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
}

.kanji-grid-item .star-btn {
  position: absolute;
  top: 1px;
  right: 1px;
  font-size: 13px;
  padding: 0 2px;
  min-width: auto;
  min-height: auto;
}

/* ===== SIMPLE LIST (Kanji + Grammar) ===== */
.simple-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 13px;
  padding-bottom: 140px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.simple-item {
  border-radius: 0;
  border-bottom: 1px solid rgba(192, 57, 43, 0.07);
  background: transparent;
  padding: 6px 8px;
  cursor: pointer;
  transition: background var(--transition-fast);
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 6px;
  min-height: 44px;
}

.simple-item:hover {
  background: rgba(192, 57, 43, 0.04);
}

.simple-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  gap: 1px;
}

.simple-main-text {
  font-weight: 600;
  color: var(--text);
}

.simple-sub-text {
  font-size: 10px;
  color: var(--text-muted);
}

/* Grammar list */
.simple-list--grammar .simple-item {
  align-items: stretch;
  border-left: 3px solid transparent;
  position: relative;
}

.simple-stt {
  flex: 0 0 34px;
  min-width: 34px;
  text-align: right;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 2px;
}

.simple-main--grammar {
  gap: 2px;
}

.simple-main-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}

.simple-sub-text--grammar {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.simple-list--grammar .simple-item:hover {
  background: rgba(192, 57, 43, 0.04);
  border-left-color: rgba(192, 57, 43, 0.45);
}

.simple-list--grammar .simple-item::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 0 0, rgba(192, 57, 43, 0.04), transparent 55%);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.simple-list--grammar .simple-item:hover::after {
  opacity: 1;
}

.kanji-large {
  text-align: center;
  font-family: var(--font-jp);
  font-size: 120px;
  font-weight: 300;
  margin-bottom: 4px;
  color: var(--text);
}

.grammar-structure {
  font-family: var(--font-jp);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.grammar-structure-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.grammar-structure-row .grammar-structure {
  margin-bottom: 0;
  min-width: 0;
}

.grammar-gpt-link {
  white-space: nowrap;
}

/* ===== APP FOOTER ===== */
.app-footer {
  padding: 6px 14px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  font-size: 10px;
  text-align: right;
  color: var(--text-muted);
  background: rgba(255, 254, 249, 0.80);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.app-footer span {
  opacity: 0.8;
}

/* ===== NOTE SECTION ===== */
#section-note.section--active {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

#section-note.section--active .section-inner {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

#section-note.section--active .card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

#section-note.section--active .note-content-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: visible;
  max-height: none;
}

/* Khi tab Ghi chú đang mở: bỏ giới hạn chiều cao của cả khung app để
   nếu nội dung markdown dài, trang sẽ tự cuộn ở cấp trình duyệt thay vì
   xuất hiện thanh cuộn riêng bên trong khung nội dung. */
.app-shell:has(#section-note.section--active) {
  height: auto;
  min-height: calc(100vh - 24px);
  overflow: visible;
}

.app-shell:has(#section-note.section--active) .app-body {
  overflow: visible;
}

@media (max-width: 480px) {
  .app-shell:has(#section-note.section--active) {
    height: auto;
    min-height: 100dvh;
    min-height: 100vh;
  }
}

.note-doc-select select {
  font-size: 16px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  max-width: 160px;
  width: 100%;
}

.note-search-box {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 140px;
  min-width: 120px;
  transition: box-shadow var(--transition-fast), background var(--transition-fast);
}

.note-search-input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 16px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
}

.note-search-count {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Nút icon nhỏ gọn dùng chung: mũi tên điều hướng kết quả tìm kiếm + tăng/giảm cỡ chữ.
   Ghi đè min-height: 44px của .btn-ghost (gây méo thành hình bầu dục) bằng cách
   tăng độ đặc trưng (kết hợp 2 class) thay vì !important. */
.btn-ghost.note-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
}

.note-search-clear {
  font-size: 16px;
}

/* Khi focus vào ô search HOẶC đang có kết quả: ghim ô search + nút điều hướng
   nổi ở góc trên-phải màn hình (mọi kích thước màn hình), để vẫn thao tác được
   dù đã cuộn trang xuống xem kết quả highlight. */
.note-search-box--fixed {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  z-index: 40;
  background: rgba(253, 248, 240, 0.97);
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 5px 8px;
  box-shadow: var(--shadow-hover);
  max-width: min(320px, calc(100vw - 20px));
}

/* .app-shell và .section dùng backdrop-filter, mà backdrop-filter khác none trên tổ tiên sẽ
   tạo containing block riêng cho con position:fixed (theo spec), khiến .note-search-box--fixed
   bị "nhốt" định vị theo tổ tiên đó thay vì theo viewport thật. Tắt tạm backdrop-filter của các
   tổ tiên này trong lúc đang ghim để nó thoát ra ghim đúng theo viewport. */
.app-shell.note-search-portal-open,
.section.note-search-portal-open {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

.note-search-hit {
  background: rgba(250, 204, 21, 0.55);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.note-search-hit--current {
  background: rgba(249, 115, 22, 0.75);
}

.note-content-text {
  margin: 0;
  font-size: 1em;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-family: inherit;
}

.note-content-markdown {
  font-size: 1em;
  line-height: 1.6;
  color: var(--text);
}

.note-content-markdown h1 { font-size: 1.6em; margin: 0 0 0.75rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--border); }
.note-content-markdown h2 { font-size: 1.4em; margin: 1rem 0 0.5rem; }
.note-content-markdown h3 { font-size: 1.2em; margin: 0.75rem 0 0.4rem; }
.note-content-markdown table { border-collapse: collapse; width: 100%; margin: 0.5rem 0; font-size: 0.95em; }
.note-content-markdown th,
.note-content-markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.note-content-markdown th { background: rgba(192, 57, 43, 0.06); font-weight: 700; }
.note-content-markdown blockquote { margin: 0.5rem 0; padding-left: 12px; border-left: 3px solid rgba(192, 57, 43, 0.35); color: var(--text-muted); }
.note-content-markdown ul { padding-left: 1.25rem; margin: 0.35rem 0; }
.note-content-markdown hr { border: none; border-top: 1px solid var(--border); margin: 0.4rem 0; }
.note-content-markdown p { margin: 0.5rem 0; }

/* ===== STARS SECTION ===== */
#section-stars.section--active {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#section-stars.section--active .section-inner {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.stars-tab-stack {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}

.stars-tab-stack > .card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stars-tab-stack .card-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

/* Duplicate vocab tab */
.dup-tab-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  flex: 1 1 auto;
}

.dup-tab-stack > .card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.dup-tab-stack .card-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

.dup-group {
  border-bottom: 1px solid var(--border);
  padding: 8px 4px;
}

.dup-group:last-child {
  border-bottom: none;
}

.dup-group-head {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.dup-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
}

.dup-row:hover {
  background: rgba(160, 100, 60, 0.08);
}

.dup-row-cb {
  cursor: pointer;
  flex-shrink: 0;
}

.dup-row-text {
  color: var(--text);
  font-size: 13px;
}

#section-stars.section--active #stars-kanji-vocab-list {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  height: 100%;
  overflow: hidden;
}

#section-stars.section--active #stars-kanji-vocab-list .simple-list {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  padding-bottom: 12px;
  overflow-x: hidden;
  overflow-y: auto;
}

.stars-fav-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(192, 57, 43, 0.07);
  cursor: pointer;
  transition: background var(--transition-fast);
  min-height: 44px;
}

.stars-fav-row .audio-btn {
  flex-shrink: 0;
  align-self: center;
}

.stars-fav-row:hover {
  background: rgba(192, 57, 43, 0.04);
}

.stars-fav-row:last-child {
  border-bottom: none;
}

.stars-fav-row-main {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stars-fav-row-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== DETAIL MODAL ===== */
.detail-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.detail-modal--open {
  display: flex;
}

.detail-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(8px) saturate(150%);
  -webkit-backdrop-filter: blur(8px) saturate(150%);
}

.detail-modal__dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 600px;
  max-height: calc(100dvh - 16px);
  max-height: calc(100vh - 16px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-modal);
  padding: 12px 12px 10px;
  gap: 8px;
}

.detail-modal--taitho .detail-modal__dialog {
  margin-top: 60px;
  margin-bottom: 30px;
  max-height: calc(100dvh - 106px);
  max-height: calc(100vh - 106px);
}

.detail-modal--taitho.detail-modal--mapping .detail-modal__dialog {
  height: calc(100dvh - 90px);
  height: calc(100vh - 90px);
  max-height: calc(100dvh - 90px);
  max-height: calc(100vh - 90px);
}

.detail-modal__dialog .detail-modal__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.detail-modal__header {
  padding: 0 80px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1px;
  margin-bottom: 2px;
}

@media (max-width: 420px) {
  .detail-modal__header {
    padding: 0 70px;
  }
}

.detail-modal__nav {
  display: contents;
}

.detail-modal__nav .kd-nav-row {
  display: contents;
}

.detail-modal__nav .kd-nav-row--header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.detail-modal__nav .kd-nav-row--header .kd-nav-btn:first-child,
.detail-modal__nav .kd-nav-row--header .kd-nav-btn:last-child,
.detail-modal__nav .kd-nav-row--header .kd-nav-btn:nth-child(2) {
  grid-column: auto;
  justify-self: auto;
}

.detail-modal__nav .kd-nav-btn:first-child {
  grid-column: 1;
  justify-self: end;
}

.detail-modal__nav .kd-nav-btn:last-child {
  grid-column: 3;
  justify-self: start;
}

.detail-modal__nav .kd-nav-btn--back {
  grid-column: 1;
  justify-self: start;
}

.detail-modal__nav .kd-nav-btn:nth-child(2) {
  grid-column: 2;
  justify-self: end;
}

.detail-modal__title {
  grid-column: 1 / -1;
  justify-self: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}

.detail-modal__header:has(.detail-modal__nav:not(:empty)) .detail-modal__title {
  grid-column: 2;
}

.detail-modal__body {
  overflow-y: visible;
  max-height: none;
  padding-right: 0;
}

.detail-modal__close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-card);
  transition: all var(--transition-fast);
}

.detail-modal__close:hover {
  background: rgba(244, 63, 94, 0.08);
  border-color: rgba(244, 63, 94, 0.3);
  color: var(--danger);
}

.test-mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
  padding: 4px 2px 12px;
}

.test-mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 14px);
  background: #fff;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.test-mode-card:hover {
  border-color: var(--primary, #4f46e5);
  box-shadow: var(--shadow-card);
  transform: translateY(-2px);
}

.test-mode-card--review {
  border-color: rgba(217, 119, 6, 0.35);
  background: rgba(217, 119, 6, 0.06);
}

.test-mode-card--review:hover {
  border-color: #d97706;
}

.test-mode-card__icon {
  font-size: 28px;
  line-height: 1;
}

.test-mode-card__label {
  font-weight: 600;
  font-size: 14px;
}

.test-mode-card__hint {
  font-size: 12px;
  color: var(--text-muted, #6b7280);
}

.detail-modal__close:active {
  transform: translateY(1px);
}

/* ===== KD NAV BUTTONS ===== */
.kd-nav-btn {
  width: 36px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--primary);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-card);
}

.kd-nav-btn:hover:not(:disabled) {
  background: rgba(192, 57, 43, 0.08);
  border-color: rgba(192, 57, 43, 0.35);
  box-shadow: var(--shadow-hover);
  transform: scale(1.06);
}

.kd-nav-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.kd-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  color: var(--text-muted);
}

.kd-nav-btn--back {
  width: auto;
  min-width: 36px;
  padding: 0 12px;
  font-size: 12px;
  white-space: nowrap;
}

.kd-nav-row--header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.kd-nav-row--header button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== DETAIL GRID ===== */
.kd-kanji-back-btn {
  margin-bottom: 8px;
  padding: 5px 12px;
  font-size: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  font-size: 12px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.detail-label {
  color: var(--text-muted);
  white-space: nowrap;
}

.detail-value {
  text-align: right;
  color: var(--text);
  word-break: break-word;
}

.detail-main-value {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.detail-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 0;
  margin-top: 5px;
}

.detail-sub b {
  font-size: 24px;
  font-weight: bold;
}

/* Detail in popup */
.detail-modal__body .detail-main-value {
  font-size: 30px;
  margin-bottom: 8px;
}

.detail-modal__body .detail-sub {
  font-size: 16px;
  margin-bottom: 1px;
  text-align: left;
  color: var(--text-muted);
}

.detail-modal__body .detail-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}

.detail-modal__body .detail-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  padding: 5px 0;
  border-bottom: 1px dashed var(--border);
}

.detail-modal__body .detail-row:last-child {
  border-bottom: none;
}

.detail-modal__body .detail-label {
  font-size: 11px;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #9ca3af;
}

.detail-modal__body .detail-value {
  text-align: left;
  font-size: 20px;
  width: 100%;
  color: var(--text);
}

/* Bỏ scroll lồng trong popup */
.detail-modal__body .scroll-thin,
.detail-modal__body .card-body {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

/* ===== GRAMMAR DETAIL MODAL ===== */
.detail-modal__dialog:has(.grammar-detail) {
  max-width: min(860px, calc(100vw - 12px));
  max-height: calc(100dvh - 8px);
  max-height: calc(100vh - 8px);
  padding: 10px 12px 8px;
  gap: 4px;
  border-radius: var(--radius-md);
}

.detail-modal__dialog:has(.grammar-detail) .detail-modal__header {
  min-height: 36px;
  margin-bottom: 0;
}

.detail-modal__dialog:has(.grammar-detail) .detail-modal__title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.detail-modal__body .grammar-detail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 0 4px;
}

.detail-modal__body .grammar-structure {
  font-family: var(--font-jp);
  font-size: clamp(16px, 3.2vw, 19px);
  font-weight: 600;
  line-height: 1.32;
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(192, 57, 43, 0.04);
  border: 1px solid var(--border);
}

.detail-modal__body .grammar-lesson-chip {
  align-self: flex-start;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: rgba(192, 57, 43, 0.06);
  border: 1px solid var(--border);
  color: var(--primary-dark);
}

.detail-modal__body .grammar-section__title,
.detail-modal__body .grammar-detail > .detail-sub {
  font-size: 11px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  margin: 0;
}

.detail-modal__body .grammar-section__body .detail-value,
.detail-modal__body .grammar-section__line {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

.detail-modal__body .grammar-section {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
}

.detail-modal__body .grammar-section + .grammar-section {
  margin-top: 0;
}

.detail-modal__body .grammar-section__line {
  padding: 2px 0;
}

.detail-modal__body .grammar-section--meaning {
  border-left: 3px solid #fca5a5;
}

.detail-modal__body .grammar-section--explanation {
  border-left: 3px solid #fcd34d;
}

.detail-modal__body .grammar-section--example {
  border-left: 3px solid #fdba74;
}

.detail-modal__body .grammar-section__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.detail-modal__body .grammar-section__title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.detail-modal__body .grammar-section__title::before {
  content: "";
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.5;
}

.detail-modal__body .grammar-section--meaning .grammar-section__title { color: #166534; }
.detail-modal__body .grammar-section--explanation .grammar-section__title { color: #9b2335; }
.detail-modal__body .grammar-section--example .grammar-section__title { color: #9f1239; }

/* Ý nghĩa hiển thị inline dạng "Ý nghĩa: xxxxx" (không tách header riêng) */
.grammar-section__title--inline {
  display: inline;
  margin-right: 4px;
}

.grammar-section__title--inline::before {
  content: none;
}

.grammar-section__line--inline {
  padding: 0;
}

.detail-modal__body .grammar-section__body {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.detail-modal__body .grammar-section--example .grammar-section__body {
  gap: 4px;
}

.detail-modal__body .grammar-section--example .grammar-section__line--example {
  font-family: var(--font-jp);
  font-size: 13px;
  line-height: 1.48;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(192, 57, 43, 0.03);
  border: 1px solid var(--border);
}

/* ===== TEST UI ===== */
.test-question {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.test-question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

.test-question-main {
  text-align: center;
  padding: 14px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(192, 57, 43, 0.04);
  box-shadow: var(--shadow-card);
}

.test-question-text {
  font-family: var(--font-jp);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.test-question-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.test-question-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 2px;
  font-family: var(--font-jp);
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 4px;
}

@media (min-width: 540px) {
  .options-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.option-btn {
  border-radius: var(--radius-full);
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: border-color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  min-height: 44px;
}

.option-index {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(192, 57, 43, 0.05);
  flex-shrink: 0;
}

.option-btn:hover {
  border-color: rgba(192, 57, 43, 0.35);
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
  background: rgba(192, 57, 43, 0.04);
}

.option-btn--selected {
  border-color: rgba(192, 57, 43, 0.55);
  background: rgba(192, 57, 43, 0.08);
  box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.12);
}

.test-progress {
  height: 5px;
  border-radius: var(--radius-full);
  background: rgba(146, 64, 14, 0.08);
  overflow: hidden;
  margin-top: 4px;
}

.test-progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--success), #34d399);
  transition: width 0.2s ease-out;
}

.test-result {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.test-config-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
}

/* Test từ vựng / Test Kanji config forms: chữ trong ô input/select giữ nguyên, còn lại thu nhỏ */
.test-config-form .field-label,
.test-config-form .kt-section-label,
.test-config-form .kt-mode-label {
  font-size: 11px;
}

.test-config-form .input-text,
.test-config-form select {
  font-size: 16px;
}

@media (max-width: 400px) {
  .test-config-fields {
    grid-template-columns: 1fr;
  }
}

.score-main {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.score-detail {
  font-size: 12px;
  color: var(--text-muted);
}

.wrong-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.wrong-item {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 10px;
  box-shadow: var(--shadow-card);
}

.wrong-q {
  font-weight: 600;
  margin-bottom: 3px;
  color: var(--text);
}

.wrong-a {
  font-size: 12px;
  color: var(--text-muted);
}

.wrong-a span {
  font-weight: 500;
}

.wrong-a--correct {
  color: var(--success);
}

.wrong-a--selected {
  color: var(--danger);
}

/* ===== KANJI TEST CONFIG ===== */
.kt-section {
  margin-bottom: 12px;
}

.kt-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kt-range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.kt-mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
}

.kt-mode-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  transition: border-color var(--transition-fast), background var(--transition-fast);
  min-height: 40px;
}

.kt-mode-label:hover {
  border-color: rgba(146, 64, 14, 0.25);
  background: rgba(192, 57, 43, 0.04);
}

.kt-mode-cb {
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.kt-mode-label:has(.kt-mode-cb:checked) {
  border-color: rgba(192, 57, 43, 0.45);
  background: rgba(192, 57, 43, 0.07);
  color: var(--primary-dark);
}

.wrong-mode-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(192, 57, 43, 0.08);
  border: 1px solid rgba(146, 64, 14, 0.20);
  border-radius: var(--radius-full);
  padding: 2px 10px;
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}

/* ===== TEST MAPPING ===== */
.detail-modal--mapping .detail-modal__dialog {
  max-width: 100vw;
  width: 100vw;
  height: 100dvh;
  height: 100vh;
  max-height: 100dvh;
  max-height: 100vh;
  border-radius: 0;
  padding: 8px 8px 6px;
}

.detail-modal--mapping .detail-modal__header {
  padding: 0 60px;
}

.detail-modal--mapping .detail-modal__body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.mapping-game {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  min-height: 0;
}

.mapping-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
  /* Chừa chỗ bên phải cho nút đóng (X) của modal, tránh che số giây đếm ngược */
  padding-right: 42px;
}

.mapping-lives {
  display: flex;
  gap: 2px;
  font-size: 16px;
  line-height: 1;
}

.mapping-heart {
  color: var(--danger);
}

.mapping-heart--lost {
  color: var(--border);
}

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

.mapping-timer {
  font-weight: 700;
  color: var(--primary);
}

.mapping-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 5px;
}

.mapping-tile {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px 6px;
  font-size: clamp(11px, 3.4vw, 15px);
  font-family: var(--font-jp);
  line-height: 1.2;
  cursor: pointer;
  word-break: break-word;
  overflow: hidden;
  transition: border-color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

.mapping-tile:hover {
  border-color: rgba(192, 57, 43, 0.35);
}

.mapping-tile--selected {
  border-color: var(--primary);
  background: rgba(192, 57, 43, 0.1);
  box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.15);
}

.mapping-tile--matched {
  visibility: hidden;
  pointer-events: none;
}

.mapping-tile--wrong-flash {
  border-color: var(--danger);
  background: rgba(244, 63, 94, 0.12);
  animation: mapping-shake 0.3s;
}

@keyframes mapping-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@media (max-width: 420px) {
  .detail-modal--mapping .detail-modal__header {
    padding: 0 50px;
  }
}

/* Kanji test reveal */
.kt-test-reveal {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.kt-test-reveal-banner {
  border-radius: var(--radius-md);
  padding: 12px 14px;
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.45;
}

.kt-test-reveal-banner--correct {
  background: rgba(5, 150, 105, 0.07);
  border-color: rgba(5, 150, 105, 0.25);
}

.kt-test-reveal-banner--wrong {
  background: rgba(245, 158, 11, 0.07);
  border-color: rgba(245, 158, 11, 0.30);
}

.kt-test-reveal-status {
  font-weight: 800;
  font-size: 15px;
  margin-bottom: 6px;
}

.kt-test-reveal-banner--wrong .kt-test-reveal-status {
  color: #b45309;
}

.kt-test-reveal-banner--correct .kt-test-reveal-status {
  color: var(--success);
}

.kt-test-reveal-answer,
.kt-test-reveal-pick,
.kt-test-reveal-mode {
  margin-top: 4px;
}

.kt-test-reveal-mode {
  font-size: 11px;
  opacity: 0.75;
  margin-top: 8px;
}

.kt-test-reveal-em {
  font-weight: 700;
  color: var(--primary);
}

.kd-detail-content--test-reveal {
  flex: 1;
  min-height: 120px;
  max-height: min(52vh, 440px);
  overflow-y: auto;
  padding-bottom: 4px;
}

.kt-test-reveal-footer {
  position: sticky;
  bottom: 0;
  padding-top: 4px;
  margin-top: 4px;
  background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 80%, transparent);
}

.kt-test-reveal-continue {
  width: 100%;
  justify-content: center;
}

/* ===== ASSEMBLE TEST (ghép từ từ tile hiragana) ===== */
.assemble-answer-wrap {
  display: grid;
  grid-template-columns: 28px 1fr 28px;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.assemble-answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.assemble-reveal-spacer {
  width: 28px;
  height: 1px;
}

.assemble-answer-row--wrong {
  animation: assembleShake 0.4s ease;
}

.assemble-answer-row--wrong .assemble-slot--filled {
  border-color: rgba(220, 38, 38, 0.55);
  background: rgba(220, 38, 38, 0.08);
}

@keyframes assembleShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-4px); }
}

.assemble-slot {
  min-width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: rgba(0, 0, 0, 0.02);
  font-family: var(--font-jp);
  font-size: 18px;
  color: var(--text);
  cursor: default;
  padding: 0 6px;
}

.assemble-slot--filled {
  border-style: solid;
  border-color: rgba(192, 57, 43, 0.4);
  background: rgba(192, 57, 43, 0.06);
  cursor: pointer;
}

.assemble-slot--revealed {
  border-style: solid;
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.1);
  color: #b45309;
  cursor: default;
}

.assemble-tile-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.assemble-tile {
  min-width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  font-family: var(--font-jp);
  font-size: 18px;
  color: var(--text);
  padding: 0 8px;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

.assemble-tile:hover:not(:disabled) {
  border-color: rgba(192, 57, 43, 0.35);
  transform: translateY(-1px);
}

.assemble-tile--used,
.assemble-tile:disabled {
  opacity: 0.25;
  cursor: default;
  transform: none;
}

/* Dấu ⚡ gợi ý: không viền/nền, chỉ là icon, nằm bên trái hàng ô ghép từ */
.assemble-reveal-btn {
  border: none;
  background: transparent;
  color: #b45309;
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

.assemble-reveal-btn:hover {
  opacity: 0.7;
}

/* ===== KANJI LIST ITEM ===== */
.kl-item {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid rgba(192, 57, 43, 0.07);
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background var(--transition-fast);
  overflow: hidden;
}

.kl-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--danger);
  transform: scaleY(0);
  transform-origin: center;
  transition: transform 0.18s ease;
  border-radius: 0 2px 2px 0;
}

.kl-item:hover {
  background: rgba(192, 57, 43, 0.04);
}

.kl-item:hover::before {
  transform: scaleY(1);
}

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

.kl-num {
  width: 38px;
  padding: 14px 0 14px 10px;
  font-size: 11px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: #bdbdbd;
  flex-shrink: 0;
  text-align: right;
  letter-spacing: 0.02em;
  font-family: "SF Mono", "Fira Mono", monospace;
}

.kl-char {
  font-family: var(--font-jp);
  font-size: 38px;
  font-weight: 400;
  color: var(--text);
  line-height: 1;
  width: 56px;
  text-align: center;
  flex-shrink: 0;
  padding: 10px 4px;
  letter-spacing: -1px;
}

.kl-item:hover .kl-char {
  color: var(--danger);
}

.kl-item::after {
  content: "";
  position: absolute;
  left: 94px;
  top: 20%;
  height: 60%;
  width: 1px;
  background: rgba(146, 64, 14, 0.08);
}

.kl-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
  padding: 10px 8px 10px 12px;
}

.kl-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1;
}

.kl-readings {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.kl-pill {
  font-size: 12px;
  font-family: var(--font-jp);
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.kl-pill--on::before {
  content: "音";
  font-size: 9px;
  font-family: var(--font-jp);
  font-weight: 700;
  color: var(--danger);
  opacity: 0.8;
  letter-spacing: 0;
}

.kl-pill--kun::before {
  content: "訓";
  font-size: 9px;
  font-family: var(--font-jp);
  font-weight: 700;
  color: var(--success);
  opacity: 0.8;
  letter-spacing: 0;
}

.kl-meaning {
  font-size: 11px;
  font-weight: 500;
  font-style: italic;
  color: var(--text-muted);
  padding: 0 12px 0 0;
  white-space: nowrap;
  flex-shrink: 0;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== KANJI DETAIL — RICH LAYOUT ===== */
.kd-hero {
  position: relative;
  display: block;
  padding: 10px 12px 12px;
  background: linear-gradient(135deg, rgba(192, 57, 43, 0.06), rgba(146, 64, 14, 0.03));
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 4px;
  box-shadow: var(--shadow-card);
}

.kd-hero .kd-index {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 2;
  margin: 0;
}

.kd-hero-main .kd-index {
  position: static;
  top: auto;
  left: auto;
  z-index: auto;
  width: fit-content;
  margin: 0 auto 4px;
  text-align: center;
}

.kd-index-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0 auto 4px;
}

.kd-hero-main .kd-index-row .kd-index {
  margin: 0;
}

.kd-index--level {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary-dark, var(--text-muted));
}

.kd-hero-body {
  display: grid;
  grid-template-columns: 25% 40% 35%;
  align-items: center;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  gap: 8px;
}

.kd-hero-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  overflow: hidden;
  min-width: 0;
  order: 1;
  grid-column: 1;
  justify-self: center;
  width: 100%;
}

.kd-hero-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  padding-top: 2px;
  text-align: center;
  width: 100%;
}

.kd-hero-meta .kd-meaning-badge,
.kd-hero-meta .kd-hanviet {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

.kd-hero-meta .kd-meaning-badge {
  white-space: normal;
  text-align: center;
  line-height: 1.3;
}

.kd-hero-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  justify-content: center;
  gap: 6px;
  width: auto;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin-left: 0;
  order: 3;
  grid-column: 3;
}

.kd-hero-actions > * {
  flex: 0 0 auto;
}

.kd-hero .star-btn {
  position: static;
  font-size: 22px;
  line-height: 1;
  padding: 2px;
  background: none;
  border: none;
  cursor: pointer;
}

.kd-char {
  font-family: var(--font-jp);
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
  color: var(--text);
  letter-spacing: -2px;
  text-shadow: 0 3px 14px rgba(146, 64, 14, 0.15);
  flex-shrink: 0;
}

.kd-hero-main .kd-char {
  width: 100%;
  text-align: center;
}

.kd-hero-mid-kanji {
  position: relative;
  width: 100%;
  max-width: 160px;
  aspect-ratio: 1 / 1;
  margin: 6px 0 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-jp);
  font-size: 86px;
  color: rgba(0, 0, 0, 0.08);
  user-select: none;
  pointer-events: auto;
  order: 2;
  flex: 0 0 auto;
  justify-self: center;
  grid-column: 2;
}

.kd-hero-mid-replay {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: rgba(15, 23, 42, 0.6);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 16px;
  padding: 0;
  transition: background var(--transition-fast);
}

.kd-hero-mid-replay:hover {
  background: rgba(146, 64, 14, 0.08);
  color: var(--primary);
}

.kd-hero-mid-fallback {
  font-family: var(--font-jp);
  font-size: 56px;
  color: rgba(0, 0, 0, 0.10);
  pointer-events: none;
}

/* Hide section titles */
.kd-section-title {
  display: none !important;
}

.kd-index {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(192, 57, 43, 0.07);
  box-shadow: var(--shadow-card);
}

.kd-meaning-badge {
  padding: 3px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  letter-spacing: 0.04em;
  box-shadow: 0 2px 10px rgba(146, 64, 14, 0.25);
  flex-shrink: 0;
}

.kd-hanviet {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  flex-shrink: 0;
}

.kd-mazii-link {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-dark);
  text-decoration: none;
  padding: 4px 9px;
  border-radius: var(--radius-full);
  background: rgba(192, 57, 43, 0.07);
  border: 1px solid rgba(146, 64, 14, 0.20);
  flex-shrink: 0;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.kd-mazii-link:hover {
  background: rgba(146, 64, 14, 0.10);
  border-color: rgba(192, 57, 43, 0.35);
}

button.kd-pip-link {
  font-family: inherit;
  line-height: inherit;
  cursor: pointer;
}

.kd-pip-link--active,
.kd-pip-link--active:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.kd-section {
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 5px;
  border: 1px solid transparent;
}

.kd-section--blue {
  background: rgba(192, 57, 43, 0.05);
  border-color: rgba(192, 57, 43, 0.12);
}

.kd-section--blue .kd-section-title { color: var(--primary-dark); }

.kd-section--amber {
  background: rgba(245, 158, 11, 0.05);
  border-color: rgba(245, 158, 11, 0.20);
}

.kd-section--amber .kd-section-title { color: #b45309; }

.kd-section--green {
  background: rgba(5, 150, 105, 0.05);
  border-color: rgba(5, 150, 105, 0.18);
}

.kd-section--green .kd-section-title { color: #9b2335; }

.kd-section--purple {
  background: rgba(146, 64, 14, 0.04);
  border-color: rgba(146, 64, 14, 0.15);
}

.kd-section--purple .kd-section-title { color: #6b21a8; }

.kd-section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

/* Reading pills */
.kd-pills-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.kd-pill-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 56px;
}

.kd-pill-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.kd-pill-values {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.kd-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-family: var(--font-jp);
  font-weight: 600;
  border: 1px solid transparent;
}

.kd-pill--on {
  background: rgba(192, 57, 43, 0.08);
  border-color: rgba(146, 64, 14, 0.20);
  color: var(--primary-dark);
}

.kd-pill--kun {
  background: rgba(146, 64, 14, 0.07);
  border-color: rgba(146, 64, 14, 0.20);
  color: #92400e;
}

.kd-pill--stroke {
  background: rgba(255, 255, 255, 0.9);
  border-color: var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
}

.kd-pill--radical {
  background: rgba(146, 64, 14, 0.05);
  border-color: rgba(146, 64, 14, 0.20);
  color: #92400e;
  font-size: 12px;
  font-family: inherit;
}

.kd-pill--radical-clickable {
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.kd-pill--radical-clickable:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(146, 64, 14, 0.18);
}

/* Kanji breakdown toggle */
.kd-breakdown-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
  padding: 2px 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.kd-breakdown-toggle-label {
  font-size: 12px;
  font-weight: 700;
  color: #b45309;
}

.kd-breakdown-toggle-icon {
  font-size: 11px;
  color: #b45309;
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.kd-breakdown-body {
  margin-top: 8px;
}

.kd-breakdown-body--collapsed {
  display: none;
}

/* Kanji breakdown tree */
.kd-tree-wrap {
  display: flex;
  justify-content: center;
  overflow-x: auto;
  padding: 4px 4px 10px;
  margin-bottom: 6px;
}

.kd-tree-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.kd-tree-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(245, 158, 11, 0.25);
  min-width: 40px;
}

.kd-tree-char {
  font-family: var(--font-jp);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.kd-tree-label {
  font-size: 9.5px;
  color: #92400e;
  max-width: 84px;
  overflow-wrap: break-word;
  text-align: center;
  line-height: 1.25;
}

.kd-tree-box--clickable {
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.kd-tree-box--clickable:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
}

.kd-tree-children {
  display: flex;
  justify-content: center;
  position: relative;
  margin-top: 14px;
}

.kd-tree-children::before {
  content: "";
  position: absolute;
  top: -14px;
  left: 0;
  right: 0;
  border-top: 1.5px solid rgba(180, 83, 9, 0.35);
}

.kd-tree-children:has(> .kd-tree-node:only-child)::before {
  display: none;
}

.kd-tree-children > .kd-tree-node {
  padding: 14px 8px 0;
}

.kd-tree-children > .kd-tree-node::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 14px;
  border-left: 1.5px solid rgba(180, 83, 9, 0.35);
}

/* Story rows */
.kd-story-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(146, 64, 14, 0.08);
}

.kd-inline-kanji-link {
  cursor: pointer;
  color: var(--primary-dark);
  font-weight: 600;
}

.kd-inline-kanji-link:hover {
  text-decoration: underline;
}

.kd-story-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.kd-story-icon {
  font-size: 16px;
  line-height: 1.4;
  flex-shrink: 0;
}

.kd-story-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.kd-story-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #92400e;
  opacity: 0.7;
}

.kd-story-value {
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}

/* Vocab section */
.kd-vocab-sublabel {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--success);
  opacity: 0.75;
  margin-bottom: 4px;
  margin-top: 2px;
}

.kd-vocab-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.kd-vocab-chip {
  display: flex;
  flex-direction: column;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(5, 150, 105, 0.25);
  gap: 1px;
  min-width: 60px;
  box-shadow: var(--shadow-card);
}

.kd-vocab-chip-word {
  font-family: var(--font-jp);
  font-size: 12px;
  font-weight: 600;
  color: var(--success);
}

.kd-vocab-chip-meaning {
  font-size: 10px;
  color: var(--text-muted);
}

.kd-vocab-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.kd-vocab-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(107, 33, 168, 0.10);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.kd-vocab-row:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(107, 33, 168, 0.22);
}

.kd-vocab-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.kd-vocab-headline {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.kd-vocab-word {
  font-family: var(--font-jp);
  font-size: 18px;
  font-weight: 700;
  color: #6b21a8;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kd-vocab-read {
  font-family: var(--font-jp);
  font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.kd-vocab-hanviet {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #6b21a8;
  background: rgba(107, 33, 168, 0.08);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  flex-shrink: 0;
}

.kd-vocab-mean {
  font-size: 14.5px;
  color: var(--text);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.kd-vocab-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  margin-left: auto;
}

.kd-vocab-actions .star-btn,
.kd-vocab-actions .audio-btn {
  margin: 0;
}

/* Kanji detail 2-column grid */
.kd-detail-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.kd-detail-content > .kd-hero { grid-column: 1 / -1; }
.kd-detail-content > .kd-hanviet { grid-column: 1 / -1; }
.kd-detail-content > .kd-section--blue { grid-column: 1; }
.kd-detail-content > .kd-section--amber { grid-column: 2; }
.kd-detail-content > .kd-section--green { grid-column: 1 / -1; }
.kd-detail-content > .kd-section--writing { grid-column: 1 / -1; }

.detail-modal__body .kd-hero {
  padding: 10px 10px 8px;
  margin-bottom: 2px;
}

.detail-modal__body .kd-char { font-size: 28px; }
.detail-modal__body .kd-meaning-badge {
  margin-top: 2px;
  padding: 2px 10px;
  font-size: 12px;
}

.detail-modal__body .kd-hero-meta .kd-meaning-badge {
  margin-top: 0;
}

.detail-modal__body .kd-hanviet {
  font-size: 15px;
}

.detail-modal__body .kd-section {
  grid-column: 1 / -1;
  margin-bottom: 6px;
  padding: 8px 10px;
  margin-bottom: 3px;
}

.detail-modal__body .kd-section-title { margin-bottom: 3px; }
.detail-modal__body .kd-pills-grid { gap: 4px; }
.detail-modal__body .kd-pill { padding: 3px 8px; font-size: 13px; }
.detail-modal__body .kd-pill--stroke { font-size: 12px; }
.detail-modal__body .kd-pill--radical { font-size: 12px; }
.detail-modal__body .kd-story-row { padding: 3px 0; }
.detail-modal__body .kd-story-label { font-size: 9px; }
.detail-modal__body .kd-story-value { font-size: 13px; }
.detail-modal__body .kd-vocab-list { gap: 5px; }
.detail-modal__body .kd-vocab-row { padding: 7px 9px; gap: 6px; }
.detail-modal__body .kd-vocab-word { font-size: 17px; }
.detail-modal__body .kd-vocab-read { font-size: 13px; }
.detail-modal__body .kd-vocab-hanviet { font-size: 11px; }
.detail-modal__body .kd-vocab-mean { font-size: 14px; }
.detail-modal__body .kd-vocab-chip-word { font-size: 13px; }
.detail-modal__body .kd-vocab-chip-meaning { font-size: 11px; }

/* Mobile 1-column kanji detail */
@media (max-width: 380px) {
  .kd-detail-content { grid-template-columns: 1fr; }
  .kd-detail-content > .kd-section--blue,
  .kd-detail-content > .kd-section--amber { grid-column: 1; }

  .kd-hero {
    padding: 8px 8px 10px;
    border-radius: var(--radius-md);
  }
  .kd-hero .kd-index {
    top: 6px;
    left: 8px;
    font-size: 11px;
    padding: 1px 7px;
  }
  .kd-hero-body {
    padding-top: 2px;
  }
  .kd-hero-main {
    gap: 8px;
    align-items: flex-start;
    min-width: 0;
  }
  .kd-hero-actions {
    width: 85%;
    max-width: 100%;
    margin-left: 5px;
    gap: 5px;
    align-items: center;
    order: 3;
    grid-column: 1;
    justify-content: center;
  }
  .kd-hero-body {
    grid-template-columns: 1fr;
    justify-content: flex-end;
  }
  .kd-hero .kd-char {
    font-size: clamp(44px, 16vw, 54px);
    letter-spacing: -1px;
  }
  .kd-hero-meta .kd-hanviet {
    font-size: 13px;
    letter-spacing: 0.08em;
    line-height: 1.25;
  }
  .kd-hero-meta .kd-meaning-badge {
    font-size: 11px;
    padding: 2px 10px;
    max-width: 100%;
    line-height: 1.2;
  }
  .kd-hero .kd-mazii-link {
    padding: 4px 8px;
    font-size: 10px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
  }
  .kd-hero .star-btn,
  .kd-hero .kd-writing-toggle-btn {
    min-width: 34px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
  }
  .kd-hero-mid-kanji {
    width: min(40vmin, 160px);
    height: min(40vmin, 160px);
    font-size: clamp(60px, 18vmin, 86px);
    order: 2;
    grid-column: 1;
    justify-self: center;
    justify-content: center;
  }
  .detail-modal__body .kd-hero {
    padding: 6px 6px 8px;
  }
  .detail-modal__body .kd-char {
    font-size: 28px;
  }
  .detail-modal__body .kd-hanviet {
    font-size: 13px;
  }
  .detail-modal__dialog {
    padding: 8px;
    gap: 6px;
  }
}

/* ===== KANJI WRITING ===== */
.kd-section--writing {
  padding: 10px 12px;
}

.kd-writing-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid rgba(146, 64, 14, 0.20);
  border-radius: var(--radius-full);
  background: rgba(192, 57, 43, 0.06);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  min-height: 36px;
}

.kd-writing-toggle-btn:hover {
  background: rgba(160, 100, 60, 0.16);
  border-color: rgba(192, 57, 43, 0.35);
}

.kd-writing-panel {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.kd-writing-canvas-wrap {
  position: relative;
  display: block;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fefefe;
  box-shadow: var(--shadow-card);
}

.kd-writing-canvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 240px;
  height: 240px;
  border-radius: 9px;
  cursor: crosshair;
  touch-action: none;
}

.kd-writing-reference {
  z-index: 1;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-jp);
  font-size: 140px;
  color: rgba(0, 0, 0, 0.08);
  pointer-events: none;
  user-select: none;
}

.kd-writing-reference svg {
  width: 100%;
  height: 100%;
  display: block;
}

.kd-writing-reference-loading {
  font-size: 14px;
  font-weight: 700;
  color: rgba(15, 23, 42, 0.50);
}

.kd-writing-ref-stroke {
  opacity: 0;
}

.kd-writing-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.kd-writing-btn {
  width: 120px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.kd-writing-btn:hover {
  background: rgba(192, 57, 43, 0.06);
  border-color: rgba(192, 57, 43, 0.35);
  color: var(--primary);
}

.kd-writing-settings {
  display: none;
  width: min(92vw, 520px);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.kd-writing-setting {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.95);
}

.kd-writing-setting-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.kd-writing-select,
.kd-writing-range {
  width: 100%;
}

.kd-writing-range-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
}

.detail-modal__body .kd-section--writing { padding: 8px 10px 10px; }
.detail-modal__body .kd-writing-canvas { width: 200px; height: 200px; }
.detail-modal__body .kd-writing-reference { font-size: 120px; }

/* Practice mode */
.detail-modal--practice .detail-modal__dialog {
  max-width: 920px;
}

.detail-modal--practice .detail-modal__body {
  display: flex;
  justify-content: center;
}

.kd-writing-modal {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
}

.detail-modal--practice .kd-writing-canvas-wrap {
  margin-bottom: 0;
}

.detail-modal--practice .kd-writing-canvas {
  width: min(86vmin, 520px);
  height: min(86vmin, 520px);
}

.detail-modal--practice .kd-writing-reference {
  font-size: clamp(220px, 48vmin, 420px);
}

/* ===== SOUND OVERLAY ===== */
#soundOverlay {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(192, 57, 43, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #ffffff;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.25s ease;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(192, 57, 43, 0.35);
}

#soundOverlay.show {
  opacity: 1;
  transform: scale(1);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.35); }
  70% { box-shadow: 0 0 0 14px rgba(192, 57, 43, 0); }
  100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0); }
}

@keyframes audio-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.15); }
}

.hidden {
    display: none !important;
}

.disabled-gray {
    background-color: #eaedf1 !important; /* Màu nền xám nhạt */
    color: #9ca3af !important;            /* Màu chữ xám mờ */
    border-color: #d1d5db !important;     /* Viền xám nhạt */
    cursor: not-allowed;                  /* Con trỏ chuột hình cấm */
    opacity: 0.7;                         /* Làm mờ nhẹ toàn bộ ô */
}

.filter-icon-btn2{
    width:36px !important;
    height:36px !important;
    border:0 !important;
    border-radius:50% !important;
    background:#2563eb !important;
    color:#fff !important;
    display:flex !important;
    align-items:center !important;
    justify-content:center !important;
    font-size:13px !important;
    font-weight:600 !important;
    text-decoration:none !important;
    cursor:pointer !important;
    box-shadow:0 5px 15px #0003 !important;
}

/* ===== FAB MENU (góc dưới-phải tab Từ vựng / Kanji: bấm nút tròn để xổ danh sách thao tác) ===== */
.fab-menu {
  position: fixed;
  right: calc(4px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 35; /* dưới .detail-modal (40) để modal che được FAB */
}

.fab-menu__toggle {
  position: relative;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(192, 57, 43, 0.25);
  border-radius: 50%;
  background: rgba(255, 254, 249, 0.96);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-hover);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast),
    background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.fab-menu--open .fab-menu__toggle {
  background: #fbeee9;
}

.fab-menu__toggle svg {
  width: 18px;
  height: 18px;
  transition: transform var(--transition-med);
}

.fab-menu--open .fab-menu__toggle svg {
  transform: rotate(45deg);
}

.fab-menu__toggle:active {
  transform: scale(0.94);
}

.fab-menu__toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.2), var(--shadow-hover);
}

.fab-menu__list {
  position: absolute;
  right: 2px; /* căn tâm icon 34px thẳng tâm nút 38px */
  bottom: calc(100% + 8px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
}

.fab-menu--open .fab-menu__list {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.fab-menu__item {
  display: inline-flex;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.fab-menu__item:focus-visible {
  outline: none;
}

.fab-menu__icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid rgba(192, 57, 43, 0.22);
  color: var(--primary);
  box-shadow: var(--shadow-card);
  font-family: var(--font-jp);
  font-size: 15px;
  font-weight: 600;
  transition: background var(--transition-fast), color var(--transition-fast),
    border-color var(--transition-fast), transform var(--transition-fast);
}

.fab-menu__icon svg {
  width: 16px;
  height: 16px;
}

.fab-menu__item:hover .fab-menu__icon,
.fab-menu__item:focus-visible .fab-menu__icon {
  background: #fbeee9;
  border-color: rgba(192, 57, 43, 0.35);
  color: var(--primary-dark);
}

.fab-menu__item:active .fab-menu__icon {
  transform: scale(0.92);
}

@media (prefers-reduced-motion: reduce) {
  .fab-menu__list,
  .fab-menu__toggle svg {
    transition: none;
  }
}

.icon-search {
  padding: 6px;
  text-decoration: none;
}

/* ===== SECTION IDs ===== */
#section-vocab,
#section-kanji,
#section-grammar,
#section-note,
#section-stars {
  /* Individual section ID targets — extend as needed */
}

/* Vocab edit tab (vocabData_1_TvkS.js editor) */
.vocab-edit-tab-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  flex: 1 1 auto;
}

.vocab-edit-tab-stack > .card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.vocab-edit-tab-stack .card-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
}

.vocab-edit-io-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  background: rgba(255, 255, 255, 0.6);
  padding: 10px;
}

.vocab-edit-io-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.vocab-edit-col-checks {
  margin-top: 6px;
}

.vocab-edit-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  white-space: nowrap;
}

.vocab-edit-table th,
.vocab-edit-table td {
  border: 1px solid var(--border);
  padding: 4px 6px;
  text-align: left;
}

.vocab-edit-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface, #fffefa);
  z-index: 1;
}

.vocab-edit-th-stt,
.vocab-edit-stt {
  text-align: center;
  color: var(--text-muted, #888);
}

.vocab-edit-input {
  width: 140px;
  border: 1px solid transparent;
  background: transparent;
  padding: 3px 4px;
  border-radius: 4px;
  font: inherit;
}

.vocab-edit-input:hover,
.vocab-edit-input:focus {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.9);
}

.vocab-edit-input--narrow {
  width: 56px;
}

.vocab-edit-del-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
}

.vocab-edit-del-btn:hover {
  opacity: 0.7;
}

/* ===== SCROLL TO TOP (FAB trong khung có scroll riêng, vd. bảng Sửa từ vựng) ===== */
.scroll-top-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-hover);
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
}

.scroll-top-btn--visible {
  opacity: 0.92;
  visibility: visible;
  transform: translateY(0);
}

.scroll-top-btn:hover {
  opacity: 1;
}

/* ===== VOCAB EDIT — MOBILE (bảng chuyển thành danh sách thẻ, mỗi dòng 1 khối) ===== */
@media (max-width: 640px) {
  .vocab-edit-title-file {
    display: none;
  }

  .vocab-edit-tab-stack .section-header {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  .vocab-edit-tab-stack .section-header > div {
    gap: 4px !important;
  }

  #vocab-edit-summary {
    flex-basis: 100%;
    order: 3;
    font-size: 11px;
  }

  .vocab-edit-tab-stack .btn-row {
    order: 4;
    width: 100%;
    margin-left: 0 !important;
    flex-wrap: nowrap !important;
    flex-shrink: 1;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .vocab-edit-tab-stack .btn-row .btn-ghost {
    flex: 0 0 auto;
    padding: 5px 10px;
    font-size: 11px;
    min-height: 30px;
    white-space: nowrap;
  }

  .vocab-edit-io-row {
    flex-direction: column;
    align-items: stretch;
  }

  #vocab-edit-search-row {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  #vocab-edit-search-row #vocab-edit-search-input {
    flex: 1 1 100%;
  }

  #vocab-edit-search-row .field-label {
    flex: 0 0 auto;
    align-self: center;
  }

  #vocab-edit-search-row input[type="number"] {
    flex: 1 1 60px;
    min-width: 0;
  }

  .vocab-edit-table {
    white-space: normal;
  }

  .vocab-edit-table thead {
    display: none;
  }

  .vocab-edit-table,
  .vocab-edit-table tbody,
  .vocab-edit-table tr {
    display: block;
    width: 100%;
  }

  .vocab-edit-table tr {
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 10px);
    background: var(--bg-card);
    padding: 6px 8px;
  }

  .vocab-edit-table td {
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 6px 2px;
  }

  .vocab-edit-table td:last-child {
    border-bottom: none;
  }

  .vocab-edit-table td::before {
    content: attr(data-label);
    flex: 0 0 84px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted, #888);
  }

  .vocab-edit-th-stt,
  .vocab-edit-stt {
    text-align: left;
  }

  .vocab-edit-input,
  .vocab-edit-input--narrow {
    width: 100%;
    flex: 1 1 auto;
  }

  .vocab-edit-del-btn {
    margin-left: auto;
  }
}
