/* Duanfangcao · Light Pastel Stationery Theme (Desktop + iPad + iPhone Ready) */
:root {
  --g1: #FFF4D6;
  --g2: #FFE2A8;
  --g3: #FFD1B8;
  --acc: #F6C445;
  --acc-dark: #7a5000;
  --acc-soft: #fff8e1;

  --ink: #2b2118;
  --ink2: #4a3f33;
  --soft: #655a4d;
  --line: #d8cfc2;

  --sf: #ffffff;
  --sf2: #fffdf8;
  --sf3: #f6efe2;
  --card: rgba(255, 255, 255, 0.88);
  --note: #fff8e1;

  --k-ok: #047857;
  --k-warn: #9A4A00;
  --k-bad: #B42318;
  --k-info: #1D4ED8;
  --k-hv: #7E22CE;

  --font-ui: 'Be Vietnam Pro', 'Noto Sans', system-ui, -apple-system, sans-serif;
  --font-han: 'Noto Serif SC', 'Songti SC', 'SimSun', 'STSong', serif;
  --shadow: 0 6px 22px rgba(60, 40, 10, 0.08);
  --border-ink: 2px solid rgba(43, 33, 24, 0.88);
  --reader-size: 1.92rem;
}

/* 5 Switchable Pastel Themes */
body[data-theme="honey"] {
  --g1: #FFF4D6; --g2: #FFE2A8; --g3: #FFD1B8;
  --acc: #F6C445; --acc-dark: #7a5000; --acc-soft: #fff8e1;
}
body[data-theme="peach"] {
  --g1: #FFE3EC; --g2: #FFD0DD; --g3: #FFE9D6;
  --acc: #F5A9BD; --acc-dark: #A8274F; --acc-soft: #fff0f5;
}
body[data-theme="matcha"] {
  --g1: #E6F4D7; --g2: #D3EBC0; --g3: #F5F2C8;
  --acc: #A5D77F; --acc-dark: #2c5e0f; --acc-soft: #f2fae9;
}
body[data-theme="sky"] {
  --g1: #DDEFFF; --g2: #CFE0FF; --g3: #E6F6F3;
  --acc: #8EC5F5; --acc-dark: #1B5A9E; --acc-soft: #eef7ff;
}
body[data-theme="lavender"] {
  --g1: #EBE3FF; --g2: #F7D9F0; --g3: #DDE9FF;
  --acc: #BCA5F2; --acc-dark: #5835b0; --acc-soft: #f5f1ff;
}

body.font-sans-han {
  --font-han: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
body.font-kaiti-han {
  --font-han: 'KaiTi', 'STKaiti', 'Kaiti SC', 'LXGW WenKai', serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  line-height: 1.55;
  background-color: var(--g1);
  background-image: linear-gradient(135deg, var(--g1) 0%, var(--g2) 55%, var(--g3) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

.han {
  font-family: var(--font-han);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar (Desktop >= 920px) */
.sidebar {
  width: 256px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.56);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1.5px solid rgba(43, 33, 24, 0.14);
  padding: 1.15rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 1.05rem;
  z-index: 40;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.6rem;
  background: rgba(255, 255, 255, 0.8);
  border: var(--border-ink);
  border-radius: 18px;
  box-shadow: 0 3px 10px rgba(43, 33, 24, 0.06);
}

.brand-avatar {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--acc);
  border: 1.5px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-han);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--ink);
  flex-shrink: 0;
}

.brand-info h1 {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.2;
}

.brand-info p {
  font-size: 0.72rem;
  color: var(--soft);
  font-weight: 600;
}

.nav-group-label {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--soft);
  padding: 0 0.55rem;
  margin-bottom: 0.35rem;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 14px;
  padding: 0.45rem 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink2);
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.16s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

.nav-item.active {
  background: var(--sf);
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(43, 33, 24, 0.08);
}

.nav-item .sh {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--sf);
  border: 1.5px solid var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-han);
  font-size: 1rem;
  font-weight: 700;
  color: var(--acc-dark);
  flex-shrink: 0;
}

.nav-item.active .sh {
  background: var(--acc);
  color: var(--ink);
}

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: var(--sf3);
  border: 1px solid rgba(43, 33, 24, 0.2);
  color: var(--ink2);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1.5px solid rgba(43, 33, 24, 0.12);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.theme-swatches {
  display: flex;
  gap: 0.45rem;
  padding: 0 0.4rem;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(43, 33, 24, 0.35);
  cursor: pointer;
  transition: transform 0.15s;
}

.swatch:hover { transform: scale(1.1); }
.swatch.active {
  border: 2.5px solid var(--ink);
  transform: scale(1.12);
  box-shadow: 0 2px 8px rgba(43, 33, 24, 0.2);
}

/* Mobile / iPad Portrait Header + Bottom Tabs + Safe Areas */
.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 45;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1.5px solid rgba(43, 33, 24, 0.14);
  padding: calc(0.55rem + env(safe-area-inset-top, 0px)) 1rem 0.55rem;
  align-items: center;
  justify-content: space-between;
}

.mobile-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1.5px solid rgba(43, 33, 24, 0.18);
  padding: 0.35rem 0.25rem calc(0.4rem + env(safe-area-inset-bottom, 0px));
  justify-content: space-around;
}

.mobile-tab-btn {
  background: transparent;
  border: none;
  min-width: 52px;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: var(--font-ui);
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--soft);
  padding: 0.25rem 0.4rem;
  border-radius: 12px;
  cursor: pointer;
}

.mobile-tab-btn.active {
  color: var(--ink);
  background: var(--acc);
}

/* Mobile More Drawer Sheet */
.more-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 95;
  background: rgba(43, 33, 24, 0.38);
  backdrop-filter: blur(3px);
  align-items: flex-end;
}

.more-drawer-backdrop.open { display: flex; }

.more-drawer {
  width: 100%;
  background: var(--sf2);
  border-top: 2.5px solid var(--ink);
  border-radius: 24px 24px 0 0;
  padding: 1.2rem 1.2rem calc(1.4rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Main Content */
.main-wrap {
  flex: 1;
  min-width: 0;
  padding: 1.4rem 1.65rem 3.5rem;
}

.content-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
}

.page-title {
  font-size: 1.42rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.page-subtitle {
  font-size: 0.88rem;
  color: var(--soft);
  font-weight: 500;
}

/* Cards */
.card {
  background: var(--card);
  border: var(--border-ink);
  border-radius: 24px;
  padding: 1.3rem 1.4rem;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1.04rem;
  font-weight: 800;
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Pills & Buttons (Touch-friendly >= 44px on mobile) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  min-height: 42px;
  padding: 0.52rem 1.1rem;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--acc);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.87rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
  text-decoration: none;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(43, 33, 24, 0.14);
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.dark { background: var(--ink); color: #ffffff; }
.btn.ghost { background: var(--sf); color: var(--ink); }
.btn.sm { min-height: 36px; padding: 0.34rem 0.78rem; font-size: 0.78rem; border-width: 1.5px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 36px;
  padding: 0.36rem 0.85rem;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: var(--sf);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.14s;
}

.chip:hover { background: var(--sf3); }
.chip.on { background: var(--ink); color: #ffffff; }
.chip.acc { background: var(--acc); color: var(--ink); }

/* Stat Tiles */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.7rem;
}

.stat-tile {
  background: var(--sf);
  border: 1.5px solid var(--ink);
  border-radius: 18px;
  padding: 0.8rem 0.65rem;
  text-align: center;
  cursor: pointer;
  transition: transform 0.14s, background 0.14s;
}

.stat-tile:hover { transform: translateY(-2px); background: var(--acc-soft); }
.stat-num { font-size: 1.45rem; font-weight: 800; line-height: 1.15; }
.stat-lbl { font-size: 0.75rem; color: var(--soft); font-weight: 600; margin-top: 0.15rem; }

/* HSK Level Multi-Select Grid (Clean 7-up on wide, auto-fit on tablet/mobile) */
.hlv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(134px, 1fr));
  gap: 0.6rem;
}

.hlv-card {
  background: var(--sf);
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 0.75rem 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
}

.hlv-card:hover { transform: translateY(-2px); }
.hlv-card.on { background: var(--acc); }

.hlv-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
  font-weight: 800;
  font-size: 0.92rem;
  white-space: nowrap;
}

.hlv-status-pill {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(43, 33, 24, 0.25);
  color: var(--ink);
}

.hlv-card.on .hlv-status-pill {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.hlv-count {
  font-size: 0.74rem;
  color: var(--ink2);
  font-weight: 600;
  line-height: 1.3;
}

.prog-track {
  height: 7px;
  background: rgba(43, 33, 24, 0.14);
  border-radius: 999px;
  overflow: hidden;
}

.prog-fill {
  height: 100%;
  background: var(--ink);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Roadmap Stages */
.roadmap-timeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
}

.stage-box {
  background: var(--sf2);
  border: 1.5px solid var(--ink);
  border-radius: 18px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.stage-box.current { background: var(--note); border-width: 2px; }
.stage-tag {
  display: inline-block;
  width: fit-content;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--acc);
  border: 1px solid var(--ink);
}

/* Toolbar & Inputs (16px font-size prevents iOS Safari zoom!) */
.controls-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
}

.search-pill {
  width: 100%;
  max-width: 380px;
  min-height: 44px;
  background: var(--sf);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  outline: none;
}

.search-pill:focus { box-shadow: 0 0 0 3px rgba(246, 196, 69, 0.45); }

/* Word Tiles Grid */
.word-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 0.65rem;
}

.w-tile {
  background: var(--sf);
  border: 1.5px solid rgba(43, 33, 24, 0.25);
  border-radius: 16px;
  padding: 0.72rem 0.52rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 114px;
}

.w-tile:hover {
  border-color: var(--ink);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(43, 33, 24, 0.1);
}

.w-tile.mastered { background: #effaf3; border-color: #2e8b57; }
.w-tile.learning { background: #fffbeb; border-color: #d97706; }
.w-tile.in-album { outline: 2.5px solid var(--acc-dark); background: var(--acc-soft); }

.w-tile-lv { position: absolute; top: 5px; left: 7px; font-size: 0.62rem; font-weight: 800; color: var(--soft); }
.w-tile-status { position: absolute; top: 5px; right: 7px; font-size: 0.72rem; }
.w-tile-han { font-family: var(--font-han); font-size: 2.02rem; font-weight: 700; color: var(--ink); line-height: 1.2; margin-top: 0.35rem; }
.w-tile-py { font-size: 0.78rem; font-weight: 700; color: var(--k-ok); }
.w-tile-hv { font-size: 0.68rem; font-weight: 800; color: var(--k-hv); }
.w-tile-vi { font-size: 0.72rem; color: var(--soft); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.25; }

/* List Rows */
.word-list-rows { display: flex; flex-direction: column; gap: 0.55rem; }
.w-row {
  background: var(--sf);
  border: 1.5px solid rgba(43, 33, 24, 0.25);
  border-radius: 16px;
  padding: 0.78rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  transition: all 0.14s;
}
.w-row:hover { border-color: var(--ink); background: var(--sf2); }
.w-row-han { font-family: var(--font-han); font-size: 2.28rem; font-weight: 700; min-width: 112px; text-align: center; }
.w-row-mid { flex: 1; min-width: 0; }
.w-row-top { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.tag {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(43, 33, 24, 0.25);
  background: var(--sf3);
}
.tag.hv { background: #f3e8ff; color: #6b21a8; }
.tag.lv { background: #fff0c7; color: #7a5000; }
.tag.rad { background: #e0f2fe; color: #075985; }
.tag.pos { background: #ddf5e4; color: #065f46; }

/* Scientific Flashcard 3D Flip + Memory Layers */
.fc-wrap { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.fc-perspective { perspective: 1200px; }
.fc-card {
  background: var(--sf);
  border: 2.5px solid var(--ink);
  border-radius: 28px;
  padding: 1.85rem 1.6rem;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  cursor: pointer;
  touch-action: pan-y;
  box-shadow: 0 12px 30px rgba(43, 33, 24, 0.1);
  transition: transform 0.25s ease, box-shadow 0.2s ease;
}
.fc-card:hover { box-shadow: 0 16px 36px rgba(43, 33, 24, 0.14); }
.fc-card.flipped {
  justify-content: flex-start;
  padding-top: 2.8rem;
  background: linear-gradient(180deg, #ffffff 0%, var(--sf2) 100%);
}
.fc-layer-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-top: 0.85rem;
  text-align: left;
}
.fc-layer-box {
  background: var(--sf3);
  border: 1.5px solid rgba(43, 33, 24, 0.18);
  border-radius: 16px;
  padding: 0.7rem 0.85rem;
}
.fc-layer-title {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--soft);
  margin-bottom: 0.35rem;
}
.fc-rel-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  margin: 2px;
  background: var(--sf);
  border: 1.5px solid rgba(43, 33, 24, 0.25);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.fc-rel-chip:hover { background: var(--acc); border-color: var(--ink); }

/* Game Nối Từ (Word Match & Word Chain) */
.match-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
  margin-top: 0.75rem;
}
.match-col { display: flex; flex-direction: column; gap: 0.55rem; }
.match-tile {
  min-height: 60px;
  background: var(--sf);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 0.6rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.14s;
  user-select: none;
}
.match-tile:hover:not(.matched) { background: var(--sf3); transform: translateY(-1px); }
.match-tile.selected { background: var(--acc); box-shadow: 0 0 0 3px rgba(43,33,24,0.2); transform: scale(1.02); }
.match-tile.matched { background: #ccf2de; border-color: #047857; color: #065f46; opacity: 0.55; cursor: default; transform: scale(0.97); }
.match-tile.wrong { background: #ffdcd6; border-color: #b91c1c; animation: shakeTile 0.3s; }
@keyframes shakeTile {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.chain-track {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.9rem;
  background: var(--sf3);
  border: 1.5px solid var(--ink);
  border-radius: 18px;
  margin: 0.75rem 0;
}
.chain-node {
  background: var(--sf);
  border: 1.5px solid var(--ink);
  border-radius: 14px;
  padding: 0.45rem 0.75rem;
  text-align: center;
  cursor: pointer;
}
.chain-node.current { background: var(--acc); border-width: 2px; }

/* Mindmap 11,083 Từ HSK 1 -> HSK 9 */
.mm-progression-bar {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
}
.mm-tier-pill {
  flex: 1;
  min-width: 112px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 0.65rem 0.6rem;
  text-align: center;
  cursor: pointer;
  background: var(--sf);
  transition: transform 0.14s;
}
.mm-tier-pill:hover { transform: translateY(-2px); }
.mm-tier-1 { background: #fef9c3; }
.mm-tier-2 { background: #fde68a; }
.mm-tier-3 { background: #fed7aa; }
.mm-tier-4 { background: #fecaca; }
.mm-tier-5 { background: #e9d5ff; }
.mm-tier-6 { background: #bfdbfe; }
.mm-tier-7 { background: #a7f3d0; }

.mm-canvas-box {
  position: relative;
  background: var(--sf2);
  border: 2px solid var(--ink);
  border-radius: 22px;
  padding: 1.25rem;
  overflow-x: auto;
}
.mm-tree {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1.2rem;
  align-items: center;
  min-width: 640px;
}
.mm-root-node {
  background: var(--acc);
  border: 2.5px solid var(--ink);
  border-radius: 24px;
  padding: 1.25rem 0.9rem;
  text-align: center;
  box-shadow: 0 8px 20px rgba(43,33,24,0.12);
}
.mm-branches {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  border-left: 3px solid var(--ink);
  padding-left: 1.15rem;
}
.mm-branch-row {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  position: relative;
}
.mm-branch-row::before {
  content: '';
  position: absolute;
  left: -1.15rem;
  top: 16px;
  width: 1.15rem;
  height: 2.5px;
  background: var(--ink);
}
.mm-lv-badge {
  min-width: 78px;
  padding: 0.32rem 0.55rem;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  font-size: 0.75rem;
  font-weight: 800;
  text-align: center;
  flex-shrink: 0;
}
.mm-word-nodes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.mm-word-chip {
  background: var(--sf);
  border: 1.5px solid rgba(43, 33, 24, 0.35);
  border-radius: 14px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.14s;
}
.mm-word-chip:hover { border-color: var(--ink); background: var(--acc-soft); transform: translateY(-2px); }
.fc-top-meta {
  position: absolute;
  top: 1.05rem;
  left: 1.35rem;
  right: 1.35rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--soft);
}
.fc-hanzi { font-family: var(--font-han); font-size: 5.45rem; font-weight: 700; line-height: 1.15; color: var(--ink); margin: 0.8rem 0 0.4rem; }
.fc-pinyin { font-size: 1.28rem; font-weight: 700; color: var(--k-ok); margin-bottom: 0.45rem; }
.fc-meaning { font-size: 1.2rem; font-weight: 800; color: var(--ink); margin-bottom: 0.9rem; }
.fc-ex-box {
  width: 100%;
  background: var(--sf3);
  border: 1.5px solid rgba(43, 33, 24, 0.18);
  border-radius: 16px;
  padding: 0.85rem 1.1rem;
  text-align: left;
}
.fc-ex-cn { font-family: var(--font-han); font-size: 1.58rem; font-weight: 700; color: var(--ink); }
.fc-ex-vi { font-size: 0.86rem; color: var(--soft); margin-top: 0.25rem; }

.srs-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.srs-btn {
  border: 2px solid var(--ink);
  border-radius: 16px;
  min-height: 54px;
  padding: 0.6rem 0.5rem;
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  transition: transform 0.12s;
}
.srs-btn:hover { transform: translateY(-2px); }
.srs-btn span.sub { font-size: 0.7rem; font-weight: 600; opacity: 0.85; }
.srs-r1 { background: #ffdcd6; color: #7f1d1d; }
.srs-r2 { background: #fff0c7; color: #78350f; }
.srs-r3 { background: #d8edb0; color: #14532d; }
.srs-r4 { background: #ccf2de; color: #064e3b; }

/* Quiz */
.quiz-box { max-width: 660px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.quiz-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.quiz-opt {
  min-height: 54px;
  background: var(--sf);
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 0.9rem 1rem;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.14s;
}
.quiz-opt:hover:not(:disabled) { background: var(--acc-soft); transform: translateY(-1px); }
.quiz-opt.ok { background: #ccf2de !important; border-color: #047857 !important; }
.quiz-opt.bad { background: #ffdcd6 !important; border-color: #b91c1c !important; }

/* 1,000 Reading Passages Library & Reader */
.reading-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

.r-card {
  background: var(--sf);
  border: 1.5px solid rgba(43, 33, 24, 0.28);
  border-radius: 18px;
  padding: 0.95rem 1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: all 0.15s;
}

.r-card:hover { border-color: var(--ink); transform: translateY(-2px); box-shadow: 0 5px 14px rgba(43,33,24,0.09); }
.r-card.read { background: #effaf3; border-color: #2e8b57; }
.r-card-title { font-weight: 800; font-size: 0.95rem; color: var(--ink); }
.r-card-snippet { font-family: var(--font-han); font-size: 1.24rem; color: var(--soft); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.reader-text {
  font-family: var(--font-han);
  font-size: var(--reader-size);
  line-height: 1.95;
  padding: 0.9rem 0.2rem;
  letter-spacing: 0;
  word-spacing: 0;
  white-space: pre-wrap;
}

.reader-text.has-ruby {
  line-height: 2.5;
}

.r-seg {
  display: inline;
  padding: 0;
  margin: 0;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s;
}
.r-seg:hover, .r-seg:active { background: var(--acc); }
.r-seg.known-hl { border-bottom: none; }
.r-seg.hsk-hl { color: #b91c1c; border-bottom: 1.5px solid rgba(185, 28, 28, 0.35); }

.reader-ruby {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 0 2px 5px;
  padding: 1px 1px;
  vertical-align: bottom;
}
.reader-ruby .py {
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 700;
  color: #065f46;
  letter-spacing: 0.1px;
  line-height: 1.25;
  margin-bottom: 1px;
  white-space: nowrap;
}

.reader-trans-box {
  background: var(--note);
  border: 1.5px solid var(--ink);
  border-left: 5px solid var(--ink);
  border-radius: 16px;
  padding: 1rem 1.15rem;
  margin: 0.85rem 0 1.15rem;
  font-size: 0.96rem;
  line-height: 1.65;
  color: var(--ink);
}

.ex-tabs-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.ex-item-card {
  background: var(--sf);
  border: 1.5px solid rgba(43, 33, 24, 0.28);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.ex-q-han {
  font-family: var(--font-han);
  font-size: 1.42rem;
  font-weight: 700;
  line-height: 1.65;
  color: var(--ink);
}

.ex-opt-han {
  font-family: var(--font-han);
  font-size: 1.28rem;
  font-weight: 700;
  line-height: 1.4;
}

.evidence-hl {
  background: linear-gradient(120deg, #fde047 0%, #fef08a 100%);
  font-weight: 700;
  border-bottom: 3px solid #b45309;
  border-radius: 6px;
  padding: 2px 3px;
  box-shadow: 0 2px 10px rgba(234, 179, 8, 0.38);
}

.ex-explain-box {
  background: #f0fdf4;
  border: 1.5px solid #16a34a;
  border-radius: 14px;
  padding: 0.78rem 0.95rem;
  font-size: 0.88rem;
  color: #14532d;
  line-height: 1.6;
}

.reading-q-box {
  background: var(--sf2);
  border: 2px solid var(--ink);
  border-radius: 20px;
  padding: 1.1rem 1.15rem;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

/* Writing Canvas */
.write-layout {
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 1.1rem;
  align-items: start;
}

.canvas-stage { display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }
.mi-grid-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  background: #fffdf8;
  border: 2.5px solid var(--ink);
  border-radius: 18px;
  overflow: hidden;
  touch-action: none;
}
.mi-grid-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-han);
  font-size: 175px;
  color: rgba(43, 33, 24, 0.1);
  user-select: none;
}
.mi-grid-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, transparent 49.5%, rgba(180, 35, 24, 0.2) 49.5%, rgba(180, 35, 24, 0.2) 50.5%, transparent 50.5%),
    linear-gradient(to bottom, transparent 49.5%, rgba(180, 35, 24, 0.2) 49.5%, rgba(180, 35, 24, 0.2) 50.5%, transparent 50.5%);
}
#writeCanvas { position: relative; z-index: 2; cursor: crosshair; touch-action: none; }

/* Modal / Detail Sheet */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(43, 33, 24, 0.42);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }

.modal-sheet {
  width: 100%;
  max-width: 580px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--sf2);
  border: 2.5px solid var(--ink);
  border-radius: 26px;
  padding: 1.4rem;
  box-shadow: 0 18px 50px rgba(43, 33, 24, 0.25);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.char-breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.6rem;
}
.char-card {
  background: var(--sf);
  border: 1.5px solid rgba(43, 33, 24, 0.22);
  border-radius: 14px;
  padding: 0.65rem;
}

.hidden { display: none !important; }

/* Fullscreen Reading Mode (Works on PC, iPad, iPhone) */
body.reader-fullscreen .sidebar,
body.reader-fullscreen .mobile-bar,
body.reader-fullscreen #view-reader > .page-header {
  display: none !important;
}
body.reader-fullscreen .main-wrap {
  padding: calc(0.65rem + env(safe-area-inset-top, 0px)) 0.85rem calc(5rem + env(safe-area-inset-bottom, 0px));
}
body.reader-fullscreen .content-inner {
  max-width: 100%;
}
body.reader-fullscreen #readerArticleCard {
  border-radius: 18px;
  min-height: calc(100vh - 1.5rem);
}

/* iPad Landscape (921px - 1180px) */
@media (max-width: 1180px) and (min-width: 921px) {
  .sidebar { width: 224px; padding: 1rem 0.7rem; }
  .main-wrap { padding: 1.2rem 1.15rem 3rem; }
}

/* iPad Portrait & Mobile (<= 920px) */
@media (max-width: 920px) {
  .sidebar { display: none; }
  .mobile-bar { display: flex; }
  .mobile-tabs { display: flex; }
  .main-wrap { padding: 0.95rem 0.85rem calc(5.8rem + env(safe-area-inset-bottom, 0px)); }
  .card { border-radius: 20px; padding: 1.05rem 1rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .quiz-opts { grid-template-columns: 1fr; }
  .srs-grid { grid-template-columns: repeat(2, 1fr); }
  .fc-layer-grid { grid-template-columns: 1fr; }
  .match-board { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .mm-tree { grid-template-columns: 1fr; min-width: 0; }
  .mm-branches { border-left: none; padding-left: 0; }
  .mm-branch-row::before { display: none; }
  .write-layout { grid-template-columns: 1fr; }
  .fc-hanzi { font-size: 4.55rem; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-sheet {
    border-radius: 26px 26px 0 0;
    max-height: 86vh;
    padding: 1.25rem 1.1rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 480px) {
  .word-tile-grid { grid-template-columns: repeat(3, 1fr); gap: 0.45rem; }
  .w-tile { min-height: 100px; padding: 0.55rem 0.35rem; }
  .w-tile-han { font-size: 1.8rem; }
  .reading-list-grid { grid-template-columns: 1fr; }
}

/* Worksheet Preview Modal + A4 Print Styles */
.ws-modal-shell {
  width: 100%;
  max-width: 960px;
  max-height: 92vh;
  background: #f1f5f9;
  border: 2.5px solid var(--ink);
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.ws-toolbar {
  background: #ffffff;
  border-bottom: 1.5px solid #cbd5e1;
  padding: 0.9rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.ws-controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
}

.ws-controls-row label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.ws-controls-row select {
  padding: 0.32rem 0.6rem;
  border-radius: 8px;
  border: 1.5px solid #94a3b8;
  background: #ffffff;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  color: #0f172a;
}

.ws-preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem;
  display: flex;
  justify-content: center;
}

.ws-a4-page {
  width: 100%;
  max-width: 840px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 22px 26px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.08);
  height: fit-content;
}

#printArea { display: none; }

.a4-sheet {
  font-family: var(--font-ui);
  color: #1f1b18;
  background: #ffffff;
  --ws-main: #b91c1c;
  --ws-dash: #e79d9d;
  --ws-diag: #f0bbbb;
}

.a4-sheet.ws-blue { --ws-main: #1d4ed8; --ws-dash: #93c5fd; --ws-diag: #bfdbfe; }
.a4-sheet.ws-green { --ws-main: #15803d; --ws-dash: #86efac; --ws-diag: #bbf7d0; }
.a4-sheet.ws-gray { --ws-main: #475569; --ws-dash: #cbd5e1; --ws-diag: #e2e8f0; }

.a4-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 2.5px solid var(--ws-main);
  padding-bottom: 8px;
  margin-bottom: 16px;
  gap: 12px;
}

.a4-title {
  color: var(--ws-main);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.25;
}

.a4-sub {
  font-size: 11px;
  color: #4b5563;
  margin-top: 3px;
  font-weight: 600;
}

.a4-meta-right {
  text-align: right;
  font-size: 11px;
  color: #374151;
  line-height: 1.65;
  min-width: 195px;
}

.a4-word-block {
  margin-bottom: 16px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.a4-word-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
}

.a4-word-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.a4-idx { color: #6b7280; font-weight: 700; font-size: 12.5px; }
.a4-han { font-family: var(--font-han); color: var(--ws-main); font-size: 21px; font-weight: 700; line-height: 1.1; }
.a4-py { font-weight: 700; font-size: 13px; color: var(--ws-main); }
.a4-hv-pill {
  background: #e0f2fe;
  color: #0369a1;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 5px;
  letter-spacing: 0.2px;
}
.a4-vi { font-size: 12.5px; font-weight: 700; color: #111827; }
.a4-lv-pill {
  font-size: 10.5px;
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}

.a4-char-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.a4-char-label {
  font-family: var(--font-han);
  color: var(--ws-main);
  font-size: 14px;
  font-weight: 700;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.a4-char-row {
  flex: 1;
  display: grid;
  gap: 3px;
}

.a4-cell {
  aspect-ratio: 1 / 1;
  border: 1.3px solid var(--ws-main);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-han);
  font-size: 24px;
  line-height: 1;
  background: #ffffff;
  overflow: hidden;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.a4-cell svg.cell-grid-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.a4-cell .char-solid { color: #111827; position: relative; z-index: 1; }
.a4-cell .char-trace { color: #cbd5e1; position: relative; z-index: 1; }

.a4-ex-line {
  font-size: 11px;
  color: #4b5563;
  margin-top: 4px;
  margin-left: 22px;
  font-style: italic;
}

.a4-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.a4-table th, .a4-table td {
  border: 1px solid #cbd5e1;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.a4-table th {
  background: #fef3c7;
  color: #78350f;
  font-weight: 800;
}

@page {
  size: A4 portrait;
  margin: 10mm;
}

@media print {
  .app-shell, .mobile-bar, .mobile-tabs, .more-drawer-backdrop, .modal-backdrop, .no-print {
    display: none !important;
  }
  body {
    background: #ffffff !important;
    background-image: none !important;
  }
  #printArea {
    display: block !important;
  }
}
