:root {
  --ink: #1F1A17;
  --muted: #6E655E;
  --line: rgba(31, 26, 23, .12);
  --panel: #FFFFFF;
  --accent: #E8590C;
  --accent-ink: #FFFFFF;
  --danger: #C92A2A;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 8px 24px -10px rgba(40, 30, 20, .18);
  --font-head: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --font-body: "DM Sans", ui-sans-serif, system-ui, -apple-system, sans-serif, var(--font-emoji);
  --font-hand: "Caveat", "Bradley Hand", cursive;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); background: var(--bg, #FBF6EE);
  font: 16px/1.5 var(--font-body); transition: background .3s;
}
h1, h2, h3 { font-family: var(--font-head); line-height: 1.1; margin: 0; letter-spacing: -.01em; }
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 13px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* Board backgrounds */
.bg-cream { --bg: #FBF6EE; }
.bg-blush { --bg: #FBE9E7; }
.bg-lilac { --bg: #EFEAFB; }
.bg-mint { --bg: #E5F3EA; }
.bg-sky { --bg: #E4EFFA; }
.bg-sunshine { --bg: #FFF3D1; }
.bg-night { --bg: #1E1B2E; --ink-board: #F6F1EA; --muted-board: #B9B1C9; }

/* Card colours */
.c-yellow { --card: #F7E3A1; }
.c-lilac { --card: #E1D9F6; }
.c-sage { --card: #DCE8D3; }
.c-blush { --card: #F3DAD5; }
.c-sky { --card: #D5E6F6; }
.c-peach { --card: #FBD8C2; }
.c-white { --card: #FFFFFF; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 10px 18px; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: transform .12s, background .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .6; cursor: progress; transform: none; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.ghost { background: transparent; }
.btn.danger { background: #fff; color: var(--danger); border-color: rgba(201, 42, 42, .35); }
.btn.small { padding: 7px 13px; font-size: 14px; }
.btn.big { padding: 14px 24px; font-size: 17px; width: 100%; }
.btn.copied { background: #2B8A3E; border-color: #2B8A3E; color: #fff; }
.icon-btn {
  border: 0; background: transparent; width: 36px; height: 36px; border-radius: 50%;
  font-size: 16px; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: rgba(0, 0, 0, .06); }
:focus-visible { outline: 3px solid #4D9DE0; outline-offset: 2px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field > span { font-weight: 600; font-size: 14px; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
input:not([type=checkbox]):not([type=file]), textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px;
  background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(31, 26, 23, .08); }
textarea { resize: vertical; min-height: 64px; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; margin: 0 0 10px; }
.toggle { display: flex; gap: 10px; align-items: center; margin: 8px 0; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--ink); }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.swatches.small .swatch { width: 30px; height: 30px; }
.swatch:hover { transform: scale(1.08); }
.swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 1.5px dashed rgba(31, 26, 23, .25); border-radius: 14px; padding: 22px; cursor: pointer;
  background: rgba(255, 255, 255, .6); text-align: center; color: var(--muted); transition: background .15s;
}
.drop:hover { background: #fff; }
.drop.small { padding: 16px; }
.drop img { max-height: 160px; max-width: 100%; border-radius: 10px; }

/* Home */
.home-wrap { max-width: 640px; margin: 0 auto; padding: 48px 16px 80px; }
.hero { text-align: center; margin-bottom: 32px; }
.hero h1 { font-size: clamp(40px, 8vw, 64px); }
.lede { font-size: 18px; color: var(--muted); max-width: 30em; margin: 14px auto 0; }
.hero-notes { display: flex; justify-content: center; gap: 10px; margin-bottom: 26px; flex-wrap: wrap; }
.mini-note {
  background: var(--card); padding: 10px 14px; border-radius: 12px; font-family: var(--font-hand);
  font-size: 21px; box-shadow: var(--shadow);
}
.mini-note:nth-child(1) { transform: rotate(-4deg); }
.mini-note:nth-child(2) { transform: rotate(2deg) translateY(6px); }
.mini-note:nth-child(3) { transform: rotate(-1deg); }
.panel {
  background: var(--panel); border-radius: 24px; padding: 28px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.panel h2 { font-size: 24px; margin-bottom: 18px; }
.link-cards { display: grid; gap: 12px; margin: 18px 0 22px; }
.link-card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px;
}
.link-card.warn { background: #FFF6E5; border-color: #F2D49B; }
.link-icon { font-size: 24px; }
.link-main { display: flex; flex-direction: column; min-width: 0; }
.link-main span { font-size: 14px; }
.link-main code {
  font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px;
}
.mine { list-style: none; padding: 0; margin: 0; }
.mine li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.mine li:first-child { border-top: 0; }
.mine a { font-weight: 600; text-decoration: none; }
.mine a:hover { text-decoration: underline; }

/* Board page */
.admin-bar {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  flex-wrap: wrap; padding: 10px 16px; background: rgba(255, 255, 255, .88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.admin-tag { font-weight: 700; font-size: 14px; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.board-head { max-width: 900px; margin: 0 auto; padding: 40px 16px 24px; text-align: center; }
.mode-view .board-head { padding-top: 56px; }
.cover { margin: 0 auto 26px; max-width: 760px; }
.cover img {
  width: 100%; max-height: 340px; object-fit: cover; border-radius: 24px; display: block; box-shadow: var(--shadow);
}
.board-head h1 { font-size: clamp(32px, 6vw, 56px); color: var(--ink-board, var(--ink)); overflow-wrap: anywhere; }
.board-desc { font-size: 19px; color: var(--muted-board, var(--muted)); margin: 12px auto 0; max-width: 36em; white-space: pre-line; }
.closed-note {
  display: inline-block; margin-top: 16px; padding: 6px 14px; border-radius: 999px;
  background: rgba(0, 0, 0, .06); font-size: 14px; color: var(--muted-board, var(--muted));
}

main { padding: 8px 16px 140px; }
.masonry { columns: 4 250px; column-gap: 18px; max-width: 1280px; margin: 0 auto; }
.card {
  position: relative; break-inside: avoid; margin: 0 0 18px; background: var(--card, #F7E3A1);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  animation: pop .45s cubic-bezier(.2, .9, .3, 1.3) both;
  transition: transform .2s, opacity .2s;
}
.masonry .card:nth-child(4n+1) { transform: rotate(-.6deg); }
.masonry .card:nth-child(4n+3) { transform: rotate(.5deg); }
.masonry .card:hover { transform: rotate(0) translateY(-2px); }
.card.leaving { opacity: 0; transform: scale(.92); }
.card.arrive { animation: arrive .7s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes arrive { 0% { opacity: 0; transform: scale(.6) rotate(-6deg); } 100% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .card, .card.arrive { animation: none; } }

.card-media { background: rgba(0, 0, 0, .04); }
.card-media img, .card-media video { display: block; width: 100%; height: auto; max-height: 520px; object-fit: cover; }
.card-body { padding: 18px 20px 16px; }
.card-msg { margin: 0 0 10px; font-size: 17px; letter-spacing: normal; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-msg.big { font-family: var(--font-head); font-size: 24px; font-weight: 500; line-height: 1.2; }
.card-name { margin: 0; font-family: var(--font-hand); font-size: 24px; color: rgba(31, 26, 23, .72); line-height: 1.1; }
.card-del {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, .9); cursor: pointer; font-size: 13px; opacity: 0; transition: opacity .15s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
}
.card:hover .card-del, .card-del:focus-visible { opacity: 1; }
@media (hover: none) { .card-del { opacity: 1; } }

.empty { text-align: center; padding: 40px 16px; color: var(--muted-board, var(--muted)); }
.empty-emoji { font-size: 44px; margin-bottom: 8px; }

.fab {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 15;
  border: 0; background: var(--ink); color: #fff; border-radius: 999px; padding: 16px 26px;
  font-weight: 700; font-size: 17px; cursor: pointer; box-shadow: 0 12px 30px -8px rgba(0, 0, 0, .45);
  transition: transform .15s; white-space: nowrap;
}
.bg-night .fab { background: #F7E3A1; color: var(--ink); }
.fab:hover { transform: translateX(-50%) translateY(-2px) scale(1.02); }
.fab span { font-size: 20px; margin-right: 4px; }
.confetti-btn {
  position: fixed; bottom: 20px; right: 20px; width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: #fff; font-size: 24px; cursor: pointer; box-shadow: var(--shadow); z-index: 15;
}
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; display: none; }
#confetti.on { display: block; }

/* Dialogs */
dialog.composer {
  border: 0; padding: 0; border-radius: 24px; width: min(980px, calc(100vw - 24px));
  max-height: calc(100vh - 24px); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45); color: var(--ink);
}
dialog.composer.narrow { width: min(520px, calc(100vw - 24px)); padding: 24px; }
dialog::backdrop { background: rgba(25, 20, 30, .45); backdrop-filter: blur(3px); }
.composer-grid { display: grid; grid-template-columns: 1.15fr 1fr; min-height: 0; }
.composer-edit { padding: 24px; overflow: auto; max-height: calc(100vh - 24px); }
.composer-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.composer-top h2 { font-size: 24px; }
.composer-preview {
  background: var(--bg, #FBF6EE); padding: 24px; display: flex; flex-direction: column; gap: 14px;
  align-self: stretch;
}
.bg-night .composer-preview { background: #2A2640; }
.preview-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--muted-board, var(--muted)); }
#preview .card { margin: 0; animation: none; }
.emoji-bar { display: flex; flex-wrap: wrap; gap: 2px; margin: -8px 0 18px; }
.emoji-bar button {
  border: 0; background: transparent; font-size: 20px; width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
}
.emoji-bar button:hover { background: rgba(0, 0, 0, .06); transform: scale(1.12); }
.tabs { display: inline-flex; background: #F2EEE8; border-radius: 999px; padding: 4px; gap: 2px; align-self: flex-start; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.tab-pane { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.gif-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; max-height: 220px; overflow: auto; margin-top: 8px; }
.gif-grid img { width: 100%; height: 80px; object-fit: cover; border-radius: 8px; cursor: pointer; outline: 3px solid transparent; }
.gif-grid img.on { outline-color: var(--ink); }
.upload-progress { height: 6px; border-radius: 3px; background: rgba(0, 0, 0, .08); overflow: hidden; }
.upload-progress div { height: 100%; width: 0; background: var(--ink); transition: width .15s; }
hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0 16px; }
dialog h3 { font-size: 16px; margin-bottom: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); opacity: 0; z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600;
  transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .composer-grid { grid-template-columns: 1fr; }
  .composer-preview { position: static; order: 2; max-height: none; }
  .composer-edit { max-height: none; overflow: visible; }
  dialog.composer { overflow: auto; }
  .panel { padding: 22px 18px; }
  .link-card { grid-template-columns: auto 1fr; }
  .link-card .btn { grid-column: 1 / -1; }
  .admin-bar { position: static; }
  .masonry { column-gap: 12px; }
  .card { margin-bottom: 12px; }
}
@media (max-width: 420px) {
  .masonry { columns: 1; }
}
