:root {
  color-scheme: dark;
  --canvas: #0b0f0e;
  --surface: #141a18;
  --surface-soft: #1a221f;
  --surface-deep: #0f1412;
  --surface-hover: #1c2522;
  --ink: #e8efeb;
  --ink-soft: #cbd6d0;
  --muted: #93a19a;
  --muted-strong: #b2beb8;
  --line: #2a3531;
  --track: #222c28;
  --sidebar: #080c0b;
  --sidebar-muted: #94a29b;
  --green: #55d6b2;
  --green-strong: #147f6d;
  --green-strong-hover: #19947e;
  --green-soft: #15352d;
  --blue: #86b7ff;
  --blue-soft: #182b46;
  --amber: #f2c36b;
  --amber-soft: #372b14;
  --violet: #c2a7ff;
  --violet-soft: #2f2549;
  --coral: #ff9484;
  --coral-strong: #a9463b;
  --coral-soft: #3a211e;
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
}

::selection {
  color: var(--ink);
  background: rgba(85, 214, 178, 0.28);
}

* {
  scrollbar-color: #3a4943 var(--surface-deep);
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--surface-deep);
}

*::-webkit-scrollbar-thumb {
  border: 2px solid var(--surface-deep);
  border-radius: 999px;
  background: #3a4943;
}

input::placeholder {
  color: #74827b;
  opacity: 1;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink);
  box-shadow: 0 0 0 1000px var(--surface) inset;
  caret-color: var(--ink);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
  background:
    radial-gradient(circle at 50% -15%, rgba(85, 214, 178, 0.12), transparent 42%),
    var(--canvas);
}

.login-page {
  width: min(420px, 100%);
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  margin-bottom: 22px;
}

.login-brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #102620;
  background: #9be6c7;
}

.login-brand-mark svg {
  width: 24px;
  height: 24px;
}

.login-brand strong,
.login-brand small {
  display: block;
}

.login-brand strong {
  font-size: 16px;
}

.login-brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.login-panel {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-heading {
  margin-bottom: 26px;
}

.login-heading h1 {
  margin: 0;
  font-size: 27px;
  line-height: 1.2;
  letter-spacing: 0;
}

.login-heading p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.login-field {
  display: grid;
  gap: 7px;
  margin-top: 16px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
}

.login-input {
  position: relative;
  display: block;
}

.login-input > svg {
  position: absolute;
  top: 50%;
  left: 13px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.login-input input {
  width: 100%;
  height: 46px;
  padding: 0 14px 0 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
}

.login-input input:focus {
  border-color: var(--blue);
}

.login-error {
  display: none;
  margin: 18px 0 0;
  padding: 10px 12px;
  border: 1px solid #693832;
  border-radius: 6px;
  color: #ffb2a6;
  background: var(--coral-soft);
  font-size: 12px;
  line-height: 1.45;
}

.login-error.is-visible {
  display: block;
}

.login-submit {
  width: 100%;
  margin-top: 22px;
}

.button-spinner {
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.login-footnote {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.login-footnote svg {
  width: 15px;
  height: 15px;
  color: var(--green);
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(134, 183, 255, 0.38);
  outline-offset: 2px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  color: #fff;
  background: var(--sidebar);
}

.brand {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #102620;
  background: #9be6c7;
}

.brand-mark svg {
  width: 21px;
  height: 21px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
  line-height: 1.25;
}

.brand small {
  margin-top: 2px;
  color: var(--sidebar-muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 4px;
  margin-top: 18px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--sidebar-muted);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.nav-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.nav-item.is-active {
  color: #fff;
  background: rgba(155, 230, 199, 0.15);
}

.nav-item svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
}

.sidebar-footer {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.main-content {
  min-width: 0;
  padding: 34px 40px 48px;
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.page-header {
  min-height: 58px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

.page-header h1,
.page-header h2,
.dialog h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: 0;
}

.page-header p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.header-actions,
.toolbar-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.button {
  min-height: 42px;
  padding: 0 15px;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
}

.button-primary {
  color: #fff;
  background: var(--green-strong);
}

.button-primary:hover {
  background: var(--green-strong-hover);
}

.button-secondary {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.button-danger {
  color: #fff;
  background: var(--coral-strong);
}

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

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric {
  min-height: 112px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.metric-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
}

.metric-icon svg {
  width: 17px;
  height: 17px;
}

.metric-value {
  display: block;
  margin-top: 13px;
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.tone-green { color: var(--green); background: var(--green-soft); }
.tone-blue { color: var(--blue); background: var(--blue-soft); }
.tone-amber { color: var(--amber); background: var(--amber-soft); }
.tone-coral { color: var(--coral); background: var(--coral-soft); }

.section {
  margin-top: 28px;
}

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

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

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

.goal-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.goal-band h2 {
  margin: 0;
  font-size: 20px;
}

.goal-band p {
  margin: 6px 0 15px;
  color: var(--muted);
  font-size: 14px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--track);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.deck-list {
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.deck-row {
  min-height: 78px;
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(160px, 1fr) 88px 42px;
  align-items: center;
  gap: 20px;
  padding: 14px 8px;
  border-bottom: 1px solid var(--line);
}

.deck-name {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.deck-swatch {
  width: 9px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 3px;
}

.deck-name strong,
.deck-name small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-name small,
.deck-count small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.deck-progress {
  min-width: 0;
}

.deck-progress-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.deck-count {
  text-align: right;
}

.deck-count strong {
  display: block;
  font-size: 18px;
}

.filter-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 190px 160px;
  gap: 10px;
  margin-bottom: 14px;
}

.search-field {
  position: relative;
}

.search-field svg {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 17px;
  height: 17px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.search-field input,
.filter-toolbar select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
}

.search-field input {
  padding: 0 12px 0 40px;
}

.filter-toolbar select {
  padding: 0 12px;
}

.card-list {
  display: grid;
  gap: 8px;
}

.card-row {
  min-height: 78px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 110px 40px;
  align-items: center;
  gap: 18px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.card-row-title {
  min-width: 0;
}

.card-row-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.card-row-title small {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cheatsheet-page {
  width: min(1280px, 100%);
}

.cheatsheet-intro {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 17px 0 19px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.cheatsheet-intro-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: var(--amber);
  background: var(--amber-soft);
}

.cheatsheet-intro-icon svg {
  width: 23px;
  height: 23px;
}

.cheatsheet-intro strong {
  display: block;
  font-size: 16px;
}

.cheatsheet-intro p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.cheatsheet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 22px;
}

.cheatsheet-card {
  min-width: 0;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-top: 4px solid var(--blue);
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease, transform 140ms ease;
}

.cheatsheet-card:hover {
  border-color: #4a5b54;
  background: var(--surface-hover);
  transform: translateY(-2px);
}

.cheatsheet-card:focus-visible {
  outline: 3px solid rgba(134, 183, 255, 0.38);
  outline-offset: 2px;
}

.cheatsheet-card.cheatsheet-tone-coral { border-top-color: var(--coral); }
.cheatsheet-card.cheatsheet-tone-amber { border-top-color: var(--amber); }
.cheatsheet-card.cheatsheet-tone-green { border-top-color: var(--green); }
.cheatsheet-card.cheatsheet-tone-violet { border-top-color: var(--violet); }

.cheatsheet-thumb {
  aspect-ratio: 7 / 5;
  display: block;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: #f7f9fc;
}

.cheatsheet-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 180ms ease;
}

.cheatsheet-card:hover .cheatsheet-thumb img {
  transform: scale(1.012);
}

.cheatsheet-card-copy {
  min-height: 130px;
  display: grid;
  align-content: start;
  gap: 7px;
  padding: 17px 18px 19px;
}

.cheatsheet-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--blue);
}

.cheatsheet-tone-coral .cheatsheet-card-top { color: var(--coral); }
.cheatsheet-tone-amber .cheatsheet-card-top { color: var(--amber); }
.cheatsheet-tone-green .cheatsheet-card-top { color: var(--green); }
.cheatsheet-tone-violet .cheatsheet-card-top { color: var(--violet); }

.cheatsheet-card-top svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.cheatsheet-number {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.cheatsheet-card-copy > strong {
  font-size: 18px;
  line-height: 1.3;
}

.cheatsheet-card-copy > small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.library-page {
  width: min(1440px, 100%);
}

.library-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 180px 220px;
  gap: 10px;
  margin-bottom: 14px;
}

.library-toolbar select,
.library-search input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
}

.library-toolbar select {
  padding: 0 12px;
}

.library-search input {
  padding: 0 12px 0 40px;
}

.library-layout {
  height: max(620px, calc(100vh - 205px));
  display: grid;
  grid-template-columns: minmax(310px, 0.85fr) minmax(0, 1.35fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.library-results,
.library-preview {
  min-width: 0;
  min-height: 0;
}

.library-results {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.library-results-head {
  min-height: 47px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 15px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  font-size: 12px;
}

.library-results-head span {
  color: var(--muted);
}

.library-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.library-row {
  width: 100%;
  min-height: 74px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto 18px;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.library-row:hover {
  background: var(--surface-hover);
}

.library-row.is-selected {
  background: var(--green-soft);
  box-shadow: inset 3px 0 0 var(--green);
}

.library-file-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 7px;
}

.library-file-icon svg {
  width: 19px;
  height: 19px;
}

.library-file-copy {
  min-width: 0;
}

.library-file-copy strong,
.library-file-copy small,
.library-file-meta strong,
.library-file-meta small,
.library-preview-title strong,
.library-preview-title small {
  display: block;
}

.library-file-copy strong,
.library-file-copy small,
.library-preview-title strong,
.library-preview-title small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-file-copy strong {
  font-size: 13px;
  line-height: 1.35;
}

.library-file-copy small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
}

.library-file-meta {
  color: var(--muted);
  text-align: right;
}

.library-file-meta strong {
  color: var(--muted-strong);
  font-size: 10px;
}

.library-file-meta small {
  margin-top: 4px;
  font-size: 10px;
}

.library-chevron {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.library-empty,
.library-preview-empty,
.library-preview-loading {
  min-height: 300px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 9px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.library-empty svg,
.library-preview-loading > svg {
  width: 30px;
  height: 30px;
}

.library-empty strong,
.library-preview-empty strong {
  color: var(--ink);
  font-size: 15px;
}

.library-empty span,
.library-preview-empty p,
.library-preview-loading p {
  max-width: 320px;
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
}

.library-preview-empty > span {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--green);
  background: var(--green-soft);
}

.library-preview-empty > span svg {
  width: 24px;
  height: 24px;
}

.library-preview-empty .button {
  margin-top: 8px;
}

.library-preview {
  display: flex;
  flex-direction: column;
  background: var(--surface-deep);
}

.library-preview-header {
  min-height: 58px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.library-preview-back {
  display: none;
}

.library-preview-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
}

.library-preview-icon svg {
  width: 18px;
  height: 18px;
}

.library-preview-title {
  min-width: 0;
}

.library-preview-title strong {
  font-size: 13px;
}

.library-preview-title small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.library-preview-content {
  min-height: 0;
  flex: 1;
  overflow: auto;
  background: var(--surface-deep);
}

.library-frame {
  width: 100%;
  height: 100%;
  min-height: 560px;
  display: block;
  border: 0;
  background: #080b0a;
  filter: brightness(0.72) contrast(1.04);
}

.library-image-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 18px;
}

.library-image-wrap img {
  max-width: 100%;
  max-height: calc(100vh - 290px);
  object-fit: contain;
  box-shadow: var(--shadow);
}

.markdown-preview,
.text-preview {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 30px clamp(20px, 5vw, 52px) 70px;
  color: var(--ink-soft);
}

.markdown-preview {
  font-size: 15px;
  line-height: 1.68;
}

.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5 {
  margin: 1.35em 0 0.55em;
  color: var(--ink);
  line-height: 1.25;
}

.markdown-preview h2:first-child,
.markdown-preview h3:first-child {
  margin-top: 0;
}

.markdown-preview h2 { font-size: 26px; }
.markdown-preview h3 { font-size: 21px; }
.markdown-preview h4 { font-size: 17px; }
.markdown-preview h5 { font-size: 15px; }

.markdown-preview p {
  margin: 0.7em 0;
}

.markdown-preview ul,
.markdown-preview ol {
  padding-left: 24px;
}

.markdown-preview blockquote {
  margin: 15px 0;
  padding: 12px 15px;
  border-left: 3px solid var(--green);
  border-radius: 0 6px 6px 0;
  background: var(--green-soft);
}

.markdown-preview code,
.text-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.markdown-preview code {
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--surface-deep);
  font-size: 0.9em;
}

.markdown-preview pre,
.text-preview {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-deep);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.markdown-preview pre {
  padding: 14px;
}

.library-preview-loading {
  min-height: 100%;
}

.module-label,
.status-label,
.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
}

.module-label {
  padding: 5px 8px;
  color: var(--ink-soft);
  background: var(--surface-soft);
}

.status-label {
  padding: 5px 8px;
}

.status-new { color: var(--blue); background: var(--blue-soft); }
.status-due { color: var(--coral); background: var(--coral-soft); }
.status-learning { color: var(--amber); background: var(--amber-soft); }
.status-mature { color: var(--green); background: var(--green-soft); }

.empty-state,
.loading-state,
.error-state {
  min-height: 380px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg,
.error-state svg {
  width: 34px;
  height: 34px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.study-page {
  width: min(900px, 100%);
  margin: 0 auto;
}

.study-topbar {
  min-height: 48px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 70px;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.study-progress {
  min-width: 0;
}

.study-progress .progress-track {
  height: 6px;
}

.study-progress strong {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  text-align: center;
}

.study-counter {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.flashcard {
  min-height: 480px;
  display: flex;
  flex-direction: column;
  padding: 28px 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.flashcard-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.flashcard-meta-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.flashcard-date {
  color: var(--muted);
  font-size: 12px;
}

.flashcard-body {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 34px 0;
}

.flashcard-question,
.flashcard-answer {
  width: min(690px, 100%);
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: center;
}

.flashcard-question-view,
.flashcard-answer-view {
  width: min(720px, 100%);
  display: grid;
  gap: 24px;
}

.formula-inline {
  display: inline-block;
  max-width: 100%;
  margin: 0 0.08em;
  vertical-align: -0.08em;
}

.formula-block {
  max-width: 100%;
  display: block;
  margin: 14px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.formula-block .katex-display {
  margin: 0;
}

.formula-fallback {
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--surface-2);
}

.flashcard-question {
  font-size: 27px;
  font-weight: 760;
  line-height: 1.42;
}

.flashcard-answer {
  color: var(--ink-soft);
  font-size: 20px;
  line-height: 1.58;
}

.study-note {
  display: grid;
  gap: 8px;
  text-align: left;
}

.study-note > span,
.self-answer > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.study-note textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface-2);
  font: inherit;
  font-size: 16px;
  line-height: 1.45;
}

.study-note textarea:focus {
  border-color: var(--green);
  outline: 3px solid var(--green-soft);
}

.study-note small {
  color: var(--muted);
  font-size: 11px;
}

.self-answer {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  text-align: left;
}

.self-answer p {
  margin: 7px 0 0;
  color: var(--ink-soft);
  line-height: 1.5;
  white-space: pre-wrap;
}

.self-answer.is-empty p {
  color: var(--muted);
  font-style: italic;
}

.answer-label {
  display: block;
  margin-bottom: 14px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.flashcard-footer {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.revealed-footer {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.flip-question-button {
  white-space: nowrap;
}

.rating-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.rating-button {
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.rating-button strong {
  font-size: 13px;
}

.rating-button small {
  color: var(--muted);
  font-size: 11px;
}

.rating-button[data-rating="again"]:hover { border-color: var(--coral); background: var(--coral-soft); }
.rating-button[data-rating="hard"]:hover { border-color: var(--amber); background: var(--amber-soft); }
.rating-button[data-rating="good"]:hover { border-color: var(--blue); background: var(--blue-soft); }
.rating-button[data-rating="easy"]:hover { border-color: var(--green); background: var(--green-soft); }

.session-complete {
  min-height: 540px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 20px;
  text-align: center;
}

.session-complete-icon {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--green);
  background: var(--green-soft);
}

.session-complete-icon svg {
  width: 30px;
  height: 30px;
}

.session-complete h2 {
  margin: 0;
  font-size: 26px;
}

.session-results {
  display: grid;
  grid-template-columns: repeat(4, 90px);
  gap: 8px;
}

.session-result {
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.session-result strong,
.session-result span {
  display: block;
}

.session-result strong {
  font-size: 20px;
}

.session-result span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
}

.stats-panel {
  min-height: 280px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.stats-panel h2 {
  margin: 0 0 20px;
  font-size: 17px;
}

.bar-list {
  display: grid;
  gap: 15px;
}

.bar-row-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.activity-chart {
  height: 205px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end;
  gap: 8px;
  padding-top: 8px;
}

.activity-day {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 7px;
  text-align: center;
}

.activity-bar-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.activity-bar {
  width: min(28px, 75%);
  min-height: 3px;
  border-radius: 4px 4px 2px 2px;
  background: var(--blue);
}

.activity-day strong {
  font-size: 11px;
}

.activity-day span {
  color: var(--muted);
  font-size: 10px;
}

.dialog {
  width: min(660px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.56);
}

.dialog::backdrop {
  background: rgba(3, 5, 4, 0.76);
}

.dialog-panel {
  padding: 24px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-card-body {
  padding: 24px;
}

.dialog-card-body h3 {
  margin: 0 0 18px;
  font-size: 20px;
  line-height: 1.4;
}

.dialog-answer {
  margin: 0;
  padding: 18px;
  border-left: 3px solid var(--green);
  color: var(--ink-soft);
  background: var(--surface-soft);
  white-space: pre-wrap;
  line-height: 1.55;
}

.tag-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.tag {
  padding: 4px 7px;
  color: var(--muted);
  border: 1px solid var(--line);
}

.source-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.dialog.cheatsheet-dialog {
  width: min(1180px, calc(100% - 32px));
  max-height: calc(100dvh - 28px);
  overflow: auto;
  background: var(--surface-deep);
}

.cheatsheet-dialog-content > .dialog-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(20, 26, 24, 0.98);
}

.cheatsheet-dialog-body {
  padding: 22px 24px 26px;
}

.cheatsheet-detail-image {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f7f9fc;
}

.cheatsheet-detail-image img {
  width: 100%;
  height: auto;
  display: block;
}

.cheatsheet-detail-copy {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 0.42fr);
  gap: 28px;
  align-items: start;
  padding-top: 22px;
}

.cheatsheet-detail-copy ol {
  margin: 9px 0 0;
  padding-left: 22px;
  color: var(--ink-soft);
}

.cheatsheet-detail-copy li {
  padding-left: 5px;
  line-height: 1.55;
}

.cheatsheet-detail-copy li + li {
  margin-top: 7px;
}

.cheatsheet-source {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 11px;
  padding: 14px 0 14px 15px;
  border-left: 3px solid var(--green);
}

.cheatsheet-source > span {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
}

.cheatsheet-source svg {
  width: 18px;
  height: 18px;
}

.cheatsheet-source p {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.cheatsheet-source strong {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 13px;
}

.setting-row,
.danger-zone,
.account-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.setting-row {
  margin: 24px 0 14px;
}

.setting-row strong,
.setting-row small,
.danger-zone strong,
.danger-zone small,
.account-zone strong,
.account-zone small {
  display: block;
}

.setting-row small,
.danger-zone small,
.account-zone small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.setting-row output {
  min-width: 50px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
  font-weight: 800;
  text-align: center;
}

#daily-goal {
  width: 100%;
  accent-color: var(--green);
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.danger-zone {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.account-zone {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 360px;
  padding: 12px 15px;
  border-radius: 6px;
  color: #fff;
  background: var(--sidebar);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.mobile-nav {
  display: none;
}

@media (max-width: 960px) {
  .main-content { padding: 28px 24px 42px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: 1fr; }
  .deck-row { grid-template-columns: minmax(170px, 1fr) minmax(140px, 0.8fr) 70px 40px; gap: 12px; }
  .filter-toolbar { grid-template-columns: 1fr 170px; }
  .filter-toolbar select:last-child { grid-column: 2; }
  .search-field { grid-row: span 2; }
  .library-toolbar { grid-template-columns: 1fr 190px; }
  .library-search { grid-row: span 2; }
  .library-layout { grid-template-columns: minmax(270px, 0.8fr) minmax(0, 1.2fr); }
  .library-file-meta { display: none; }
  .library-row { grid-template-columns: 38px minmax(0, 1fr) 18px; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main-content { padding: 22px 16px 94px; }
  .page-header { min-height: auto; margin-bottom: 20px; }
  .page-header h1, .page-header h2, .dialog h2 { font-size: 24px; }
  .header-actions .button span { display: none; }
  .header-actions .button { width: 42px; padding: 0; }
  .metric-grid { gap: 8px; }
  .metric { min-height: 98px; padding: 14px; }
  .metric-value { font-size: 24px; }
  .goal-band { grid-template-columns: 1fr; gap: 18px; padding: 18px; }
  .goal-band .button { width: 100%; }
  .deck-row { grid-template-columns: minmax(0, 1fr) 64px 40px; gap: 10px; padding: 13px 4px; }
  .deck-progress { display: none; }
  .deck-name small { white-space: normal; }
  .filter-toolbar { grid-template-columns: 1fr; }
  .search-field { grid-row: auto; }
  .filter-toolbar select:last-child { grid-column: auto; }
  .card-row { grid-template-columns: minmax(0, 1fr) 40px; gap: 10px; }
  .card-row > .module-label, .card-row > .status-label { display: none; }
  .cheatsheet-grid { grid-template-columns: 1fr; gap: 13px; }
  .cheatsheet-intro { grid-template-columns: 40px minmax(0, 1fr); gap: 12px; padding: 14px 0 16px; }
  .cheatsheet-intro-icon { width: 40px; height: 40px; }
  .cheatsheet-card-copy { min-height: auto; padding: 15px 16px 17px; }
  .dialog.cheatsheet-dialog { width: calc(100% - 16px); max-height: calc(100dvh - 16px); }
  .cheatsheet-dialog-body { padding: 14px 12px 20px; }
  .cheatsheet-detail-copy { grid-template-columns: 1fr; gap: 16px; padding: 18px 4px 0; }
  .cheatsheet-source { padding-left: 12px; }
  .study-topbar { grid-template-columns: 40px minmax(0, 1fr) 48px; gap: 10px; }
  .flashcard { min-height: 520px; padding: 20px 18px; }
  .flashcard-meta { align-items: flex-start; }
  .flashcard-question { font-size: 23px; }
  .flashcard-answer { font-size: 18px; }
  .flashcard-question-view, .flashcard-answer-view { gap: 18px; }
  .study-note textarea { min-height: 92px; }
  .revealed-footer { grid-template-columns: 1fr; }
  .flip-question-button { width: 100%; }
  .rating-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .session-results { grid-template-columns: repeat(2, 90px); }
  .mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 15;
    min-height: 70px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: rgba(11, 15, 14, 0.97);
  }
  .mobile-nav-item {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: 0;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
  }
  .mobile-nav-item.is-active { color: var(--green); background: var(--green-soft); }
  .mobile-nav-item svg { width: 19px; height: 19px; }
  .mobile-nav-item span { max-width: 100%; overflow: hidden; font-size: 10px; text-overflow: ellipsis; }
  .toast { right: 14px; bottom: 84px; left: 14px; max-width: none; }
  .library-toolbar { grid-template-columns: 1fr 1fr; }
  .library-search { grid-column: 1 / -1; grid-row: auto; }
  .library-layout {
    height: max(520px, calc(100dvh - 285px));
    min-height: 0;
    display: block;
  }
  .library-results { height: 100%; border-right: 0; }
  .library-preview:not(.is-open) { display: none; }
  .library-layout.has-selection .library-results { display: none; }
  .library-layout.has-selection .library-preview { height: 100%; }
  .library-preview-header { grid-template-columns: 40px 34px minmax(0, 1fr) 40px; }
  .library-preview-back { display: inline-flex; }
  .library-frame { min-height: 100%; }
  .library-row { min-height: 70px; }
  .markdown-preview, .text-preview { padding: 24px 18px 60px; }
}

@media (max-width: 420px) {
  .login-body { padding: 20px 14px; }
  .login-panel { padding: 24px 20px; }
  .login-heading h1 { font-size: 24px; }
  .metric-head span:first-child { max-width: 90px; }
  .page-header { gap: 10px; }
  .flashcard { min-height: 500px; }
  .flashcard-meta-left { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
