:root {
  --paper: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe8da;
  --ink: #2a2420;
  --ink-2: #6d6257;
  --ink-3: #897d70;
  --line: #e2d9c8;
  --accent: #a94b24;
  --accent-ink: #fffaf3;
  --accent-soft: #f3dfd1;
  --moss: #4f6b4a;
  --moss-soft: #dfe7d6;
  --amber: #8a6512;
  --amber-soft: #f3e7c5;
  --rose: #8b3a3a;
  --rose-soft: #f0dcd8;
  --star: #c9861a;
  --shadow: 0 1px 2px rgb(60 45 30 / 8%), 0 4px 16px rgb(60 45 30 / 6%);
  --shadow-lg: 0 8px 40px rgb(40 30 20 / 25%);
  --radius: 14px;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1e1a17;
    --surface: #2a2521;
    --surface-2: #38322c;
    --ink: #f1e9dd;
    --ink-2: #b9ad9e;
    --ink-3: #a09384;
    --line: #443c34;
    --accent: #e08a5e;
    --accent-ink: #231a14;
    --accent-soft: #4a3226;
    --moss: #a9c4a0;
    --moss-soft: #333f2f;
    --amber: #e3c477;
    --amber-soft: #463a1d;
    --rose: #e3a6a0;
    --rose-soft: #4a2c2a;
    --star: #e8b04a;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 22%);
    --shadow-lg: 0 8px 40px rgb(0 0 0 / 55%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 0;
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 12px; max-width: 1400px; margin: 0 auto; }
.brand { font: 600 22px/1 var(--serif); letter-spacing: .04em; white-space: nowrap; }
.search { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 12px; color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%; height: 42px; padding: 0 12px 0 40px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 21px; outline-offset: 0;
}
.search input::placeholder { color: var(--ink-3); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; flex: none; padding: 0;
  background: none; border: 0; border-radius: 50%; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }
.btn.desktop-add { display: none; }

.chips {
  display: flex; gap: 8px; max-width: 1400px; margin: 0 auto; padding: 10px 0;
  overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  color: var(--ink-2); font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip .count { font-size: 12px; opacity: .7; }
.chip-add { border-style: dashed; }

.status-line {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  max-width: 1400px; margin: 0 auto; padding: 12px 16px 0;
  color: var(--ink-2); font-size: 14px;
}
.active-filter {
  display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 6px 0 12px;
  background: var(--accent-soft); color: var(--accent); border: 0; border-radius: 16px; font-size: 13px;
}
.active-filter .icon { width: 16px; height: 16px; }

/* ---------- card wall ---------- */
.wall { display: flex; gap: 12px; align-items: flex-start; max-width: 1400px; margin: 0 auto; padding: 12px 16px 104px; }
.wall-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.card {
  position: relative; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; transition: transform .15s ease, box-shadow .15s ease;
}
@media (hover: hover) { .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); } }
.card-open { position: absolute; inset: 0; z-index: 1; width: 100%; background: none; border: 0; border-radius: inherit; }
.card-cover { width: 100%; object-fit: cover; background: var(--surface-2); }
.card-cover-wrap { position: relative; }
.card-more {
  position: absolute; right: 8px; bottom: 8px; padding: 0 8px; border-radius: 10px;
  background: rgb(20 15 10 / 62%); color: #fff; font-size: 12px; line-height: 22px;
}
.card-body { padding: 10px 12px 12px; }
.card-title { margin: 0; font: 600 15px/1.45 var(--serif); overflow-wrap: anywhere; }
.card-snippet {
  margin: 4px 0 0; color: var(--ink-2); font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden;
}
.card-file { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--ink-2); font-size: 13px; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.pill { padding: 0 8px; border-radius: 9px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; line-height: 20px; }
.pill-room { background: var(--moss-soft); color: var(--moss); }
.pill-considering { background: var(--amber-soft); color: var(--amber); }
.pill-adopted { background: var(--moss); color: var(--surface); }
.pill-rejected { background: var(--rose-soft); color: var(--rose); }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--ink-3); font-size: 12px; }
.star-btn {
  position: relative; z-index: 2; display: inline-flex; width: 32px; height: 32px; margin: -6px -6px -6px 0;
  align-items: center; justify-content: center; padding: 0;
  background: none; border: 0; border-radius: 50%; color: var(--ink-3);
}
.star-btn[aria-pressed="true"] { color: var(--star); }
.star-btn[aria-pressed="true"] .icon { fill: currentColor; }
.star-btn .icon { width: 18px; height: 18px; }

.empty { max-width: 420px; margin: 18vh auto 0; padding: 0 24px; text-align: center; color: var(--ink-2); }
.empty h2 { margin: 0 0 6px; font: 600 20px/1.4 var(--serif); color: var(--ink); }
.empty p { margin: 0; }
.loading-more { padding: 0 0 24px; text-align: center; color: var(--ink-3); font-size: 14px; }

.fab {
  position: fixed; z-index: 6; right: 20px; bottom: calc(env(safe-area-inset-bottom) + 24px);
  display: inline-flex; align-items: center; gap: 6px; height: 56px; padding: 0 22px 0 18px;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 28px;
  box-shadow: var(--shadow-lg); font-weight: 600;
}

/* ---------- sheets ---------- */
dialog { color: inherit; }
dialog::backdrop { background: rgb(25 18 12 / 50%); }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; padding: 0;
  background: var(--surface); border: 0; border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg);
  overflow: auto; overscroll-behavior: contain;
}
.sheet-wide { max-width: 720px; }
.sheet-small { max-width: 420px; }
.sheet-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 8px 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font: 600 17px/1.4 var(--serif); min-width: 0; }
.sheet-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.sheet-body { padding: 16px 20px calc(env(safe-area-inset-bottom) + 20px); }
@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 20px; }
}

/* ---------- forms ---------- */
.field { display: block; margin-top: 12px; }
.field > span { display: block; margin-bottom: 4px; color: var(--ink-2); font-size: 13px; }
.field input, .composer-text {
  width: 100%; padding: 10px 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
}
.composer-text { min-height: 112px; resize: vertical; line-height: 1.6; }
.composer-tools { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  background: var(--surface-2); border: 0; border-radius: 12px; color: var(--ink); font-size: 15px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-danger { color: var(--rose); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-grow { flex: 1; }
.composer-url { margin-top: 8px; color: var(--moss); font-size: 13px; overflow-wrap: anywhere; }
.section-label { margin: 14px 0 6px; color: var(--ink-2); font-size: 13px; }
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-group .chip { min-height: 34px; padding: 0 12px; }
.chip-group .chip[aria-pressed="true"] { background: var(--moss); border-color: var(--moss); color: var(--surface); }
details.more { margin-top: 12px; }
details.more > summary { min-height: 36px; padding: 6px 0; color: var(--ink-2); font-size: 14px; cursor: pointer; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumb {
  position: relative; width: 76px; height: 76px; border-radius: 10px; background: var(--surface-2); overflow: hidden;
  display: flex; align-items: center; justify-content: center; color: var(--ink-3); font-size: 11px; text-align: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-remove {
  position: absolute; top: 2px; right: 2px; display: flex; width: 26px; height: 26px; padding: 0;
  align-items: center; justify-content: center; border: 0; border-radius: 50%; background: rgb(20 15 10 / 65%); color: #fff;
}
.thumb-remove .icon { width: 14px; height: 14px; }
.form-error { margin: 10px 0 0; color: var(--rose); font-size: 14px; }

/* ---------- detail ---------- */
.gallery { display: flex; flex-direction: column; gap: 8px; margin: -16px -20px 16px; }
.gallery button { padding: 0; background: var(--surface-2); border: 0; }
.gallery img { width: 100%; height: auto; }
.detail-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.75; }
.detail-title { margin: 0 0 8px; font: 600 21px/1.45 var(--serif); overflow-wrap: anywhere; }
.meta { margin-top: 14px; color: var(--ink-2); font-size: 13.5px; }
.meta a { overflow-wrap: anywhere; }
.pill-btn { border: 0; padding: 0 10px; line-height: 26px; font-size: 13px; border-radius: 13px; }
.status-group { display: flex; gap: 6px; flex-wrap: wrap; }
.status-group .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.file-link { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.history { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); }
.history li { padding: 6px 0; border-top: 1px solid var(--line); }
.detail-actions { display: flex; gap: 8px; margin-top: 18px; }

.lightbox {
  width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0;
  background: #0d0b09; border: 0; overflow: auto;
}
.lightbox::backdrop { background: #0d0b09; }
.lightbox img { width: 100%; min-height: 100%; object-fit: contain; }
.lightbox-bar { position: fixed; top: calc(env(safe-area-inset-top) + 8px); right: 8px; display: flex; gap: 4px; }
.lightbox-bar a, .lightbox-bar button {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px; border: 0; border-radius: 20px;
  background: rgb(0 0 0 / 60%); color: #fff; font-size: 14px; text-decoration: none;
}

/* ---------- login, menu, toast ---------- */
.login { max-width: 360px; margin: 0 auto; padding: 16vh 24px 24px; }
.login h1 { margin: 0; font: 600 30px/1.3 var(--serif); letter-spacing: .04em; }
.login p { margin: 4px 0 20px; color: var(--ink-2); }
.login .btn { width: 100%; margin-top: 18px; }
.menu-list { display: flex; flex-direction: column; gap: 4px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 0 12px;
  background: none; border: 0; border-radius: 10px; color: var(--ink); text-align: left; text-decoration: none;
}
.menu-item:hover { background: var(--surface-2); }
.menu-who { margin: 0 0 8px; padding: 0 12px; color: var(--ink-2); font-size: 14px; }
.toast {
  position: fixed; z-index: 30; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); translate: -50% 0;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); padding: 10px 16px;
  background: var(--ink); color: var(--paper); border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 14px;
}
.toast button { min-height: 32px; padding: 0 4px; background: none; border: 0; color: inherit; font-weight: 600; text-decoration: underline; white-space: nowrap; }

@media (min-width: 768px) {
  .fab { display: none; }
  .btn.desktop-add { display: inline-flex; }
  .topbar { padding-inline: 24px; }
  .wall { gap: 16px; padding: 16px 24px 48px; }
  .wall-col { gap: 16px; }
  .status-line { padding-inline: 24px; }
  .search { max-width: 520px; margin-right: auto; }
  .toast { bottom: 28px; }
}

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