:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #7b8794;
  --border: #e1e4e8;
  --accent: #2f6fed;
  --again: #e5534b;
  --hard: #e8a13c;
  --good: #4caf50;
  --easy: #3b82f6;
}

* { box-sizing: border-box; }

/* 作者样式（如 label 的 display:flex）不能覆盖 hidden 属性 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; font-size: 18px; }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.current-user { font-size: 13px; color: var(--muted); }
.logout-btn { padding: 6px 12px; font-size: 13px; }

nav { display: flex; gap: 4px; }
.nav-mobile { display: none; }

.tab-btn {
  border: none;
  background: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  color: var(--muted);
  touch-action: manipulation;
}
.tab-btn:hover { background: #eef1f5; }
.tab-btn.active { background: #e3ecfd; color: var(--accent); font-weight: 600; }

main { max-width: 860px; margin: 24px auto; padding: 0 16px 60px; }
.tab { display: none; }
.tab.active { display: block; }

/* 通用 */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.panel h3 { margin: 0 0 12px; font-size: 16px; }
.inline-form { display: flex; gap: 8px; }

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 20px;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
}
button.primary:hover { filter: brightness(1.1); }
button.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
}
button.secondary:hover { background: #eef1f5; }

input[type="text"], input[type="search"], select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
textarea { resize: vertical; width: 100%; }
label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.toolbar { display: flex; gap: 8px; align-items: end; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1; min-width: 160px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td .row-actions { display: flex; gap: 6px; }
.link-btn {
  border: none; background: none; color: var(--accent);
  cursor: pointer; font-size: 13px; padding: 2px 4px;
}
.link-btn.danger { color: var(--again); }
.link-btn:hover { text-decoration: underline; }

/* 复习页 */
.study-home-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.study-home-head h2 { margin: 0; font-size: 20px; }
.study-home-head .hint { font-size: 12px; color: var(--muted); }

#deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.deck-card {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  touch-action: manipulation;
}
.deck-card:hover { border-color: var(--accent); box-shadow: 0 3px 10px rgba(0,0,0,.08); }
.deck-card.all { border-color: var(--accent); background: #f2f7ff; }
.deck-card-name { font-size: 16px; font-weight: 600; }
.deck-card-stats { display: flex; gap: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.deck-card-stats b { color: var(--text); }

.study-deck-name { font-weight: 600; font-size: 15px; }

.study-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.study-head select { min-width: 140px; }

.counts { display: flex; gap: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.counts b { color: var(--text); }

#card-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
#card-meta { font-size: 12px; color: var(--muted); min-height: 18px; }
#card-front, #card-back {
  font-size: 22px;
  text-align: center;
  padding: 20px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
#card-back { border-top: 1px dashed var(--border); color: #444; }
#btn-row { text-align: center; }
#btn-show { font-size: 16px; padding: 12px 32px; }

#rating-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: auto; }
.rate {
  border: none;
  border-radius: 10px;
  color: #fff;
  padding: 14px 0;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.rate span { font-size: 12px; opacity: .85; }
.rate:hover { filter: brightness(1.08); }
.r-again { background: var(--again); }
.r-hard { background: var(--hard); }
.r-good { background: var(--good); }
.r-easy { background: var(--easy); }

#study-done { text-align: center; padding: 60px 0; }
.done-icon { font-size: 48px; }

/* 表单 */
#note-form { display: flex; flex-direction: column; gap: 10px; }
#note-form label { display: block; }
#note-form textarea { display: block; }
.form-actions { display: flex; gap: 8px; }

/* 统计 */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.stat-card .num { font-size: 28px; font-weight: 700; }
.stat-card .lbl { font-size: 13px; color: var(--muted); }

.bar-row { display: grid; grid-template-columns: 44px 1fr; gap: 6px 10px; align-items: center; }
.bar-label { font-size: 13px; color: var(--muted); }
.bar { height: 14px; background: #eef1f5; border-radius: 7px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 7px; transition: width .3s; }
#stats-tbody td:first-child { color: var(--muted); }

/* 提示 */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323f4b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}

/* 修改密码弹窗 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
#pw-form { display: flex; flex-direction: column; gap: 10px; }
#pw-form input { width: 100%; }
.modal .form-actions { justify-content: flex-end; }

@media (max-width: 640px) {
  /* 头部精简：导航移到屏幕底部 */
  header {
    padding: 10px 12px;
    gap: 8px;
    position: sticky;
  }
  .brand { font-size: 16px; }
  .nav-desktop { display: none; }
  .current-user { display: none; }

  .nav-mobile {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .nav-mobile .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    font-size: 11px;
    border-radius: 10px;
    min-height: 48px;
    justify-content: center;
  }
  .nav-icon { font-size: 20px; line-height: 1; }
  .nav-mobile .tab-btn.active { background: none; color: var(--accent); }

  main {
    margin: 12px auto;
    padding: 0 12px calc(84px + env(safe-area-inset-bottom));
  }

  /* 输入框 16px 防止 iOS 聚焦时自动放大页面 */
  input[type="text"], input[type="search"], select, textarea { font-size: 16px; }
  textarea { min-height: 64px; }

  /* 复习卡片 */
  #card-box { padding: 20px 16px; min-height: 240px; gap: 14px; }
  #card-front, #card-back { font-size: 18px; padding: 14px 4px; }
  #btn-show { width: 100%; padding: 14px 0; font-size: 16px; }
  #rating-bar { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .rate { padding: 16px 2px; font-size: 15px; border-radius: 10px; }
  .study-head { gap: 8px; }
  .study-head select { flex: 1; }

  /* 表格横向滑动 */
  #note-table { min-width: 620px; }
  #deck-table { min-width: 520px; }
  td, th { padding: 8px 10px; }
  .link-btn { padding: 8px 6px; font-size: 14px; }

  /* 提示条移到底部导航上方 */
  #toast { bottom: calc(76px + env(safe-area-inset-bottom)); width: max-content; max-width: 90vw; }

  .toolbar { align-items: stretch; }
  .toolbar select, .toolbar button { font-size: 15px; }
  .toolbar input[type="search"] { min-width: 0; }
  .inline-form { flex-direction: column; }
  .inline-form button { padding: 12px; }
}
