/* Group Card — warm, handmade paper theme */

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

:root {
  --paper: #faf6ec;
  --paper-deep: #f3ecdb;
  --card-paper: #fffdf6;
  --ink: #3a3226;
  --ink-soft: #6b6154;
  --ink-faint: #a1958200;
  --line: rgba(90, 74, 50, 0.16);
  --accent: #a84a32;
  --accent-soft: #c96f55;
  --sea: #1e6a7a;
  --plum: #7a3b78;
  --forest: #3d6b35;
  --brick: #a84a32;
  --shadow-soft: 0 10px 30px rgba(90, 70, 40, 0.14);
  --shadow-card: 0 3px 8px rgba(90, 70, 40, 0.12), 0 12px 28px rgba(90, 70, 40, 0.10);
  --radius: 10px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(200, 150, 90, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 15%, rgba(120, 140, 90, 0.08), transparent 55%),
    var(--paper);
  color: var(--ink);
  line-height: 1.65;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink);
}

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

.shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.masthead { text-align: center; margin-bottom: 36px; }
.masthead h1 { font-size: clamp(2.1rem, 6vw, 3.1rem); }
.masthead .sub {
  color: var(--ink-soft);
  font-size: 1.02rem;
  max-width: 34em;
  margin: 10px auto 0;
}
.masthead .rule {
  width: 72px; height: 2px; margin: 18px auto 0;
  background: linear-gradient(90deg, transparent, var(--accent-soft), transparent);
}

/* ------------------------------------------------------------- panels */

.panel {
  background: var(--card-paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 28px;
  margin-bottom: 24px;
}
.panel h2 { font-size: 1.5rem; margin-bottom: 6px; }
.panel .hint { color: var(--ink-soft); font-size: 0.92rem; margin-bottom: 18px; }

.hidden { display: none !important; }

/* -------------------------------------------------------------- forms */

.field { margin-bottom: 20px; }
.field > label {
  display: block;
  font-weight: 500;
  font-size: 0.95rem;
  margin-bottom: 6px;
}
.field .note { font-size: 0.84rem; color: var(--ink-soft); margin-top: 5px; }

input[type="text"], textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(200, 111, 85, 0.15);
}
textarea { resize: vertical; min-height: 120px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 500;
  color: #fffdf6;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 12px 28px;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease, box-shadow .15s ease;
  box-shadow: 0 4px 14px rgba(168, 74, 50, 0.28);
}
.btn:hover { background: #934028; transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.btn-quiet {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn-quiet:hover { background: rgba(90, 74, 50, 0.06); color: var(--ink); }

.btn-small { padding: 7px 16px; font-size: 0.87rem; }

.btn-danger {
  background: transparent;
  color: var(--brick);
  border: 1px solid rgba(168, 74, 50, 0.4);
  box-shadow: none;
}
.btn-danger:hover { background: rgba(168, 74, 50, 0.08); }

.error-msg {
  background: rgba(168, 74, 50, 0.08);
  border: 1px solid rgba(168, 74, 50, 0.35);
  color: #8c3a24;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.92rem;
  margin: 14px 0;
}

/* ------------------------------------------------------- cover upload */

.cover-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 170px;
  border: 2px dashed rgba(90, 74, 50, 0.3);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink-soft);
  cursor: pointer;
  text-align: center;
  padding: 18px;
  transition: border-color .15s ease, background .15s ease;
  position: relative;
  overflow: hidden;
}
.cover-drop:hover, .cover-drop.dragover {
  border-color: var(--accent-soft);
  background: rgba(255, 253, 246, 0.9);
}
.cover-drop img.cover-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cover-drop .cover-cta { position: relative; z-index: 1; }
.cover-drop.has-image .cover-cta {
  background: rgba(30, 24, 15, 0.6);
  color: #fdf9ee;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.85rem;
}
.cover-drop.has-image .cover-icon { display: none; }
.cover-icon { width: 42px; height: 42px; opacity: 0.5; }

/* --------------------------------------------------------- share links */

.link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px dashed var(--line);
}
.link-row:last-child { border-bottom: none; }
.link-row .link-info { flex: 1; min-width: 0; }
.link-row .link-name { font-weight: 500; font-size: 0.95rem; }
.link-row .link-desc { font-size: 0.83rem; color: var(--ink-soft); }
.link-row .link-url {
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
  font-family: ui-monospace, monospace;
}
.copy-btn {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  background: rgba(168, 74, 50, 0.08);
  border: 1px solid rgba(168, 74, 50, 0.3);
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  transition: background .15s ease;
}
.copy-btn:hover { background: rgba(168, 74, 50, 0.16); }
.copy-btn.copied { color: var(--forest); border-color: rgba(61, 107, 53, 0.4); background: rgba(61, 107, 53, 0.08); }

.keep-safe {
  background: rgba(200, 150, 90, 0.12);
  border: 1px solid rgba(200, 150, 90, 0.35);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.88rem;
  color: #7a5a2e;
  margin-top: 16px;
}

/* ----------------------------------------------------------- note card */

.note-card {
  background: var(--card-paper);
  border: 1px solid rgba(90, 74, 50, 0.12);
  border-radius: 6px;
  box-shadow: var(--shadow-card);
  padding: 20px 22px 16px;
  transform: rotate(var(--tilt, 0deg));
  max-width: 480px;
  margin: 0 auto;
}

.note-media { text-align: center; margin-bottom: 12px; }
.note-media img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(90, 70, 40, 0.18);
}
.note-doodle img { background: #fff; }

.note-message {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 1.35rem;
  line-height: 1.45;
}
.note-author {
  margin-top: 10px;
  text-align: right;
  font-size: 1.15rem;
  opacity: 0.85;
}

/* handwriting fonts (ids match the server allowlist) */
.font-caveat .note-message, .font-caveat .note-author { font-family: 'Caveat', cursive; }
.font-shadows .note-message, .font-shadows .note-author { font-family: 'Shadows Into Light', cursive; font-size: 1.15rem; }
.font-homemade .note-message, .font-homemade .note-author { font-family: 'Homemade Apple', cursive; font-size: 1.05rem; line-height: 1.8; }
.font-kalam .note-message, .font-kalam .note-author { font-family: 'Kalam', cursive; font-size: 1.15rem; }
.font-shadows .note-author, .font-homemade .note-author, .font-kalam .note-author { font-size: 1rem; }

/* ink colors (ids match the server allowlist) */
.ink-ink .note-message, .ink-ink .note-author { color: #3a3226; }
.ink-sea .note-message, .ink-sea .note-author { color: var(--sea); }
.ink-plum .note-message, .ink-plum .note-author { color: var(--plum); }
.ink-forest .note-message, .ink-forest .note-author { color: var(--forest); }
.ink-brick .note-message, .ink-brick .note-author { color: var(--brick); }

/* --------------------------------------------------- sign page pickers */

.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ink-soft);
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--accent-soft); color: var(--ink); }
.chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(168, 74, 50, 0.07);
  font-weight: 500;
}
.chip.font-chip-caveat { font-family: 'Caveat', cursive; font-size: 1.1rem; }
.chip.font-chip-shadows { font-family: 'Shadows Into Light', cursive; font-size: 1rem; }
.chip.font-chip-homemade { font-family: 'Homemade Apple', cursive; font-size: 0.88rem; }
.chip.font-chip-kalam { font-family: 'Kalam', cursive; font-size: 0.98rem; }

.swatch-row { display: flex; gap: 10px; }
.swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 0 0 1px var(--line), 0 2px 6px rgba(90,70,40,0.15);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(90,70,40,0.2); transform: scale(1.12); }

.media-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.media-preview { position: relative; text-align: center; margin-top: 12px; }
.media-preview img { max-width: 100%; max-height: 240px; border-radius: 6px; box-shadow: var(--shadow-card); }
.media-remove {
  position: absolute;
  top: -8px; right: -4px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* live preview */
.preview-stage {
  background:
    radial-gradient(500px 220px at 80% 0%, rgba(200, 150, 90, 0.10), transparent 55%),
    var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px 22px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-stage .note-card { width: 100%; }
.preview-label {
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 12px;
}

/* two-column sign layout on wide screens */
@media (min-width: 880px) {
  .sign-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
  .sign-layout .preview-col { position: sticky; top: 24px; }
}

/* ------------------------------------------------------------ GIF grid */

.gif-search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.gif-search-row input { flex: 1; }

.gif-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding: 2px;
}
.gif-grid button {
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 0;
  background: var(--paper-deep);
  cursor: pointer;
  overflow: hidden;
  line-height: 0;
}
.gif-grid button:hover { border-color: var(--accent-soft); }
.gif-grid button.active { border-color: var(--accent); }
.gif-grid img { width: 100%; height: 90px; object-fit: cover; }

/* -------------------------------------------------------- doodle modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--card-paper);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  padding: 18px;
  max-width: 860px;
  width: 100%;
}
.modal h3 { font-size: 1.3rem; margin-bottom: 10px; }
.doodle-canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.doodle-canvas-wrap canvas {
  display: block;
  width: 100%;
  touch-action: none;
  cursor: crosshair;
}
.doodle-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}
.doodle-toolbar .spacer { flex: 1; }
.stroke-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fffef9;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.stroke-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(168,74,50,0.25); }
.stroke-dot { border-radius: 50%; background: var(--ink); }
.stroke-dot.thin { width: 4px; height: 4px; }
.stroke-dot.thick { width: 10px; height: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* --------------------------------------------------- "your entry" panel */

.mine-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  background: rgba(61, 107, 53, 0.08);
  border: 1px solid rgba(61, 107, 53, 0.3);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.93rem;
  color: var(--forest);
}
.mine-banner .grow { flex: 1; min-width: 200px; }

/* thanks screen */
.thanks { text-align: center; padding: 40px 10px; }
.thanks h2 { font-size: 2rem; margin-bottom: 8px; }
.thanks p { color: var(--ink-soft); max-width: 30em; margin: 0 auto 8px; }

/* ------------------------------------------------------------ flip book */

.book-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0 30px;
}

.book {
  position: relative;
  width: min(94vw, 900px);
  aspect-ratio: 3 / 2;      /* two 3:4 pages side by side */
  perspective: 2400px;
  margin: 0 auto;
}

.sheet {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.4, 0.05, 0.3, 1);
}
.sheet.flipped { transform: rotateY(-180deg); }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--card-paper);
  border: 1px solid rgba(90, 74, 50, 0.18);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.face.back { transform: rotateY(180deg); }
.face.front { border-radius: 0 8px 8px 0; box-shadow: inset 12px 0 24px -14px rgba(90,70,40,0.35); }
.face.back  { border-radius: 8px 0 0 8px; box-shadow: inset -12px 0 24px -14px rgba(90,70,40,0.35); }

.page-inner {
  flex: 1;
  overflow-y: auto;
  padding: clamp(12px, 3vw, 28px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(10px, 2vw, 20px);
}
.page-inner .note-card { flex-shrink: 0; }

.page-num {
  text-align: center;
  font-size: 0.72rem;
  color: var(--ink-soft);
  padding: 4px 0 8px;
}

/* cover face */
.face.cover-face {
  background: linear-gradient(160deg, #8c5a3a, #6e4128);
  color: #fdf6e8;
  justify-content: flex-end;
  border-radius: 4px 10px 10px 4px;
}
.cover-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cover-scrim {
  position: relative;
  background: linear-gradient(transparent, rgba(30, 18, 8, 0.72));
  padding: clamp(40px, 8vw, 80px) clamp(16px, 4vw, 32px) clamp(18px, 3vw, 30px);
  text-align: center;
}
.cover-scrim h1 {
  color: #fdf6e8;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  text-shadow: 0 2px 14px rgba(0,0,0,0.5);
}
.cover-scrim .cover-for {
  font-family: 'Caveat', cursive;
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  opacity: 0.92;
  margin-top: 4px;
}
.cover-hint {
  position: absolute;
  bottom: 8px; left: 0; right: 0;
  text-align: center;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.75;
}

/* blank page-backing (left of cover / after last page) */
.face.blank-face {
  background: var(--paper-deep);
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
}

/* colophon */
.face.colophon-face { align-items: center; justify-content: center; text-align: center; }
.colophon { padding: 20px; color: var(--ink-soft); font-size: 0.9rem; }
.colophon .heart { color: var(--accent); font-size: 1.2rem; }

.book-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 22px;
}
.book-controls .page-indicator { font-size: 0.85rem; color: var(--ink-soft); min-width: 90px; text-align: center; }

.nav-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card-paper);
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .15s ease, background .15s ease;
}
.nav-btn:hover { transform: scale(1.08); background: #fff; }
.nav-btn:disabled { opacity: 0.35; cursor: default; transform: none; }

.view-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

/* ------------------------------------------------- mobile: single page */

@media (max-width: 700px) {
  .book {
    aspect-ratio: 3 / 4;
    width: min(94vw, 420px);
    perspective: none;
  }
  /* slide instead of 3D flip: each sheet's faces become sequential pages */
  .sheet {
    left: 0;
    width: 100%;
    transform-origin: center;
    transition: none;
    transform: none;
  }
  .sheet.flipped { transform: none; }
  .face {
    position: absolute;
    inset: 0;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    transform: none;
    border-radius: 8px;
    transition: transform 0.45s ease, opacity 0.45s ease;
    opacity: 0;
    transform: translateX(60px);
    pointer-events: none;
  }
  .face.back { transform: translateX(60px); }
  .face.mobile-current {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
    z-index: 5;
  }
  .face.mobile-passed { transform: translateX(-60px); }
  .face.cover-face { border-radius: 8px; }
}

/* ------------------------------------------------------------- admin */

.admin-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: rgba(122, 59, 120, 0.07);
  border: 1px solid rgba(122, 59, 120, 0.25);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 18px;
  font-size: 0.9rem;
}
.admin-bar .grow { flex: 1; }

.admin-entries { max-width: 620px; margin: 0 auto; }
.admin-entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.92rem;
}
.admin-entry-row .who { font-weight: 500; }
.admin-entry-row .what {
  flex: 1;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.footer-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  opacity: 0.75;
  margin-top: 40px;
}
.footer-note a { color: inherit; }

/* ================================================================ PRINT
   Flatten the book into sequential paper pages for Download PDF. */

@media print {
  body { background: #fff; }
  .no-print, .book-controls, .view-toolbar, .admin-bar, .masthead, .footer-note,
  .cover-hint, .admin-panel { display: none !important; }

  .shell { max-width: none; padding: 0; }
  .book-stage { padding: 0; display: block; }

  .book {
    width: auto;
    aspect-ratio: auto;
    perspective: none;
  }
  .sheet {
    position: static;
    width: auto;
    height: auto;
    transform: none !important;
    transition: none;
  }
  .face {
    position: static;
    inset: auto;
    transform: none !important;
    opacity: 1 !important;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    box-shadow: none;
    border: none;
    border-radius: 0;
    overflow: visible;
    height: auto;
    min-height: 90vh;
    break-after: page;
    page-break-after: always;
    display: flex;
    pointer-events: auto;
  }
  .face.print-skip { display: none !important; }

  .page-inner { overflow: visible; justify-content: flex-start; padding: 24px; }

  .note-card {
    box-shadow: none;
    border: 1px solid #d8d0c0;
    transform: rotate(var(--tilt, 0deg));
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .face.cover-face {
    min-height: 95vh;
    position: relative;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .cover-photo { position: absolute; }

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
