:root {
  color-scheme: light;
  --bg: #f5f1ea;
  --paper: #fffaf2;
  --ink: #241f1a;
  --muted: #746b60;
  --line: #ded1c1;
  --accent: #1f7466;
  --accent-dark: #15564b;
  --warm: #b95032;
  --soft: #ebe2d6;
  --green-soft: rgba(31, 116, 102, 0.12);
  --shadow: 0 14px 34px rgba(48, 35, 20, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

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

.app {
  display: grid;
  gap: 14px;
  width: min(100%, 520px);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(22px, env(safe-area-inset-bottom));
}

.journal,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.96);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 16px 8px;
}

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

.date-label,
.panel-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 2px;
  font-size: 28px;
  font-weight: 780;
  text-transform: lowercase;
}

h2 {
  font-size: 17px;
}

.icon-button,
.delete-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.entry-form {
  display: grid;
  gap: 13px;
  padding: 10px 16px 16px;
}

.prompt {
  margin: 0;
  border: 1px solid rgba(31, 116, 102, 0.2);
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--accent-dark);
  padding: 10px 12px;
  line-height: 1.45;
}

label,
.score-row {
  display: grid;
  gap: 7px;
}

label span,
.score-row span {
  color: var(--muted);
  font-size: 13px;
}

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

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

textarea {
  resize: vertical;
  min-height: 82px;
  padding: 11px 12px;
  line-height: 1.5;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 116, 102, 0.14);
}

.score-row label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

input[type="range"] {
  min-height: 30px;
  padding: 0;
  accent-color: var(--accent);
  background: transparent;
}

.more-fields {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(235, 226, 214, 0.28);
  padding: 0;
}

.more-fields summary {
  min-height: 44px;
  padding: 12px;
  color: var(--accent-dark);
  cursor: pointer;
  list-style-position: inside;
}

.more-fields[open] {
  padding-bottom: 12px;
}

.more-fields[open] > label {
  margin: 0 12px 12px;
}

.choice-row,
.tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-row label,
.tag-grid label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdf8;
  color: var(--muted);
  padding: 0 12px;
  cursor: pointer;
}

.choice-row input,
.tag-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-row label.selected,
.tag-grid label.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.actions {
  position: sticky;
  bottom: max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 82px;
  gap: 10px;
  margin-top: 2px;
  z-index: 2;
}

.primary,
.secondary {
  min-height: 48px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: white;
  font-weight: 760;
}

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

.secondary {
  border-color: var(--line);
  background: var(--soft);
  color: var(--ink);
}

.overview {
  display: grid;
  gap: 14px;
}

.panel {
  padding: 16px;
}

.presence-panel {
  display: grid;
  gap: 8px;
}

.presence-copy {
  display: grid;
  gap: 3px;
}

.presence-copy span {
  color: var(--muted);
  font-size: 13px;
}

.presence-copy strong {
  font-size: 21px;
}

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

.habit-panel {
  display: grid;
  gap: 12px;
}

.habit-editor {
  display: grid;
  grid-template-columns: 1fr 76px;
  gap: 8px;
}

.habit-editor .secondary {
  min-height: 44px;
}

.habit-toggle {
  min-height: 50px;
  border: 1px solid rgba(31, 116, 102, 0.28);
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 760;
}

.habit-toggle.done {
  background: var(--accent);
  color: white;
}

.habit-toggle:disabled {
  cursor: default;
  opacity: 0.55;
}

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

.habit-day {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf8;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.habit-day.done {
  border-color: rgba(185, 80, 50, 0.35);
  background: rgba(185, 80, 50, 0.18);
  color: var(--warm);
  font-weight: 760;
}

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

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

.day-cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf8;
  color: var(--muted);
  font-size: 12px;
}

.day-cell.recorded {
  border-color: rgba(31, 116, 102, 0.35);
  background: rgba(31, 116, 102, 0.18);
  color: var(--accent-dark);
  font-weight: 750;
}

canvas {
  display: block;
  width: 100%;
  height: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.segmented {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.segmented button {
  min-width: 52px;
  min-height: 32px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--accent);
  color: white;
}

.lookback,
.entry-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.lookback {
  min-height: 126px;
  padding: 14px;
}

.lookback time,
.entry-main time {
  color: var(--warm);
  font-size: 13px;
  font-weight: 750;
}

.lookback h3 {
  margin: 8px 0;
  font-size: 17px;
}

.lookback p {
  margin: 7px 0;
  color: var(--muted);
  line-height: 1.55;
}

.empty {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.entries {
  display: grid;
  gap: 10px;
}

.entry-card {
  display: grid;
  grid-template-columns: 1fr 40px;
  overflow: hidden;
}

.entry-main {
  display: grid;
  gap: 7px;
  width: 100%;
  min-height: 96px;
  padding: 12px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.entry-meta,
.entry-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.entry-main strong {
  overflow-wrap: anywhere;
}

.entry-main p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.entry-score,
.entry-afternoon,
.entry-tags span {
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--accent-dark);
  padding: 2px 8px;
  font-size: 12px;
}

.entry-afternoon:empty,
.entry-tags:empty {
  display: none;
}

.delete-button {
  width: 40px;
  height: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  color: var(--muted);
  background: rgba(235, 226, 214, 0.5);
}

@media (min-width: 900px) {
  body {
    background:
      linear-gradient(180deg, rgba(255, 250, 242, 0.74), rgba(245, 241, 234, 0.96)),
      var(--bg);
  }

  .app {
    grid-template-columns: minmax(350px, 0.82fr) minmax(420px, 1.18fr);
    gap: 22px;
    width: min(1180px, calc(100vw - 32px));
    padding: 28px 0;
  }

  .journal {
    position: sticky;
    top: 20px;
    align-self: start;
    max-height: calc(100vh - 40px);
    overflow: auto;
  }

  .actions {
    position: static;
  }

  canvas {
    height: 210px;
  }
}
