:root {
  --bg: #fffdf7;
  --ink: #23211d;
  --ink-soft: #6b665c;
  --line: #ebe6da;
  --accent: #ff6b6b;
  --accent-ink: #fff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 50, 30, .08), 0 6px 18px rgba(60, 50, 30, .08);
  --shadow-lift: 0 2px 4px rgba(60, 50, 30, .1), 0 14px 30px rgba(60, 50, 30, .14);

  --note-yellow: #fff1a8;
  --note-pink: #ffd6e0;
  --note-blue: #d2e9ff;
  --note-green: #d6f3d1;
  --note-purple: #e6dcff;
  --note-orange: #ffdcbc;

  /* ALTCHA widget theme */
  --altcha-color-base: #fff;
  --altcha-color-border: var(--line);
  --altcha-color-text: var(--ink);
  --altcha-border-radius: 10px;
  --altcha-max-width: 100%;

  color-scheme: light;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 1px 1px, rgba(60, 50, 30, .07) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255, 253, 247, .86);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.top__inner {
  max-width: 1200px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand__mark { width: 38px; height: 38px; flex: none; }
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__name { font-size: 1.35rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.brand__tagline { font-size: .85rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 10px 18px;
  font-weight: 650; font-size: .95rem; cursor: pointer; white-space: nowrap;
  transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease, opacity .12s ease;
}
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--ink); color: #fff; box-shadow: 0 2px 8px rgba(35, 33, 29, .18); }
.btn--primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(35, 33, 29, .22); }
.btn--ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn--ghost:hover { background: rgba(35, 33, 29, .04); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .swatch input:focus-visible + span, .link:focus-visible {
  outline: 3px solid #8fb8ff; outline-offset: 2px;
}
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer; color: var(--ink-soft);
}
.icon-btn:hover { background: rgba(35, 33, 29, .06); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.link { border: 0; background: none; padding: 0; text-decoration: underline; cursor: pointer; font-weight: 600; }

/* Wall */
.main { max-width: 1200px; margin: 0 auto; padding: 28px 20px 64px; }
.wall {
  display: grid; gap: 26px 22px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  align-items: start;
}
.note {
  --tilt: 0deg;
  position: relative;
  display: flex; flex-direction: column; gap: 14px;
  min-height: 170px; padding: 26px 18px 14px;
  background: var(--note-yellow);
  border-radius: 4px 4px 14px 4px;
  box-shadow: var(--shadow);
  transform: rotate(var(--tilt));
  transition: transform .18s ease, box-shadow .18s ease;
  animation: pop .28s ease-out both;
}
.note::before {
  /* the pin */
  content: ""; position: absolute; top: 8px; left: 50%;
  width: 12px; height: 12px; margin-left: -6px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, .7) 0 18%, transparent 20%), var(--accent);
  box-shadow: 0 2px 3px rgba(0, 0, 0, .2);
}
.note:hover { transform: rotate(0deg) translateY(-2px); box-shadow: var(--shadow-lift); }
.note--yellow { background: var(--note-yellow); }
.note--pink { background: var(--note-pink); }
.note--blue { background: var(--note-blue); }
.note--green { background: var(--note-green); }
.note--purple { background: var(--note-purple); }
.note--orange { background: var(--note-orange); }
.note__msg {
  margin: 0; flex: 1;
  font-size: 1.02rem; line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.note__meta {
  display: flex; align-items: center; gap: 8px;
  font-size: .8rem; color: rgba(35, 33, 29, .62);
}
.note__author { font-weight: 650; color: rgba(35, 33, 29, .78); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note__time { margin-left: auto; white-space: nowrap; }
.note__delete {
  display: grid; place-items: center; width: 28px; height: 28px; margin: -4px -6px -4px 0;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer; color: rgba(35, 33, 29, .5);
}
.note__delete:hover { background: rgba(35, 33, 29, .08); color: #b3261e; }
.note__delete svg { width: 15px; height: 15px; }
.note--leaving { animation: leave .22s ease-in forwards; }

@keyframes pop { from { opacity: 0; transform: rotate(var(--tilt)) scale(.94); } }
@keyframes leave { to { opacity: 0; transform: rotate(var(--tilt)) scale(.9); } }

/* Empty, loading, errors */
.empty { text-align: center; padding: 72px 20px; color: var(--ink-soft); }
.empty h2 { margin: 18px 0 4px; color: var(--ink); font-size: 1.3rem; }
.empty p { margin: 0 0 22px; }
.empty__note {
  width: 96px; height: 96px; margin: 0 auto; border-radius: 4px 4px 14px 4px;
  background: var(--note-yellow); box-shadow: var(--shadow); transform: rotate(-4deg);
}
.load-error { text-align: center; color: var(--ink-soft); }
.sentinel { height: 1px; }
.more { display: flex; justify-content: center; padding-top: 28px; min-height: 40px; }
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid rgba(35, 33, 29, .15); border-top-color: var(--ink);
  animation: spin .7s linear infinite;
}
.spinner--small { width: 16px; height: 16px; border-width: 2px; border-color: rgba(255, 255, 255, .35); border-top-color: #fff; display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Composer */
.composer {
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 20px;
  background: #fff; color: var(--ink);
  box-shadow: 0 24px 60px rgba(35, 33, 29, .28);
}
.composer::backdrop { background: rgba(35, 33, 29, .35); backdrop-filter: blur(2px); }
.composer[open] { animation: rise .2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.composer__form { display: flex; flex-direction: column; gap: 18px; padding: 20px 22px 22px; }
.composer__head { display: flex; align-items: center; justify-content: space-between; }
.composer__head h2 { margin: 0; font-size: 1.2rem; }
.composer__paper {
  position: relative; border-radius: 4px 4px 14px 4px; padding: 14px 14px 30px;
  background: var(--note-yellow); box-shadow: var(--shadow); transition: background-color .15s ease;
}
.composer__paper[data-color="pink"] { background: var(--note-pink); }
.composer__paper[data-color="blue"] { background: var(--note-blue); }
.composer__paper[data-color="green"] { background: var(--note-green); }
.composer__paper[data-color="purple"] { background: var(--note-purple); }
.composer__paper[data-color="orange"] { background: var(--note-orange); }
.composer__paper textarea {
  display: block; width: 100%; min-height: 130px; resize: vertical;
  border: 0; background: transparent; outline: none;
  font-size: 1.05rem; line-height: 1.45;
}
.composer__paper textarea::placeholder { color: rgba(35, 33, 29, .45); }
.composer__count { position: absolute; right: 14px; bottom: 8px; font-size: .8rem; color: rgba(35, 33, 29, .55); font-variant-numeric: tabular-nums; }
.composer__count .over { color: #b3261e; font-weight: 700; }
.composer__actions { display: flex; justify-content: flex-end; gap: 10px; }
.composer__actions .btn { min-width: 96px; }
#publish.is-busy .spinner--small { display: inline-block; }
#publish.is-busy { cursor: progress; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: .85rem; font-weight: 650; padding: 0; }
.field__hint { font-weight: 450; color: var(--ink-soft); }
.field input {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field input:focus { outline: none; border-color: #8fb8ff; box-shadow: 0 0 0 3px rgba(143, 184, 255, .3); }

.colors { border: 0; margin: 0; padding: 0; }
.colors__list { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.swatch { position: relative; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch span {
  display: block; width: 34px; height: 34px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(35, 33, 29, .12);
  transition: transform .12s ease, box-shadow .12s ease;
}
.swatch:hover span { transform: scale(1.08); }
.swatch input:checked + span { box-shadow: inset 0 0 0 1px rgba(35, 33, 29, .12), 0 0 0 3px #fff, 0 0 0 5px var(--ink); }

.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* Toasts */
.toasts {
  position: fixed; left: 50%; bottom: 20px; z-index: 100; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  pointer-events: auto; padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: #fff; font-size: .92rem; box-shadow: var(--shadow-lift);
  animation: rise .2s ease-out;
}
.toast--error { background: #b3261e; }
.toast--out { opacity: 0; transition: opacity .3s ease; }

@media (max-width: 560px) {
  .top__inner { padding: 12px 16px; }
  .brand__mark { width: 32px; height: 32px; }
  .brand__tagline { font-size: .78rem; }
  .top .btn { padding: 9px 14px; }
  .main { padding: 20px 14px 48px; }
  .wall { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; }
  .note { min-height: 140px; padding: 24px 14px 12px; }
  .note__msg { font-size: .95rem; }
  .composer { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 92dvh; }
}
@media (max-width: 380px) {
  .brand__tagline { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
