/* ==========================================================================
   闪卡 · 样式表
   设计目标：iOS 原生质感 / 安全区适配 / 深色模式 / 单手可操作
   ========================================================================== */

:root {
  --bg: #f2f4f8;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #eceff5;
  --surface-3: #e3e7ef;
  --text: #12151b;
  --text-2: #626b7a;
  --text-3: #8b94a3;
  --line: #e2e6ee;
  --accent: #3f6df2;
  --accent-soft: rgba(63, 109, 242, 0.12);
  --seg-active: #ffffff;
  --again: #e5484d;
  --hard: #cf7a0a;
  --good: #2f9e44;
  --easy: #0c8ea8;
  --skip: #8b94a3;
  --shadow-1: 0 1px 2px rgba(16, 22, 34, 0.06), 0 4px 14px rgba(16, 22, 34, 0.06);
  --shadow-2: 0 8px 30px rgba(16, 22, 34, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro SC", "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

html[data-theme="dark"] {
  --bg: #0d0f13;
  --bg-elev: #16191f;
  --surface: #16191f;
  --surface-2: #1e222a;
  --surface-3: #272c36;
  --text: #eef1f6;
  --text-2: #9aa4b4;
  --text-3: #6f7887;
  --line: #262b34;
  --accent: #5f86ff;
  --accent-soft: rgba(95, 134, 255, 0.16);
  --seg-active: rgba(255, 255, 255, 0.15);
  --again: #ff6369;
  --hard: #f5a623;
  --good: #4cc76a;
  --easy: #35c0d8;
  --skip: #8b94a3;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.28);
  --shadow-2: 0 10px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* 禁止双击放大 / 长按选择（卡片区域单独允许选择） */
body, button, a { touch-action: manipulation; }
button { font: inherit; color: inherit; -webkit-user-select: none; user-select: none; }

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

.view {
  flex: 1;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 10px) 18px calc(var(--safe-b) + 22px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------------------------------------------------------------- 通用组件 */

.btn {
  appearance: none;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 14px;
  padding: 13px 18px;
  font-size: 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-1); }
.btn--primary:active { background: #3059d6; }
html[data-theme="dark"] .btn--primary:active { background: #4d74e8; }
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--danger { background: rgba(229, 72, 77, 0.12); color: var(--again); }
.btn--block { width: 100%; }
.btn--lg { padding: 17px 22px; font-size: 17px; border-radius: 16px; }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-2);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.3; }

.card-surface {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 2px;
  min-height: 44px;
}
.topbar__title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  flex: 1;
  text-align: center;
}
.topbar__sub { font-size: 12px; color: var(--text-3); text-align: center; font-weight: 500; }

/* ---------------------------------------------------------------- 首页 */

.hero {
  padding: 22px 20px 18px;
  border-radius: 22px;
  background: linear-gradient(150deg, var(--accent) 0%, #6b4bf0 100%);
  color: #fff;
  box-shadow: var(--shadow-2);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  width: 220px; height: 220px;
  right: -70px; top: -110px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 50%;
}
.hero__label { font-size: 13px; opacity: 0.85; font-weight: 500; letter-spacing: 0.4px; }
.hero__num {
  font-size: 46px;
  font-weight: 800;
  line-height: 1.05;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}
.hero__split { font-size: 13px; opacity: 0.9; margin-bottom: 16px; }
.hero .btn--primary {
  background: rgba(255, 255, 255, 0.96);
  color: #2b3a8f;
  position: relative;
  z-index: 1;
}
.hero .btn--primary:active { background: #fff; }
.hero__secondary {
  display: flex;
  gap: 8px;
  position: relative;
  z-index: 1;
  margin-top: 10px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  box-shadow: var(--shadow-1);
}
.stat__k { font-size: 12px; color: var(--text-3); font-weight: 500; }
.stat__v { font-size: 22px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat__u { font-size: 12px; color: var(--text-3); font-weight: 500; margin-left: 2px; }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 2px 2px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.4px;
}

.deck-list { display: flex; flex-direction: column; gap: 8px; }
.deck {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 13px 12px 13px 15px;
  box-shadow: var(--shadow-1);
}
.deck__main { flex: 1; min-width: 0; cursor: pointer; }
.deck__name {
  font-size: 15px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck__meta { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.deck__action {
  appearance: none;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}
.deck__action:disabled { background: var(--surface-2); color: var(--text-3); }
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
  margin-left: 6px;
  vertical-align: 1px;
}
.pill--due { background: var(--accent-soft); color: var(--accent); }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-2);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.empty__emoji { font-size: 40px; margin-bottom: 10px; }
.empty__title { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }

.fab-bar {
  position: sticky;
  bottom: 0;
  padding-bottom: calc(var(--safe-b) + 4px);
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  display: flex;
  gap: 10px;
  padding-top: 8px;
}

/* ---------------------------------------------------------------- 复习 */

.review-top { display: flex; align-items: center; gap: 10px; padding-top: 2px; }
.progress {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}
.review-count { font-size: 13px; color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums; min-width: 74px; text-align: right; }

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  padding: 6px 0 2px;
}

.flashcard {
  width: 100%;
  min-height: 260px;
  max-height: 62vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow-2);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.flashcard:active { transform: scale(0.995); }
.flashcard__front {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.2px;
  word-break: break-word;
}
.flashcard__front.is-long { font-size: 20px; }
.flashcard__front.is-xlong { font-size: 17px; font-weight: 600; }
.flashcard__divider { height: 1px; background: var(--line); }
.flashcard__back {
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
}
.flashcard__back.is-empty { color: var(--text-3); font-style: italic; }
.flashcard__hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
  padding-bottom: 2px;
}
.flashcard__tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; }

.rating-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  padding-bottom: 2px;
}
.rating {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 11px 4px 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  color: #fff;
  background: var(--skip);
  transition: transform 0.1s ease, filter 0.15s ease;
  min-height: 64px;
  justify-content: center;
}
.rating:active { transform: scale(0.95); filter: brightness(0.94); }
.rating__label { font-size: 15px; font-weight: 700; }
.rating__ivl { font-size: 11px; opacity: 0.82; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rating--again { background: var(--again); }
.rating--hard { background: var(--hard); }
.rating--good { background: var(--good); }
.rating--easy { background: var(--easy); }
.rating--skip { background: var(--surface-2); color: var(--text-2); }

.done {
  text-align: center;
  padding: 30px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.done__emoji { font-size: 52px; }
.done__title { font-size: 22px; font-weight: 800; margin: 10px 0 6px; }
.done__grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 20px 0 18px; }
.done__cell { background: var(--surface-2); border-radius: 12px; padding: 10px 4px; }
.done__n { font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; }
.done__k { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ---------------------------------------------------------------- 表单 */

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 4px 16px;
}
.field { padding: 14px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: none; }
.field__label { font-size: 15px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.field__hint { font-size: 12px; color: var(--text-3); margin-top: 4px; line-height: 1.5; }
.input, .select, .textarea {
  width: 100%;
  margin-top: 9px;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 11px;
  padding: 11px 13px;
  font-size: 16px; /* 16px 防止 iOS 自动放大 */
  font-family: inherit;
}
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.textarea { min-height: 150px; resize: vertical; line-height: 1.6; }
.select { background-image: none; }
.range-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
input[type="range"] { flex: 1; accent-color: var(--accent); height: 28px; }
.range-val { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 52px; text-align: right; }
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
  margin-top: 9px;
}
.seg__btn {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-2);
  border-radius: 9px;
  padding: 8px 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.seg__btn.is-active { background: var(--seg-active); color: var(--text); box-shadow: var(--shadow-1); }
html[data-theme="dark"] .seg__btn.is-active { box-shadow: none; }

/* ---------------------------------------------------------------- 导入 */

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 26px 18px;
  text-align: center;
  color: var(--text-2);
  background: var(--surface);
  cursor: pointer;
}
.dropzone:active { border-color: var(--accent); color: var(--accent); }

.preview-list { display: flex; flex-direction: column; gap: 8px; }
.preview-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-1);
  font-size: 14px;
  line-height: 1.55;
}
.preview-card__front { font-weight: 650; }
.preview-card__back { color: var(--text-2); margin-top: 4px; white-space: pre-wrap; }
.preview-card__idx { font-size: 11px; color: var(--text-3); margin-bottom: 4px; font-variant-numeric: tabular-nums; }

.notice {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.6;
  background: var(--accent-soft);
  color: var(--accent);
}
.notice--warn { background: rgba(207, 122, 10, 0.12); color: var(--hard); }

/* ---------------------------------------------------------------- 统计 */

.bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 120px;
  padding: 10px 4px 0;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%;
  max-width: 34px;
  border-radius: 6px 6px 3px 3px;
  background: var(--accent);
  min-height: 3px;
  transition: height 0.3s ease;
}
.bar.is-empty { background: var(--surface-3); }
.bar-day { font-size: 10px; color: var(--text-3); }
.bar-n { font-size: 10px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- 提示 / 弹层 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 28px);
  transform: translate(-50%, 20px);
  background: rgba(20, 24, 32, 0.94);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 88vw;
  text-align: center;
  z-index: 90;
  backdrop-filter: blur(8px);
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

#modal-root { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, 0.44);
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: auto;
}
.modal-backdrop.is-show { opacity: 1; }
.modal-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -46%) scale(0.97);
  width: min(92vw, 420px);
  background: var(--bg-elev);
  border-radius: 20px;
  box-shadow: var(--shadow-2);
  padding: 22px 20px 16px;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: auto;
}
.modal-panel.is-show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.modal__title { font-size: 17px; font-weight: 750; margin-bottom: 8px; }
.modal__body { font-size: 14px; line-height: 1.65; color: var(--text-2); }
.modal__actions { display: flex; gap: 8px; margin-top: 18px; }
.modal__actions .btn { flex: 1; }

.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  padding: 10px 12px calc(var(--safe-b) + 12px);
  transform: translateY(100%);
  transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: auto;
}
.sheet-panel.is-show { transform: translateY(0); }
.sheet-item {
  width: 100%;
  appearance: none;
  border: none;
  background: transparent;
  text-align: left;
  padding: 15px 14px;
  font-size: 16px;
  border-radius: 12px;
  cursor: pointer;
}
.sheet-item:active { background: var(--surface-2); }
.sheet-item--danger { color: var(--again); }
.sheet-cancel {
  width: 100%;
  appearance: none;
  border: none;
  background: var(--surface-2);
  margin-top: 8px;
  padding: 15px;
  font-size: 16px;
  font-weight: 650;
  border-radius: 13px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- 杂项 */

.hr { height: 1px; background: var(--line); margin: 4px 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* 历史版本列表 */
.snap-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  appearance: none;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}
.snap-row:active { background: var(--surface-3); }
.snap-row__time { font-size: 14px; font-weight: 650; }
.snap-row__meta { font-size: 12px; color: var(--text-3); }
.snap-empty { font-size: 13px; color: var(--text-3); padding: 10px 2px 14px; }
.center-block { margin: 0 auto; }
.spin {
  width: 22px; height: 22px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 640px) {
  .view { padding-left: 28px; padding-right: 28px; }
  .flashcard__front { font-size: 30px; }
  .hero__num { font-size: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
