:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #162033;
  --muted: #697386;
  --line: #d9e1ec;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #15803d;
  --shadow: 0 12px 32px rgba(29, 78, 216, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 42%, #ffffff 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body.login-open {
  overflow: hidden;
}

body.loading-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  min-height: 44px;
  padding: 0 18px;
  font-weight: 700;
  cursor: pointer;
}

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

button.secondary {
  background: #e8eef8;
  color: #243044;
}

button.secondary:hover {
  background: #dbe5f4;
}

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

input {
  min-height: 44px;
  padding: 0 14px;
}

textarea {
  min-height: 120px;
  padding: 14px;
  line-height: 1.6;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px;
  transition: filter 0.18s ease, opacity 0.18s ease;
}

.app.locked {
  filter: blur(10px);
  opacity: 0.5;
  pointer-events: none;
  user-select: none;
}

.app.loading {
  filter: blur(10px);
  opacity: 0.5;
  pointer-events: none;
  user-select: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  margin: -18px -18px 0;
  padding: 18px 18px 10px;
  background: rgba(244, 247, 251, 0.94);
  backdrop-filter: blur(10px);
}

.topbar > div {
  grid-column: 2;
  min-width: 160px;
  width: auto;
}

.topbar.home {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  padding-bottom: 14px;
}

.topbar.home > div {
  flex: 1 1 auto;
  align-self: center;
  min-width: 0;
}

.topbar.home .home-account-actions {
  display: flex;
  flex: 0 0 auto;
}

.topbar.home .icon-btn {
  display: none !important;
}

.back-btn {
  grid-column: 1;
}

.icon-btn {
  grid-column: 3;
}

.back-btn,
.icon-btn {
  width: 48px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 8px 22px rgba(22, 32, 51, 0.08);
}

.back-btn {
  font-size: 36px;
  line-height: 1;
}

.icon-btn {
  font-size: 22px;
}

.home-account-actions {
  display: none;
  flex-shrink: 0;
  gap: 6px;
}

.topbar:not(.home) .home-account-actions {
  display: none !important;
}

.home-account-actions[hidden] {
  display: none !important;
}

.account-btn {
  min-width: 54px;
  min-height: 44px;
  padding: 0 8px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

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

.change-password-form label {
  font-weight: 700;
}

.change-password-form .message,
.change-password-form .modal-actions {
  margin-top: 2px;
}

.back-btn:hover,
.icon-btn:hover {
  background: #f8fbff;
}

.icon-btn.locked {
  border-color: #f3b4b4;
  background: #fff1f1;
  color: #dc2626;
}

.icon-btn.locked:hover {
  background: #ffe7e7;
}

.icon-btn.unlocked {
  color: #2563eb;
}

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

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

h2 {
  font-size: 18px;
}

.page-eyebrow-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.create-panel,
.editor-panel,
.today-list,
.stats-bar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.create-panel,
.editor-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.create-panel label,
.editor-panel label {
  font-weight: 800;
}

.create-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.password-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
}

.password-toggle input {
  width: 18px;
  min-height: 18px;
}

.library-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.library-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(22, 32, 51, 0.08);
  cursor: pointer;
  text-align: left;
}

.library-item:active {
  transform: translateY(1px);
}

.library-name {
  overflow-wrap: anywhere;
  font-size: 20px;
  font-weight: 800;
}

.library-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.library-date {
  overflow-wrap: anywhere;
}

.load-more-btn {
  display: block;
  width: min(320px, 100%);
  margin: 18px auto 0;
}

.lock {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 2px solid #aab7ca;
  border-radius: 8px;
  background: #f7faff;
  font-size: 28px;
}

.lock.locked {
  border-color: #f3b4b4;
  background: #fff1f1;
  color: #dc2626;
}

.lock.unlocked {
  border-color: #aab7ca;
  background: #f7faff;
  color: #2563eb;
}

.today-list {
  padding: 16px;
  margin-bottom: 100px;
}

#todayView.active {
  padding-bottom: 250px;
}

#todayView .editor-panel {
  position: fixed;
  right: max(18px, calc((100vw - 1120px) / 2 + 18px));
  bottom: 18px;
  z-index: 11;
  width: min(420px, calc(100vw - 36px));
  overflow: visible;
}

#todayView .editor-panel textarea {
  height: 120px;
  min-height: 120px;
}

.section-heading,
.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.section-heading span {
  color: var(--muted);
}

ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.today-list ol,
.all-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

.log-item:last-child {
  border-bottom: 0;
}

.log-index {
  color: var(--muted);
  font-weight: 800;
}

.log-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.log-time {
  color: var(--muted);
  font-size: 13px;
}

.log-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}

.log-actions {
  display: flex;
  gap: 8px;
}

.log-actions button {
  min-height: 30px;
}

.log-icon-btn {
  display: inline-grid;
  width: 32px;
  min-width: 32px;
  height: 30px;
  padding: 0;
  place-items: center;
  background: #e8eef7;
  color: #34435a;
}

.log-icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.log-icon-btn.delete-btn {
  background: #fee2e2;
  color: #b91c1c;
}

.log-icon-btn:hover {
  background: #d9e3f1;
}

.log-icon-btn.delete-btn:hover {
  background: #fecaca;
}

.stats-bar {
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-bottom: 14px;
  padding: 12px 14px;
}

.stats-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 6px;
  width: 100%;
}

.stats-actions button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 38px;
  padding: 0 6px;
  font-size: 12px;
  white-space: nowrap;
}

.stats-actions .password-remove {
  background: #fee2e2;
  color: #b91c1c;
}

.stats-actions .password-remove:hover {
  background: #fecaca;
}

.stats-actions .library-delete-btn {
  background: #fee2e2;
  color: #b91c1c;
}

.stats-actions .library-delete-btn:hover {
  background: #fecaca;
}

.message {
  margin: 0;
  font-weight: 700;
}

.message.success {
  color: var(--success);
}

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

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

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

.empty-state {
  margin: 18px 0 0;
  padding: 20px;
  border: 1px dashed #aab7ca;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border-radius: 8px;
  background: #162033;
  color: #fff;
  box-shadow: 0 12px 28px rgba(22, 32, 51, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 32, 51, 0.34);
  backdrop-filter: blur(4px);
}

.loading-panel {
  width: min(420px, 100%);
  padding: 24px 20px;
  border: 1px solid rgba(217, 225, 236, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 22px 60px rgba(22, 32, 51, 0.3);
  text-align: center;
}

.loading-panel h2 {
  margin: 14px 0 8px;
  font-size: 24px;
}

.loading-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.loading-spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border: 4px solid #d9e1ec;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 32, 51, 0.34);
  backdrop-filter: blur(4px);
}

.login-panel {
  width: min(420px, 100%);
  padding: 20px;
  border: 1px solid rgba(217, 225, 236, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 22px 60px rgba(22, 32, 51, 0.3);
}

.login-panel h2 {
  margin-top: 2px;
  font-size: 24px;
}

.login-panel p {
  margin: 10px 0 14px;
  color: var(--muted);
  line-height: 1.6;
}

.login-panel .message {
  min-height: 22px;
  margin: 10px 0 0;
}

.login-panel.required-login .modal-actions {
  grid-template-columns: 1fr;
}

.login-panel.required-login #loginCancel {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 32, 51, 0.42);
}

.modal-panel {
  width: min(420px, 100%);
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(22, 32, 51, 0.28);
}

.modal-panel p {
  margin: 10px 0 14px;
  color: var(--muted);
  line-height: 1.6;
}

.error-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 32, 51, 0.42);
}

.error-panel {
  width: min(420px, 100%);
  padding: 20px;
  border: 1px solid #f3b4b4;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(22, 32, 51, 0.28);
}

.error-panel h2 {
  color: var(--danger);
}

.error-panel p {
  margin: 10px 0 16px;
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-wrap;
}

.error-panel button {
  width: 100%;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.hidden {
  display: none !important;
}

@media (min-width: 820px) {
  .app {
    padding: 28px;
  }

  .topbar {
    margin: -28px -28px 0;
    padding: 28px 28px 12px;
  }

  #todayView {
    grid-template-columns: minmax(0, calc(100% - 456px));
    gap: 18px;
  }

  #todayView.active {
    display: grid;
  }

  .today-list {
    margin-bottom: 100px;
  }

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

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

  .topbar {
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 6px;
    margin: -12px -12px 0;
    padding: 12px 12px 8px;
  }

  .back-btn,
  .icon-btn {
    width: 42px;
    min-height: 42px;
  }

  .create-row,
  .action-row {
    grid-template-columns: 1fr;
  }

  #todayView.active {
    padding-bottom: 280px;
  }

  #todayView .editor-panel {
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-height: none;
  }

  #todayView .editor-panel textarea {
    height: 120px;
    min-height: 120px;
  }

  .library-item {
    min-height: 84px;
    padding: 14px;
  }

  .lock {
    width: 50px;
    height: 50px;
    font-size: 24px;
  }

  .log-item {
    grid-template-columns: auto 1fr;
  }

  .log-actions {
    grid-column: 2;
  }
}
