/* ---------- base ---------- */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --sky-top: #171238;
  --sky-mid: #2c1e57;
  --sky-low: #4b2a63;
  --town: #120f2e;
  --glow: #ffc46b;
  --paper: #fff7e8;
  --ink: #6b4a2b;
  --ink-strong: #7c3d12;
  --rose: #ff9db4;
}

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

body {
  font-family: "Quicksand", "Segoe UI", sans-serif;
  color: var(--paper);
  background: linear-gradient(to bottom,
    var(--sky-top) 0%,
    var(--sky-mid) 55%,
    var(--sky-low) 100%);
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- night scene (injected by common.js) ---------- */

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.moon {
  position: absolute;
  top: 36%;
  right: 7%;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fffbe9 0%, #ffe9b8 60%, #f5d489 100%);
  box-shadow: 0 0 40px 14px rgba(255, 235, 180, 0.35),
              0 0 120px 40px rgba(255, 235, 180, 0.12);
}

.moon::after {
  /* little sleepy craters */
  content: "";
  position: absolute;
  top: 20px;
  left: 16px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(214, 178, 110, 0.45);
  box-shadow: 22px 14px 0 -3px rgba(214, 178, 110, 0.4),
              8px 28px 0 -5px rgba(214, 178, 110, 0.35);
}

.star {
  position: absolute;
  border-radius: 50%;
  background: #fff6dd;
  opacity: 0.8;
  animation: twinkle 3.4s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: 0.25; transform: scale(0.8); }
  to   { opacity: 0.95; transform: scale(1.05); }
}

.town {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: min(30vh, 260px);
}

/* ---------- layout chrome ---------- */

.top-nav {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.4rem;
}

.nav-title {
  font-family: "Caveat", cursive;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 0 14px rgba(255, 196, 107, 0.5);
}

.nav-link {
  color: #ffe3ae;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  padding: 0.45rem 1rem;
  border: 1.5px dashed rgba(255, 227, 174, 0.55);
  border-radius: 999px;
  transition: background 0.25s, transform 0.25s;
}

.nav-link:hover {
  background: rgba(255, 227, 174, 0.12);
  transform: translateY(-1px);
}

.content {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 1.2rem 22vh;
}

.page-header {
  text-align: center;
  margin-bottom: 1.4rem;
}

.page-header h1 {
  font-family: "Caveat", cursive;
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  font-weight: 700;
  color: #ffeec9;
  text-shadow: 0 0 22px rgba(255, 196, 107, 0.45);
}

.page-header p {
  margin-top: 0.2rem;
  color: #d9c6ef;
  font-size: 1rem;
}

/* ---------- write page: the lantern card ---------- */

.write-card {
  position: relative;
  width: min(440px, 100%);
  transition: transform 1.4s ease-in, opacity 1.4s ease-in;
}

.write-card.sending {
  transform: translateY(-120vh) rotate(-5deg) scale(0.7);
  opacity: 0;
}

.write-card.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

.card-caps {
  width: 38%;
  height: 14px;
  margin: 0 auto;
  background: linear-gradient(#a03a3a, #74232c);
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.card-caps.top { border-radius: 8px 8px 4px 4px; }
.card-caps.bottom { border-radius: 4px 4px 8px 8px; }

.card-tassel {
  width: 4px;
  height: 30px;
  margin: 0 auto;
  background: linear-gradient(#e8b04b, #d18f2c);
  border-radius: 0 0 4px 4px;
  position: relative;
}

.card-tassel::after {
  content: "";
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 16px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(#e8b04b, #b8781f);
}

.card-paper {
  background:
    repeating-linear-gradient(to bottom,
      transparent 0 34px,
      rgba(214, 155, 90, 0.25) 34px 35px),
    radial-gradient(ellipse at 50% 20%, #fff9ec 0%, #ffedc8 55%, #ffd99b 100%);
  border-radius: 42px 42px 38px 38px / 30px 30px 26px 26px;
  padding: 1.6rem 1.7rem 1.5rem;
  box-shadow:
    0 0 30px 8px rgba(255, 190, 90, 0.4),
    0 0 90px 24px rgba(255, 160, 70, 0.18),
    inset 0 -16px 30px rgba(214, 106, 37, 0.18);
}

.card-date {
  font-family: "Caveat", cursive;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink-strong);
  text-align: center;
  margin-bottom: 0.4rem;
}

.card-date::before { content: "❀ "; color: var(--rose); }
.card-date::after  { content: " ❀"; color: var(--rose); }

#message-input {
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  font-family: "Caveat", cursive;
  font-size: 1.65rem;
  line-height: 35px;
  color: var(--ink);
  caret-color: var(--ink-strong);
}

#message-input:focus {
  outline: none;
}

#message-input::placeholder,
#location-input::placeholder {
  color: rgba(150, 110, 60, 0.55);
}

.location-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  padding-top: 0.55rem;
  border-top: 1.5px dashed rgba(180, 120, 60, 0.4);
}

#location-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: "Caveat", cursive;
  font-size: 1.3rem;
  color: var(--ink);
}

#location-input:focus {
  outline: none;
}

/* photo attachments on the write card */

.photo-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.7rem;
}

.photo-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: visible;
  background: #fff;
  padding: 4px;
  box-shadow: 0 3px 8px rgba(120, 70, 20, 0.3);
  transform: rotate(-2deg);
}

.photo-thumb:nth-child(even) {
  transform: rotate(2deg);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
  display: block;
}

.photo-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: #8f2b35;
  color: #ffe9c2;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-top: 1.1rem;
}

.photo-btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border: 1.5px dashed rgba(160, 90, 40, 0.55);
  border-radius: 999px;
  color: var(--ink-strong);
  font-family: "Quicksand", sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.photo-btn:hover {
  background: rgba(160, 90, 40, 0.1);
  transform: translateY(-1px);
}

.photo-btn input {
  display: none;
}

.send-btn {
  display: block;
  padding: 0.6rem 1.7rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(#c14646, #8f2b35);
  color: #ffe9c2;
  font-family: "Quicksand", sans-serif;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(120, 30, 40, 0.45);
  transition: transform 0.2s, box-shadow 0.2s;
}

.send-btn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 6px 18px rgba(120, 30, 40, 0.55);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 12vh;
  transform: translate(-50%, 20px);
  z-index: 5;
  background: rgba(28, 18, 52, 0.92);
  border: 1.5px solid rgba(255, 210, 130, 0.5);
  color: #ffe9c2;
  font-family: "Caveat", cursive;
  font-size: 1.4rem;
  padding: 0.7rem 1.5rem;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s, transform 0.4s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- view page: the lantern sky ---------- */

.lantern-sky {
  width: min(980px, 100%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 2.2rem 2.6rem;
  padding: 0.8rem 0.4rem;
}

.lantern {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  margin-top: var(--drift, 0px);
  animation: float var(--dur, 6s) ease-in-out var(--delay, 0s) infinite alternate;
  transition: transform 0.25s;
}

.lantern:hover,
.lantern:focus-visible {
  transform: scale(1.08);
}

.lantern:focus-visible {
  outline: 2px dashed #ffe3ae;
  outline-offset: 6px;
  border-radius: 20px;
}

@keyframes float {
  from { translate: 0 0; rotate: -1.2deg; }
  to   { translate: 0 -12px; rotate: 1.2deg; }
}

.lantern-cap {
  display: block;
  width: 34px;
  height: 9px;
  margin: 0 auto;
  background: linear-gradient(#a03a3a, #74232c);
  border-radius: 4px;
}

.lantern-body {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 106px;
  margin: 1px auto;
  position: relative;
  overflow: hidden;
  background:
    repeating-linear-gradient(to bottom,
      rgba(190, 90, 30, 0.16) 0 1.5px,
      transparent 1.5px 13px),
    radial-gradient(ellipse at 50% 38%, #ffe9b0 0%, #ffc46b 55%, #f2913f 100%);
  border-radius: 46% 46% 44% 44% / 36% 36% 40% 40%;
  box-shadow:
    0 0 22px 6px rgba(255, 190, 90, 0.5),
    0 0 60px 18px rgba(255, 160, 70, 0.22),
    inset 0 -10px 18px rgba(214, 106, 37, 0.35);
}

.lantern-date {
  font-family: "Caveat", cursive;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--ink-strong);
  text-shadow: 0 1px 0 rgba(255, 245, 220, 0.5);
}

.lantern-tassel {
  display: block;
  width: 3px;
  height: 20px;
  margin: 0 auto;
  background: linear-gradient(#e8b04b, #d18f2c);
  border-radius: 0 0 3px 3px;
  position: relative;
}

.lantern-tassel::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 9px;
  height: 12px;
  border-radius: 0 0 6px 6px;
  background: linear-gradient(#e8b04b, #b8781f);
}

.empty-state {
  margin-top: 2.5rem;
  font-family: "Caveat", cursive;
  font-size: 1.7rem;
  color: #d9c6ef;
  text-align: center;
}

/* ---------- opened letter ---------- */

.letter-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  background: rgba(14, 9, 36, 0.65);
  backdrop-filter: blur(4px);
}

.letter-overlay[hidden] {
  display: none;
}

.letter {
  position: relative;
  width: min(440px, 100%);
  max-height: 82vh;
  overflow-y: auto;
  background:
    repeating-linear-gradient(to bottom,
      transparent 0 33px,
      rgba(214, 155, 90, 0.22) 33px 34px),
    radial-gradient(ellipse at 50% 15%, #fffaf0 0%, #fff0d2 60%, #ffe2ad 100%);
  border-radius: 22px;
  padding: 2rem 2rem 1.6rem;
  box-shadow:
    0 0 40px 10px rgba(255, 190, 90, 0.35),
    0 18px 50px rgba(0, 0, 0, 0.45);
  animation: letter-open 0.35s ease-out;
  text-align: center;
}

@keyframes letter-open {
  from { transform: scale(0.7) translateY(24px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.letter-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(160, 90, 40, 0.14);
  color: var(--ink-strong);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.letter-close:hover {
  background: rgba(160, 90, 40, 0.28);
  transform: rotate(90deg);
}

.letter-hearts {
  font-size: 1.6rem;
  filter: drop-shadow(0 0 8px rgba(255, 170, 80, 0.8));
}

.letter-date {
  font-family: "Caveat", cursive;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--ink-strong);
  margin-top: 0.3rem;
}

.letter-meta {
  font-family: "Quicksand", sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  color: #a3703d;
  margin-top: 0.15rem;
}

.letter-message {
  font-family: "Caveat", cursive;
  font-size: 1.75rem;
  line-height: 34px;
  color: var(--ink);
  margin-top: 1rem;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.letter-photos {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.9rem;
  margin-top: 1.2rem;
}

.letter-photos img {
  width: min(170px, 42%);
  border-radius: 6px;
  border: 6px solid #fff;
  border-bottom-width: 20px;
  box-shadow: 0 6px 16px rgba(90, 50, 15, 0.35);
  transform: rotate(var(--tilt, -2deg));
  transition: transform 0.25s;
}

.letter-photos img:hover {
  transform: rotate(0deg) scale(1.04);
}

.letter-sign {
  font-family: "Caveat", cursive;
  font-size: 1.3rem;
  color: var(--rose);
  text-align: right;
  margin-top: 1.1rem;
}

/* ---------- small screens ---------- */

button,
.nav-link,
.photo-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 480px) {
  .lantern-sky {
    gap: 1.5rem 1.1rem;
  }

  .content {
    padding-bottom: 26vh;
  }

  .moon {
    width: 56px;
    height: 56px;
  }

  .top-nav {
    padding: 0.8rem 1rem;
  }

  .nav-title {
    font-size: 1.3rem;
  }

  .card-paper {
    padding: 1.3rem 1.2rem 1.2rem;
  }

  .letter {
    padding: 1.6rem 1.2rem 1.3rem;
  }

  .letter-message {
    font-size: 1.55rem;
  }
}

/* ---------- sign-out badge ---------- */

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-signout {
  background: none;
  border: 1.5px dashed rgba(255, 227, 174, 0.35);
  border-radius: 999px;
  color: rgba(255, 227, 174, 0.75);
  font-family: "Quicksand", sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.38rem 0.85rem;
  cursor: pointer;
  transition: background 0.25s, color 0.25s;
}

.nav-signout:hover {
  background: rgba(255, 227, 174, 0.1);
  color: #ffe3ae;
}

/* ---------- login ---------- */

.page-login .content {
  align-items: center;
  justify-content: center;
}

.login-card {
  position: relative;
  z-index: 2;
  width: min(92vw, 25rem);
  display: flex;
  flex-direction: column;
  gap: 1.3rem;
  padding: 1.9rem 1.6rem;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 247, 232, 0.97), rgba(255, 236, 205, 0.94));
  box-shadow: 0 0 46px rgba(255, 180, 90, 0.32), 0 14px 34px rgba(10, 6, 30, 0.5);
}

.login-card .who {
  border: none;
  padding: 0;
  margin: 0;
}

.login-card legend {
  font-family: "Caveat", cursive;
  font-size: 1.42rem;
  color: var(--ink-strong);
  margin-bottom: 0.55rem;
}

.author-choices {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.author-choice {
  flex: 1 1 6rem;
  cursor: pointer;
}

.author-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.author-name {
  display: block;
  text-align: center;
  padding: 0.6rem 0.5rem;
  border: 2px solid rgba(140, 80, 40, 0.22);
  border-radius: 12px;
  color: var(--ink);
  font-weight: 600;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.author-choice input:checked + .author-name {
  border-color: #c14646;
  background: rgba(193, 70, 70, 0.1);
  color: var(--ink-strong);
  transform: translateY(-1px);
}

.author-choice input:focus-visible + .author-name {
  outline: 2px solid #c14646;
  outline-offset: 2px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field span {
  font-family: "Caveat", cursive;
  font-size: 1.42rem;
  color: var(--ink-strong);
}

.field input {
  font-family: "Quicksand", sans-serif;
  font-size: 1rem;
  color: var(--ink);
  padding: 0.65rem 0.8rem;
  border: 2px solid rgba(140, 80, 40, 0.22);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
}

.field input:focus {
  outline: none;
  border-color: #c14646;
}

.login-error {
  margin: -0.5rem 0 0;
  color: #8f2b35;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

.login-card .send-btn {
  align-self: center;
}

.send-btn:disabled {
  opacity: 0.65;
  cursor: default;
  transform: none;
  box-shadow: 0 4px 14px rgba(120, 30, 40, 0.3);
}
