:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --paper: #fffdf8;
  --paper-2: #fbf7ea;
  --ink: #24211c;
  --muted: #706b61;
  --line: #ddd5c5;
  --accent: #2f6f62;
  --accent-2: #d94f30;
  --accent-soft: #e7f2ee;
  --gold: #b77a18;
  --shadow: 0 14px 34px rgba(53, 43, 25, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100dvh;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(47, 111, 98, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(217, 79, 48, 0.08), transparent 32%),
    var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button,
.file-label {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:hover,
.file-label:hover {
  border-color: #b9ad9a;
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button.secondary {
  background: #fff2ec;
  color: #943a23;
  border-color: #efc4b5;
}

button.ghost,
.ghost {
  background: transparent;
}

button.marked {
  background: #fff0e8;
  color: #a34329;
  border-color: #efb59f;
}

button:disabled {
  cursor: default;
  opacity: 0.82;
}

button.full {
  width: 100%;
}

button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.topbar,
.app-shell,
.library-panel {
  width: 100%;
  max-width: none;
}

.topbar {
  margin: 0 auto;
  height: 88px;
  padding: 18px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

h3 {
  margin-bottom: 10px;
  font-size: 17px;
}

.top-actions,
.button-row,
.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-label input {
  display: none;
}

.app-shell {
  margin: 0 auto;
  height: calc(100dvh - 88px);
  padding: 8px 20px 18px;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.panel {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid rgba(221, 213, 197, 0.85);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.add-panel,
.dashboard {
  min-height: 0;
}

.add-panel {
  overflow: auto;
}

.dashboard {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-pinyin {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: lowercase;
}

.card-pinyin.pending {
  color: var(--gold);
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 98, 0.12);
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 16px 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.stat b {
  display: block;
  font-size: 28px;
  line-height: 1;
  margin-bottom: 6px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.tab {
  white-space: nowrap;
  background: transparent;
}

.tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.tab-content {
  min-height: 0;
  padding-top: 10px;
  flex: 1;
  overflow: auto;
  padding-right: 4px;
}

.new-tab-content {
  overflow: hidden;
}

.new-learning-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  gap: 12px;
}

.new-cards-grid {
  min-height: 0;
  overflow: hidden;
  grid-template-columns: repeat(5, minmax(96px, 1fr));
  align-content: start;
  gap: 10px;
}

.hanzi-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.hanzi-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 98, 0.12);
}

.hanzi-card[data-new-card] {
  cursor: pointer;
}

.new-learning-layout .hanzi-card {
  gap: 6px;
  padding: 8px;
}

.hanzi {
  min-height: 92px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background:
    linear-gradient(var(--line), var(--line)) center/100% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) center/1px 100% no-repeat,
    #fffaf1;
  color: #1f1b16;
  font-family: "Kaiti SC", "STKaiti", "Songti SC", serif;
  font-size: 64px;
  line-height: 1;
}

.new-learning-layout .hanzi {
  min-height: 58px;
  font-size: 48px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--accent-soft);
  color: #24594f;
  font-size: 12px;
  font-weight: 700;
}

.tag.warn {
  background: #fff0e8;
  color: #a34329;
}

.tag.gold {
  background: #fff3cf;
  color: #7a530e;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.lesson-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.new-learning-layout .lesson-panel {
  min-height: 0;
  margin-top: 0;
  padding: 12px;
  gap: 8px;
  align-content: start;
  overflow: hidden;
}

.lesson-header-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.lesson-hero {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.new-learning-layout .lesson-hero {
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
}

.lesson-visual {
  min-height: 150px;
  border-radius: 8px;
  border: 1px solid #ead9bd;
  background:
    linear-gradient(var(--line), var(--line)) center/100% 1px no-repeat,
    linear-gradient(90deg, var(--line), var(--line)) center/1px 100% no-repeat,
    radial-gradient(circle at 70% 28%, rgba(217, 79, 48, 0.18), transparent 26%),
    #fff8e8;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.new-learning-layout .lesson-visual {
  min-height: 100px;
}

.lesson-visual span {
  position: relative;
  z-index: 1;
  color: #1f1b16;
  font-family: "Kaiti SC", "STKaiti", "Songti SC", serif;
  font-size: 86px;
  line-height: 1;
}

.new-learning-layout .lesson-visual span {
  font-size: 62px;
}

.lesson-visual i {
  position: absolute;
  width: 96px;
  height: 42px;
  left: 24px;
  bottom: 18px;
  border-radius: 999px 999px 14px 14px;
  background: rgba(47, 111, 98, 0.14);
  border: 1px solid rgba(47, 111, 98, 0.2);
}

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

.new-learning-layout .lesson-grid {
  gap: 8px;
}

.lesson-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-2);
  padding: 12px;
}

.new-learning-layout .lesson-grid > div {
  padding: 9px;
}

.lesson-grid strong {
  display: block;
  margin-bottom: 6px;
}

.lesson-panel p,
.lesson-grid p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.section-title.compact {
  margin-bottom: 8px;
}

.review-row,
.story-box {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
}

.review-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.review-groups {
  display: grid;
  gap: 14px;
}

.review-group {
  display: grid;
  gap: 10px;
}

.review-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.review-group-title h3 {
  margin: 0;
}

.review-group-title span {
  color: var(--muted);
  font-size: 13px;
}

.empty.compact {
  padding: 18px;
}

.review-char {
  font-family: "Kaiti SC", "STKaiti", "Songti SC", serif;
  font-size: 52px;
  line-height: 1;
}

.story-text {
  font-family: "Kaiti SC", "STKaiti", "Songti SC", serif;
  font-size: 28px;
  line-height: 1.75;
}

.library-panel {
  margin: 0 auto 34px;
}

.filter-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-chip {
  min-height: 36px;
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.72);
}

.filter-chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.library-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.library-item {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.deleted-bin {
  margin-top: 16px;
  border: 1px dashed #c8bcaa;
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.62);
  display: grid;
  gap: 10px;
}

.deleted-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

.deleted-item {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.deleted-item strong {
  font-family: "Kaiti SC", "STKaiti", "Songti SC", serif;
  font-size: 34px;
  line-height: 1;
}

.deleted-item span {
  color: var(--muted);
  font-size: 12px;
}

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

.library-char {
  font-family: "Kaiti SC", "STKaiti", "Songti SC", serif;
  font-size: 42px;
}

.empty {
  border: 1px dashed #c8bcaa;
  border-radius: 8px;
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

.empty strong {
  display: block;
  color: var(--ink);
  margin-bottom: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: #221f1b;
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 900px) {
  body {
    height: auto;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
    height: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .dashboard {
    overflow: visible;
  }

  .tab-content {
    overflow: visible;
  }

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

  .review-row {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .review-row .card-actions {
    grid-column: 1 / -1;
  }

  .lesson-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar,
  .app-shell,
  .library-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  .grid-2,
  .stats {
    grid-template-columns: 1fr;
  }

  .cards-grid,
  .library-list {
    grid-template-columns: 1fr;
  }

  .lesson-hero {
    grid-template-columns: 1fr;
  }

  .lesson-visual {
    min-height: 132px;
  }
}
