:root {
  --ink: var(--text-1);
  --muted: var(--text-2);
  --accent: var(--accent-primary);
  --accent-ink: var(--text-on-accent);
  --cork: #b9824e;
  --cork-edge: #704928;
  --note-ink: #292419;
  --font-body: var(--font-ui);
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.45;
  background: var(--surface-0);
}

.banner {
  position: fixed;
  top: 56px;
  left: 50%;
  z-index: 30;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 2rem));
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-1);
  color: var(--text-1);
  font-size: 0.88rem;
  box-shadow: var(--shadow-modal);
}

.banner a {
  color: var(--accent-primary);
}

.board-chrome {
  position: fixed;
  top: 12px;
  left: 108px;
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  pointer-events: none;
}

.board-chrome > * {
  pointer-events: auto;
}

.brand {
  margin: 0;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface-1);
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text-1);
  box-shadow: var(--shadow-card);
}

.board {
  position: fixed;
  inset: 0;
  overflow: auto;
  cursor: cell;
  background-color: var(--cork);
  background-image: radial-gradient(
      circle at 15% 20%,
      rgba(85, 46, 20, 0.16) 0 1px,
      transparent 2px
    ),
    radial-gradient(circle at 75% 60%, rgba(255, 232, 188, 0.13) 0 1px, transparent 2px),
    linear-gradient(105deg, transparent 48%, rgba(87, 47, 22, 0.05) 50%, transparent 52%);
  background-size: 29px 31px, 37px 41px, 11px 100%;
  box-shadow: inset 0 0 60px rgba(72, 39, 15, 0.35);
}

.board-surface {
  position: relative;
  width: 100%;
  min-width: 100%;
  min-height: 100%;
}

.empty {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0;
  transform: translate(-50%, -50%);
  padding: 0.75rem 1rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-2);
  font-size: 0.95rem;
  pointer-events: none;
  box-shadow: var(--shadow-card);
}

.add-note {
  position: fixed;
  left: 22px;
  bottom: 22px;
  right: auto;
  z-index: 25;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  aspect-ratio: 1;
  background: #fff3a6;
  color: #292419;
  box-shadow: 0 2px 2px rgba(44, 24, 8, 0.2), 0 14px 28px rgba(44, 24, 8, 0.35);
  cursor: pointer;
  font: 500 32px/1 var(--font-body);
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.add-note:hover,
.add-note:focus-visible {
  transform: scale(1.06);
  outline: 2px solid var(--focus-ring-inner);
  outline-offset: 2px;
  box-shadow: 0 3px 3px rgba(44, 24, 8, 0.22), 0 18px 34px rgba(44, 24, 8, 0.4);
}

.board-status {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 24;
  transform: translateX(-50%);
  min-height: 0;
  margin: 0;
  max-width: min(420px, calc(100vw - 10rem));
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-1);
  font-size: 0.88rem;
  text-align: center;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.board-status.is-visible {
  opacity: 1;
}

.board-status.error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.btn {
  appearance: none;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-1);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
}

.btn:focus-visible {
  outline: 2px solid var(--focus-ring-inner);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent-primary-bg);
  color: var(--text-on-accent);
  border-color: transparent;
  font-weight: 650;
}

.btn.ghost {
  background: var(--surface-1);
}

.btn.sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
}

.honeypot {
  position: absolute !important;
  left: -10000px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.post {
  position: absolute;
  width: clamp(230px, 28vw, 310px);
  max-height: min(480px, calc(100vh - 40px));
  padding: 1.25rem 1.1rem 1rem;
  overflow: auto;
  border: 0;
  border-radius: 2px;
  background: var(--note-color, #fff3a6);
  color: var(--note-ink);
  box-shadow: 0 2px 2px rgba(44, 24, 8, 0.18), 0 10px 20px rgba(44, 24, 8, 0.22);
  cursor: grab;
  touch-action: none;
  transform: translate(var(--tx), var(--ty)) rotate(var(--rotation));
  transform-origin: center;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.post::before {
  content: '';
  position: absolute;
  top: 7px;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c85142;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), inset 0 1px rgba(255, 255, 255, 0.45);
  transform: translateX(-50%);
}

.post:hover,
.post:focus-within {
  z-index: 10;
  box-shadow: 0 3px 3px rgba(44, 24, 8, 0.2), 0 16px 28px rgba(44, 24, 8, 0.3);
  transform: translate(var(--tx), var(--ty)) rotate(var(--rotation)) scale(1.015);
}

.post:focus-visible {
  z-index: 10;
  outline: 2px solid var(--focus-ring-inner);
  outline-offset: 3px;
  box-shadow: 0 0 0 5px var(--focus-ring-outer), 0 16px 28px rgba(44, 24, 8, 0.3);
}

.post.dragging,
.post.dragging:hover,
.post.dragging:focus-within {
  z-index: 50;
  cursor: grabbing;
  user-select: none;
  transition: none;
  transform: translate(var(--tx), var(--ty)) rotate(var(--rotation)) scale(1.025);
  box-shadow: 0 5px 6px rgba(44, 24, 8, 0.2), 0 22px 38px rgba(44, 24, 8, 0.38);
}

.post button,
.post a,
.post input,
.post textarea,
.post audio,
.post video {
  touch-action: auto;
}

.post.draft {
  z-index: 12;
  outline: 2px solid rgba(41, 36, 25, 0.28);
  outline-offset: -4px;
  max-height: none;
}

.post.draft.drop-target {
  outline: 2px solid var(--accent-primary);
  outline-offset: -3px;
  box-shadow: 0 0 0 4px var(--focus-ring-outer), 0 16px 28px rgba(44, 24, 8, 0.3);
}

.board.drop-target::after {
  content: 'Drop to start a note';
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 22;
  transform: translate(-50%, -50%);
  padding: 0.7rem 1rem;
  border: 1px dashed var(--accent-primary);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-1);
  box-shadow: var(--shadow-card);
  pointer-events: none;
  font-size: 0.95rem;
}

.board.drop-target {
  outline: 3px dashed var(--accent-primary);
  outline-offset: -8px;
}

.post.pending {
  outline: 2px dashed rgba(41, 36, 25, 0.42);
  outline-offset: -5px;
  opacity: 0.85;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  margin-bottom: 0.55rem;
  padding-right: 1.4rem;
  color: rgba(41, 36, 25, 0.62);
  font-size: 0.8rem;
}

.post-remove,
.post-discard {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(41, 36, 25, 0.54);
  cursor: pointer;
  font: 700 20px/1 var(--font-body);
}

.post-remove:hover,
.post-remove:focus-visible,
.post-discard:hover,
.post-discard:focus-visible {
  background: rgba(41, 36, 25, 0.1);
  color: #8b1e1e;
  outline: 2px solid rgba(139, 30, 30, 0.24);
}

.post-body {
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

.post-body > *:first-child {
  margin-top: 0;
}

.post-body > *:last-child {
  margin-bottom: 0;
}

.post-body pre,
.post-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.post-body pre {
  overflow-x: auto;
  padding: 0.65rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.32);
  border: 1px solid rgba(41, 36, 25, 0.14);
}

.post-body a {
  color: #315b86;
}

.post-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.post-attachment-btn {
  display: block;
  width: 100%;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(41, 36, 25, 0.16);
  background: rgba(255, 255, 255, 0.2);
  cursor: zoom-in;
}

.post-attachment-btn:hover,
.post-attachment-btn:focus-visible {
  border-color: rgba(41, 36, 25, 0.4);
  outline: 2px solid var(--focus-ring-inner);
  outline-offset: 2px;
}

.post-attachments img {
  display: block;
  width: 100%;
  height: auto;
}

.post-attachments audio {
  width: 100%;
  grid-column: 1 / -1;
}

.note-editor {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.note-editor textarea,
.note-editor input[type='text'] {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(41, 36, 25, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.35);
  color: var(--note-ink);
  font: inherit;
  resize: vertical;
}

.note-editor textarea {
  min-height: 110px;
}

.note-editor textarea:focus,
.note-editor input:focus {
  outline: 2px solid var(--focus-ring-inner);
  outline-offset: 1px;
}

.note-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.note-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(41, 36, 25, 0.16);
  background: rgba(255, 255, 255, 0.25);
}

.note-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.note-thumb.audio {
  width: 100%;
  height: auto;
  min-height: 44px;
  padding: 6px 28px 6px 6px;
}

.note-thumb audio {
  display: block;
  width: 100%;
}

.note-thumb button {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}

.note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.note-actions .file-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.6rem;
  border: 1px dashed rgba(41, 36, 25, 0.35);
  border-radius: 6px;
  color: rgba(41, 36, 25, 0.82);
  cursor: pointer;
  font-size: 0.82rem;
  background: rgba(255, 255, 255, 0.2);
}

.note-actions .btn.primary {
  margin-left: auto;
}

.lightbox {
  max-width: min(960px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  margin: auto;
  padding: 0.75rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-1);
  color: var(--text-1);
  box-shadow: var(--shadow-modal);
}

.lightbox::backdrop {
  background: var(--scrim-strong);
}

.lightbox-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.lightbox img {
  display: block;
  width: min(900px, calc(100vw - 3.5rem));
  max-width: 100%;
  max-height: calc(100vh - 6rem);
  margin: 0 auto;
  border-radius: 8px;
  object-fit: contain;
}

.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;
}

@media (max-width: 640px) {
  .board-chrome {
    left: 96px;
    top: 10px;
  }

  .add-note {
    left: 16px;
    right: auto;
    bottom: 16px;
    width: 54px;
    height: 54px;
  }

  .post {
    width: min(270px, calc(100vw - 28px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .add-note,
  .board-status,
  .post,
  .btn {
    transition: none;
  }

  .add-note:hover,
  .add-note:focus-visible {
    transform: none;
  }

  .post:hover,
  .post:focus-within,
  .post.dragging,
  .post.dragging:hover,
  .post.dragging:focus-within {
    transform: translate(var(--tx, 0), var(--ty, 0)) rotate(var(--rotation, 0deg));
  }
}

@media (prefers-contrast: more) {
  .brand,
  .banner,
  .btn,
  .board-status,
  .post {
    border-width: 2px;
  }
}

@media (forced-colors: active) {
  .brand,
  .banner,
  .btn,
  .board-status,
  .post,
  .lightbox {
    border: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
    forced-color-adjust: none;
  }

  .post::before {
    background: Highlight;
  }
}
