:root {
  color-scheme: light;
  --bg: #f7f3ed;
  --ink: #221f1b;
  --muted: #6e665c;
  --paper: #fffaf0;
  --line: rgba(46, 38, 30, 0.18);
  --blue: #6faed1;
  --blue-deep: #2f6e97;
  --green: #86bd8a;
  --green-deep: #3e7d4b;
  --shadow: 0 24px 70px rgba(40, 32, 25, 0.17);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.94), rgba(239, 235, 227, 0.88)),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-form {
  display: grid;
  gap: 12px;
  width: min(100%, 320px);
}

.login-form input,
.login-form button,
.compose-card input,
.compose-card textarea,
.compose-card > button[type="submit"] {
  width: 100%;
  border-radius: 6px;
}

input,
textarea {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  outline: none;
}

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

textarea {
  min-height: 260px;
  padding: 14px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: rgba(47, 110, 151, 0.68);
  box-shadow: 0 0 0 3px rgba(111, 174, 209, 0.2);
}

.login-form button,
.compose-card > button[type="submit"] {
  min-height: 44px;
  border: 1px solid #2f6e97;
  color: #fff;
  background: #2f6e97;
  font-weight: 800;
}

.form-error,
.status {
  min-height: 20px;
  margin: 0;
  color: #96392f;
  font-size: 0.88rem;
  text-align: center;
}

.letter-world {
  min-height: 100vh;
}

.intro-message {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: clamp(24px, 8vw, 92px);
}

.intro-message p {
  max-width: 850px;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.24rem, 2.5vw, 2.1rem);
  line-height: 1.58;
  letter-spacing: 0;
}

.envelope-field {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: clamp(38px, 8vw, 100px);
  align-items: center;
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 12vh 0 18vh;
}

.envelope {
  --envelope: var(--blue);
  --envelope-deep: var(--blue-deep);
  position: relative;
  display: grid;
  align-content: end;
  width: min(100%, 270px);
  aspect-ratio: 1.42;
  margin: 0 auto;
  padding: 0 18px 20px;
  border: 0;
  color: #143040;
  background: transparent;
  isolation: isolate;
  animation: arrive 520ms ease forwards;
  animation-delay: var(--delay, 0ms);
}

.envelope.from-lainey {
  --envelope: var(--green);
  --envelope-deep: var(--green-deep);
  color: #173b22;
}

.envelope-front,
.envelope-flap {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: var(--envelope);
  box-shadow: var(--shadow);
}

.envelope-front {
  z-index: 1;
  overflow: hidden;
}

.envelope-front::before,
.envelope-front::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 55%;
  height: 86%;
  background: color-mix(in srgb, var(--envelope) 82%, #ffffff);
  border-top: 1px solid rgba(255, 255, 255, 0.52);
}

.envelope-front::before {
  left: 0;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.envelope-front::after {
  right: 0;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.envelope-flap {
  z-index: 2;
  transform-origin: top center;
  clip-path: polygon(0 0, 100% 0, 50% 62%);
  background: color-mix(in srgb, var(--envelope) 74%, #ffffff);
  transition: transform 260ms ease;
}

.envelope.read .envelope-flap {
  transform: rotateX(155deg);
}

.envelope.unread::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 5;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--envelope-deep);
}

.envelope-title,
.envelope-meta {
  position: relative;
  z-index: 4;
  text-align: left;
}

.envelope-title {
  font-weight: 900;
  font-size: 1.05rem;
}

.envelope-meta {
  margin-top: 6px;
  color: rgba(20, 30, 30, 0.76);
  font-size: 0.83rem;
  font-weight: 800;
}

.compose-trigger {
  position: fixed;
  right: clamp(18px, 4vw, 38px);
  bottom: clamp(18px, 4vw, 38px);
  z-index: 20;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(34, 31, 27, 0.15);
  border-radius: 999px;
  color: #fff;
  background: #2f6e97;
  box-shadow: var(--shadow);
  font-size: 2rem;
  line-height: 1;
}

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

.letter-stage {
  position: relative;
  width: min(920px, 100%);
  min-height: min(720px, calc(100vh - 44px));
  display: grid;
  place-items: center;
}

.modal-close {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(34, 31, 27, 0.16);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.94);
  font-weight: 900;
}

.opened-envelope {
  --envelope: var(--blue);
  position: absolute;
  bottom: 0;
  width: min(560px, 90%);
  aspect-ratio: 1.6;
  border-radius: 10px;
  background: var(--envelope);
  box-shadow: var(--shadow);
}

.opened-envelope.from-lainey {
  --envelope: var(--green);
}

.opened-envelope::before {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateY(-48%);
  transform-origin: bottom center;
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
  border-radius: 10px;
  background: color-mix(in srgb, var(--envelope) 70%, #ffffff);
}

.letter-sheet {
  position: relative;
  z-index: 2;
  width: min(680px, 88%);
  max-height: min(680px, calc(100vh - 96px));
  overflow: auto;
  margin-top: 28px;
  padding: clamp(26px, 5vw, 54px);
  border: 1px solid rgba(42, 34, 27, 0.16);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  animation: slideLetter 420ms ease both;
}

.letter-meta {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.letter-sheet h1 {
  margin: 0 0 22px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  line-height: 1;
  letter-spacing: 0;
}

.letter-body {
  display: grid;
  gap: 18px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.04rem, 2vw, 1.22rem);
  line-height: 1.74;
}

.letter-body p {
  margin: 0;
}

.compose-card {
  position: relative;
  display: grid;
  gap: 12px;
  width: min(680px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid rgba(42, 34, 27, 0.16);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.compose-card .modal-close {
  left: 12px;
  top: 12px;
}

.compose-card input {
  margin-top: 42px;
}

@keyframes arrive {
  from {
    transform: translateY(24px) rotate(-1deg);
  }
  to {
    transform: translateY(0) rotate(0deg);
  }
}

@keyframes slideLetter {
  from {
    opacity: 0;
    transform: translateY(90px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 640px) {
  .intro-message {
    align-items: start;
    min-height: auto;
    padding: 32px 20px 72px;
  }

  .intro-message p {
    font-size: 1.14rem;
  }

  .envelope-field {
    grid-template-columns: 1fr;
    gap: 52px;
    padding-top: 8vh;
  }

  .letter-sheet {
    width: 94%;
    max-height: calc(100vh - 72px);
  }
}
