/* === Reset & Root === */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --primary: #5b8def;
  --primary-dark: #4170d8;
  --primary-light: #eaf1ff;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --success: #10b981;
  --danger: #ef4444;
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}
input, textarea, select { user-select: text; -webkit-user-select: text; }

.top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: calc(52px + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: 8px; padding-right: 8px;
  display: flex; align-items: center;
  background: linear-gradient(180deg, #7aa6f3 0%, #5b8def 100%);
  color: #fff;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(91,141,239,0.18);
}
.top-bar .title {
  flex: 1; text-align: center; font-size: 17px; font-weight: 600;
}
.icon-btn {
  width: 44px; height: 44px; border: none; background: transparent;
  color: #fff; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,0.15); }

#app {
  position: fixed;
  top: calc(52px + var(--safe-top));
  bottom: calc(64px + var(--safe-bottom));
  left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.view { padding: 16px; }

.storage-tip {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--primary-light);
  border-radius: 10px;
  font-size: 13px;
  color: var(--primary-dark);
  margin-bottom: 14px;
}
.storage-tip .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(16,185,129,0.2);
}

.quick-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 20px;
}
.action-tile {
  background: var(--card);
  border: none; border-radius: var(--radius);
  padding: 16px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.action-tile:active { transform: scale(0.96); }
.tile-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 700;
  background: linear-gradient(135deg, #a3c2f7 0%, #5b8def 100%);
}
.action-tile span { font-size: 13px; font-weight: 500; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 12px 4px 10px;
}
.section-header h3 { font-size: 15px; font-weight: 600; }
.header-actions { display: flex; gap: 12px; }
.link-btn {
  background: transparent; border: none;
  color: var(--primary); font-size: 14px; font-weight: 500;
  padding: 4px 8px; cursor: pointer;
}

.folder-list { display: flex; flex-direction: column; gap: 10px; }
.folder-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.folder-card:active { transform: scale(0.98); background: #fafbfc; }
.folder-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, #cfe0fb 0%, #5b8def 100%);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.folder-info { flex: 1; min-width: 0; }
.folder-info h4 {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.folder-info p {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.folder-stats {
  text-align: right;
  font-size: 11px; color: var(--text-muted);
  flex-shrink: 0;
}
.folder-stats b { font-size: 18px; color: var(--primary); display: block; font-weight: 700; }

.folder-banner {
  background: linear-gradient(135deg, #7aa6f3 0%, #5b8def 100%);
  color: #fff; border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 4px 16px rgba(91,141,239,0.22);
}
.folder-banner h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.folder-banner .muted { color: rgba(255,255,255,0.85); font-size: 13px; margin-bottom: 12px; }
.folder-meta {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 13px; color: rgba(255,255,255,0.9);
}
.folder-meta b { font-weight: 700; }

.study-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.study-bar .ghost-btn { flex: 1; min-width: 30%; }
.ghost-btn {
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; font-weight: 500;
  color: var(--text); cursor: pointer;
}
.ghost-btn:active { background: var(--primary-light); color: var(--primary); }

.search-bar { margin: 0 0 10px; }
.search-bar input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; background: var(--card);
}
.search-bar input:focus {
  outline: none; border-color: var(--primary);
}

.word-list { display: flex; flex-direction: column; gap: 8px; }
.word-card {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex; align-items: flex-start; gap: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.word-card.mastered { opacity: 0.55; }
.word-card.mastered .w { text-decoration: line-through; }
.word-main { flex: 1; min-width: 0; }
.word-main .w {
  font-size: 17px; font-weight: 600;
  color: var(--text); margin-right: 6px;
}
.word-main .pos {
  display: inline-block;
  background: var(--primary-light); color: var(--primary);
  padding: 1px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 600; margin-right: 4px;
}
.word-main .m {
  color: var(--text-muted); font-size: 14px;
  margin-top: 4px;
}
.word-main .note {
  color: var(--text-muted); font-size: 12px;
  margin-top: 2px; font-style: italic;
}
.word-actions { display: flex; flex-direction: column; gap: 4px; }
.icon-mini {
  width: 30px; height: 30px;
  border: none; background: transparent;
  color: var(--text-muted); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-mini:active { background: var(--primary-light); color: var(--primary); }
.icon-mini.danger:active { background: #fee2e2; color: var(--danger); }

.empty-hint {
  text-align: center; color: var(--text-muted);
  padding: 32px 16px; font-size: 14px;
}

.study-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
  font-size: 14px; color: var(--text-muted);
}
.study-header #studyProgress { font-weight: 600; color: var(--text); }
.flash-card {
  background: var(--card);
  border-radius: 20px;
  padding: 32px 20px;
  min-height: 320px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  position: relative;
  transition: transform 0.4s;
  transform-style: preserve-3d;
}
.flash-card.flipped { transform: rotateY(180deg); }
.flash-side {
  text-align: center; width: 100%;
  backface-visibility: hidden;
}
.flash-back { transform: rotateY(180deg); position: absolute; top: 32px; left: 20px; right: 20px; }
.flash-side .w {
  font-size: 36px; font-weight: 700;
  color: var(--text);
  word-break: break-all;
}
.flash-side .pos {
  display: inline-block; margin-top: 8px;
  background: var(--primary-light); color: var(--primary);
  padding: 3px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
}
.flash-side .meaning {
  font-size: 22px; font-weight: 600;
  color: var(--text); margin-bottom: 12px;
}
.flash-side .note {
  font-size: 14px; color: var(--text-muted);
  font-style: italic;
}
.tap-hint {
  position: absolute; bottom: 12px; left: 0; right: 0;
  text-align: center; color: var(--text-muted); font-size: 12px;
}
.study-controls { display: flex; gap: 10px; margin-top: 16px; }
.study-tools {
  display: flex; justify-content: center; gap: 20px;
  margin-top: 12px;
}

.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(60px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex; z-index: 90;
}
.tab-btn {
  flex: 1; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer;
  color: var(--text-muted); font-size: 10px;
  padding-top: 6px;
}
.tab-btn span { font-size: 22px; line-height: 1; }
.tab-btn b { font-size: 11px; font-weight: 500; }
.tab-btn.active { color: var(--primary); }
.tab-btn .plus-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, #7aa6f3 0%, #5b8def 100%);
  color: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  box-shadow: 0 4px 12px rgba(91,141,239,0.4);
  margin-bottom: 2px;
}

.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-mask {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
  animation: fadeIn 0.2s ease;
}
.modal-card {
  position: relative;
  background: var(--card);
  width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 22px 18px max(22px, env(safe-area-inset-bottom));
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 14px; text-align: center; }
.modal-actions {
  display: flex; gap: 10px; margin-top: 16px;
}
.modal-actions .primary-btn,
.modal-actions .ghost-btn { flex: 1; margin-top: 0; }
.modal-actions .ghost-btn { background: #f3f4f6; border-color: #f3f4f6; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; color: var(--text);
  background: #f9fafb;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--primary); background: #fff;
}
.primary-btn {
  width: 100%; padding: 13px;
  background: linear-gradient(135deg, #7aa6f3 0%, #5b8def 100%);
  color: #fff; border: none; border-radius: 10px;
  font-size: 16px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 12px rgba(91,141,239,0.28);
}
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.muted { color: var(--text-muted); font-size: 13px; }

.toast {
  position: fixed; top: 80px; left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(0,0,0,0.86); color: #fff;
  padding: 10px 18px; border-radius: 22px;
  font-size: 14px; z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 80%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.import-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 28px 16px;
  text-align: center;
  background: #fafbfc;
  cursor: pointer;
}
.import-zone input { display: none; }
.import-zone p { color: var(--text-muted); font-size: 13px; margin-top: 8px; }
