:root {
  --paper: #f7f4ee;
  --panel: #fffdf8;
  --ink: #1f2a28;
  --muted: #68746f;
  --line: #ded8cb;
  --fern: #2f6b4f;
  --fern-dark: #1f4d39;
  --clay: #c36f43;
  --sky: #7ca9b8;
  --amber: #e2ad45;
  --danger: #a5483c;
  --shadow: 0 18px 48px rgba(31, 42, 40, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(31, 42, 40, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(31, 42, 40, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

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

button,
.file-label {
  border: 0;
  cursor: pointer;
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
.file-label:focus-visible {
  outline: 3px solid rgba(124, 169, 184, 0.55);
  outline-offset: 2px;
}

.topbar {
  width: min(1200px, calc(100% - 32px));
  margin: 24px auto 18px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--fern);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 6vw, 68px);
  line-height: 0.95;
  font-weight: 700;
}

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

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

.top-actions,
.button-row,
.month-actions,
.range-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto 42px;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.panel,
.stat-card {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.checkin-panel {
  border-top: 5px solid var(--fern);
}

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

.stat-card {
  padding: 16px;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.stat-card strong {
  font-size: 30px;
  line-height: 1;
}

.stat-card.ink {
  color: #fffdf8;
  background: var(--ink);
}

.stat-card.ink span {
  color: rgba(255, 253, 248, 0.72);
}

.chart-panel,
.calendar-panel,
.import-panel,
.library-panel {
  grid-column: span 1;
}

.library-panel {
  grid-column: 1 / -1;
}

.selected-strip {
  min-height: 58px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(47, 107, 79, 0.05);
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 10px;
  background: #e7efe7;
  color: var(--fern-dark);
  max-width: 100%;
}

.selected-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-chip button {
  width: 22px;
  min-height: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  color: var(--fern-dark);
  background: rgba(47, 107, 79, 0.12);
}

.empty-inline,
.empty-state {
  margin: 0;
  color: var(--muted);
}

.log-form,
.manual-form,
.library-filters {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(120px, 0.45fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

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

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

.primary {
  color: #fff;
  background: var(--fern);
}

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

.ghost {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

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

.danger {
  color: var(--danger);
  background: #fff;
  border: 1px solid rgba(165, 72, 60, 0.32);
}

.danger:hover {
  background: rgba(165, 72, 60, 0.08);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--fern-dark);
  background: #e7efe7;
  font-size: 13px;
  font-weight: 800;
}

.today-list {
  margin-top: 18px;
}

.log-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.log-item p {
  margin-bottom: 4px;
}

.log-item small {
  display: block;
  color: var(--muted);
  line-height: 1.5;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(var(--bar-count, 7), minmax(8px, 1fr));
  gap: 6px;
  align-items: end;
  min-height: 210px;
  padding-top: 12px;
}

.bar {
  min-height: 36px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
}

.bar-fill {
  height: var(--bar-height);
  min-height: 4px;
  border-radius: 7px 7px 2px 2px;
  background: linear-gradient(180deg, var(--sky), var(--fern));
}

.bar.zero .bar-fill {
  background: rgba(31, 42, 40, 0.12);
}

.bar small {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.seg {
  min-height: 32px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.seg.active {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-weekdays {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.day-cell {
  position: relative;
  min-height: 58px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  display: block;
  width: 100%;
  overflow: hidden;
}

.day-cell.dim {
  opacity: 0.38;
}

.day-cell.done {
  border-color: rgba(47, 107, 79, 0.4);
  background: #edf4ed;
}

.day-cell.today {
  box-shadow: inset 0 0 0 2px var(--clay);
}

.day-cell strong,
.day-cell small,
.day-cell span,
.day-cell em {
  display: block;
}

.day-cell small {
  margin-top: 6px;
  color: var(--fern-dark);
  font-weight: 800;
}

.day-cell span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  max-height: 28px;
  overflow: hidden;
}

.day-cell em {
  margin-top: 2px;
  color: var(--clay);
  font-style: normal;
  font-size: 11px;
  font-weight: 800;
}

.day-cell.selected {
  border-color: var(--fern);
  box-shadow: inset 0 0 0 2px rgba(47, 107, 79, 0.28);
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 24px;
  background: #fff;
  border: 1px solid var(--line);
}

.calendar-detail {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.detail-head span {
  color: var(--fern-dark);
  font-weight: 800;
}

.detail-log {
  padding: 10px 0;
  border-top: 1px dashed var(--line);
}

.detail-log p {
  margin-bottom: 4px;
  font-weight: 800;
  line-height: 1.45;
}

.detail-log small {
  color: var(--muted);
}

.helper-box {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(226, 173, 69, 0.09);
}

.helper-box summary {
  cursor: pointer;
  padding: 12px;
  font-weight: 800;
}

.helper-box ol,
.helper-box p {
  margin: 0;
  padding: 0 14px 14px 32px;
  color: var(--muted);
  line-height: 1.7;
}

.import-tools {
  display: grid;
  gap: 10px;
}

.manual-form {
  grid-template-columns: 1fr 1.2fr 0.5fr auto;
}

.library-filters {
  grid-template-columns: 1fr 220px;
  margin-bottom: 14px;
}

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

.video-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.thumb {
  aspect-ratio: 16 / 9;
  background:
    linear-gradient(135deg, rgba(47, 107, 79, 0.16), rgba(124, 169, 184, 0.24)),
    #eef2ef;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb span {
  color: var(--fern-dark);
  font-weight: 900;
}

.video-body {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.video-title {
  color: var(--ink);
  font-weight: 800;
  line-height: 1.45;
  text-decoration: none;
}

.video-title:hover {
  color: var(--fern);
}

.video-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.select-video.active {
  color: #fff;
  background: var(--fern);
  border-color: var(--fern);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(18px);
  max-width: min(520px, calc(100% - 28px));
  padding: 12px 16px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .topbar,
  .app-shell {
    width: min(100% - 24px, 680px);
  }

  .topbar,
  .app-shell,
  .log-form,
  .manual-form,
  .library-filters {
    grid-template-columns: 1fr;
  }

  .app-shell {
    display: grid;
  }

  .stats-grid,
  .chart-panel,
  .calendar-panel,
  .import-panel,
  .library-panel {
    grid-column: 1;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .section-head {
    align-items: flex-start;
  }

  .calendar-grid {
    gap: 4px;
  }

  .day-cell {
    min-height: 76px;
    padding: 6px;
  }

  .day-cell span {
    font-size: 10px;
  }

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

  .video-actions .select-video {
    grid-column: 1 / -1;
  }
}

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