:root {
  color-scheme: light;
  --bg: #efe3cc;
  --surface: #161511;
  --surface-strong: #222019;
  --ink: #2b2419;
  --ink-on-dark: #f7ead1;
  --muted: #8b7a61;
  --muted-on-dark: #b6a98e;
  --line: rgba(91, 78, 54, 0.24);
  --line-dark: rgba(247, 234, 209, 0.12);
  --accent: #d9bd82;
  --accent-dark: #a98142;
  --rose: #bb6b5a;
  --gold: #e5c990;
  --blue: #bfa671;
  --peach: #d9bd82;
  --mint: #312d21;
  --lilac: #3a3325;
  --shadow: 0 30px 70px rgba(31, 27, 20, 0.28);
  --round-sm: 14px;
  --round-md: 20px;
  --round-lg: 30px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 247, 229, 0.82), transparent 20%),
    radial-gradient(circle at 18% 14%, rgba(246, 224, 184, 0.78), transparent 30%),
    radial-gradient(circle at 84% 82%, rgba(210, 179, 126, 0.5), transparent 34%),
    linear-gradient(160deg, #f5ead7 0%, #ead9bb 48%, #d7bd8d 100%);
  color: var(--ink);
  font-family: "手札体-简", "ShouZhaTi-Jian", "Hannotate SC", "Kaiti SC", "STKaiti", ui-serif, serif;
  letter-spacing: 0;
}

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

input,
select,
textarea {
  font-family: "手札体-简", "ShouZhaTi-Jian", "Hannotate SC", "Kaiti SC", "STKaiti", ui-serif, serif;
}

button {
  cursor: pointer;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(430px, 100%);
  border: 1px solid var(--line-dark);
  border-radius: var(--round-lg);
  padding: 28px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 32%),
    linear-gradient(160deg, #222018 0%, #12110e 78%);
  box-shadow: 0 28px 70px rgba(30, 26, 20, 0.36), 0 18px 34px rgba(157, 121, 65, 0.22);
  color: var(--ink-on-dark);
}

.auth-card h2,
.auth-card p {
  margin: 0;
}

.auth-card h2 {
  font-size: 28px;
}

.auth-card p {
  color: var(--muted-on-dark);
  line-height: 1.55;
}

.auth-message {
  min-height: 22px;
  font-size: 13px;
  font-weight: 700;
}

.auth-message.error {
  color: var(--rose);
}

.auth-message.ok {
  color: var(--gold);
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  max-width: 220px;
  border: 1px solid rgba(229, 201, 144, 0.28);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted-on-dark);
  background: rgba(22, 21, 17, 0.72);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  border-right: 1px solid rgba(91, 78, 54, 0.28);
  background: rgba(238, 221, 190, 0.64);
  backdrop-filter: blur(22px);
}

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

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(145deg, #1c1a15, #3b3324);
  color: var(--gold);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 12px 28px rgba(45, 35, 18, 0.2);
  font-weight: 800;
}

.brand h1,
.topbar h2,
.composer h2 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  font-weight: 800;
}

.brand p,
.eyebrow {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.nav-list,
.sidebar-actions {
  display: grid;
  gap: 8px;
}

.nav-button,
.ghost-button,
.primary-button,
.danger-button,
.text-button,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 14px;
  color: var(--ink);
  background: transparent;
}

.nav-button {
  text-align: left;
}

.nav-button:hover,
.nav-button.active,
.ghost-button:hover,
.text-button:hover {
  border-color: var(--line);
  background: rgba(255, 247, 230, 0.72);
}

.primary-button {
  background: linear-gradient(135deg, #ecd7a5, #b98c4f);
  color: #211b12;
  font-weight: 700;
  box-shadow: 0 14px 28px rgba(87, 60, 24, 0.26);
}

.primary-button:hover {
  background: linear-gradient(135deg, #f4dfae, #a97a3b);
}

.ghost-button {
  border-color: var(--line);
  background: rgba(255, 247, 230, 0.58);
}

.danger-button {
  color: white;
  background: var(--rose);
}

.text-button {
  color: #6f512a;
  font-weight: 700;
}

.icon-button {
  width: 40px;
  padding: 0;
  border-color: var(--line);
  border-radius: 16px;
  background: #f8ecd4;
  font-size: 24px;
}

.file-button {
  display: grid;
  place-items: center;
}

.file-button input {
  display: none;
}

.image-field {
  display: grid;
  gap: 12px;
}

.image-picker {
  display: grid;
  min-height: 46px;
  place-items: center;
  border: 1px dashed rgba(229, 201, 144, 0.34);
  border-radius: 18px;
  color: var(--gold) !important;
  background: rgba(255, 243, 218, 0.07);
  cursor: pointer;
}

.image-picker input {
  display: none;
}

.image-preview {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.image-preview img,
.entry-image,
.viewer-image-button img {
  width: 100%;
  border: 1px solid rgba(229, 201, 144, 0.2);
  border-radius: 18px;
  object-fit: cover;
  background: rgba(255, 243, 218, 0.08);
}

.image-preview img {
  aspect-ratio: 1;
}

.entry-image {
  max-height: 260px;
  margin-top: 10px;
}

.entry-card {
  cursor: pointer;
}

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

.bottom-guide {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1fr 92px 1fr 1fr;
  align-items: center;
  gap: 8px;
  width: min(720px, calc(100vw - 22px));
  min-height: 72px;
  padding: 10px;
  border: 1px solid rgba(247, 234, 209, 0.14);
  border-radius: 28px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.045), transparent 34%),
    linear-gradient(160deg, rgba(33, 31, 24, 0.96), rgba(14, 13, 11, 0.96));
  box-shadow: 0 24px 58px rgba(31, 27, 20, 0.34), 0 12px 26px rgba(169, 122, 59, 0.18);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.bottom-nav-button,
.bottom-compose-button {
  min-width: 0;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--muted-on-dark);
  background: transparent;
  font-weight: 800;
}

.bottom-nav-button.active,
.bottom-nav-button:hover {
  border-color: rgba(229, 201, 144, 0.22);
  color: var(--gold);
  background: rgba(229, 201, 144, 0.1);
}

.bottom-compose-button {
  min-height: 54px;
  color: #211b12;
  background: linear-gradient(135deg, #f1daa4, #b88949);
  box-shadow: 0 14px 28px rgba(185, 140, 79, 0.3);
}

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

.topbar h2 {
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 800;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(110, 91, 57, 0.26);
  border-radius: 16px;
  padding: 10px 12px;
  background: rgba(255, 248, 233, 0.92);
  color: var(--ink);
}

textarea {
  resize: vertical;
}

a {
  color: #e5c990;
}

.auth-card input,
.composer input,
.composer select,
.composer textarea {
  border-color: rgba(229, 201, 144, 0.2);
  background: rgba(255, 243, 218, 0.08);
  color: var(--ink-on-dark);
}

.auth-card input::placeholder,
.composer input::placeholder,
.composer textarea::placeholder {
  color: rgba(247, 234, 209, 0.45);
}

#searchInput {
  width: min(340px, 38vw);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.panel {
  border: 1px solid var(--line-dark);
  border-radius: var(--round-md);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 34%),
    linear-gradient(160deg, #222019 0%, #13120f 80%);
  box-shadow: 0 18px 48px rgba(35, 29, 19, 0.24), 0 12px 28px rgba(174, 132, 70, 0.13);
  color: var(--ink-on-dark);
}

.panel {
  min-height: 280px;
  padding: 18px;
}

.panel.wide {
  grid-column: span 3;
}

.panel-header,
.filter-row,
.composer-header,
.viewer-header,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header {
  margin-bottom: 12px;
}

.panel h3 {
  margin: 0;
  font-size: 18px;
}

.calendar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.mini-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

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

.calendar-weekday {
  color: var(--muted-on-dark);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.calendar-cell {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 92px;
  border: 1px solid rgba(229, 201, 144, 0.14);
  border-radius: 14px;
  padding: 8px;
  color: var(--ink-on-dark);
  background: rgba(255, 243, 218, 0.045);
  text-align: left;
}

.calendar-cell:hover {
  border-color: rgba(229, 201, 144, 0.42);
  background: rgba(229, 201, 144, 0.09);
}

.calendar-cell.muted {
  opacity: 0.42;
}

.calendar-cell.today {
  border-color: rgba(229, 201, 144, 0.7);
  box-shadow: inset 0 0 0 1px rgba(229, 201, 144, 0.28);
}

.calendar-date {
  color: var(--gold);
  font-size: 15px;
  font-weight: 900;
}

.calendar-items {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.calendar-items b {
  overflow: hidden;
  border-radius: 8px;
  padding: 3px 5px;
  color: #211b12;
  background: linear-gradient(135deg, #f1daa4, #c39a5e);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.filter-row {
  justify-content: flex-start;
}

.filter-row select {
  max-width: 190px;
}

.item-list,
.compare-list {
  display: grid;
  gap: 10px;
}

.entry-card,
.compare-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line-dark);
  border-radius: var(--round-md);
  padding: 15px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 30%),
    linear-gradient(160deg, #211f18 0%, #12110e 85%);
  box-shadow: 0 14px 34px rgba(35, 29, 19, 0.2);
  color: var(--ink-on-dark);
}

.entry-card {
  grid-template-columns: minmax(0, 1fr) auto;
}

.entry-card:hover {
  border-color: rgba(229, 201, 144, 0.42);
  transform: translateY(-1px);
}

.entry-main {
  min-width: 0;
}

.entry-title-row,
.entry-meta,
.tag-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.entry-title-row h3 {
  margin: 0;
  font-size: 17px;
}

.entry-body {
  margin: 8px 0 0;
  color: var(--muted-on-dark);
  line-height: 1.5;
  white-space: pre-wrap;
}

.entry-meta,
.tag-row {
  color: var(--muted-on-dark);
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: rgba(229, 201, 144, 0.16);
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
}

.pill.compare {
  background: rgba(229, 201, 144, 0.2);
  color: #f3dcaa;
}

.pill.calendar {
  background: rgba(241, 218, 164, 0.22);
  color: #f6ddb0;
}

.pill.idea {
  background: rgba(217, 189, 130, 0.18);
  color: #f0d69a;
}

.pill.material {
  background: rgba(185, 140, 79, 0.2);
  color: #e8c98b;
}

.pill.reading {
  background: rgba(255, 240, 206, 0.13);
  color: #ead4a1;
}

.entry-side {
  display: grid;
  justify-items: end;
  align-content: start;
  gap: 8px;
  min-width: 96px;
}

.amount {
  font-size: 20px;
  font-weight: 800;
}

.progress-track {
  width: 118px;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(247, 234, 209, 0.13);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #9d7942, #e8cf9a);
}

.compare-card strong {
  font-size: 16px;
}

.compare-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  color: var(--muted-on-dark);
  font-size: 13px;
}

.compare-stats span {
  display: grid;
  gap: 2px;
}

.compare-stats b {
  color: var(--ink-on-dark);
  font-size: 16px;
}

dialog {
  width: min(720px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--round-lg);
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(36, 33, 29, 0.42);
}

.composer,
.viewer {
  display: grid;
  gap: 14px;
  max-height: min(86vh, 880px);
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line-dark);
  border-radius: var(--round-lg);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.04), transparent 32%),
    linear-gradient(160deg, #242119 0%, #12110e 80%);
  color: var(--ink-on-dark);
  box-shadow: var(--shadow);
}

.composer label {
  display: grid;
  gap: 7px;
  color: var(--muted-on-dark);
  font-size: 13px;
  font-weight: 700;
}

.viewer {
  gap: 16px;
}

.viewer-header h2,
.viewer-header p {
  margin: 0;
}

.viewer-meta,
.viewer-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted-on-dark);
  font-size: 14px;
}

.viewer-body {
  margin: 0;
  color: var(--ink-on-dark);
  line-height: 1.7;
  white-space: pre-wrap;
}

.viewer-detail {
  border: 1px solid rgba(229, 201, 144, 0.16);
  border-radius: 18px;
  padding: 12px;
  background: rgba(255, 243, 218, 0.06);
}

.viewer-image-button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 22px;
  padding: 0;
  background: transparent;
}

.viewer-image-button img {
  display: block;
  max-height: min(54vh, 520px);
}

#imageDialog {
  width: min(1120px, calc(100vw - 18px));
}

#imageDialog::backdrop {
  background: rgba(10, 9, 7, 0.78);
}

.image-viewer {
  position: relative;
  display: block;
  max-height: 90vh;
  min-height: min(86vh, 900px);
  overflow: auto;
  padding: 72px 18px 18px;
}

.image-viewer img {
  display: block;
  width: 100%;
  min-width: min(100%, 980px);
  max-width: none;
  max-height: none;
  margin: 0 auto;
  border: 1px solid rgba(229, 201, 144, 0.2);
  border-radius: 22px;
  object-fit: contain;
  box-shadow: var(--shadow);
}

.image-tools {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: -54px 0 14px;
  padding: 8px;
  border: 1px solid rgba(229, 201, 144, 0.18);
  border-radius: 999px;
  background: rgba(18, 17, 14, 0.86);
  backdrop-filter: blur(12px);
}

.image-tools .ghost-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--ink-on-dark);
}

.image-tools .icon-button {
  width: 36px;
  height: 36px;
  background: rgba(255, 243, 218, 0.08);
}

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

.type-fields {
  display: none;
  gap: 12px;
}

.type-fields.visible {
  display: grid;
}

.form-actions {
  justify-content: flex-end;
  padding-top: 6px;
}

#deleteEntry {
  margin-right: auto;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed rgba(229, 201, 144, 0.28);
  border-radius: var(--round-md);
  color: var(--muted-on-dark);
  text-align: center;
}

.empty-state strong {
  color: var(--ink-on-dark);
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 4;
    gap: 14px;
    padding: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-button {
    flex: 0 0 auto;
  }

  .sidebar-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  #searchInput {
    width: 100%;
  }

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

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

@media (max-width: 560px) {
  .main {
    padding: 18px 12px 116px;
  }

  .brand p,
  .sidebar-actions .file-button,
  .sidebar-actions #exportCsv {
    display: none;
  }

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

  .dashboard-grid,
  .form-grid,
  .compare-stats {
    grid-template-columns: 1fr;
  }

  .calendar-grid {
    gap: 4px;
  }

  .calendar-cell {
    min-height: 72px;
    border-radius: 12px;
    padding: 6px;
  }

  .calendar-items b {
    padding: 2px 4px;
    font-size: 11px;
  }

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

  .entry-card {
    grid-template-columns: 1fr;
  }

  .entry-side {
    justify-items: start;
  }

  .progress-track {
    width: 100%;
  }

  .image-preview {
    grid-template-columns: 1fr;
  }

  .bottom-guide {
    grid-template-columns: 1fr 1fr 78px 1fr 1fr;
    gap: 5px;
    width: calc(100vw - 14px);
    min-height: 66px;
    padding: 8px;
    border-radius: 24px;
  }

  .bottom-nav-button,
  .bottom-compose-button {
    min-height: 44px;
    padding: 0 6px;
    font-size: 13px;
  }
}
