/**
 * main.css — All app styles
 * 
 * Sections:
 *   :root + dark theme variables (lines 1-50)
 *   Layout (header, sidebar, panel)
 *   Cards (test, random, stats, map)
 *   Sentence practice (sp-*)
 *   Mobile responsive (@media max-width:700px)
 * 
 * Theme variables:
 *   --bg, --surface, --surface2 (backgrounds)
 *   --ink, --ink2, --ink3 (text)
 *   --border, --border2 (lines)
 *   --blue, --green, --amber, --red (status colors)
 *   --r, --r-lg, --r-full (border radius)
 */

:root {
  --bg: #F8F7F4;
  --surface: #FFFFFF;
  --surface2: #F1F0ED;
  --ink: #1C1917;
  --ink2: #57534E;
  --ink3: #A8A29E;
  --border: #E7E5E4;
  --border2: #D6D3D1;
  --blue: #2563EB;
  --blue-bg: #EFF6FF;
  --green: #16A34A;
  --green-bg: #F0FDF4;
  --amber: #D97706;
  --amber-bg: #FFFBEB;
  --red: #DC2626;
  --red-bg: #FEF2F2;
  --purple: #7C3AED;
  --purple-bg: #F5F3FF;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, .07), 0 2px 4px rgba(0, 0, 0, .04);
  --r: 8px;
  --r-lg: 12px;
  --r-full: 999px;
}

@media(prefers-color-scheme:dark) {
  :root {
    --bg: #0C0A09;
    --surface: #1C1917;
    --surface2: #292524;
    --ink: #FAFAF9;
    --ink2: #D6D3D1;
    --ink3: #78716C;
    --border: #292524;
    --border2: #44403C;
    --blue: #3B82F6;
    --blue-bg: #1E3A5F;
    --green: #22C55E;
    --green-bg: #14532D;
    --amber: #F59E0B;
    --amber-bg: #451A03;
    --red: #F87171;
    --red-bg: #450A0A;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, .5), 0 2px 4px rgba(0, 0, 0, .4);
  }

  .lbtn.active {
    background: #292524;
    color: var(--blue);
    box-shadow: none;
  }

  .langbtn.active {
    background: #292524;
    color: var(--blue);
    box-shadow: none;
  }

  .topt {
    color: var(--ink);
  }

  .gex-word,
  .sp-word {
    color: var(--ink);
  }

  input,
  select {
    color-scheme: dark;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

/* ─── HEADER ─── */
header {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
}

.logo em {
  color: var(--blue);
  font-style: normal;
}

.top-nav {
  display: flex;
  gap: 2px;
  padding: 5px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.top-nav::-webkit-scrollbar {
  display: none;
}

.tnav {
  padding: 6px 13px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--ink2);
  border: none;
  border-radius: var(--r);
  transition: .15s;
  white-space: nowrap;
  font-weight: 500;
}

.tnav.active {
  background: var(--blue);
  color: #fff;
}

.tnav:hover:not(.active) {
  background: var(--surface2);
}

.lang-sw {
  display: flex;
  flex-direction: row;
  background: var(--surface2);
  border-radius: var(--r-full);
  padding: 2px;
  gap: 1px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.langbtn {
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--ink3);
  border: none;
  border-radius: var(--r-full);
  transition: .12s;
  line-height: 1.5;
}

.langbtn.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .1);
}

.langbtn:hover:not(.active) {
  color: var(--ink);
  background: rgba(255, 255, 255, .5);
}

.lsw-wrap {
  position: relative;
  flex: 1;
  display: flex;
  min-width: 0;
}

.lsw {
  display: flex;
  flex: 1;
  background: var(--surface2);
  border-radius: var(--r-full);
  padding: 2px;
  gap: 1px;
  border: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
}

.lsw::-webkit-scrollbar {
  display: none;
}

.lbtn {
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--ink3);
  border: none;
  border-radius: var(--r-full);
  transition: .12s;
  white-space: nowrap;
  scroll-snap-align: center;
  flex-shrink: 0;
}

.lbtn.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .1);
}

/* ─── LAYOUT ─── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sbar-top {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 7px 10px 7px 32px;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: .15s;
}

.search-wrap input:focus {
  border-color: var(--blue);
  background: #fff;
}

.search-wrap::before {
  content: '⌕';
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink3);
  font-size: 15px;
  pointer-events: none;
}

.filter-row {
  display: flex;
  gap: 4px;
}

.fbtn {
  flex: 1;
  padding: 5px 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink2);
  transition: .12s;
}

.fbtn:hover {
  background: var(--surface2);
}

.fbtn.fa {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.fbtn.fh {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.fbtn.fe {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.fbtn.fn {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* Custom add */
.custom-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.crow {
  display: flex;
  gap: 4px;
}

.crow input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  font-size: 12px;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  min-width: 0;
  transition: .15s;
}

.crow input:focus {
  border-color: var(--blue);
  background: #fff;
}

.crow button {
  padding: 6px 10px;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  font-weight: 600;
}

.crow button:hover {
  opacity: .9;
}

.cstatus {
  font-size: 11px;
  color: var(--ink3);
  min-height: 14px;
}

.wcount {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--ink3);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

.wlist {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.wlist::-webkit-scrollbar {
  width: 3px;
}

.wlist::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 2px;
}

/* Word items */
.wi {
  padding: 10px 12px 10px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0;
  transition: .1s;
  border-bottom: 1px solid var(--border);
  position: relative;
  min-height: 52px;
}

.wi:hover {
  background: var(--bg);
}

.wi.sel {
  background: var(--blue-bg);
}

.wi-badge {
  width: 3px;
  min-height: 44px;
  border-radius: 2px;
  flex-shrink: 0;
  background: transparent;
  margin-right: 10px;
  align-self: stretch;
}

.wg .wi-badge {
  background: var(--green);
}

.wy .wi-badge {
  background: var(--amber);
}

.wr .wi-badge {
  background: var(--red);
}

.wi-hz {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1;
  margin-right: 8px;
}

.wi-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.wi-py {
  font-size: 14px;
  color: var(--blue);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
}

.wi-ru {
  font-size: 11px;
  color: var(--ink3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.wi-b {
  font-size: 12px;
  flex-shrink: 0;
  margin-left: 6px;
}

.wg .wi-b {
  color: var(--green);
}

.wy .wi-b {
  color: var(--amber);
}

.wr .wi-b {
  color: var(--red);
}

.wi.sel .wi-hz,
.wi.sel .wi-py,
.wi.sel .wi-ru {
  color: var(--blue);
}

/* ─── PANEL ─── */
.panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  min-height: 0;
  contain: layout;
}

.panel::-webkit-scrollbar {
  width: 4px;
}

.panel::-webkit-scrollbar-thumb {
  background: var(--border2);
}

/* Empty state */
.ph {
  text-align: center;
  color: var(--ink3);
  padding: 40px 20px;
}

.phb {
  display: block;
  font-size: 48px;
  margin-bottom: 8px;
  opacity: .4;
}

.ph-text {
  font-size: 15px;
}

/* ─── CARDS ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  width: 100%;
  box-shadow: var(--shadow);
}

.card-sm {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
  width: 100%;
}

/* ─── BUTTONS ─── */
.btn {
  padding: 8px 16px;
  border-radius: var(--r);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--ink);
  transition: .15s;
  font-weight: 500;
}

.btn:hover {
  background: var(--surface2);
  border-color: var(--border);
}

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

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

.btn-primary:hover {
  opacity: .9;
  background: var(--blue);
}

.btn-red {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.btn-red:hover {
  opacity: .9;
  background: var(--red);
}

.btn-green {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.btn-green:hover {
  opacity: .9;
}

.btn-amber {
  background: var(--amber);
  color: #fff;
  border-color: var(--amber);
}

.btn-amber:hover {
  opacity: .9;
}

/* Legacy aliases */
.btn-dk {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.btn-dk:hover {
  opacity: .85;
  background: var(--ink);
}

/* ─── PRACTICE MODE ─── */
.whdr {
  text-align: center;
  min-height: 80px;
}

.wfull {
  font-size: 28px;
  letter-spacing: .05em;
  font-weight: 300;
}

.wpy {
  font-size: 13px;
  color: var(--ink3);
  margin-top: 3px;
}

.wru {
  font-size: 16px;
  font-weight: 600;
  margin-top: 4px;
  color: var(--blue);
}

.cdots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border2);
  cursor: pointer;
  transition: .15s;
}

.dot.cur {
  background: var(--blue);
  transform: scale(1.4);
}

.dot.dn {
  background: var(--green);
}

.cwrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
  display: block;
  overflow: hidden;
}

.cgrid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.clbl {
  font-size: 12px;
  color: var(--ink3);
  text-align: center;
}

.clbl strong {
  font-size: 16px;
  color: var(--ink);
  font-weight: 600;
}

.fb {
  height: 22px;
  font-size: 12px;
  color: var(--ink3);
  display: flex;
  align-items: center;
  font-weight: 500;
}

.fbok {
  color: var(--green);
}

.fberr {
  color: var(--red);
}

.ctrls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.errs {
  font-size: 11px;
  color: var(--ink3);
  text-align: center;
}

.errs span {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  display: block;
}

/* Related */
.related {
  width: 100%;
  max-width: 420px;
}

.rel-t {
  font-size: 10px;
  color: var(--ink3);
  letter-spacing: .06em;
  margin-bottom: 6px;
  text-transform: uppercase;
  font-weight: 600;
}

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

.chip {
  padding: 4px 10px;
  border: 1px solid var(--border2);
  border-radius: var(--r-full);
  font-size: 13px;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink);
  transition: .12s;
  font-weight: 500;
}

.chip:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-bg);
}

/* Complete */
.compbox {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px 32px;
  box-shadow: var(--shadow-md);
  max-width: 400px;
  width: 100%;
}

.comphz {
  font-size: 48px;
  margin-bottom: 6px;
}

.compt {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.comps {
  font-size: 13px;
  color: var(--ink2);
  margin-bottom: 20px;
  line-height: 1.6;
}

.compb {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ─── TEST MODE ─── */
.test-wrap {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.test-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.test-score {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--ink3);
}

.test-score span {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  display: block;
  text-align: center;
}

.test-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow);
}

.test-hz {
  font-size: 56px;
  margin-bottom: 4px;
  font-weight: 300;
}

.test-py {
  font-size: 14px;
  color: var(--ink3);
}

.test-prog {
  font-size: 12px;
  color: var(--ink3);
  font-weight: 500;
}

.topts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.topt {
  padding: 12px 10px;
  border: 1.5px solid var(--border2);
  border-radius: var(--r);
  font-size: 13px;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  line-height: 1.4;
  text-align: center;
  transition: .15s;
  font-weight: 500;
}

.topt:hover:not(:disabled) {
  background: var(--surface2);
  border-color: var(--border);
}

.topt.tc {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green);
}

.topt.tw {
  background: var(--red-bg);
  border-color: var(--red);
  color: var(--red);
}

.topt:disabled {
  cursor: default;
}

/* ─── RANDOM MODE ─── */
.rand-wrap {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rand-score {
  display: flex;
  gap: 16px;
  justify-content: center;
  font-size: 12px;
  color: var(--ink3);
}

.rand-score span {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  display: block;
  text-align: center;
}

.rmsw {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.rmbtn {
  padding: 6px 14px;
  border-radius: var(--r-full);
  font-size: 12px;
  cursor: pointer;
  border: 1.5px solid var(--border2);
  background: var(--surface);
  color: var(--ink2);
  font-family: inherit;
  transition: .12s;
  font-weight: 500;
}

.rmbtn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.rcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.rlvl {
  font-size: 10px;
  letter-spacing: .08em;
  color: var(--ink3);
  margin-bottom: 8px;
  text-transform: uppercase;
  font-weight: 600;
}

.rhz {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 6px;
  font-weight: 300;
}

.rpy {
  font-size: 14px;
  color: var(--ink3);
  margin-bottom: 8px;
}

.rru {
  font-size: 17px;
  font-weight: 600;
  color: var(--blue);
}

.rru-h {
  font-size: 13px;
  color: transparent;
  background: var(--surface2);
  border-radius: var(--r);
  cursor: pointer;
  user-select: none;
  padding: 6px 14px;
  display: inline-block;
  transition: .2s;
}

.rru-h.shown {
  color: var(--blue);
  background: var(--blue-bg);
}

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

.ract .btn {
  flex: 1;
  padding: 12px;
  font-size: 13px;
  font-weight: 600;
}

/* ─── STATS ─── */
.stats-wrap {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.scard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
  text-align: center;
}

.scard-v {
  font-size: 24px;
  font-weight: 700;
}

.scard-l {
  font-size: 11px;
  color: var(--ink3);
  margin-top: 2px;
  font-weight: 500;
}

.pbar-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
}

.pbar-t {
  font-size: 12px;
  color: var(--ink3);
  margin-bottom: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.pbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  margin-bottom: 6px;
}

.pbar-lbl {
  width: 44px;
  color: var(--ink2);
  font-weight: 500;
}

.pbar-track {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.pbar-fill {
  height: 100%;
  border-radius: 3px;
  transition: .3s;
}

.pbar-pct {
  min-width: 60px;
  text-align: right;
  color: var(--ink3);
  font-weight: 600;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.hw-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
}

.hw-t {
  font-size: 12px;
  color: var(--ink3);
  margin-bottom: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.hw-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  transition: .1s;
}

.hw-item:last-child {
  border: none;
}

.hw-item:hover {
  color: var(--blue);
}

.hw-hz {
  font-size: 20px;
  min-width: 44px;
  width: auto;
  white-space: nowrap;
}

.hw-info {
  flex: 1;
  color: var(--ink2);
  min-width: 0;
  overflow: hidden;
}

.hw-rate {
  color: var(--red);
  font-weight: 700;
  font-size: 11px;
}

.sreset {
  width: 100%;
  padding: 9px;
  font-size: 12px;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  background: transparent;
  cursor: pointer;
  color: var(--ink3);
  font-family: inherit;
  font-weight: 500;
  transition: .15s;
}

.sreset:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ─── MAP ─── */
.map-panel {
  width: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.map-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 11px;
  color: var(--ink3);
  font-weight: 500;
}

.map-leg {
  display: flex;
  align-items: center;
  gap: 4px;
}

.map-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.msec {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  flex-shrink: 0;
}

.msec-head {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  margin: 0;
  gap: 8px;
}

.msec-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.msec-right {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink3);
  margin-left: auto;
  white-space: nowrap;
}

.msec-bar {
  display: inline-block;
  width: 60px;
  height: 5px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
}

.msec-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
}

.mgrid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-content: flex-start;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 14px;
  border-radius: 0;
  background: var(--bg);
}

.mgrid::-webkit-scrollbar {
  width: 4px;
}

.mgrid::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 2px;
}

.mtile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 6px;
  transition: transform .1s;
  border: 1px solid transparent;
  white-space: nowrap;
  font-weight: 500;
}

.mtile:hover {
  transform: scale(1.15);
  z-index: 3;
  box-shadow: var(--shadow-md);
}

.mt-n {
  background: #F5F3F0;
  color: #6B6560;
  border-color: #E7E5E4;
}

.mt-g {
  background: #D1FAE5;
  color: #166534;
  border-color: #86EFAC;
}

.mt-y {
  background: #FEF3C7;
  color: #92400E;
  border-color: #FCD34D;
}

.mt-r {
  background: #FEE2E2;
  color: #991B1B;
  border-color: #FCA5A5;
}

/* Dark theme tile colors — without these, all tiles look like bright
   white/yellow chips on a dark background which hurts the eyes. */
html[data-theme="dark"] .mt-n {
  background: #33302E;
  color: #A8A29E;
  border-color: #57534E;
}

html[data-theme="dark"] .mt-g {
  background: #14532D;
  color: #86EFAC;
  border-color: #22C55E;
}

html[data-theme="dark"] .mt-y {
  background: #451A03;
  color: #FCD34D;
  border-color: #F59E0B;
}

html[data-theme="dark"] .mt-r {
  background: #450A0A;
  color: #FCA5A5;
  border-color: #F87171;
}

html[data-theme="dark"] .mgrid {
  background: var(--surface2);
}

/* ─── GRAMMAR & SENTENCES ─── */
.gram-wrap {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 20px;
}

.gram-level-sw {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.glbtn {
  padding: 5px 13px;
  border-radius: var(--r-full);
  font-size: 12px;
  cursor: pointer;
  border: 1.5px solid var(--border2);
  background: var(--surface);
  color: var(--ink2);
  font-family: inherit;
  transition: .12s;
  font-weight: 500;
}

.glbtn.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.gram-prog {
  font-size: 12px;
  color: var(--ink3);
  text-align: center;
  font-weight: 500;
}

.gram-legend {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.gl-item {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: var(--ink3);
}

.gl-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.gpat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow);
}

.gpat-hsk {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 3px;
}

.gpat-desc {
  font-size: 12px;
  color: var(--ink2);
  margin-bottom: 12px;
  line-height: 1.6;
}

.gram-formula {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  background: var(--bg);
  border-radius: var(--r);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.gf-part {
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}

.gf-plus {
  color: var(--ink3);
  font-size: 14px;
}

.gram-exs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gram-ex {
  background: var(--bg);
  border-radius: var(--r);
  padding: 12px;
}

.gram-ex-zh {
  font-size: 17px;
  line-height: 1.7;
  margin-bottom: 3px;
}

.gram-ex-py {
  font-size: 10px;
  color: var(--ink3);
  margin-bottom: 2px;
}

.gram-ex-ru {
  font-size: 12px;
  color: var(--ink2);
}

.gram-nav {
  display: flex;
  gap: 8px;
}

.gnav-btn {
  flex: 1;
  padding: 9px;
  border-radius: var(--r);
  font-size: 12px;
  cursor: pointer;
  border: 1.5px solid var(--border2);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  transition: .15s;
  font-weight: 500;
}

.gnav-btn:hover {
  background: var(--surface2);
}

.gnav-btn.primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* Exercise slots */
.gex-sent {
  font-size: 13px;
  color: var(--ink2);
  margin-bottom: 3px;
  font-style: italic;
}

.gex-ru {
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 14px;
  font-weight: 600;
}

.gex-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.gex-slot {
  min-width: 80px;
  min-height: 56px;
  border: 2px dashed var(--border2);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  cursor: pointer;
  transition: .12s;
  text-align: center;
}

.gex-slot.filled {
  border-style: solid;
}

.gex-slot-word {
  font-size: 16px;
  font-weight: 600;
}

.gex-slot-label {
  font-size: 9px;
  margin-top: 2px;
}

.gex-words {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}

.gex-word {
  padding: 9px 14px;
  border: 1.5px solid var(--border2);
  border-radius: var(--r);
  font-size: 16px;
  cursor: grab;
  background: var(--surface);
  transition: .12s;
  font-family: inherit;
  font-weight: 500;
}

.gex-word:hover {
  border-color: var(--blue);
  background: var(--blue-bg);
}

.gex-word.sel {
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}

.gex-word.placed {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green);
  font-size: 13px;
  opacity: .7;
  cursor: default;
}

.gex-fb {
  padding: 10px 12px;
  border-radius: var(--r);
  font-size: 12px;
  margin-top: 4px;
}

.gex-ok {
  background: var(--green-bg);
  color: var(--green);
  font-weight: 600;
}

.gex-err {
  background: var(--red-bg);
  color: var(--red);
}

/* Sentence practice */
.sp-task {
  font-size: 12px;
  color: var(--ink3);
  margin-bottom: 5px;
}

.sp-ru {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--ink);
}

.sp-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.sp-slot {
  min-width: 76px;
  min-height: 56px;
  border: 2px dashed var(--border2);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  cursor: pointer;
  transition: .15s;
  text-align: center;
}

.sp-slot:hover {
  opacity: .8;
}

.sp-slot.filled {
  border-style: solid;
}

.sp-slot-word {
  font-size: 17px;
  font-weight: 600;
}

.sp-slot-label {
  font-size: 9px;
  margin-top: 2px;
}

.sp-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.sp-word {
  padding: 10px 16px;
  border: 1.5px solid var(--border2);
  border-radius: var(--r);
  font-size: 17px;
  cursor: grab;
  background: var(--surface);
  transition: .12s;
  user-select: none;
  font-family: inherit;
  font-weight: 500;
}

.sp-word:hover {
  border-color: var(--blue);
  background: var(--blue-bg);
}

.sp-word.sel {
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}

.sp-word.placed {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green);
  font-size: 13px;
  opacity: .6;
  cursor: default;
}

.sp-fb {
  padding: 10px 12px;
  border-radius: var(--r);
  font-size: 12px;
  margin-top: 2px;
}

.sp-ok {
  background: var(--green-bg);
  color: var(--green);
  font-weight: 600;
}

.sp-err {
  background: var(--red-bg);
  color: var(--red);
}

/* Notes */
.notes-wrap {
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 20px;
}

.notes-score {
  display: flex;
  gap: 16px;
  justify-content: center;
  font-size: 12px;
  color: var(--ink3);
}

.notes-score span {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  display: block;
  text-align: center;
}

.notes-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.notes-label {
  font-size: 10px;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 12px;
  font-weight: 600;
}

.notes-zh {
  font-size: 28px;
  line-height: 1.5;
  margin-bottom: 8px;
  cursor: pointer;
  font-weight: 300;
}

.notes-py {
  font-size: 13px;
  color: var(--blue);
  margin-bottom: 6px;
  min-height: 20px;
  font-weight: 500;
}

.notes-ru {
  font-size: 15px;
  color: var(--ink);
  min-height: 20px;
  font-weight: 600;
}

.notes-ru-hidden {
  background: var(--surface2);
  color: transparent;
  border-radius: var(--r);
  cursor: pointer;
  padding: 4px 14px;
  user-select: none;
  display: inline-block;
  font-size: 13px;
  transition: .2s;
}

.notes-ru-hidden.shown {
  background: var(--blue-bg);
  color: var(--blue);
}

.notes-hint {
  font-size: 10px;
  color: var(--ink3);
  margin-top: 6px;
}

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

.notes-actions .btn {
  flex: 1;
  min-width: 90px;
  padding: 11px 8px;
  font-size: 13px;
  font-weight: 600;
}

.notes-idx {
  font-size: 12px;
  color: var(--ink3);
  text-align: center;
  font-weight: 500;
}

.notes-filter {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.nfbtn {
  padding: 5px 13px;
  border-radius: var(--r-full);
  font-size: 12px;
  cursor: pointer;
  border: 1.5px solid var(--border2);
  background: var(--surface);
  color: var(--ink2);
  font-family: inherit;
  transition: .12s;
  font-weight: 500;
}

.nfbtn.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ─── LOADING ─── */
.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--blue);
  transition: width .3s;
  z-index: 100;
}

.w-more-btn {
  padding: 12px;
  text-align: center;
  color: var(--blue);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  transition: .12s;
  display: none;
}

.w-more-btn:hover {
  background: var(--blue-bg);
}

@media(max-width:700px) {
  .w-more-btn {
    padding: 6px 12px;
    font-size: 11px;
    border-top: none;
    border-right: 1px solid var(--border);
    display: flex;
    align-items: center;
    min-width: 100px;
  }
}

/* ─── MOBILE ─── */
@media(max-width:700px) {

  /* Header: two-row, auto height */
  header {
    padding: 0;
  }

  .header-top {
    padding: 6px 10px;
    gap: 8px;
    flex-wrap: wrap;
    min-height: 44px;
  }

  .logo {
    font-size: 14px;
  }

  .lsw {
    max-width: calc(100vw - 120px);
  }

  .lbtn {
    padding: 3px 7px;
    font-size: 10px;
  }

  .langbtn {
    padding: 2px 6px;
    font-size: 10px;
  }

  .lang-select {
    font-size: 12px;
    padding: 4px 6px;
  }

  .theme-btn {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  /* Nav row */
  .top-nav {
    padding: 4px 8px;
    gap: 2px;
    border-top: 1px solid var(--border);
  }

  .tnav {
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
  }

  /* Hide header-search on mobile */
  .header-search {
    display: none !important;
  }

  /* Layout */
  .layout {
    flex-direction: column;
    overflow: visible;
    height: auto;
    min-height: 0;
  }

  /* Sidebar: compact horizontal word strip */
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    flex-shrink: 0;
  }

  .sbar-top {
    padding: 6px 10px;
    gap: 6px;
  }

  .filter-row {
    gap: 4px;
  }

  .fbtn {
    font-size: 11px;
    padding: 6px 4px;
  }

  .custom-section {
    display: none;
  }

  /* hide on mobile */
  /* Word list: horizontal scrollable */
  .wlist {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-height: 60px;
    min-height: 60px;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--border);
  }

  .wlist::-webkit-scrollbar {
    height: 2px;
  }

  .wi {
    flex-shrink: 0;
    flex-direction: column;
    gap: 1px;
    min-width: 52px;
    max-width: 52px;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 6px 4px;
    align-items: center;
    justify-content: center;
    min-height: 58px;
  }

  .wi-badge {
    width: 100%;
    height: 2px;
    min-height: 2px;
    margin: 0 0 3px 0;
  }

  .wi-hz {
    font-size: 18px;
    margin-right: 0;
  }

  .wi-info,
  .wi-b {
    display: none;
  }

  .wcount {
    display: none;
  }

  /* Panel */
  .panel {
    flex: 1;
    min-height: 60vh;
    padding: 12px 12px 80px;
    justify-content: flex-start;
    overflow-y: auto;
  }

  /* Practice canvas */
  .cwrap {
    width: 240px !important;
    height: 240px !important;
  }

  #hz-target {
    width: 240px !important;
    height: 240px !important;
  }

  /* Cards */
  .test-wrap,
  .rand-wrap,
  .stats-wrap,
  .notes-wrap,
  .gram-wrap,
  .sp-wrap {
    max-width: 100%;
  }

  .topts {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .topt {
    padding: 12px 6px;
    font-size: 13px;
  }

  .test-hz,
  .rhz {
    font-size: 44px;
  }

  .rand-score,
  .test-score {
    gap: 12px;
  }

  .ract {
    flex-wrap: wrap;
    gap: 8px;
  }

  .ract .btn {
    min-width: 80px;
    flex: 1;
  }

  .compb {
    flex-direction: column;
    gap: 8px;
  }

  .compb .btn {
    width: 100%;
  }

  /* Stats */
  .scards {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .scard-v {
    font-size: 18px;
  }

  /* Map */
  .map-panel {
    padding: 10px 8px;
  }

  .mtile {
    font-size: 12px;
    padding: 3px 4px;
  }

  /* Grammar / Sentence */
  .gram-formula {
    gap: 3px;
    padding: 8px;
  }

  .gf-part {
    padding: 3px 7px;
    font-size: 11px;
  }

  .gram-legend {
    gap: 4px;
  }

  .gl-item {
    font-size: 9px;
  }

  .gram-nav {
    flex-wrap: wrap;
  }

  .gnav-btn {
    min-width: 80px;
  }
}

@media(max-width:390px) {
  .cwrap {
    width: 200px !important;
    height: 200px !important;
  }

  #hz-target {
    width: 200px !important;
    height: 200px !important;
  }

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

  .tnav {
    padding: 5px 8px;
    font-size: 11px;
  }
}

/* Language dropdown (mobile) */
.lang-select {
  display: none;
  padding: 5px 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
}

@media(max-width:700px) {
  .lang-sw {
    display: none !important;
  }

  .lang-select {
    display: block;
  }

  .header-top {
    padding: 6px 10px;
    gap: 8px;
  }

  .lbtn {
    padding: 3px 8px;
    font-size: 11px;
  }
}

/* Prevent canvas jump */
.practice-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.cwrap {
  display: flex;
  align-items: center;
  justify-content: center;
}

.cwrap>div {
  display: flex;
  align-items: center;
  justify-content: center;
}

#hz-target {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#hz-target svg {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* ── Theme toggle button ── */
.theme-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--ink2);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: .15s;
  line-height: 1;
  padding: 0;
}

.theme-btn:hover {
  background: var(--border2);
}

.header-search {
  flex: 5;
  max-width: 800px;
  min-width: 200px;
  position: relative;
}

.header-search input {
  width: 100%;
  padding: 5px 14px 5px 34px;
  border: 1px solid var(--border2);
  border-radius: var(--r-full);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface2);
  color: var(--ink);
  outline: none;
  transition: .15s;
  box-sizing: border-box;
}

.header-search input:focus {
  border-color: var(--blue);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

.header-search::before {
  content: '⌕';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink3);
  font-size: 14px;
  pointer-events: none;
  z-index: 1;
}

/* Search Popover */
#searchPopover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  padding: 8px;
}

#searchPopover .hw-item {
  padding: 8px;
  border-radius: var(--r);
}

#searchPopover .hw-item:hover {
  background: var(--bg);
}

#searchPopover .hw-hz {
  font-size: 18px;
  width: 30px;
}

#searchPopover .hw-py {
  color: var(--blue);
  font-weight: 600;
  margin-right: 8px;
}

#searchPopover .hw-ru {
  color: var(--ink2);
  font-size: 12px;
}

/* ─── AUTH & PROFILE ─── */
.btn-profile {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface2);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: .15s;
}

.btn-profile:hover {
  background: var(--border);
  border-color: var(--border2);
}

.btn-profile .nav-label {
  font-size: 12px;
}

@media(max-width:700px) {
  .btn-profile .nav-label {
    display: none;
  }

  .btn-profile {
    padding: 6px 8px;
    font-size: 16px;
  }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  position: relative;
  box-shadow: var(--shadow-md);
  animation: modalIn .3s ease-out;
}

@keyframes modalIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  color: var(--ink3);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: .15s;
}

.auth-form input:focus {
  border-color: var(--blue);
  background: var(--surface);
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--ink3);
  margin-top: 12px;
}

.auth-switch a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}

.profile-info {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.profile-email {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink2);
}

.profile-stats {
  background: var(--surface2);
  border-radius: var(--r);
  padding: 12px;
  font-size: 13px;
  text-align: left;
}

.ps-row {
  display: flex;
  justify-content: space-between;
  color: var(--ink2);
}

.ps-row span:first-child {
  font-weight: 700;
  color: var(--blue);
}


/* ── Mobile search in sidebar ── */
.mobile-search-wrap {
  display: none;
  position: relative;
}

.mobile-search-wrap input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}

.mobile-search-wrap::before {
  content: '⌕';
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink3);
  font-size: 15px;
  pointer-events: none;
}

/* search-wrap was old class — hide it */
.search-wrap {
  display: none;
}

@media(max-width:700px) {
  .header-search {
    display: none !important;
  }

  .mobile-search-wrap {
    display: block;
  }
}

/* Force html/body to respect dark override */
html[data-theme="dark"] {
  --bg: #0C0A09;
  --surface: #1C1917;
  --surface2: #292524;
  --ink: #FAFAF9;
  --ink2: #D6D3D1;
  --ink3: #78716C;
  --border: #292524;
  --border2: #44403C;
  --blue: #3B82F6;
  --blue-bg: #1E3A5F;
  --green: #22C55E;
  --green-bg: #14532D;
  --amber: #F59E0B;
  --amber-bg: #451A03;
  --red: #F87171;
  --red-bg: #450A0A;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, .5);
}

html[data-theme="light"] {
  --bg: #F8F7F4;
  --surface: #FFFFFF;
  --surface2: #F1F0ED;
  --ink: #1C1917;
  --ink2: #57534E;
  --ink3: #A8A29E;
  --border: #E7E5E4;
  --border2: #D6D3D1;
  --blue: #2563EB;
  --blue-bg: #EFF6FF;
  --green: #16A34A;
  --green-bg: #F0FDF4;
  --amber: #D97706;
  --amber-bg: #FFFBEB;
  --red: #DC2626;
  --red-bg: #FEF2F2;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, .07);
}

/* Dark mode button/input fixes */
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] button {
  color-scheme: dark;
}

html[data-theme="dark"] .topt,
html[data-theme="dark"] .gex-word,
html[data-theme="dark"] .sp-word {
  color: var(--ink);
}

html[data-theme="dark"] .lbtn.active {
  background: #292524;
  color: var(--blue);
}

html[data-theme="dark"] .langbtn.active {
  background: #292524;
  color: var(--blue);
}


/* Collapsible map sections */
.msec-collapsible .msec-head {
  border-left: 3px solid var(--border2);
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}

.msec-collapsible .msec-head:hover {
  background: var(--surface2);
}

.msec-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--ink3);
  transition: transform .2s;
  width: 12px;
  flex-shrink: 0;
}

.msec-open>.msec-head {
  border-bottom: 1px solid var(--border);
}

.msec-collapsible .mgrid {
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

/* ── Speak button (audio.js) ─────────────────────────────────
   Inline pronunciation trigger — appears next to hanzi in every mode.
   Designed to be small enough not to dominate the UI but still
   tap-friendly on mobile (min 28×28). */
.speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin-left: 8px;
  background: var(--surface2);
  color: var(--ink2);
  border: 1px solid var(--border2);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: transform .12s, background .15s, color .15s;
  flex-shrink: 0;
  /* Default size; per-instance size set via inline style from speakBtn() */
  min-width: 28px;
  min-height: 28px;
}

.speak-btn:hover {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.speak-btn:active {
  transform: scale(.92);
}

.speak-btn.speak-active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  animation: speak-pulse .4s ease-out;
}

@keyframes speak-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, .6);
  }

  100% {
    box-shadow: 0 0 0 12px rgba(37, 99, 235, 0);
  }
}

/* Don't let the speak button push hanzi off-baseline in headers */
.wfull,
.comphz,
.rhz,
.test-hz {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* ─── TOASTS ─── */
.toast-wrap {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 24px;
  border-radius: 50px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--sh-lg);
  border: 1px solid var(--border);
  animation: toastIn .3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  transition: .3s;
}
@keyframes toastIn {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.toast.err { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--green); color: var(--green); }

/* ─── GOOGLE & AUTH EXTRA ─── */
.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 20px 0;
  color: var(--ink3);
  font-size: 12px;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.auth-divider:not(:empty)::before { margin-right: .5em; }
.auth-divider:not(:empty)::after { margin-left: .5em; }

.btn-google {
  background: white;
  color: #374151;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 500;
  transition: .2s;
}
.btn-google:hover { background: #f9fafb; border-color: #d1d5db; }
.btn-google img { width: 18px; height: 18px; }

.forgot-link {
  display: block;
  text-align: right;
  font-size: 12px;
  margin-top: -10px;
  margin-bottom: 15px;
  color: var(--ink3);
  text-decoration: none;
}
.forgot-link:hover { color: var(--blue); }