:root {
  --paper: #f4ecd8;
  --paper-2: #efe6cc;
  --ink: #1a1816;
  --ink-soft: #4a4742;
  --ink-muted: #8a857b;
  --accent: #c0392b;
  --tape: rgba(220, 200, 130, 0.55);
  --tape-shadow: rgba(0, 0, 0, 0.08);

  --note-1: #fff8d6;
  --note-2: #ffe3c4;
  --note-3: #d9f0d3;
  --note-4: #d2ecf7;
  --note-5: #f7d6e6;
  --note-6: #efe7ff;
  --note-7: #fef0c7;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.5), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(0,0,0,0.04), transparent 40%),
    repeating-linear-gradient(
      45deg,
      var(--paper) 0 6px,
      var(--paper-2) 6px 12px
    );
  color: var(--ink);
  font-family: "Patrick Hand", "Kalam", "Comic Sans MS", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  min-height: 100dvh;
  padding-bottom: calc(112px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); }

/* ---------- Header ---------- */
.header {
  text-align: center;
  padding: 28px 20px 14px;
}
.name {
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: clamp(2.4rem, 9vw, 3.6rem);
  margin: 0;
  letter-spacing: 0.5px;
  color: var(--ink);
  transform: rotate(-1.5deg);
}
.prompt {
  font-family: "Patrick Hand", cursive;
  font-size: clamp(1.05rem, 4vw, 1.3rem);
  color: var(--ink-soft);
  margin: 4px 0 8px;
  transform: rotate(0.8deg);
}
.stats {
  font-size: 0.92rem;
  color: var(--ink-muted);
  margin: 0;
  min-height: 1.2em;
}

/* ---------- Wall (notes grid) ---------- */
.wall {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px 14px;
  padding: 8px 14px 32px;
  max-width: 1200px;
  margin: 0 auto;
}
@media (min-width: 720px) {
  .wall { grid-template-columns: 1fr 1fr; gap: 28px 20px; padding: 16px 24px 48px; }
}
@media (min-width: 1080px) {
  .wall { grid-template-columns: repeat(3, 1fr); }
}

.loading, .empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ink-muted);
  padding: 24px 0;
  font-size: 1.05rem;
}

/* ---------- Note card ---------- */
.note {
  position: relative;
  background: var(--note-1);
  padding: 22px 18px 16px;
  border-radius: 2px;
  box-shadow:
    0 1px 0 rgba(0,0,0,0.04),
    0 6px 16px rgba(60, 50, 30, 0.14),
    0 2px 4px rgba(60, 50, 30, 0.08);
  font-family: "Kalam", "Patrick Hand", cursive;
  font-weight: 400;
  line-height: 1.45;
  color: var(--ink);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  transform-origin: center 10%;
  animation: drop-in 320ms ease-out both;
}
.note::before {
  /* tape */
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  width: 64px;
  height: 18px;
  background: var(--tape);
  transform: translateX(-50%) rotate(-3deg);
  box-shadow: 0 1px 2px var(--tape-shadow);
  border-left: 1px dashed rgba(0,0,0,0.06);
  border-right: 1px dashed rgba(0,0,0,0.06);
}

/* paper colors + rotations cycled by index */
.note:nth-child(7n+1) { background: var(--note-1); transform: rotate(-1.4deg); }
.note:nth-child(7n+2) { background: var(--note-2); transform: rotate(1.2deg); }
.note:nth-child(7n+3) { background: var(--note-3); transform: rotate(-0.6deg); }
.note:nth-child(7n+4) { background: var(--note-4); transform: rotate(1.8deg); }
.note:nth-child(7n+5) { background: var(--note-5); transform: rotate(-1.1deg); }
.note:nth-child(7n+6) { background: var(--note-6); transform: rotate(0.7deg); }
.note:nth-child(7n)   { background: var(--note-7); transform: rotate(-1.7deg); }
.note:nth-child(7n+2)::before { left: 30%; transform: translateX(-50%) rotate(8deg); }
.note:nth-child(7n+4)::before { left: 70%; transform: translateX(-50%) rotate(-7deg); }
.note:nth-child(7n+6)::before { left: 22%; transform: translateX(-50%) rotate(12deg); }

.note-body {
  white-space: pre-wrap;
  font-size: 1.08rem;
  margin: 0 0 12px;
}
.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  font-family: "Patrick Hand", cursive;
}
.note-meta .who::before { content: "— "; }
.note-meta .where { color: var(--ink-muted); }
.note-meta .when { color: var(--ink-muted); white-space: nowrap; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  height: 56px;
  border-radius: 14px;
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-family: "Patrick Hand", cursive;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0,0,0,0.25);
  z-index: 30;
  transition: transform 120ms ease;
}
.fab:active { transform: scale(0.98); }
@media (min-width: 720px) {
  .fab {
    left: auto;
    right: 24px;
    bottom: 24px;
    width: 220px;
  }
}

/* ---------- Scrim + Sheet ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 8, 0.45);
  backdrop-filter: blur(2px);
  z-index: 40;
  animation: fade-in 180ms ease-out;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--paper);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  box-shadow: 0 -12px 40px rgba(0,0,0,0.25);
  padding: 6px 18px calc(16px + var(--safe-bottom));
  max-height: min(92dvh, 720px);
  overflow-y: auto;
  animation: sheet-up 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, calc(100vw - 32px));
    border-radius: 20px;
    animation: pop-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }
}
.sheet-grip {
  width: 44px;
  height: 4px;
  background: rgba(0,0,0,0.18);
  border-radius: 999px;
  margin: 8px auto 4px;
}
@media (min-width: 720px) { .sheet-grip { display: none; } }
.sheet-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 0;
  font-size: 1.4rem;
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1;
}
.sheet-title {
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: 1.9rem;
  margin: 4px 0 12px;
  color: var(--ink);
}

/* ---------- Form ---------- */
.field {
  display: block;
  margin: 0 0 14px;
}
.field-label {
  display: block;
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.muted { color: var(--ink-muted); }
textarea, input[type="text"] {
  width: 100%;
  border: 1.5px solid rgba(0,0,0,0.15);
  background: #fffaee;
  border-radius: 10px;
  padding: 12px 14px;
  font-family: "Kalam", "Patrick Hand", cursive;
  font-size: 1.05rem;
  color: var(--ink);
  line-height: 1.4;
  resize: vertical;
  min-height: 44px;
}
textarea { min-height: 110px; }
textarea:focus, input[type="text"]:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  background: #fffdf2;
}
.counter {
  display: block;
  text-align: right;
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-top: 4px;
}
.counter.warn { color: var(--accent); }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 8px;
  min-height: 44px;
  font-size: 1rem;
}
.toggle input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--ink);
}
.location-status {
  font-size: 0.9rem;
  color: var(--ink-muted);
  margin: 0 0 10px;
  padding-left: 32px;
}

.turnstile-wrap {
  margin: 8px 0 12px;
  min-height: 0;
}
.turnstile-wrap:not(:empty) { min-height: 70px; }

.form-error {
  color: var(--accent);
  background: rgba(192,57,43,0.08);
  border: 1px solid rgba(192,57,43,0.25);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  background: var(--ink);
  color: var(--paper);
  border: 0;
  border-radius: 12px;
  font-family: "Patrick Hand", cursive;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.15);
}
.primary:disabled { opacity: 0.6; cursor: not-allowed; }
.primary:active { transform: scale(0.99); }
.btn-spinner {
  display: none;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: var(--paper);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.primary.loading .btn-spinner { display: inline-block; }
.primary.loading .btn-label { opacity: 0.7; }

.rules {
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin: 12px 0 4px;
}

/* ---------- Animations ---------- */
@keyframes fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up  { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes pop-in    { from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes drop-in   { from { opacity: 0; transform: translateY(-6px) rotate(var(--rot, 0deg)); } to { opacity: 1; } }
@keyframes spin      { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .note,
  .note:nth-child(7n+1),
  .note:nth-child(7n+2),
  .note:nth-child(7n+3),
  .note:nth-child(7n+4),
  .note:nth-child(7n+5),
  .note:nth-child(7n+6),
  .note:nth-child(7n) {
    transform: none;
    animation: none;
  }
  .scrim, .sheet { animation: none; }
}
