/* Letter size shrinks on tablets and phones so more of them fit on the screen.
   box.js measures the rendered letter, so the physics and the count follow these. */
:root {
  --letter-width: 60px;
  --letter-icon: 40px;
  --letter-font: 11px;
}

@media (max-width: 1024px) {
  :root {
    --letter-width: 52px;
    --letter-icon: 34px;
    --letter-font: 10px;
  }
}

@media (max-width: 600px) {
  :root {
    --letter-width: 44px;
    --letter-icon: 28px;
    --letter-font: 9px;
  }
}

/* The box page keeps the home header at the top and gives the rest of the
   screen to the letter pile. */
.desktop {
  align-items: stretch;
  padding-right: 0;
  padding-bottom: 0;
  padding-left: 0;
}

.desktop > .frame {
  width: 100%;
  margin: 0 auto;
  min-height: calc(100vh - 24px);
  gap: 32px;
}

.letters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 20px 28px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.letter-named {
  width: var(--letter-width);
  user-select: none;
}

.letter-open {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  color: inherit;
  border-radius: 6px;
}

.letter-open:focus-visible {
  outline: 2px solid #000;
  outline-offset: 3px;
}

.letters:not(.has-physics) {
  padding: 0 16px 32px;
}

/* Static layout (no physics): tilt each letter a little so it feels hand-dropped */
.letters:not(.has-physics) .letter-named:nth-child(4n + 1) { transform: rotate(-6deg); }
.letters:not(.has-physics) .letter-named:nth-child(4n + 2) { transform: rotate(4deg); }
.letters:not(.has-physics) .letter-named:nth-child(4n + 3) { transform: rotate(-2deg); }
.letters:not(.has-physics) .letter-named:nth-child(4n + 4) { transform: rotate(7deg); }

/* Physics layout: the letters fill the whole screen, behind the title and button,
   which act as solid shapes the letters pile around. */
.letters.has-physics {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  cursor: grab;
  touch-action: none;
  overflow: clip;
}

.desktop > .frame > .div,
.desktop > .frame > .drop-button {
  position: relative;
  z-index: 1;
}

/* The title stays readable on top, but taps go through it to the letters underneath. */
.desktop > .frame > .div {
  pointer-events: none;
}

.letters.has-physics.is-dragging {
  cursor: grabbing;
}

.letters.has-physics .letter-named {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  will-change: transform;
  transform: translateY(-9999px);
}

.letter-img {
  width: var(--letter-icon);
  height: auto;
}

.letter-named .text-wrapper {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: Georgia, "Times New Roman", serif;
  font-size: var(--letter-font);
}

/* The opened letter */
.note {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 36px 28px 28px;
  border: 2px solid #000;
  border-radius: 12px;
  background: #fff;
  color: #000;
  font-family: Georgia, "Times New Roman", serif;
  overflow-y: auto;
}

.note::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.note[open] {
  animation: note-open 0.2s ease-out;
}

@keyframes note-open {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
}

@media (prefers-reduced-motion: reduce) {
  .note[open] {
    animation: none;
  }
}

.note-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
  color: #000;
}

.note-close:hover {
  background: #f0f0f0;
}

.note-close:focus-visible {
  outline: 2px solid #000;
}

.note-label {
  margin: 0 0 6px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: #555;
}

.note-name {
  margin: 0 0 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid #000;
  font-size: 24px;
  font-weight: normal;
}

.note-request {
  margin: 0;
  font-size: 17px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.note-date {
  margin: 18px 0 0;
  font-size: 13px;
  color: #666;
}

.note-date:empty {
  display: none;
}

/* Replies inside the opened letter */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.replies {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #ddd;
}

.reply-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.reply {
  padding: 10px 12px;
  border-left: 3px solid #000;
  border-radius: 0 8px 8px 0;
  background: #f6f6f6;
}

.reply-who {
  margin: 0 0 4px;
  font-size: 12px;
  color: #666;
}

.reply-body {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.reply-empty {
  margin: 0 0 16px;
  font-size: 14px;
  color: #666;
}

.reply-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reply-text,
.reply-name {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #000;
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  color: #000;
}

.reply-text {
  resize: vertical;
  line-height: 1.5;
}

.reply-text:focus,
.reply-name:focus {
  outline: 2px solid #000;
  outline-offset: 2px;
}

.reply-name[hidden] {
  display: none;
}

/* Name / anonymous switch, same look as the prayer form's visibility toggle */
.reply-as {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 4px;
  border: 1.5px solid #000;
  border-radius: 24px;
}

.reply-as label {
  position: relative;
  flex: 1 1 auto;
  cursor: pointer;
}

.reply-as input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.reply-as span {
  display: block;
  padding: 8px 10px;
  border-radius: 999px;
  text-align: center;
  font-size: 14px;
  white-space: nowrap;
}

.reply-as input:checked + span {
  background: #000;
  color: #fff;
}

.reply-as input:focus-visible + span {
  outline: 2px solid #000;
  outline-offset: 3px;
}

.reply-send {
  align-self: flex-end;
  padding: 10px 18px;
  border-radius: 10px;
  background: #000;
  color: #fff;
  font-size: 15px;
}

.reply-send:hover {
  opacity: 0.85;
}

.reply-send:focus-visible {
  outline: 3px solid #000;
  outline-offset: 3px;
}

.note-sample {
  margin: 18px 0 0;
  font-size: 13px;
  font-style: italic;
  color: #666;
}

.reply-error {
  margin: 0;
  font-size: 14px;
  color: #b3261e;
}

.reply-send:disabled {
  opacity: 0.6;
  cursor: default;
}

.reply-login {
  align-self: flex-start;
}

.replies {
  display: flex;
  flex-direction: column;
}

.replies[hidden],
.reply-form[hidden],
.reply-login[hidden] {
  display: none;
}

/* Phones: a little less padding inside the opened letter */
@media (max-width: 600px) {
  .note {
    padding: 32px 20px 20px;
  }

  .note-name {
    font-size: 21px;
  }

  .note-request {
    font-size: 16px;
  }

  .reply-as span {
    padding: 8px 6px;
    font-size: 13px;
  }

  .reply-text,
  .reply-name {
    font-size: 16px;
  }

  .reply-send {
    min-height: 44px;
  }
}
