:root {
  color-scheme: light;
  --paper: #f8f7f2;
  --ink: #151816;
  --muted: #75786f;
  --line: rgba(151, 153, 140, 0.2);
  --accent: #2f5e55;
  --accent-soft: #dfe9e4;
  --warning: #9b493f;
  --shadow: 0 24px 70px rgba(36, 44, 38, 0.12);
  --history-shadow-gutter: clamp(96px, 12vw, 120px);
  --history-top-space: 76px;
  --history-edge-fade: 78px;
  --latest-card-radius: 28px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  width: 100%;
  height: 100%;
  background: var(--paper);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  width: 100%;
  height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.46), rgba(248, 247, 242, 0) 44%),
    linear-gradient(115deg, var(--paper) 0%, #f4f5ef 56%, #eef3f0 100%);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.38;
  background-image:
    linear-gradient(rgba(90, 92, 82, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(90, 92, 82, 0.018) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, black, transparent 72%);
}

button,
textarea,
input {
  font: inherit;
}

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

.app-shell {
  width: min(100%, 760px);
  height: 100dvh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 clamp(22px, 5vw, 48px);
  position: relative;
  overflow: visible;
}

.today-panel {
  height: 100dvh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 0 max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.topbar {
  min-height: var(--history-top-space);
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
}

.topbar::before {
  content: "";
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: calc(max(24px, env(safe-area-inset-top)) + var(--history-top-space) + var(--history-edge-fade));
  z-index: -1;
  background: linear-gradient(180deg, rgba(248, 247, 242, 1) 0%, rgba(248, 247, 242, 0.96) 48%, rgba(248, 247, 242, 0) 100%);
  pointer-events: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: 0;
  font-weight: 750;
  transition: color 160ms ease;
}

.is-over-limit h1 {
  color: var(--warning);
}

.date-label {
  margin-top: 4px;
  color: rgba(117, 120, 111, 0.62);
  font-size: 16px;
  line-height: 1.35;
  font-weight: 650;
}

.entry-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  align-items: center;
  padding: clamp(42px, 9dvh, 88px) 0 clamp(34px, 8dvh, 76px);
}

textarea {
  width: 100%;
  min-height: min(46dvh, 430px);
  max-height: 54dvh;
  resize: none;
  border: 0;
  outline: 0;
  padding: 0;
  color: rgba(21, 24, 22, 0.84);
  background: transparent;
  text-align: left;
  font-family: "Indie Flower", cursive;
  font-size: clamp(3.6rem, 8.2vw, 7.4rem);
  line-height: 0.98;
  letter-spacing: 0;
  overflow: hidden;
  caret-color: var(--accent);
}

textarea::placeholder {
  color: rgba(21, 24, 22, 0.18);
}

.save-button {
  width: auto;
  min-height: 0;
  margin: 0 auto;
  border: 0;
  border-radius: 999px;
  padding: 10px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(180deg, #3b746a 0%, var(--accent) 54%, #254d46 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    inset 0 -1px 0 rgba(18, 41, 36, 0.28),
    0 18px 40px rgba(47, 94, 85, 0.2);
  font-size: 1rem;
  font-weight: 520;
  cursor: pointer;
  transition: opacity 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.save-button:not(:disabled):hover {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -1px 0 rgba(18, 41, 36, 0.3),
    0 22px 48px rgba(47, 94, 85, 0.24);
  transform: translateY(-1px);
}

.save-button:not(:disabled):active {
  transform: translateY(0);
}

.save-button:disabled {
  color: rgba(21, 24, 22, 0.2);
  background: rgba(21, 24, 22, 0.045);
  box-shadow: none;
  cursor: default;
}

.today-panel.is-history .entry-stage,
.today-panel.is-history .save-button,
.today-panel.is-loading .entry-stage,
.today-panel.is-loading .save-button {
  display: none !important;
}

.today-panel.is-history .history-view {
  display: block;
  flex: 1 1 auto;
}

h2 {
  font-size: 1.15rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.history-view {
  --history-top-padding: clamp(26px, 6dvh, 58px);
  flex: 1;
  min-height: 0;
  padding: var(--history-top-padding) var(--history-shadow-gutter) calc(var(--history-edge-fade) + 18px);
  margin: 0 calc(var(--history-shadow-gutter) * -1);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(
    180deg,
    transparent 0,
    black var(--history-edge-fade),
    black calc(100% - var(--history-edge-fade)),
    transparent 100%
  );
  mask-image: linear-gradient(
    180deg,
    transparent 0,
    black var(--history-edge-fade),
    black calc(100% - var(--history-edge-fade)),
    transparent 100%
  );
}

.today-panel.is-history .history-view {
  margin-top: calc(var(--history-top-space) * -1);
  padding-top: calc(var(--history-top-space) + var(--history-top-padding));
}

.history-view::-webkit-scrollbar {
  display: none;
}

.history-list {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100%;
}

.history-item {
  position: relative;
  display: block;
  width: 100%;
  appearance: none;
  border: 0;
  border-top: 1px solid rgba(151, 153, 140, 0.18);
  padding: clamp(20px, 4dvh, 38px) 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.history-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.history-item.is-latest {
  isolation: isolate;
  margin-top: clamp(10px, 2.5dvh, 24px);
  margin-bottom: 18px;
  padding: clamp(22px, 4.4dvh, 42px) 0;
  border-top: 0;
  cursor: pointer;
}

.history-item.is-latest::before {
  content: "";
  position: absolute;
  inset: 0 -42px;
  z-index: -1;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: var(--latest-card-radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 34px rgba(38, 48, 42, 0.1);
  pointer-events: none;
}

@supports (corner-shape: squircle) {
  .history-item.is-latest::before {
    border-radius: 34px;
    corner-shape: squircle;
  }
}

.history-item.is-latest::before {
  transition: box-shadow 160ms ease, background-color 160ms ease;
}

.history-item.is-latest:hover::before,
.history-item.is-latest:focus-visible::before {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 42px rgba(38, 48, 42, 0.18);
}

.history-item.is-latest:hover p {
  color: rgba(21, 24, 22, 0.9);
}

.history-item time {
  display: block;
  color: rgba(117, 120, 111, 0.62);
  font-size: 0.88rem;
  font-weight: 700;
}

.history-item.is-latest time {
  text-align: right;
  color: inherit;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.latest-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  color: rgba(117, 120, 111, 0.62);
  font-size: 0.88rem;
  font-weight: 700;
}

.latest-meta span {
  color: rgba(117, 120, 111, 0.62);
}

.history-item p {
  margin-top: 12px;
  color: rgba(21, 24, 22, 0.74);
  font-family: "Indie Flower", cursive;
  font-size: clamp(1.8rem, 4.2vw, 3.1rem);
  line-height: 1.08;
  min-height: 1.08em;
  transition: color 150ms ease;
}

.history-item.is-latest p {
  color: rgba(21, 24, 22, 0.86);
  font-size: clamp(2.15rem, 5.2vw, 3.8rem);
}

.history-item.is-locked p {
  color: rgba(21, 24, 22, 0.48);
}

@media (min-width: 900px) {
  .app-shell {
    width: min(100%, 860px);
  }

  .today-panel {
    height: 100dvh;
    padding-top: 44px;
    padding-bottom: 34px;
  }

  textarea {
    min-height: min(48dvh, 470px);
    font-size: clamp(5.8rem, 8vw, 8.4rem);
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 0 22px;
  }

  .today-panel {
    height: 100dvh;
    padding-top: max(22px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .entry-stage {
    padding-top: 44px;
    padding-bottom: 30px;
  }

  textarea {
    min-height: 50dvh;
    max-height: 56dvh;
    font-size: clamp(3.2rem, 17vw, 4.9rem);
    line-height: 1.02;
  }

}

@media (max-width: 360px) {
  textarea {
    font-size: 3rem;
  }
}
