@import url("https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap");

:root {
  --bg: #f4efe8;
  --ink: #2a1f1b;
  --muted: #6e5f57;
  --paper: rgba(255, 251, 247, 0.85);
  --line: rgba(128, 101, 86, 0.25);
  --accent: #a44c2f;
  --accent-deep: #7f341c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(48rem 28rem at -10% -20%, #fff8f2 10%, transparent 60%),
    radial-gradient(35rem 24rem at 110% 5%, #edd6ca 0%, transparent 60%),
    linear-gradient(160deg, #f8f3ed 0%, #eee3d8 45%, #e7d7c8 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image: radial-gradient(#000 0.4px, transparent 0.4px);
  background-size: 4px 4px;
}

.container {
  width: min(980px, 92vw);
  margin: 48px auto 64px;
  position: relative;
  z-index: 1;
}

.hero {
  text-align: center;
  margin-bottom: 18px;
  animation: rise 700ms ease both;
}

.tag {
  display: inline-block;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent-deep);
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(127, 52, 28, 0.22);
  border-radius: 999px;
  padding: 8px 14px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(2.05rem, 5vw, 3.6rem);
  line-height: 1.08;
}

.sub {
  margin: 12px auto 0;
  max-width: 720px;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  min-height: 30px;
}

.letter {
  margin-top: 28px;
  background: var(--paper);
  backdrop-filter: blur(2px);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow:
    0 25px 55px rgba(50, 28, 20, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  overflow: hidden;
  animation: rise 900ms 120ms ease both;
}

.letter-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
}

.content {
  padding: clamp(22px, 3.8vw, 42px);
}

.line {
  margin: 0 0 16px;
  line-height: 1.9;
  font-size: clamp(0.99rem, 1.7vw, 1.08rem);
  min-height: 34px;
}

.typing-caret::after {
  content: "|";
  margin-left: 2px;
  color: var(--accent);
  animation: blink 1s steps(1, end) infinite;
}

.highlight {
  border-left: 4px solid var(--accent);
  background: linear-gradient(90deg, rgba(244, 217, 204, 0.68), rgba(244, 217, 204, 0.2));
  padding: 14px 14px 14px 16px;
  border-radius: 10px;
  margin: 18px 0;
}

.sign {
  margin-top: 20px;
  font-weight: 600;
}

.side {
  border-left: 1px dashed var(--line);
  padding: clamp(20px, 2.8vw, 34px);
  background: linear-gradient(190deg, rgba(255, 255, 255, 0.5), rgba(244, 222, 210, 0.44));
}

.side h2,
.puzzle-card h2 {
  margin: 0 0 14px;
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.4rem;
}

.promise-item {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid rgba(127, 52, 28, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.54);
  font-size: 0.95rem;
}

.actions {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button,
.file-label,
select {
  border: none;
  border-radius: 999px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
}

button,
.file-label {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.btn-primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-deep));
  color: #fff;
  box-shadow: 0 8px 20px rgba(127, 52, 28, 0.3);
}

.btn-light,
.file-label,
select {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  border: 1px solid rgba(127, 52, 28, 0.2);
}

button:hover,
.file-label:hover {
  transform: translateY(-2px);
}

.note {
  margin-top: 14px;
  min-height: 24px;
  color: var(--muted);
  font-size: 0.95rem;
}

.puzzle-card {
  margin-top: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: clamp(20px, 3vw, 30px);
  box-shadow: 0 16px 36px rgba(50, 28, 20, 0.1);
  animation: rise 900ms 200ms ease both;
}

.puzzle-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.puzzle-controls {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

input[type="file"] {
  display: none;
}

.puzzle-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.93rem;
}

.board-wrap {
  margin-top: 16px;
  width: min(100%, 520px);
}

.puzzle-board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  gap: 2px;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(127, 52, 28, 0.2);
}

.tile {
  border: 0;
  background-repeat: no-repeat;
  background-size: cover;
  cursor: pointer;
  position: relative;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.tile.empty {
  background: rgba(255, 255, 255, 0.35);
  cursor: default;
}

.puzzle-status {
  margin-top: 12px;
  min-height: 26px;
  font-weight: 600;
  color: var(--accent-deep);
}

.gift-modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(42, 31, 27, 0.55);
  z-index: 20;
  padding: 20px;
}

.gift-modal.show {
  display: grid;
}

.gift-box {
  width: min(560px, 94vw);
  background: #fff9f3;
  border: 1px solid rgba(127, 52, 28, 0.2);
  border-radius: 20px;
  box-shadow: 0 20px 45px rgba(50, 28, 20, 0.22);
  padding: 24px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.gift-box h3 {
  margin: 0 0 8px;
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.9rem;
}

.gift-text {
  margin: 0;
  line-height: 1.8;
  color: var(--muted);
}

.gift-actions {
  margin-top: 16px;
}

.confetti {
  position: absolute;
  width: 8px;
  height: 14px;
  border-radius: 4px;
  top: -16px;
  opacity: 0.9;
  animation: fall linear forwards;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.99);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes fall {
  to {
    transform: translateY(340px) rotate(720deg);
    opacity: 0.2;
  }
}

@media (max-width: 860px) {
  .letter-grid {
    grid-template-columns: 1fr;
  }

  .side {
    border-left: 0;
    border-top: 1px dashed var(--line);
  }

  .puzzle-top {
    grid-template-columns: 1fr;
  }
}
