:root {
  color-scheme: only light;
  --scene-cream: #fff9e8;
  --scene-ink: #324526;
  --scene-tree-height: min(122.666667vw, 88svh, 920px);
  --scene-floor: 5svh;
}

html {
  color-scheme: only light;
  background: #dfeabd;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  position: relative;
  isolation: isolate;
  min-height: 100%;
  color-scheme: only light;
  background: #dfeabd;
}

/* Keep form controls and page surfaces in the authored light palette even
   when a mobile browser is configured to force a dark theme. */
body, body * {
  color-scheme: only light;
}

body::before {
  position: fixed;
  inset: 0 0 auto;
  height: 100lvh;
  z-index: -2;
  background: #e7efc9 url('assets/letter-tree/forest-breeze.gif') center / cover no-repeat;
  content: '';
  pointer-events: none;
  filter: brightness(1.16) saturate(.92);
}

/* Keep the forest artwork unobstructed by a full-page tint or blur. */
body::after {
  content: none;
}

.letter-page {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: none;
  padding: max(14px, env(safe-area-inset-top)) 12px max(24px, env(safe-area-inset-bottom));
  font-size: 13px;
  pointer-events: none;
}

.letter-tree-section {
  position: relative;
  min-height: calc(100lvh + 72px);
}

.letter-hero {
  position: relative;
  z-index: 15;
  width: min(100%, 560px);
  padding: 4px 6px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  pointer-events: auto;
}

.letter-kicker {
  font-size: 9px;
  letter-spacing: .13em;
  color: #496333;
}

.letter-hero h1 {
  margin-top: 4px;
  color: #365728;
  font-size: clamp(26px, 4.6vw, 40px);
  text-shadow: 0 1px 3px #fff9e8;
}

.letter-hero > p {
  margin-top: 6px;
  color: #3d5330;
  font-size: 12px;
  line-height: 1.5;
  text-shadow: 0 1px 2px #fff9e8;
}

.forest-scene {
  position: fixed;
  inset: 0 0 auto;
  z-index: 0;
  height: 100svh;
  overflow: hidden;
  pointer-events: none;
}

.tree-viewport {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  margin: 0;
  padding-bottom: var(--scene-floor);
  overflow: visible;
  border-radius: 0;
  background: transparent;
  pointer-events: none;
}

.tree-canvas {
  position: relative;
  flex: none;
  width: calc(var(--scene-tree-height) * .75);
  height: var(--scene-tree-height);
  aspect-ratio: 3 / 4;
  margin: 0;
  overflow: visible;
  filter: none;
}

/* A narrow contact shadow and meadow colors anchor the roots to the grass. */
.tree-canvas::before {
  position: absolute;
  left: 39%;
  bottom: .9%;
  z-index: 0;
  width: 22%;
  height: 2.3%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgb(90 116 47 / .35), transparent 70%);
  content: '';
  pointer-events: none;
}

.tree-canvas::after {
  position: absolute;
  left: 43%;
  bottom: 1.1%;
  z-index: 4;
  width: 14%;
  height: 1.8%;
  background: radial-gradient(ellipse at 25% 80%, rgb(143 164 76 / .65), transparent 58%),
    radial-gradient(ellipse at 75% 90%, rgb(183 195 101 / .65), transparent 60%);
  content: '';
  pointer-events: none;
}

.tree-canvas > #tree-image {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: none;
  transition: opacity 1.2s ease;
}

.tree-canvas > .tree-complete-image {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  filter: none;
  pointer-events: none;
  transition: opacity 1.2s ease;
}

.tree-canvas.is-complete > #tree-image { opacity: 0; }
.tree-canvas.is-complete > .tree-complete-image { opacity: 1; }
.tree-canvas.is-complete .letter-leaf { opacity: 0; }
.tree-canvas.is-complete .letter-leaf:hover,
.tree-canvas.is-complete .letter-leaf:focus-visible,
.tree-canvas.is-complete .letter-leaf.is-selected { opacity: 1; }

.letter-leaves {
  z-index: 3;
}

.letter-leaf {
  pointer-events: auto;
  width: clamp(34px, 5.6vw, 54px);
  height: clamp(27px, 4.1vw, 42px);
  border-radius: 55% 45% 55% 45%;
  background: transparent;
  filter: drop-shadow(0 4px 3px rgb(42 68 25 / .25));
  opacity: 1;
  transition: filter .16s ease, opacity .18s ease, transform .18s ease;
}

.letter-leaf img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 1;
  pointer-events: none;
}

.letter-leaf.green-1 { filter: hue-rotate(-4deg) saturate(.94) drop-shadow(0 4px 3px rgb(42 68 25 / .25)); }
.letter-leaf.green-2 { filter: hue-rotate(5deg) brightness(1.06) drop-shadow(0 4px 3px rgb(42 68 25 / .24)); }
.letter-leaf.green-3 { filter: hue-rotate(-10deg) brightness(.88) drop-shadow(0 4px 3px rgb(42 68 25 / .26)); }
.letter-leaf.lime-1 { filter: hue-rotate(13deg) brightness(1.12) saturate(.92) drop-shadow(0 4px 3px rgb(42 68 25 / .22)); }
.letter-leaf.gold-1 { filter: hue-rotate(24deg) brightness(1.08) saturate(.78) drop-shadow(0 4px 3px rgb(42 68 25 / .22)); }
.letter-leaf:hover,
.letter-leaf:focus-visible,
.letter-leaf.is-selected {
  z-index: 12;
  background: transparent;
  filter: brightness(1.15) drop-shadow(0 5px 5px rgb(38 61 22 / .32)) drop-shadow(0 0 8px #fff);
  transform: translate(-50%, -50%) rotate(var(--leaf-rotation)) scale(calc(var(--leaf-scale) * 1.12)) scaleX(var(--leaf-flip));
}
.letter-leaf.is-awaiting-flight { opacity: 0; }

.compose-reveal {
  position: absolute;
  left: 50%;
  top: calc(100svh - var(--scene-floor) - var(--scene-tree-height) / 2);
  z-index: 10;
  width: min(64%, 300px);
  opacity: 0;
  transform: translate(-50%, calc(-50% + 24px));
  transition: opacity .75s ease;
  pointer-events: auto;
}

.compose-reveal.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%);
}

body.tree-intro-pending .compose-reveal.is-visible {
  opacity: 0;
  transform: translate(-50%, calc(-50% + 24px));
}

body.tree-intro-ready .compose-reveal.is-visible {
  transition-delay: .68s;
}

.letter-compose {
  width: 100%;
  margin: 0;
  padding: 13px 14px 12px;
  border: 1px solid rgb(211 200 162 / .8);
  border-radius: 12px;
  background: rgb(255 249 232 / .9);
  box-shadow: 0 4px 14px rgb(58 65 36 / .1);
  backdrop-filter: none;
}

.letter-compose::after { content: none; }
.compose-heading { margin-bottom: 6px; }
.compose-heading span { font-size: 10px; }
.compose-heading h2 { margin-top: 2px; font-size: 18px; }
.compose-toggle {
  flex: none;
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 1px solid #d4dabc;
  border-radius: 8px;
  color: #415c2d;
  background: #f1f5df;
  font-size: 23px;
  line-height: 1;
}
.compose-toggle:focus-visible { outline: 3px solid #668947; outline-offset: 2px; }
.compose-toggle:disabled { cursor: wait; opacity: .5; }
.compose-reveal.is-collapsed {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 76px);
  right: max(14px, env(safe-area-inset-right));
  left: auto;
  z-index: 30;
  width: 40px;
  transform: none;
}
.compose-reveal.is-collapsed .letter-compose { padding: 3px; border-radius: 10px; }
.compose-reveal.is-collapsed .compose-heading { justify-content: flex-end; margin: 0; }
.compose-reveal.is-collapsed .compose-heading > div { display: none; }
#letter-compose-body[hidden] { display: none; }
.letter-compose label { margin: 6px 0 4px; font-size: 11px; }

.letter-compose textarea {
  height: 82px;
  min-height: 82px;
  max-height: 160px;
  padding: 8px 9px;
  border-radius: 9px;
  color: #3b3b31;
  background: #fffdf6;
  box-shadow: none;
  font-size: 16px;
  line-height: 1.4;
}

.letter-compose textarea::placeholder { color: #737963; font-size: 12px; }
.letter-compose .letter-counter { margin-top: 4px; font-size: 10px; }
.letter-compose .form-message { min-height: 0; margin: 5px 0 0; font-size: 11px; }
.form-message:empty { display: none; }
.letter-submit { min-height: 36px; margin-top: 7px; padding: 7px; border-radius: 9px; font-size: 13px; }

.letter-compose.is-sending {
  animation: letter-card-breathe .72s ease both;
}

@keyframes letter-card-breathe {
  40% { opacity: .55; transform: scale(.965) rotateX(4deg); }
  100% { opacity: .78; transform: scale(.985); }
}

.other-content {
  position: relative;
  width: min(100%, 360px);
  margin: 14px auto 0;
  padding: 8px;
  border: 1px solid #ded3b6;
  border-radius: 12px;
  background: var(--scene-cream);
  box-shadow: none;
  backdrop-filter: none;
  pointer-events: auto;
}

.other-kicker {
  margin: 0 0 5px;
  color: #52673b;
  font-size: 9px;
  line-height: 1.2;
  letter-spacing: .12em;
}

#home-card-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  margin-top: 0;
}

.home-card {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 5px 3px;
  border: 1px solid #ded3b6;
  border-radius: 8px;
  color: #435534;
  background: var(--scene-cream);
  box-shadow: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.3;
}

dialog {
  width: min(88vw, 400px);
  border-radius: 16px;
  font-size: 13px;
}

dialog::backdrop {
  background: transparent;
  backdrop-filter: none;
}

.dialog-card { padding: 16px; border-radius: 16px; box-shadow: 0 5px 22px rgb(43 55 32 / .14); }
.dialog-header { gap: 10px; }
.dialog-header span { font-size: 9px; letter-spacing: .12em; }
.dialog-header h2 { font-size: 20px; }
.dialog-header small { font-size: 11px; }
.icon-button { width: 34px; height: 34px; font-size: 22px; }
.auth-guide { margin: 12px 0 4px; font-size: 12px; line-height: 1.45; }
.auth-dialog label, .letter-edit-panel label { margin: 9px 0 5px; font-size: 12px; }
.auth-dialog input { height: 40px; border-radius: 10px; font-size: 16px; }
.dialog-button-row { gap: 7px; margin-top: 10px; }
.dialog-button-row button { min-height: 36px; padding: 7px 9px; border-radius: 10px; font-size: 12px; }
.letter-view-content { min-height: 96px; margin: 16px 0 4px; padding: 13px; border-radius: 12px; font-size: 14px; line-height: 1.6; }
.letter-edit-panel { margin-top: 12px; }
.letter-edit-panel textarea { min-height: 120px; padding: 10px; font-size: 16px; }
.letter-menu { top: 56px; right: 46px; font-size: 12px; }
#home-toast { bottom: calc(14px + env(safe-area-inset-bottom)); padding: 8px 12px; font-size: 12px; }
#home-offline { font-size: 11px; }

.flying-letter { width: 64px; height: 50px; }
.flying-paper,
.flying-leaf-shape { animation-duration: .95s; }
.flying-leaf-shape img {
  display: block;
  width: 64px;
  height: 50px;
  object-fit: contain;
  filter: drop-shadow(0 6px 5px rgb(49 72 26 / .25));
}

.name-stream {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

.drifting-name {
  position: absolute;
  top: var(--name-y);
  left: 0;
  padding: 2px 4px;
  color: #283b27;
  font-size: clamp(14px, 1.7vw, 23px);
  line-height: 1.4;
  white-space: nowrap;
  text-shadow: 0 1px 3px #fffdf2;
  opacity: var(--name-opacity);
  animation: name-drift var(--name-duration) var(--name-delay) linear forwards;
  will-change: transform;
}

.name-stream.is-paused .drifting-name { animation-play-state: paused; }

@keyframes name-drift {
  from { transform: translateX(-120%); }
  to { transform: translateX(calc(100vw + 120%)); }
}

@media (max-width: 760px) {
  .letter-page { padding-inline: 10px; }
}

@media (max-width: 760px) and (prefers-color-scheme: dark) {
  body::before {
    filter: brightness(1.72) saturate(.9) contrast(.96);
  }
  .tree-canvas > #tree-image,
  .tree-canvas > .tree-complete-image,
  .letter-leaf img {
    filter: brightness(1.18) saturate(.96);
  }
}

@media (max-width: 560px) {
  /* Lower the whole tree, including its leaves and root contact shadow. */
  :root { --scene-floor: 1svh; }
  .letter-page { padding-top: max(10px, env(safe-area-inset-top)); }
  .letter-kicker { font-size: 8px; }
  .letter-hero h1 { font-size: 27px; }
  .letter-hero > p { margin-top: 5px; font-size: 11px; }
  .compose-reveal { width: min(70%, 252px); }
  .letter-compose { padding: 10px 11px; border-radius: 11px; }
  .compose-heading { margin-bottom: 4px; }
  .compose-heading h2 { font-size: 16px; }
  .letter-compose textarea { height: 76px; min-height: 76px; }
  .letter-submit { font-size: 12px; }
  .letter-leaf { width: clamp(30px, 10.8vw, 45px); height: clamp(24px, 7.4vw, 34px); }
  .other-content { padding: 7px; margin-top: 12px; }
  .home-card { font-size: 11px; }
  dialog { width: min(calc(100vw - 28px), 360px); margin-bottom: 14px; }
  .dialog-card { padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); border-radius: 14px; }
  .dialog-header h2 { font-size: 18px; }
  .drifting-name { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  body::before {
    background-image: url('assets/letter-tree/forest-watercolor-still.png');
  }
  .drifting-name { display: none; animation: none; }
}
.tree-election-home { display: inline-block; margin-top: .75rem; padding: .25rem; color: #485738; font-size: .875rem; text-underline-offset: .2em; }
