:root {
  color-scheme: light;
  --paper: #f7f4ed;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #1f2933;
  --muted: #667085;
  --line: #ded8ce;
  --blue: #2563eb;
  --green: #13795b;
  --amber: #b7791f;
  --red: #ba3b46;
  --violet: #6750a4;
  --shadow: 0 18px 50px rgba(31, 41, 51, 0.09);
  --radius: 8px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

.update-banner {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(360px, calc(100vw - 28px));
  min-height: 48px;
  padding: 9px 10px 9px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.update-banner span {
  flex: 1;
  font-weight: 700;
}

.update-banner button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 6px 10px;
  font-weight: 700;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: #ece9e0;
}

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

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
}

.brand-mark svg {
  display: block;
  width: 42px;
  height: 42px;
}

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

.brand strong {
  font-size: 17px;
}

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

.nav {
  display: grid;
  gap: 8px;
}

.sync-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.72);
}

.sync-card strong,
.sync-card span {
  display: block;
}

.sync-card strong {
  font-size: 14px;
}

.sync-card span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  line-height: 1.35;
}

.sync-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sync-actions .ghost {
  grid-column: 1 / -1;
}

.nav button,
.icon-text-button,
.primary-button,
.icon-button,
.rating-row button,
.segmented-control button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 42px;
}

.nav button {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.nav button:hover,
.nav button.active {
  background: var(--surface);
  border-color: var(--line);
}

.nav .nav-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffaf0;
  color: var(--blue);
  font-weight: 700;
}

.nav .nav-count {
  min-width: 24px;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
}

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

.icon-text-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  padding: 8px 10px;
}

.icon-text-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.main {
  min-width: 0;
  padding: 28px clamp(18px, 3vw, 42px) 48px;
}

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

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

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

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

h2 {
  margin-bottom: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.target-date {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.target-date input,
.compact-input,
.stack-form input,
.stack-form textarea,
.stack-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  min-height: 42px;
  padding: 10px 12px;
  outline: none;
}

.target-date input:focus,
.compact-input:focus,
.stack-form input:focus,
.stack-form textarea:focus,
.stack-form select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.dashboard-grid,
.resource-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.module-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
  align-items: start;
  max-width: 1040px;
}

.span-2 {
  grid-column: span 2;
}

.metric-band {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
  box-shadow: var(--shadow);
}

.metric-band article {
  min-height: 126px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 20px;
  background: var(--surface);
}

.metric-label,
.metric-unit,
.source-pill,
.record-meta,
.resource-meta {
  color: var(--muted);
  font-size: 12px;
}

.metric-band strong {
  font-size: 34px;
  line-height: 1;
  color: var(--ink);
}

.workbench-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.tool-panel {
  grid-column: span 1;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 34px;
}

.source-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: #faf7ef;
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  background: var(--ink);
  color: #fff;
  padding: 11px 14px;
  font-weight: 700;
}

.primary-button:hover,
.icon-button:hover {
  background: #0f1720;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.stack-form {
  display: grid;
  gap: 10px;
}

.stack-form textarea {
  min-height: 108px;
  resize: vertical;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.auto-classify-note {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #faf7ef;
  color: var(--muted);
  font-size: 13px;
}

.task-list,
.source-stack,
.activity-list,
.record-list,
.resource-list,
.policy-grid {
  display: grid;
  gap: 10px;
}

.task-item,
.activity-item,
.record-item,
.resource-item,
.policy-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 12px;
}

.task-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.task-mark {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--blue);
}

.task-item:nth-child(2) .task-mark {
  background: var(--green);
}

.task-item:nth-child(3) .task-mark {
  background: var(--amber);
}

.task-item:nth-child(4) .task-mark {
  background: var(--red);
}

.task-item strong,
.record-item strong,
.resource-item strong,
.policy-item strong {
  display: block;
  margin-bottom: 4px;
}

.exam-map {
  display: grid;
  gap: 12px;
}

.exam-row {
  display: grid;
  gap: 6px;
}

.exam-row > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #e6e1d8;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.exam-row:nth-child(2) .bar span {
  background: var(--green);
}

.exam-row:nth-child(3) .bar span {
  background: var(--amber);
}

.exam-row:nth-child(4) .bar span {
  background: var(--violet);
}

.exam-row:nth-child(5) .bar span {
  background: var(--red);
}

.exam-row:nth-child(6) .bar span {
  background: #0f766e;
}

.source-stack .resource-pill {
  justify-content: space-between;
  gap: 10px;
  border-radius: var(--radius);
  min-height: 44px;
}

.flashcard {
  min-height: 260px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf0;
}

.daily-vocab-plan {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.plan-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.plan-head strong {
  font-size: 15px;
}

.plan-head span,
.daily-vocab-plan p {
  color: var(--muted);
  font-size: 12px;
}

.daily-vocab-plan p {
  margin: 0;
  line-height: 1.45;
}

.plan-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.plan-grid div {
  min-height: 66px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #faf7ef;
}

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

.plan-grid strong {
  font-size: 20px;
}

.flashcard .word {
  font-size: clamp(34px, 6vw, 54px);
  font-weight: 800;
  line-height: 1.05;
}

.flashcard .word-meta {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.word-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.flashcard .base-meaning {
  margin-top: 10px;
  color: var(--amber);
  font-size: 13px;
}

.flashcard .meaning {
  margin-top: 14px;
  color: var(--muted);
  font-size: 17px;
}

.flashcard .example {
  margin-top: 16px;
  color: var(--ink);
  font-size: 14px;
}

.rating-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.rating-row button {
  background: var(--surface-strong);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 700;
}

.rating-row button[data-rating="again"] {
  color: var(--red);
}

.rating-row button[data-rating="hard"] {
  color: var(--amber);
}

.rating-row button[data-rating="good"] {
  color: var(--green);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #faf7ef;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.delete-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--red);
  min-width: 34px;
  min-height: 34px;
  font-weight: 800;
}

.auth-dialog {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(31, 41, 51, 0.36);
}

.auth-box {
  display: grid;
  gap: 14px;
  width: min(420px, calc(100vw - 28px));
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.auth-box label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.auth-box input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  padding: 10px 12px;
}

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

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #faf7ef;
}

.segmented-control button {
  background: transparent;
  color: var(--muted);
}

.segmented-control button.active {
  background: var(--surface-strong);
  color: var(--ink);
  border-color: var(--line);
  font-weight: 700;
}

.record-item p,
.resource-item p,
.policy-item p,
.activity-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.record-meta,
.resource-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-cloud span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
}

.resource-item a {
  color: var(--blue);
  text-decoration: none;
}

.resource-item a:hover {
  text-decoration: underline;
}

.empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: #fbf8f1;
  text-align: center;
  padding: 18px;
}

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

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

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

  .sync-card {
    grid-column: 1 / -1;
  }

  .dashboard-grid,
  .module-layout,
  .resource-layout {
    grid-template-columns: 1fr;
    max-width: none;
  }

  .span-2,
  .tool-panel {
    grid-column: span 1;
  }

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

@media (max-width: 620px) {
  .main {
    padding: 20px 14px 36px;
  }

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

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

  .sync-actions {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .sync-actions .ghost {
    grid-column: auto;
  }

  .nav button {
    grid-template-columns: 28px 1fr;
  }

  .nav .nav-count {
    display: none;
  }

  .metric-band {
    grid-template-columns: 1fr;
  }

  .field-grid,
  .rating-row,
  .plan-grid {
    grid-template-columns: 1fr;
  }
}
