:root {
  --bg: #fff;
  --fg: #000;
  --muted: #666;
  --line: #111;
  --soft: #f4f4f4;
  --tap: 48px;
  --nav-h: 64px;
  --top-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  border-radius: 0 !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  padding-top: calc(var(--top-h) + var(--safe-t));
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
}
body.no-nav { padding-bottom: var(--safe-b); }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--top-h) + var(--safe-t));
  padding-top: var(--safe-t);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 12px;
  padding-right: 12px;
  border-bottom: 2px solid var(--fg);
  background: var(--bg);
  z-index: 50;
  gap: 10px;
}
.header-stats {
  display: flex;
  gap: 16px;
  align-items: baseline;
  min-width: 0;
}
.hstat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.hstat .hl {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.hstat .hn {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.badge {
  font-size: 12px;
  border: 1.5px solid var(--fg);
  padding: 4px 8px;
  flex-shrink: 0;
}
.badge.offline { background: var(--fg); color: var(--bg); }

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 2px solid var(--fg);
  background: var(--bg);
  z-index: 50;
}
.nav-btn {
  appearance: none;
  background: transparent;
  border: 0;
  border-right: 1px solid #ddd;
  font-size: 14px;
  font-weight: 600;
  min-height: var(--nav-h);
  cursor: pointer;
  color: var(--muted);
}
.nav-btn:last-child { border-right: 0; }
.nav-btn.active {
  color: var(--fg);
  background: var(--soft);
  box-shadow: inset 0 -3px 0 var(--fg);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

h1, h2 { margin: 0 0 12px; font-size: 22px; }
h2 { font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }

.card {
  border: 2px solid var(--fg);
  padding: 14px;
  margin-bottom: 12px;
  background: var(--bg);
}

.q-card {
  border: 2px solid var(--fg);
  padding: 16px;
  background: var(--bg);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 16px;
}
.stat {
  border: 2px solid var(--fg);
  text-align: center;
  padding: 14px 8px;
  min-height: 72px;
}
.stat .n { font-size: 28px; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: 12px; margin-top: 6px; }

.btn, button.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 10px 16px;
  border: 2px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  width: 100%;
  margin: 6px 0;
}
.btn.primary { background: var(--fg); color: var(--bg); }
.btn.ghost { background: var(--bg); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn-row .btn { margin: 0; }

.quiz-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
}
#timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 22px;
  border: 2px solid var(--fg);
  min-width: 64px;
  text-align: center;
  padding: 6px 10px;
}
#timer.warn { background: var(--fg); color: var(--bg); }

.stem {
  font-size: 18px;
  line-height: 1.55;
  margin: 0 0 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.options { display: grid; gap: 10px; }
.option {
  appearance: none;
  text-align: left;
  border: 2px solid var(--fg);
  background: var(--bg);
  min-height: var(--tap);
  padding: 14px 12px;
  font-size: 16px;
  line-height: 1.4;
  cursor: pointer;
  width: 100%;
}
.option .key {
  display: inline-block;
  width: 1.6em;
  font-weight: 800;
}
.option.correct { background: var(--fg); color: var(--bg); }
.option.wrong { background: #ddd; text-decoration: line-through; }
.option:disabled { cursor: default; }

.feedback {
  margin-top: 12px;
  border: 2px solid var(--fg);
  padding: 12px;
}
.feedback.ok { background: var(--fg); color: var(--bg); }
.feedback.bad { background: #eee; }
.explain { margin-top: 8px; font-size: 14px; opacity: 0.85; white-space: pre-wrap; }

.search {
  width: 100%;
  min-height: var(--tap);
  border: 2px solid var(--fg);
  padding: 10px 12px;
  font-size: 16px;
  margin-bottom: 10px;
}
.list-item {
  border: 2px solid var(--fg);
  padding: 12px;
  margin-bottom: 8px;
}
.list-item .title {
  font-size: 15px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.list-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.list-actions { display: flex; gap: 8px; margin-top: 8px; }
.list-actions .btn { width: auto; min-width: 88px; padding: 8px 12px; min-height: 40px; font-size: 14px; }

.file-box {
  border: 2px dashed var(--fg);
  padding: 18px;
  text-align: center;
}
.file-box input[type=file] { width: 100%; margin-top: 10px; }

.empty {
  text-align: center;
  padding: 40px 12px;
  color: var(--muted);
  border: 2px dashed #bbb;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 16px;
  font-size: 14px;
  z-index: 80;
  max-width: 90vw;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

.progress-bar {
  height: 6px;
  background: #eee;
  border: 1px solid var(--fg);
  margin: 8px 0 14px;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--fg);
  width: 0%;
}

@media (min-width: 721px) {
  .app { padding: 24px; }
}


.hdr-back {
  appearance: none;
  border: 2px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  font-weight: 700;
  min-height: 36px;
  padding: 4px 10px;
  margin-right: 8px;
  flex-shrink: 0;
  cursor: pointer;
}
.header-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hdr-deck {
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.deck-card {
  border: 2px solid var(--fg);
  padding: 14px;
  margin-bottom: 10px;
  background: var(--bg);
  cursor: pointer;
}
.deck-card .deck-name {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 8px;
}
.deck-card .deck-stats {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
}
.deck-card .deck-stats strong {
  color: var(--fg);
  font-size: 18px;
  font-weight: 800;
  margin-left: 4px;
}
.deck-card .deck-actions {
  display: none;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}
.deck-card.show-actions .deck-actions { display: grid; }
.deck-card .deck-actions .btn { margin: 0; min-height: 40px; font-size: 14px; }

.next-hint {
  margin-top: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #111;
}
