:root {
  color-scheme: light;
  --bg: #f3f4ef;
  --surface: #fafbf7;
  --surface-strong: #e8ebe3;
  --text: #20231f;
  --muted: #6b7168;
  --line: #d7dbd2;
  --accent: #246b52;
  --accent-hover: #1c5944;
  --accent-soft: #dcebe3;
  --danger: #a13f38;
  --shadow: 0 22px 70px rgba(55, 67, 58, 0.12);
  --radius: 16px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171a17;
  --surface: #1f231f;
  --surface-strong: #292e29;
  --text: #edf0e9;
  --muted: #a5ada2;
  --line: #383e38;
  --accent: #67b797;
  --accent-hover: #7cc4a7;
  --accent-soft: #263d33;
  --danger: #ec8e85;
  --shadow: 0 22px 70px rgba(4, 8, 5, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, color-mix(in srgb, var(--accent-soft) 52%, transparent), transparent 28rem),
    var(--bg);
  font-family: "Avenir Next", "Segoe UI Variable", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.page-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 88px;
}

.site-header {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--text);
  border-radius: 50%;
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.text-button,
.auth-tab,
.mood-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.text-button {
  padding: 9px 11px;
  color: var(--muted);
  border-radius: 8px;
}

.text-button:hover {
  color: var(--text);
  background: var(--surface-strong);
}

.auth-layout {
  min-height: calc(100dvh - 164px);
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.78fr);
  align-items: center;
  gap: clamp(64px, 10vw, 150px);
  padding: 48px 0 70px;
}

.eyebrow {
  margin: 0 0 20px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.intro-panel h1,
.app-heading h1 {
  margin: 0;
  max-width: 720px;
  font-size: clamp(44px, 6.5vw, 86px);
  font-weight: 560;
  letter-spacing: -0.065em;
  line-height: 1.03;
}

.intro-copy {
  max-width: 430px;
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.8;
}

.date-note {
  display: flex;
  align-items: center;
  gap: 18px;
  width: fit-content;
  margin-top: 64px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.date-day {
  color: var(--accent);
  font-size: 48px;
  font-weight: 500;
  line-height: 1;
}

.date-note div {
  display: grid;
  gap: 4px;
}

.date-note strong {
  font-size: 14px;
}

.date-note span:not(.date-day) {
  color: var(--muted);
  font-size: 13px;
}

.auth-panel,
.composer,
.memory-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: 30px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 34px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-strong);
}

.auth-tab {
  padding: 10px;
  color: var(--muted);
  border-radius: 9px;
}

.auth-tab.is-active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 3px 12px color-mix(in srgb, var(--text) 8%, transparent);
}

.form-heading {
  margin-bottom: 26px;
}

.form-heading h2,
.memory-header h2 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -0.035em;
}

.form-heading p,
.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.field {
  display: grid;
  gap: 8px;
  margin: 18px 0;
  font-size: 14px;
  font-weight: 650;
}

.field input,
.search-box input,
.title-input,
.composer textarea {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input {
  height: 48px;
  padding: 0 14px;
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 78%, transparent);
}

.field input:focus,
.search-box input:focus,
.title-input:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.field-error {
  min-height: 16px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 500;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  padding: 0 18px;
  color: #f7fbf8;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
  transition: background 160ms ease, transform 120ms ease;
}

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

.primary-button:active,
.text-button:active,
.mood-button:active {
  transform: scale(0.98);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.form-message {
  min-height: 22px;
  margin: 4px 0 10px;
  color: var(--danger);
  font-size: 13px;
}

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

.privacy-note {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

.app-view {
  padding: 70px 0 80px;
}

.app-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 40px;
  margin-bottom: 52px;
}

.app-heading h1 {
  font-size: clamp(40px, 5.6vw, 68px);
}

.profile-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 250px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.avatar {
  display: grid;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  place-items: center;
  color: var(--accent);
  border-radius: 50%;
  background: var(--accent-soft);
  font-weight: 800;
}

.profile-strip div:last-child {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.profile-strip span {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-strip small {
  color: var(--muted);
  font-size: 11px;
}

.journal-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(320px, 0.82fr);
  align-items: start;
  gap: 24px;
}

.composer,
.memory-panel {
  padding: clamp(22px, 3vw, 34px);
}

.title-input,
.composer textarea {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.title-input {
  padding: 0 0 18px;
  border-bottom: 1px solid var(--line);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.composer textarea {
  min-height: 260px;
  padding: 24px 0;
  resize: vertical;
  line-height: 1.85;
}

.title-input:focus,
.composer textarea:focus {
  box-shadow: none;
}

.composer-footer {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.mood-picker {
  display: grid;
  gap: 10px;
}

.mood-picker > span,
.save-area > span {
  color: var(--muted);
  font-size: 12px;
}

.mood-picker div {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.mood-button {
  padding: 7px 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}

.mood-button.is-selected {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: var(--accent-soft);
}

.save-area {
  display: flex;
  align-items: center;
  gap: 14px;
}

.primary-button.compact {
  width: auto;
}

.memory-panel {
  box-shadow: none;
}

.memory-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.memory-header .eyebrow {
  margin-bottom: 10px;
}

.memory-header > span {
  color: var(--muted);
  font-size: 13px;
}

.search-box {
  display: block;
  margin: 24px 0 12px;
}

.search-box input {
  height: 42px;
  padding: 0 12px;
  font-size: 13px;
}

.entries-list {
  max-height: 470px;
  overflow: auto;
  scrollbar-width: thin;
}

.entry-item {
  padding: 20px 2px;
  border-bottom: 1px solid var(--line);
}

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

.entry-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 11px;
}

.entry-item h3 {
  margin: 10px 0 8px;
  font-size: 16px;
}

.entry-item p {
  display: -webkit-box;
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.delete-button {
  padding: 4px 0;
  color: var(--muted);
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}

.delete-button:hover {
  color: var(--danger);
}

.empty-state {
  padding: 54px 12px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

.icp-footer {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  min-height: 46px;
  place-items: center;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.icp-footer a {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.icp-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.toast {
  position: fixed;
  z-index: 20;
  right: 24px;
  bottom: 66px;
  max-width: min(360px, calc(100vw - 48px));
  padding: 12px 16px;
  color: #f7fbf8;
  border-radius: 10px;
  background: #2c4f40;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.is-hidden {
  display: none !important;
}

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

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent);
  outline-offset: 2px;
}

@media (max-width: 820px) {
  .page-shell {
    width: min(100% - 30px, 680px);
  }

  .auth-layout,
  .journal-grid {
    grid-template-columns: 1fr;
  }

  .auth-layout {
    gap: 48px;
    padding-top: 34px;
  }

  .intro-panel h1 {
    font-size: clamp(44px, 12vw, 68px);
  }

  .date-note {
    margin-top: 40px;
  }

  .auth-panel {
    width: min(100%, 520px);
  }

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

  .profile-strip {
    min-width: 0;
    width: fit-content;
    max-width: 100%;
  }
}

@media (max-width: 540px) {
  .site-header {
    height: 66px;
  }

  .auth-layout {
    min-height: auto;
    padding: 30px 0 70px;
  }

  .auth-panel,
  .composer,
  .memory-panel {
    padding: 20px;
  }

  .intro-copy {
    font-size: 15px;
  }

  .app-view {
    padding-top: 44px;
  }

  .app-heading {
    margin-bottom: 34px;
  }

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

  .save-area {
    justify-content: space-between;
  }
}

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

@media (prefers-reduced-transparency: reduce) {
  .icp-footer,
  .auth-panel,
  .composer,
  .memory-panel {
    background: var(--surface);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
