:root {
  --cork: #7C5A3B;
  --cork-dark: #5E4429;
  --cork-light: #8F6B48;
  --paper: #F1ECDD;
  --paper-alt: #E8E0CB;
  --ink: #2B2620;
  --ink-soft: #6B6252;
  --teal: #2F7B78;
  --red: #B8432F;
  --tape: #E3B94A;
}

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

html, body {
  background: var(--paper-alt);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  min-height: 100%;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--ink);
  border-bottom: 3px solid var(--tape);
}
.logo {
  font-family: 'Permanent Marker', cursive;
  font-size: 26px; font-weight: 400;
  color: var(--paper);
  letter-spacing: 0.5px;
  display: flex; align-items: center;
}
.logo img { height: 40px; width: auto; display: block; border-radius: 8px; }
.sort-tabs { display: flex; gap: 4px; }
.sort-tabs button {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 4px;
  font-size: 13px; font-weight: 500;
  color: var(--paper);
}
.sort-tabs button.active { background: var(--tape); color: var(--ink); }

.searchbox { flex: 1; max-width: 420px; }
.searchbox input, .mobile-search input {
  width: 100%; padding: 9px 12px; border-radius: 4px;
  border: none; background: #3B342A; color: var(--paper);
  outline: none;
}
.searchbox input::placeholder, .mobile-search input::placeholder { color: var(--ink-soft); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.create-btn {
  padding: 8px 14px; border-radius: 4px;
  background: var(--tape); color: var(--ink);
  font-size: 13px; font-weight: 600;
}
.icon-btn { font-size: 18px; padding: 6px; color: var(--paper); }
.avatar-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--paper); color: var(--ink);
  font-weight: 700; font-size: 14px;
  overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

.mobile-search { padding: 8px 12px; background: var(--cork-dark); }
.mobile-sorts {
  padding: 8px 12px; background: var(--cork-dark);
  overflow-x: auto;
}
.mobile-sorts button { background: rgba(241,236,221,0.12); border-radius: 999px; flex-shrink: 0; }
.mobile-sorts button.active { background: var(--tape); color: var(--ink); }

/* ---------- layout ---------- */
.layout { display: flex; }

.sidebar {
  width: 230px; flex-shrink: 0;
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
  min-height: calc(100vh - 60px);
  background:
    radial-gradient(circle at 20% 20%, var(--cork-light) 0, transparent 45%),
    radial-gradient(circle at 80% 60%, var(--cork-light) 0, transparent 40%),
    var(--cork);
}
.sidebar .all-btn, .sidebar .newboard-btn {
  text-align: left; padding: 10px 12px; border-radius: 4px;
  font-size: 14px; font-weight: 600;
  background: rgba(241,236,221,0.18); color: var(--paper);
}
.sidebar .all-btn.active { background: var(--paper); color: var(--ink); }
.board-card {
  position: relative; text-align: left; width: 100%;
  padding: 12px; border-radius: 3px;
  background: var(--paper);
  box-shadow: 0 3px 6px rgba(0,0,0,0.25);
  transition: transform 0.15s ease;
}
.board-card .pinhead {
  position: absolute; top: -7px; left: 50%; transform: translateX(-50%);
  width: 12px; height: 12px; border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.board-card .b-name { font-weight: 600; font-size: 14px; }
.board-card .b-tag { font-family: 'Kalam', cursive; font-size: 12px; color: var(--ink-soft); }
.board-card.active { transform: rotate(0deg) !important; }
.board-card .manage-btn {
  position: absolute; top: 6px; right: 6px;
  font-size: 13px; padding: 2px;
}

.feed-area { flex: 1; padding: 16px; padding-bottom: 90px; }

/* ---------- feed ---------- */
.feed-grid {
  display: grid; gap: 22px;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) { .feed-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .feed-grid { grid-template-columns: 1fr 1fr 1fr; } }

.post-card {
  background: var(--paper);
  border-radius: 3px; overflow: hidden;
  border: 1px solid var(--paper-alt);
  box-shadow: 0 3px 8px rgba(43,38,32,0.28), 0 1px 2px rgba(43,38,32,0.2);
  transition: transform 0.15s ease;
  cursor: pointer;
}
.post-card:hover { transform: rotate(0deg) scale(1.02) !important; }
.post-media { position: relative; aspect-ratio: 4/3; background: var(--paper-alt); }
.post-media img, .post-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-badge {
  position: absolute; top: 8px; right: 8px;
  padding: 3px 7px; border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 700;
  background: rgba(43,38,32,0.75); color: var(--paper);
}
.post-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.board-chip {
  align-self: flex-start;
  padding: 3px 8px; border-radius: 3px;
  font-size: 12px; font-weight: 600; color: var(--paper);
}
.post-title { font-size: 16px; font-weight: 600; line-height: 1.35; }
.post-meta-row { display: flex; align-items: center; justify-content: space-between; }
.vote-group { display: flex; align-items: center; gap: 7px; }
.pin-btn {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  border: 1.5px solid;
  transition: transform 0.1s ease;
}
.pin-btn.up { border-color: var(--teal); color: var(--teal); }
.pin-btn.down { border-color: var(--red); color: var(--red); }
.pin-btn.up.active { background: var(--teal); color: var(--paper); }
.pin-btn.down.active { background: var(--red); color: var(--paper); }
.pin-btn.up span { display: inline-block; transform: rotate(-45deg); }
.pin-btn.down span { display: inline-block; transform: rotate(135deg); }
.score { font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 600; color: var(--ink-soft); min-width: 28px; text-align: center; }
.comment-count { color: var(--ink-soft); font-size: 13px; font-weight: 500; }

/* ---------- recently viewed ---------- */
#recentRail:not(:empty) { margin-bottom: 20px; }
.rail-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.rail-scroll { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.rail-card {
  flex-shrink: 0; width: 150px; text-align: left;
  background: var(--paper); border-radius: 3px; overflow: hidden;
  box-shadow: 0 2px 6px rgba(43,38,32,0.25);
}
.rail-card .post-media { aspect-ratio: 4/3; }
.rail-card .rail-board { font-size: 11px; font-weight: 700; padding: 6px 8px 0; }
.rail-card .rail-name {
  font-size: 12.5px; padding: 2px 8px 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------- empty / loading ---------- */
.empty-state { text-align: center; padding: 80px 20px; }
.empty-title { font-family: 'Permanent Marker', cursive; font-size: 19px; }
.empty-sub { margin-top: 6px; font-size: 13.5px; color: var(--ink-soft); }

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-around;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: var(--ink);
  border-top: 2px solid var(--tape);
}
.bottom-nav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--paper); font-size: 17px;
}
.bottom-nav button span { font-size: 10.5px; }
.bottom-nav .nav-create {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--tape); color: var(--ink);
  font-size: 24px; margin-top: -18px;
  justify-content: center;
}

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,17,13,0.62);
  display: flex; align-items: flex-end; justify-content: center;
  overflow-y: auto;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  width: 100%; max-width: 560px;
  background: var(--paper);
  border-radius: 12px 12px 0 0;
  max-height: 92vh; overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 24px; }
  .modal-box { border-radius: 8px; }
}
.modal-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--ink); color: var(--paper);
}
.modal-head .m-title { font-family: 'Permanent Marker', cursive; font-size: 16px; }
.modal-head .close-x { font-size: 20px; color: var(--paper); padding: 4px; }
.modal-content { padding: 18px; display: flex; flex-direction: column; gap: 12px; }

.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border-radius: 4px;
  border: 1px solid var(--paper-alt); background: var(--paper-alt);
  color: var(--ink); outline: none;
}
.primary-btn {
  padding: 11px; border-radius: 4px;
  background: var(--ink); color: var(--paper);
  font-size: 14px; font-weight: 600;
}
.secondary-btn {
  padding: 11px; border-radius: 4px;
  background: var(--paper-alt); color: var(--ink);
  font-size: 14px; font-weight: 600;
}
.danger-btn {
  padding: 8px 12px; border-radius: 4px;
  background: var(--red); color: var(--paper);
  font-size: 13px; font-weight: 600;
}
.tab-row { display: flex; gap: 8px; }
.tab-row button { flex: 1; padding: 9px; border-radius: 4px; font-size: 13px; font-weight: 600; background: var(--paper-alt); }
.tab-row button.active { background: var(--tape); }
.error-text { color: var(--red); font-size: 13.5px; }
.hint-text { color: var(--ink-soft); font-size: 12.5px; }

.color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-dot { width: 28px; height: 28px; border-radius: 50%; }
.color-dot.active { box-shadow: 0 0 0 2px var(--ink); }

.upload-preview { border-radius: 4px; overflow: hidden; aspect-ratio: 4/3; background: var(--paper-alt); }
.upload-preview img, .upload-preview video { width: 100%; height: 100%; object-fit: cover; display: block; }

/* post detail */
.detail-media { aspect-ratio: 4/3; background: var(--paper-alt); }
.detail-media img, .detail-media video { width: 100%; height: 100%; object-fit: contain; background: #1d1a15; display: block; }
.detail-title { font-size: 19px; font-weight: 700; }
.detail-author { font-family: 'Kalam', cursive; font-size: 14px; color: var(--ink-soft); }
.divider { height: 1px; background: var(--paper-alt); margin: 6px 0; }
.comment { display: flex; gap: 10px; }
.comment-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--paper-alt); color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; overflow: hidden;
}
.comment-avatar img { width: 100%; height: 100%; object-fit: cover; }
.comment-author { font-family: 'Kalam', cursive; font-weight: 700; font-size: 14.5px; }
.comment-time { font-size: 11.5px; color: var(--ink-soft); margin-left: 6px; }
.comment-text { font-size: 15px; }
.comment-form { display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--paper); padding-top: 8px; }
.comment-form input { flex: 1; padding: 10px 12px; border-radius: 4px; border: 1px solid var(--paper-alt); background: var(--paper-alt); outline: none; }
.comment-actions { display: flex; gap: 12px; margin-top: 4px; }
.comment-actions button { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.comment-actions button:hover { color: var(--ink); }
.reply-slot:not(:empty) { margin-top: 8px; margin-bottom: 4px; }

.note-media {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    repeating-linear-gradient(var(--paper-alt) 0 1px, transparent 1px 28px),
    var(--paper);
}
.note-text {
  font-family: 'Kalam', cursive;
  font-size: 22px; line-height: 1.5; text-align: center;
  color: var(--ink); max-width: 90%;
}

.ban-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-radius: 4px; background: var(--paper-alt);
}
.profile-header { display: flex; align-items: center; gap: 12px; }
.big-avatar {
  width: 64px; height: 64px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--paper-alt); color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px;
}
.big-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* boards sheet list */
.sheet-board-list { display: flex; flex-direction: column; gap: 10px; }
.sheet-board-list .board-card { transform: none !important; }

/* toast */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  z-index: 60;
  padding: 10px 18px; border-radius: 6px;
  background: var(--ink); color: var(--paper);
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

/* responsive visibility */
.mobile-only { display: none; }
@media (max-width: 899px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex; }
  .mobile-search[hidden] { display: none; }
}
@media (min-width: 900px) {
  .feed-area { padding: 24px; padding-bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
