:root {
  color-scheme: light;
  --ink: #223036;
  --muted: #617078;
  --paper: #fffaf0;
  --paper-strong: #fff4d8;
  --line: #eadfca;
  --rose: #c85d6d;
  --teal: #1f7a73;
  --blue: #294f73;
  --bg: #f6f2e9;
  --white: #ffffff;
  --shadow: 0 22px 60px rgba(55, 42, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(200, 93, 109, 0.18), transparent 30rem),
    linear-gradient(135deg, #f7f0e1 0%, #eef5f2 48%, #f8f1e8 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  color: var(--white);
  background: linear-gradient(135deg, var(--teal), var(--blue));
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  padding: 13px 16px;
  border-radius: 8px;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(55, 42, 28, 0.08);
}

.flash.error {
  border-color: rgba(200, 93, 109, 0.38);
  color: #923848;
}

.flash.success {
  border-color: rgba(31, 122, 115, 0.35);
  color: #14645e;
}

.hero-grid,
.letter-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 24px;
  align-items: start;
}

.common-letter,
.personal-letter,
.unlock-panel,
.reply-panel,
.center-panel,
.response-card,
.empty-state {
  border: 1px solid rgba(234, 223, 202, 0.92);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.88);
  box-shadow: var(--shadow);
}

.common-letter,
.personal-letter {
  position: relative;
  overflow: hidden;
  padding: clamp(28px, 5vw, 62px);
}

.common-letter::before,
.personal-letter::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(200, 93, 109, 0.16);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--rose);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  letter-spacing: 0;
}

h1 {
  max-width: 760px;
  font-size: clamp(2.35rem, 5vw, 4.8rem);
  line-height: 0.98;
}

h2 {
  font-size: 1.8rem;
  line-height: 1.05;
}

.letter-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(18px, 3vw, 34px);
}

.letter-heading h1 {
  max-width: none;
  min-width: 0;
  font-size: clamp(2.45rem, 4.4vw, 4.2rem);
  line-height: 1.04;
  overflow-wrap: break-word;
}

.student-photo {
  flex: 0 0 auto;
  display: block;
  width: clamp(104px, 12vw, 150px);
  aspect-ratio: 1;
  border: 6px solid rgba(255, 255, 255, 0.88);
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 14px 34px rgba(55, 42, 28, 0.16);
}

.letter-body {
  margin-top: 30px;
  font-size: 1.03rem;
  line-height: 1.86;
}

.letter-body p {
  margin: 0 0 18px;
}

.letter-body .signature {
  color: var(--blue);
  font-weight: 700;
}

.unlock-panel,
.reply-panel {
  padding: 24px;
}

.unlock-panel p,
.reply-panel p,
.center-panel p {
  color: var(--muted);
  line-height: 1.65;
}

.envelope {
  position: relative;
  width: 156px;
  height: 108px;
  margin: 6px 0 26px;
  border-radius: 6px;
  background: linear-gradient(135deg, #f8d6aa, #f7efe0);
  border: 1px solid #ddb987;
  overflow: hidden;
}

.envelope::before,
.envelope::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 50%;
  height: 72%;
  background: rgba(255, 250, 240, 0.72);
}

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

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

.envelope-flap {
  position: absolute;
  inset: 0;
  background: rgba(200, 93, 109, 0.18);
  clip-path: polygon(0 0, 100% 0, 50% 54%);
}

.envelope-paper {
  position: absolute;
  left: 26px;
  right: 26px;
  top: 18px;
  height: 62px;
  border-radius: 4px;
  background: var(--white);
  box-shadow: 0 4px 16px rgba(55, 42, 28, 0.12);
}

.unlock-form,
.reply-form {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

label {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  outline: 0;
}

select,
input {
  height: 48px;
  padding: 0 14px;
}

textarea {
  min-height: 180px;
  padding: 14px;
  resize: vertical;
  line-height: 1.6;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(31, 122, 115, 0.13);
}

button {
  min-height: 50px;
  border-radius: 8px;
  color: var(--white);
  background: linear-gradient(135deg, var(--teal), var(--blue));
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(31, 122, 115, 0.24);
}

.personal-letter {
  background:
    linear-gradient(rgba(255, 250, 240, 0.92), rgba(255, 250, 240, 0.92)),
    repeating-linear-gradient(0deg, transparent 0, transparent 35px, rgba(41, 79, 115, 0.08) 36px);
}

.center-panel,
.responses-page {
  max-width: 840px;
  margin: 0 auto;
}

.center-panel {
  padding: 36px;
}

.center-panel code {
  display: inline-block;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--white);
  color: var(--blue);
}

.section-heading {
  margin-bottom: 18px;
}

.response-list {
  display: grid;
  gap: 14px;
}

.response-card {
  padding: 18px;
}

.response-card div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.response-card time {
  color: var(--muted);
  font-size: 0.86rem;
}

.response-card p {
  margin: 0;
  line-height: 1.7;
  white-space: pre-wrap;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
}

@media (max-width: 640px) {
  body {
    background: linear-gradient(180deg, #f7f0e1 0%, #eef5f2 100%);
  }

  .page-shell {
    width: min(100% - 18px, 680px);
    padding: 12px 0 28px;
  }

  .topbar {
    margin-bottom: 14px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .brand strong {
    font-size: 0.96rem;
  }

  .brand small {
    font-size: 0.78rem;
  }

  .hero-grid,
  .letter-layout {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .unlock-panel {
    order: -1;
  }

  .common-letter,
  .personal-letter,
  .unlock-panel,
  .reply-panel,
  .center-panel,
  .response-card,
  .empty-state {
    box-shadow: 0 12px 34px rgba(55, 42, 28, 0.1);
  }

  .common-letter,
  .personal-letter {
    padding: 26px 18px;
  }

  .common-letter::before,
  .personal-letter::before {
    inset: 8px;
  }

  h1 {
    font-size: clamp(2.05rem, 11vw, 3.25rem);
    line-height: 1.03;
  }

  h2 {
    font-size: 1.55rem;
  }

  .letter-body {
    margin-top: 22px;
    font-size: 1rem;
    line-height: 1.76;
  }

  .letter-heading {
    align-items: flex-start;
  }

  .letter-heading h1 {
    font-size: clamp(2rem, 8.5vw, 3.05rem);
  }

  .student-photo {
    width: 82px;
    border-width: 5px;
  }

  .letter-body p {
    margin-bottom: 15px;
  }

  .unlock-panel,
  .reply-panel {
    padding: 20px;
  }

  .unlock-panel p,
  .reply-panel p,
  .center-panel p {
    line-height: 1.55;
  }

  .envelope {
    width: 126px;
    height: 86px;
    margin: 0 0 18px;
  }

  .envelope-paper {
    left: 20px;
    right: 20px;
    top: 14px;
    height: 50px;
  }

  .unlock-form,
  .reply-form {
    gap: 10px;
    margin-top: 16px;
  }

  select,
  input {
    height: 52px;
    font-size: 1rem;
  }

  textarea {
    min-height: 150px;
  }

  button {
    min-height: 52px;
  }

  .response-card div {
    display: grid;
  }
}

.intro {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 250, 240, 0.95), rgba(246, 242, 233, 0.98) 60%),
    linear-gradient(160deg, #2a3b44 0%, #3c2a2f 100%);
  transition: opacity 0.9s ease;
}

.intro.hidden {
  opacity: 0;
  pointer-events: none;
}

.intro-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  padding: 24px;
  max-width: 560px;
  width: calc(100% - 32px);
}

.intro-portrait {
  width: min(82vw, 460px);
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.45);
  border: 6px solid rgba(255, 255, 255, 0.9);
  transform: translateY(0);
  transition: transform 0.9s ease, opacity 0.9s ease;
}

.intro.opening .intro-portrait {
  transform: translateY(-40px) scale(0.92);
  opacity: 0;
}

.intro-hint {
  margin: 0;
  color: #d63243;
  font-size: 0.98rem;
  letter-spacing: 0.02em;
  animation: hintPulse 2.2s ease-in-out infinite;
}

.intro.opening .intro-hint {
  opacity: 0;
  transition: opacity 0.4s ease;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.env {
  position: relative;
  width: 210px;
  height: 140px;
  padding: 0;
  background: transparent;
  box-shadow: none;
  border: 0;
  perspective: 900px;
  cursor: pointer;
}

.env-body {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.env-pocket {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #f6d9a8, #efd9b8);
  border: 1px solid #d8b178;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  z-index: 3;
}

.env-pocket::before,
.env-pocket::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 50%;
  height: 78%;
  background: rgba(255, 250, 240, 0.82);
  border-top: 1px solid rgba(216, 177, 120, 0.6);
}

.env-pocket::before {
  left: 0;
  clip-path: polygon(0 0, 100% 55%, 0 100%);
}

.env-pocket::after {
  right: 0;
  clip-path: polygon(100% 0, 0 55%, 100% 100%);
}

.env-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 62%;
  background: linear-gradient(160deg, #f3cf95, #e9c486);
  border: 1px solid #d8b178;
  border-radius: 8px 8px 0 0;
  clip-path: polygon(0 0, 100% 0, 50% 92%);
  transform-origin: top center;
  transform: rotateX(0deg);
  z-index: 4;
  transition: transform 0.7s cubic-bezier(0.6, 0, 0.4, 1);
  backface-visibility: hidden;
}

.env.opening .env-flap {
  transform: rotateX(180deg);
}

.env-letter {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 18px;
  height: 70px;
  border-radius: 5px;
  background: #fffaf0;
  box-shadow: 0 4px 14px rgba(55, 42, 28, 0.18);
  z-index: 2;
  transform: translateY(0) scale(1);
  transition:
    transform 0.9s cubic-bezier(0.5, 0, 0.3, 1) 0.35s,
    opacity 0.5s ease 1s;
}

.env.opening .env-letter {
  transform: translateY(-150px) scale(1.35);
  opacity: 0;
}

@media (max-width: 640px) {
  .intro-stage {
    gap: 18px;
    padding: 16px;
  }

  .intro-portrait {
    width: 74vw;
  }

  .env {
    width: 170px;
    height: 116px;
  }

  .env-letter {
    height: 60px;
  }
}

@media (max-width: 430px) {
  .page-shell {
    width: min(100% - 12px, 480px);
  }

  .common-letter,
  .personal-letter,
  .unlock-panel,
  .reply-panel,
  .center-panel,
  .response-card,
  .empty-state {
    border-radius: 7px;
  }

  .common-letter,
  .personal-letter {
    padding: 24px 16px;
  }

  .eyebrow {
    font-size: 0.75rem;
  }

  h1 {
    font-size: clamp(1.9rem, 12vw, 2.8rem);
  }

  .letter-body {
    font-size: 0.98rem;
    line-height: 1.72;
  }

  .letter-heading {
    display: grid;
    grid-template-columns: 1fr;
  }

  .student-photo {
    width: 92px;
  }

  .center-panel {
    padding: 24px 18px;
  }

  .center-panel code {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
}
