:root {
  color-scheme: light;
  --page: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #eef2ed;
  --ink: #171b1a;
  --muted: #68716d;
  --line: #dce2dd;
  --accent: #275e52;
  --accent-strong: #173f37;
  --blue: #355f88;
  --amber: #9a6b2e;
  --rose: #8e4d63;
  --danger: #8a3f3f;
  --shadow: 0 14px 34px rgba(30, 42, 38, 0.08);
  --shadow-soft: 0 2px 10px rgba(30, 42, 38, 0.05);
}

body.dark {
  color-scheme: dark;
  --page: #171a19;
  --panel: #202523;
  --panel-soft: #29302d;
  --ink: #f1eee7;
  --muted: #a8b0ad;
  --line: #3b4143;
  --accent: #8cc9b8;
  --accent-strong: #a8ddce;
  --blue: #9dbfe8;
  --amber: #ddb572;
  --rose: #dfa7ba;
  --danger: #e0a2a2;
  --shadow: 0 20px 48px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 2px 10px rgba(0, 0, 0, 0.18);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #fbfcf9 0%, var(--page) 360px);
  color: var(--ink);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.dark {
  background:
    linear-gradient(180deg, #1e2421 0%, var(--page) 360px);
}

a { color: inherit; text-decoration: none; }

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

button,
.icon-action,
.file-action {
  position: relative;
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: 260px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, var(--panel-soft));
  padding: 22px;
  box-shadow: var(--shadow-soft);
}

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

.brand img {
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.brand strong {
  display: block;
  font-size: 23px;
  line-height: 1.05;
}

.brand small,
.search-box span,
.side-panel span,
.kicker,
.label,
.reading-tile span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.storage-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-soft);
}

.storage-note strong {
  display: block;
  margin-bottom: 4px;
}

.storage-note p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.search-box {
  display: grid;
  gap: 7px;
}

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

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 92px;
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.nav-list {
  display: grid;
  gap: 7px;
}

.nav-list a,
.secondary,
.primary,
.mini-btn,
.filter,
.icon-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.nav-list a {
  display: flex;
  align-items: center;
  padding: 0 12px;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.nav-list a:hover,
.secondary:hover,
.mini-btn:hover,
.filter:hover,
.icon-action:hover {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  transform: translateY(-1px);
}

.nav-list a.active,
.primary,
.filter.active {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

body.dark .nav-list a.active,
body.dark .primary,
body.dark .filter.active {
  color: #0c1c18;
}

.side-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.side-panel div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.side-panel strong {
  display: block;
  font-size: 22px;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: auto;
}

.icon-action,
.secondary,
.primary,
.mini-btn,
.filter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
}

.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  min-width: 0;
  padding: 30px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 3px 0 0;
  font-size: clamp(30px, 4vw, 46px);
  font-weight: 740;
  line-height: 1.05;
}

.kicker {
  margin: 0;
}

.topbar-tools,
.phrase-tools,
.toolbar-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.content-view {
  display: grid;
  gap: 18px;
}

.status-line {
  width: fit-content;
  max-width: 100%;
  margin: -8px 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 86%, var(--panel-soft));
  font-size: 12px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--panel) 94%, #f3fbf7) 0%, var(--panel) 58%, color-mix(in srgb, var(--panel) 88%, #fff4e4) 100%);
  box-shadow: var(--shadow);
  padding: 28px;
}

.hero-panel h2 {
  margin: 8px 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.08;
}

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

.hero-panel p,
.section-head p,
.topic-page p,
.reading-tile p,
.empty-state {
  color: var(--muted);
}

.hero-metrics {
  display: grid;
  align-content: center;
  gap: 2px;
  border-left: 1px solid var(--line);
  padding-left: 20px;
}

.hero-metrics strong {
  color: var(--accent);
  font-size: 34px;
  line-height: 1;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}

.section-head h2 {
  margin: 0;
}

.section-head p {
  margin: 0;
  max-width: 540px;
}

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

.topic-card,
.reading-tile,
.phrase-card,
.detail-card,
.practice-card,
.reader-card,
.notes-layout,
.empty-state,
.composer,
.topic-page {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.topic-card,
.reading-tile {
  display: grid;
  gap: 8px;
  padding: 16px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.topic-card:hover,
.reading-tile:hover,
.phrase-card:hover {
  border-color: color-mix(in srgb, var(--accent) 32%, var(--line));
  box-shadow: 0 18px 38px rgba(30, 42, 38, 0.1);
  transform: translateY(-2px);
}

.topic-card span,
.pill {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--amber);
  padding: 0 9px;
  font-size: 12px;
}

.topic-card:nth-child(3n + 2) span,
.phrase-card:nth-child(3n + 2) .pill {
  color: var(--blue);
}

.topic-card:nth-child(3n) span,
.phrase-card:nth-child(3n) .pill {
  color: var(--rose);
}

.topic-card strong,
.reading-tile strong {
  font-size: 18px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: 14px;
}

.phrase-card {
  display: grid;
  gap: 11px;
  padding: 16px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.phrase-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.save-btn {
  border: 0;
  background: transparent;
  color: var(--amber);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.phrase-title {
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
}

.phrase-title:hover {
  color: var(--accent);
}

.meaning,
.detail-meaning,
.practice-answer,
.translation-block {
  color: var(--blue);
}

.card-note {
  min-height: 64px;
}

.mini-btn {
  min-height: 32px;
  font-size: 13px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(150px, 220px) auto;
  gap: 12px;
  align-items: end;
  padding: 18px;
}

.composer label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.detail-card,
.practice-card,
.reader-card,
.notes-layout,
.topic-page {
  padding: 22px;
}

.detail-card {
  max-width: 780px;
}

.detail-card dl {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.detail-card dt {
  color: var(--muted);
  font-size: 13px;
}

.detail-card dd {
  margin: 3px 0 0;
}

.detail-note {
  min-height: 120px;
  margin-bottom: 12px;
}

.practice-card {
  max-width: 760px;
}

.practice-card h2 {
  margin: 18px 0;
  font-size: clamp(28px, 5vw, 48px);
}

.practice-answer {
  min-height: 32px;
  font-size: 22px;
}

.reading-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.reader-card {
  max-width: 860px;
}

.reader-card .english {
  font-size: 24px;
  line-height: 1.65;
}

.translation-block {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
  font-size: 18px;
}

.notes-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
}

.notes-layout textarea {
  min-height: 420px;
}

.empty-state {
  padding: 24px;
  grid-column: 1 / -1;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .hero-panel,
  .composer,
  .notes-layout {
    grid-template-columns: 1fr;
  }

  .hero-metrics {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 16px 0 0;
  }
}

@media (max-width: 560px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }
}
