:root {
  color-scheme: light;
  --ink: #17201f;
  --muted: #63716f;
  --line: #d9e1de;
  --wash: #f2f6f4;
  --paper: #fbfdfc;
  --accent: #0f5c56;
  --accent-soft: #e0eeea;
  --accent-deep: #093f3b;
  --radius: 16px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
}

.login-gate { display: grid; min-height: 100dvh; place-items: center; padding: 24px; background: #f5f8f6; }
.login-gate[hidden], .app-shell[hidden] { display: none !important; }
.login-card { display: grid; width: min(100%, 360px); gap: 14px; padding: 30px; border: 1px solid var(--line); border-radius: 20px; background: white; box-shadow: 0 14px 36px rgb(14 62 57 / 8%); }
.login-card .brand-mark { margin-bottom: 3px; }
.login-card h1 { margin: 0; font-size: 31px; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.login-card input { width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 10px; outline: none; color: var(--ink); background: #fcfefd; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(15 92 86 / 12%); }
.login-card button { min-height: 43px; border: 0; border-radius: 10px; color: white; background: var(--accent); font-weight: 720; }
.login-card button:disabled { cursor: wait; opacity: .7; }
.login-card .login-error { min-height: 20px; color: #ae3d35; }

button, input { font: inherit; }
button { cursor: pointer; }

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100dvh;
  flex-direction: column;
  padding: 28px 20px;
  border-right: 1px solid var(--line);
  background: #f5f8f6;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 760;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 11px;
  color: white;
  background: var(--accent);
  font-size: 16px;
  letter-spacing: 0;
}

.primary-nav { display: grid; gap: 4px; margin-top: 42px; }

.nav-item, .bottom-nav-item {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-weight: 650;
  text-align: left;
}

.nav-item {
  padding: 10px 12px;
  border-radius: 10px;
}

.nav-item:hover, .nav-item.is-active { color: var(--accent-deep); background: var(--accent-soft); }

.sidebar-section { margin-top: 42px; }
.section-label, .eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.topic-list { display: grid; gap: 3px; margin-top: 11px; }
.topic-list button {
  padding: 7px 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  text-align: left;
}
.topic-list button:hover { color: var(--accent); }

.main-content { width: min(100%, 1020px); padding: 56px clamp(28px, 6vw, 72px) 80px; }

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

h1 { margin: 8px 0 0; font-size: clamp(30px, 4vw, 44px); line-height: 1.08; letter-spacing: -0.055em; }

.toolbar { display: flex; flex: 0 1 300px; align-items: center; gap: 8px; }
.finance-actions { display: flex; gap: 6px; flex: none; }
.finance-action { min-height: 40px; padding: 8px 12px; border: 1px solid; border-radius: 10px; font-size: 13px; font-weight: 760; transition: background-color .15s ease, transform .15s ease; }
.finance-action:active { transform: translateY(1px); }
.finance-action.income { border-color: #9bc8af; color: #236b42; background: #f1faf4; }
.finance-action.income:hover { background: #e5f5ea; }
.finance-action.expense { border-color: #d8b19f; color: #984d36; background: #fff6f1; }
.finance-action.expense:hover { background: #ffebe3; }
.search { min-width: 0; flex: 1; }
.search input {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  background: white;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(15 92 86 / 12%); }

.icon-button {
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--accent-deep);
  background: white;
  font-size: 21px;
  line-height: 1;
}
.icon-button:active, .topic-button:active, .nav-item:active, .bottom-nav-item:active { transform: translateY(1px); }
.icon-button:disabled { cursor: wait; color: var(--muted); }
.language-button { font-size: 12px; font-weight: 760; }

.update-line { min-height: 22px; margin-top: 23px; color: var(--muted); font-size: 13px; }
.view { margin-top: 18px; }
.today-summary { margin: 0 0 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #f8fbf9; }
.today-summary summary { color: var(--accent-deep); cursor: pointer; font-size: 14px; font-weight: 720; }
.today-summary ul { display: grid; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: 13px; }
.today-summary li { padding-left: 10px; border-left: 2px solid #b9d5cd; }

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

.home-category-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.home-category { display: flex; min-height: 164px; flex-direction: column; align-items: flex-start; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: white; box-shadow: 0 8px 24px rgb(14 62 57 / 4%); text-align: left; }
.home-category:hover { border-color: #a1c5bc; background: #fcfffd; }
.home-category-meta { color: var(--accent); font-size: 13px; font-weight: 720; }
.home-category strong { display: -webkit-box; overflow: hidden; margin-top: 11px; color: var(--accent-deep); font-size: 19px; line-height: 1.32; letter-spacing: -0.025em; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.home-category-summary { display: -webkit-box; overflow: hidden; margin-top: 9px; color: #53635f; font-size: 13px; line-height: 1.55; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

.reading-card {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  box-shadow: 0 8px 24px rgb(14 62 57 / 4%);
}

.card-meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.tag { color: var(--accent); font-weight: 720; }
.dot { width: 3px; height: 3px; border-radius: 999px; background: #9aa8a5; }
.reading-card h2 { max-width: 24ch; margin: 13px 0 10px; font-size: clamp(21px, 2.5vw, 28px); line-height: 1.25; letter-spacing: -0.035em; }
.summary { max-width: 68ch; margin: 0; color: #3b4b48; font-size: 15px; line-height: 1.75; }
.content-tags { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 14px; color: var(--accent); font-size: 13px; font-weight: 650; }
.terms { display: flex; flex-wrap: wrap; gap: 7px 10px; margin-top: 17px; padding: 10px 12px; border-radius: 10px; color: #40524f; background: var(--wash); font-size: 13px; line-height: 1.6; }
.terms strong { flex: none; color: var(--accent-deep); }
.terms span + span::before { content: "·"; margin-right: 10px; color: #90a39f; }
.word { padding: 0; border: 0; border-bottom: 1px dashed var(--accent); color: inherit; background: transparent; font: inherit; cursor: pointer; }
.word:hover { color: var(--accent); }
.word-popover { position: fixed; z-index: 30; width: min(276px, calc(100vw - 24px)); padding: 11px 12px; border: 1px solid #d8e5df; border-radius: 12px; box-shadow: 0 12px 28px rgba(38, 68, 59, .16); color: #40524f; background: #fff; font-size: 13px; line-height: 1.65; }
.word-popover strong { display: block; margin-bottom: 2px; color: var(--accent-deep); }
.source-list { display: flex; flex-wrap: wrap; gap: 7px 11px; align-items: center; margin-top: 18px; padding-top: 14px; border-top: 1px solid #e8eeeb; color: var(--muted); font-size: 13px; }
.source-list strong { color: var(--accent-deep); }
.source-list a { color: var(--accent); text-decoration: none; }
.source-list a:hover { text-decoration: underline; }

.details { margin-top: 21px; }
.details > summary { color: var(--accent); cursor: pointer; font-size: 14px; font-weight: 720; }
.details[open] > summary { margin-bottom: 12px; }
.details.is-full > summary { display: none; }
.details.is-full { margin-top: 24px; }
.detail { padding-top: 14px; border-top: 1px solid #e8eeeb; }
.detail h3 { margin: 0 0 6px; color: var(--accent-deep); font-size: 14px; }
.detail p { margin: 0; color: #4b5a57; font-size: 14px; line-height: 1.7; white-space: pre-line; }
.detail.is-flowing { padding-top: 10px; border-top: 0; }
.detail.is-flowing + .detail.is-flowing { padding-top: 12px; }
.reflection { margin-top: 22px; padding-top: 16px; border-top: 1px solid #e8eeeb; }
.reflection label { display: grid; gap: 8px; }
.reflection span { color: var(--accent-deep); font-size: 14px; font-weight: 720; }
.reflection textarea { width: 100%; min-height: 76px; resize: vertical; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; outline: none; color: var(--ink); background: #fcfefd; line-height: 1.55; }
.reflection textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(15 92 86 / 12%); }
.read-toggle { display: inline-flex; min-height: 38px; align-items: center; margin-top: 18px; padding: 8px 14px; border: 1px solid var(--accent); border-radius: 10px; color: var(--accent); background: white; font-size: 14px; font-weight: 720; }
.read-toggle:hover { background: var(--accent-soft); }
.read-toggle.is-read { border-color: var(--line); color: var(--muted); background: var(--wash); }
.back-button { margin: 0 0 13px; padding: 0; border: 0; color: var(--accent); background: transparent; font-size: 14px; font-weight: 720; }

.topic-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.topic-button {
  min-height: 150px;
  padding: 21px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: white;
  text-align: left;
}
.topic-button:hover { border-color: #a1c5bc; background: #fcfffd; }
.topic-button strong { display: block; color: var(--accent-deep); font-size: 19px; }
.topic-button span { display: block; margin-top: 12px; color: var(--muted); font-size: 14px; line-height: 1.6; }

.archive-list { display: grid; gap: 10px; }
.archive-day { display: flex; align-items: center; justify-content: space-between; gap: 20px; width: 100%; padding: 19px 0; border: 0; border-bottom: 1px solid var(--line); color: var(--ink); background: transparent; text-align: left; }
.archive-day:hover { color: var(--accent); }
.archive-day strong { font-size: 17px; }
.archive-day span { color: var(--muted); font-size: 13px; }

.records-summary { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: baseline; margin-bottom: 16px; color: var(--muted); font-size: 14px; }
.records-summary strong { color: var(--accent-deep); font-size: 17px; }
.finance-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: baseline; margin-bottom: 18px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: #f8fbf9; font-size: 13px; }
.finance-summary strong { width: 100%; color: var(--accent-deep); font-size: 14px; }
.finance-summary span { font-variant-numeric: tabular-nums; }
.finance-summary span:nth-child(2) { color: #236b42; }
.finance-summary span:nth-child(3) { color: #984d36; }
.finance-entry-list { display: grid; gap: 1px; margin: -9px 0 18px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.finance-entry { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 13px; color: #4b5a57; background: white; font-size: 13px; }
.finance-entry strong { font-variant-numeric: tabular-nums; }
.finance-entry.income strong { color: #236b42; }
.finance-entry.expense strong { color: #984d36; }
.sync-panel { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #f8fbf9; }
.sync-panel strong { margin-right: 4px; color: var(--accent-deep); font-size: 14px; }
.sync-panel input, .sync-panel button { min-height: 36px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: white; font-size: 13px; }
.sync-panel input { min-width: min(100%, 240px); flex: 1 1 180px; color: var(--ink); }
.sync-panel button { color: var(--accent-deep); font-weight: 680; }
.sync-panel button:hover { border-color: #a1c5bc; background: #fcfffd; }
.sync-panel button:disabled { cursor: wait; color: var(--muted); }
.sync-panel > span { color: var(--accent); font-size: 13px; font-weight: 680; }
.sync-panel small { width: 100%; color: var(--muted); font-size: 12px; }
.record-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.record-controls select, .record-controls input[type="date"], .record-controls button, .import-button { min-height: 38px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; color: var(--accent-deep); background: white; font-size: 13px; font-weight: 680; }
.record-controls select, .record-controls input[type="date"] { color: var(--ink); font-weight: 500; }
.record-controls button:hover, .import-button:hover { border-color: #a1c5bc; background: #fcfffd; }
.import-button { display: inline-flex; align-items: center; cursor: pointer; }
.import-button input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.record-list { display: grid; gap: 14px; }
.record-item { padding: 19px 0; border-bottom: 1px solid var(--line); }
.record-meta { margin: 0; color: var(--muted); font-size: 13px; }
.record-item h2 { margin: 8px 0 0; color: var(--accent-deep); font-size: 19px; letter-spacing: -0.025em; }
.record-note { max-width: 68ch; margin: 10px 0 0; color: #40524f; line-height: 1.7; white-space: pre-line; }
.record-open { margin-top: 12px; padding: 0; border: 0; color: var(--accent); background: transparent; font-size: 13px; font-weight: 720; }

.empty { padding: 46px 20px; border: 1px dashed #b7c7c2; border-radius: var(--radius); color: var(--muted); text-align: center; }
.loading-list { display: grid; gap: 15px; }
.skeleton { border-radius: var(--radius); background: linear-gradient(90deg, #eef3f0 25%, #f8faf9 40%, #eef3f0 60%); background-size: 200% 100%; animation: loading 1.25s ease-in-out infinite; }
.skeleton-title { width: 42%; height: 36px; }
.skeleton-card { height: 178px; }
@keyframes loading { to { background-position: -200% 0; } }

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

.modal { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgb(12 34 30 / 42%); }
.finance-dialog { position: relative; display: grid; width: min(100%, 390px); gap: 9px; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 20px 52px rgb(15 45 39 / 22%); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 6px; }
.dialog-heading h2 { margin: 5px 0 0; color: var(--accent-deep); font-size: 23px; }
.dialog-close { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: white; font-size: 23px; line-height: 1; }
.finance-dialog label { color: var(--accent-deep); font-size: 13px; font-weight: 700; }
.finance-dialog input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; outline: none; color: var(--ink); background: #fcfefd; }
.finance-dialog input:focus, .finance-dialog button:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(15 92 86 / 14%); outline: 2px solid transparent; outline-offset: 2px; }
.amount-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: #fcfefd; }
.amount-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(15 92 86 / 14%); }
.amount-input span { padding-left: 12px; color: var(--muted); font-weight: 700; }
.amount-input input { min-width: 0; border: 0; background: transparent; box-shadow: none !important; }
.form-error { min-height: 20px; margin: 1px 0 0; color: #a43c31; font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dialog-actions button { min-height: 44px; padding: 9px 16px; border: 1px solid var(--line); border-radius: 10px; font-weight: 720; }
.dialog-cancel { color: var(--muted); background: white; }
.finance-submit { color: white; background: var(--accent); }
.finance-submit.is-income { background: #28764a; }
.finance-submit.is-expense { background: #a45238; }
.finance-submit:disabled { cursor: wait; opacity: .7; }

@media (max-width: 760px) {
  .app-shell { display: block; min-height: auto; }
  .sidebar { display: none; }
  .main-content { width: 100%; min-height: 100dvh; padding: calc(28px + env(safe-area-inset-top)) 18px calc(88px + env(safe-area-inset-bottom)); }
  .topbar { align-items: flex-start; flex-direction: column; gap: 19px; }
  .toolbar { width: 100%; max-width: none; flex: none; flex-wrap: wrap; }
  .finance-actions { order: 2; }
  .search { order: 1; flex: 1 1 180px; }
  .language-button, .icon-button { order: 3; }
  h1 { font-size: 32px; }
  .reading-card { padding: 19px; }
  .reading-card h2 { font-size: 23px; }
  .reflection textarea { min-height: 68px; }
  .home-category-grid { gap: 10px; }
  .home-category { min-height: 142px; padding: 15px; }
  .home-category strong { margin-top: 8px; font-size: 16px; }
  .home-category-summary { margin-top: 7px; font-size: 12px; }
  .topic-grid { grid-template-columns: 1fr; }
  .bottom-nav { position: fixed; z-index: 5; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(4, 1fr); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgb(251 253 252 / 94%); backdrop-filter: blur(16px); }
  .bottom-nav-item { padding: 9px 6px; border-radius: 9px; text-align: center; }
  .bottom-nav-item.is-active { color: var(--accent); }
}

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