:root {
  --bg: #fbf9f5;
  --surface: #ffffff;
  --surface-soft: #f3efe7;
  --border: #e6dfd3;
  --text: #27322e;
  --text-muted: #66756f;
  --primary: #2f8f78;
  --primary-hover: #257562;
  --primary-soft: #e6f4f0;
  --accent: #e07a5f;
  --accent-soft: #fceee9;
  --danger: #d45555;
  --danger-soft: #fdecec;
  --success: #2a8a5e;
  --success-soft: #e7f6ee;
  --shadow: 0 10px 28px rgba(39, 50, 46, 0.06);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-latin: "Avenir Next", "SF Pro Display", "Segoe UI", system-ui, sans-serif;
}

[data-theme="blueberry"] {
  --bg: #f5f8fc;
  --surface: #ffffff;
  --surface-soft: #ebf0f8;
  --border: #dce4f1;
  --text: #222e42;
  --text-muted: #60708a;
  --primary: #4c6ef5;
  --primary-hover: #3b5bdb;
  --primary-soft: #edf2ff;
  --accent: #7950f2;
  --accent-soft: #f3f0ff;
}

[data-theme="peach"] {
  --bg: #fdf8f5;
  --surface: #ffffff;
  --surface-soft: #f7ece6;
  --border: #eddcd2;
  --text: #382a25;
  --text-muted: #7a645b;
  --primary: #d96b52;
  --primary-hover: #c25941;
  --primary-soft: #fceee9;
  --accent: #4e9f8b;
  --accent-soft: #e7f5f1;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.55;
  min-height: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.app-shell {
  max-width: 1060px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
}

/* 顶部栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--primary);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-family: var(--font-latin);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
}

.brand-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.theme-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.theme-dot[data-theme-choice="mint"] {
  background: #2f8f78;
}

.theme-dot[data-theme-choice="blueberry"] {
  background: #4c6ef5;
}

.theme-dot[data-theme-choice="peach"] {
  background: #d96b52;
}

.theme-dot.is-selected {
  transform: scale(1.12);
  border-color: var(--text);
}

.pill-btn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.pill-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.pill-btn.is-active,
.pill-btn.is-active:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* 导航栏 */
.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 6px;
  border-radius: 18px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  min-height: 44px;
  border: none;
  border-radius: 13px;
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.tab-btn.is-active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

/* 通用卡片与按钮 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
}

.card-desc {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.btn {
  min-height: 46px;
  padding: 0 20px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

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

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

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

.btn-soft {
  background: var(--primary-soft);
  color: var(--primary);
}

.btn-soft:hover {
  filter: brightness(0.97);
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--primary);
}

.btn-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-primary {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-muted {
  background: var(--surface-soft);
  color: var(--text-muted);
}

/* 今日计划布局 */
.today-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 18px;
  align-items: start;
}

.hero-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hero-title {
  margin: 6px 0 4px;
  font-size: 26px;
  line-height: 1.25;
}

.ring-wrap {
  width: 96px;
  height: 96px;
  position: relative;
  flex-shrink: 0;
}

.ring-wrap svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--surface-soft);
  stroke-width: 9;
}

.ring-fg {
  fill: none;
  stroke: var(--primary);
  stroke-width: 9;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.35s ease;
}

.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
}

.ring-label strong {
  font-size: 20px;
  color: var(--text);
  line-height: 1.1;
}

.today-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.mini-stat {
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.mini-stat span {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.mini-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  font-family: var(--font-latin);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-actions .btn-primary {
  flex: 1 1 220px;
  min-height: 52px;
  font-size: 16px;
}

.book-selector-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.book-option {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.book-option.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.book-option-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.book-option-name {
  font-weight: 700;
  font-size: 15px;
}

.book-option-meta {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.quota-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}

/* 背词拼写沉浸区（iPad 键盘友好：核心内容靠上居中） */
.study-wrap {
  max-width: 720px;
  margin: 0 auto;
}

.study-progress-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.progress-track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.study-card {
  padding: 26px;
}

.study-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.star-btn {
  min-width: 40px;
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 18px;
  cursor: pointer;
}

.star-btn.is-starred {
  background: #fff7db;
  border-color: #f0c94d;
}

.word-display {
  text-align: center;
  padding: 8px 0 18px;
}

.word-main {
  margin: 0;
  font-family: var(--font-latin);
  font-size: clamp(36px, 6vw, 48px);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.word-meta-line {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--text-muted);
  font-size: 15px;
}

.syllable-chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  font-family: var(--font-latin);
  font-size: 14px;
  color: var(--text);
}

.audio-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 18px;
}

.meaning-box {
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 20px;
}

.meaning-zh {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.meaning-example {
  margin: 8px 0 0;
  font-family: var(--font-latin);
  font-size: 16px;
  color: var(--text-muted);
}

.study-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.study-actions .btn-primary {
  flex: 1 1 220px;
  min-height: 52px;
}

/* 拼写模式 */
.spell-prompt {
  text-align: center;
  margin-bottom: 16px;
}

.spell-meaning {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.spell-cloze {
  margin: 8px 0 0;
  font-family: var(--font-latin);
  font-size: 16px;
  color: var(--text-muted);
}

.letter-slots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 14px 0;
}

.letter-slot {
  min-width: 26px;
  height: 32px;
  padding: 0 4px;
  border-bottom: 2.5px solid var(--border);
  display: grid;
  place-items: center;
  font-family: var(--font-latin);
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.letter-slot.is-space {
  border-bottom-color: transparent;
  min-width: 14px;
}

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

.spell-input {
  width: 100%;
  min-height: 58px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: 2px solid var(--border);
  background: var(--bg);
  text-align: center;
  font-family: var(--font-latin);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.08em;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.spell-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
  background: var(--surface);
}

.feedback-banner {
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 16px;
}

.feedback-banner.is-ok {
  background: var(--success-soft);
  border: 1px solid #bce4cf;
}

.feedback-banner.is-wrong {
  background: var(--danger-soft);
  border: 1px solid #f4c6c6;
}

.feedback-title {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
}

.diff-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.diff-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.diff-label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 64px;
}

.diff-char {
  min-width: 28px;
  height: 32px;
  padding: 0 6px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-family: var(--font-latin);
  font-size: 17px;
  font-weight: 700;
}

.diff-char.is-match {
  background: #d7f3e3;
  color: #1f6d48;
}

.diff-char.is-miss {
  background: #fad4d4;
  color: #a93030;
}

.diff-char.is-target {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
}

/* 词库管理 */
.books-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.book-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1 1 200px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
}

.search-input:focus {
  border-color: var(--primary);
}

.word-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.word-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}

.word-row-main {
  min-width: 0;
  flex: 1;
}

.word-row-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.word-row-en {
  font-family: var(--font-latin);
  font-size: 19px;
  font-weight: 700;
}

.word-row-phonetic {
  font-size: 13px;
  color: var(--text-muted);
}

.word-row-meaning {
  margin: 4px 0 0;
  font-size: 14px;
}

.word-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* 统计与打印视图 */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
  align-items: start;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.heat-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--surface-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid transparent;
}

.heat-cell[data-level="1"] {
  background: color-mix(in srgb, var(--primary) 22%, white);
  color: var(--text);
}

.heat-cell[data-level="2"] {
  background: color-mix(in srgb, var(--primary) 45%, white);
  color: var(--text);
}

.heat-cell[data-level="3"] {
  background: color-mix(in srgb, var(--primary) 72%, white);
  color: #ffffff;
}

.heat-cell[data-level="4"] {
  background: var(--primary);
  color: #ffffff;
}

.heat-cell strong {
  font-size: 13px;
}

.weak-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.weak-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.print-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.lan-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  font-size: 13px;
}

.lan-url {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
}

/* 表单与弹窗 */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.field input,
.field select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.5;
}

.field input:focus,
.field select:focus,
textarea:focus {
  border-color: var(--primary);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 25, 0.42);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 40;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(640px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  padding: 20px 22px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.icon-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 20px;
  cursor: pointer;
}

.form-row.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.import-help-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.link-btn {
  border: none;
  background: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.import-preview {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--text);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
  z-index: 60;
}

.empty-state {
  text-align: center;
  padding: 36px 20px;
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 20px;
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--text-muted);
}

/* 打印专用样式 */
.print-only {
  display: none;
}

@media print {
  .no-print {
    display: none !important;
  }

  .print-only {
    display: block !important;
    color: #111111;
    background: #ffffff;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  }

  .sheet-page {
    padding: 8mm 10mm;
  }

  .sheet-page + .sheet-page {
    page-break-before: always;
  }

  .sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 2px solid #222222;
    padding-bottom: 8px;
    margin-bottom: 14px;
  }

  .sheet-header h2 {
    margin: 0;
    font-size: 20px;
  }

  .sheet-meta {
    font-size: 12px;
    color: #444444;
  }

  .sheet-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 24px;
  }

  .sheet-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #999999;
    font-size: 14px;
  }

  .sheet-num {
    min-width: 24px;
    font-weight: 700;
  }

  .sheet-prompt {
    flex: 1;
  }

  .sheet-answer {
    font-family: var(--font-latin);
    font-weight: 700;
  }
}

/* 响应式：iPad 竖屏与手机 */
@media (max-width: 820px) {
  .today-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stats-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 580px) {
  .app-shell {
    padding: 12px 14px 24px;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .tab-btn {
    font-size: 13px;
    padding: 0 4px;
  }

  .form-row.two-col,
  .quota-row {
    grid-template-columns: 1fr;
  }

  .word-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .word-row-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
