:root {
  --paper: #f1eee8;
  --paper-2: #e9e4db;
  --slip: #fffdf9;
  --ink: #1d1a17;
  --soft: #6e675f;
  --rose: #d4958a;
  --rose-deep: #b8685c;
  --manila: #e8d9b8;
  --manila-edge: #cdb98f;
  --stamp: #b4473a;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Jost", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 150px; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  line-height: 1.5;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .4  0 0 0 0 .33  0 0 0 .09 0'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--rose-deep); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 2px dotted var(--ink);
}
.top-inner {
  max-width: 1100px; margin: 0 auto; padding: 18px 20px 10px;
  display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: end; justify-content: space-between;
}
h1 {
  margin: 0; font-family: var(--serif); font-weight: 500;
  font-size: clamp(2.2rem, 6vw, 3.4rem); line-height: 1; letter-spacing: .01em;
}
.sub { margin: 6px 0 0; color: var(--soft); font-size: .95rem; }
.controls { display: flex; gap: 10px; flex: 1 1 340px; max-width: 560px; }
.controls input[type=search] { flex: 1; min-width: 0; }
.controls input, .controls select, .form input, .form textarea {
  background: var(--slip); border: 1.5px solid var(--ink); border-radius: 999px;
  padding: 9px 16px;
}
.controls select { border-radius: 999px; padding-right: 10px; }

.tabs {
  max-width: 1100px; margin: 0 auto; padding: 0 20px 0;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; cursor: pointer; border: 1.5px solid var(--manila-edge); border-bottom: 0;
  background: var(--manila); border-radius: 12px 12px 0 0; padding: 7px 16px 6px;
  font-size: .92rem; color: var(--soft); transition: transform .15s;
}
.tab:hover { transform: translateY(-2px); }
.tab[aria-current=true] { background: var(--slip); color: var(--ink); border-color: var(--ink); font-weight: 500; }

/* ---------- folders ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 36px 20px 60px; display: grid; gap: 54px; }

.folder { position: relative; padding-top: 34px; }
.folder-tab {
  position: absolute; top: 0; left: 28px; height: 36px; padding: 6px 22px 0;
  background: var(--manila); border: 1.5px solid var(--manila-edge); border-bottom: 0;
  border-radius: 14px 14px 0 0; font-family: var(--serif); font-size: 1.15rem; font-weight: 600;
}
.folder-body {
  background: var(--manila); border: 1.5px solid var(--manila-edge);
  border-radius: 6px 18px 18px 18px; padding: 28px;
  box-shadow: 0 1px 0 #fff8 inset, 0 14px 30px -18px #3b2f1a66;
  display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 34px; align-items: start;
}

.card-col { position: sticky; top: 170px; }
.card-btn {
  display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; position: relative;
  transform: rotate(-1.2deg); transition: transform .2s;
}
.card-btn:hover { transform: rotate(0deg) scale(1.015); }
.card-btn img { display: block; width: 100%; height: auto; border-radius: 4px; box-shadow: 0 10px 24px -10px #2b1f0f88, 0 0 0 1px #0002; }
.card-btn::before {
  content: ""; position: absolute; top: -14px; right: 26px; width: 16px; height: 44px; z-index: 2;
  border: 3px solid #9a9a9a; border-radius: 10px; border-bottom-color: transparent; transform: rotate(8deg);
  background: linear-gradient(90deg, transparent 40%, #fff6 50%, transparent 60%);
}
.card-hint { margin: 12px 0 0; text-align: center; font-size: .82rem; color: #6d5b36; }

.slips-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.slips-head h2 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 2rem; line-height: 1.05; }
.slips-head .by { margin: 2px 0 0; color: #6d5b36; font-size: .92rem; }
.avg { margin: 6px 0 0; font-size: .92rem; color: #5a4a2a; }

.btn {
  cursor: pointer; border: 1.5px solid var(--ink); background: var(--ink); color: var(--paper);
  border-radius: 999px; padding: 9px 20px; font-weight: 500; transition: transform .12s, background .12s;
}
.btn:hover { background: #3a342e; transform: translateY(-1px); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: #0001; }
.btn.danger { background: transparent; color: var(--stamp); border-color: var(--stamp); }
.btn:disabled { opacity: .55; cursor: wait; }

.slips { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.slip {
  background: var(--slip); border-radius: 3px; padding: 18px 18px 12px;
  box-shadow: 0 6px 14px -8px #3b2f1a77, 0 0 0 1px #0000000d;
  display: flex; flex-direction: column; gap: 12px;
}
.slip:nth-child(odd)  { transform: rotate(-.45deg); }
.slip:nth-child(even) { transform: rotate(.5deg); }
.slip-head { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 2px dotted #1d1a1766; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--rose); color: #fff; font-family: var(--serif); font-size: 1.4rem; font-weight: 600;
}
.who { flex: 1; min-width: 0; }
.who h3 { margin: 0; font-size: 1.05rem; font-weight: 500; overflow-wrap: anywhere; }
.who time { color: var(--soft); font-size: .8rem; }
.stamp {
  flex: none; display: flex; align-items: baseline; padding: 2px 10px 0; border: 2px solid var(--stamp);
  border-radius: 8px; color: var(--stamp); transform: rotate(-5deg);
}
.stamp b { font-family: var(--serif); font-size: 1.9rem; font-weight: 600; line-height: 1.1; }
.stamp span { font-size: .8rem; margin-left: 1px; }
.ans h4 { margin: 0 0 2px; font-size: .82rem; font-weight: 500; color: var(--rose-deep); }
.ans p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .97rem; }
.slip footer { margin-top: auto; padding-top: 4px; text-align: right; }

.none {
  border: 2px dashed var(--manila-edge); border-radius: 12px; padding: 28px; text-align: center; color: #6d5b36; background: #ffffff40;
}
.none p { margin: 0 0 12px; }

.linklike { background: none; border: 0; padding: 2px 4px; cursor: pointer; color: var(--soft); text-decoration: underline; text-underline-offset: 3px; font-size: .88rem; }
.linklike:hover { color: var(--ink); }

.empty { text-align: center; padding: 60px 20px; color: var(--soft); }
.empty h2 { font-family: var(--serif); font-weight: 500; font-size: 2rem; color: var(--ink); margin: 0 0 6px; }

.banner { max-width: 1100px; margin: 16px auto 0; padding: 10px 16px; border: 1.5px solid var(--stamp); color: var(--stamp); border-radius: 10px; background: #fff7; }
body.owner .sub::after { content: "  (owner mode on)"; color: var(--stamp); }

.foot { text-align: center; padding: 10px 20px 40px; color: var(--soft); font-size: .9rem; }
.foot p { margin: 0 0 4px; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; background: transparent; max-width: 100vw; }
dialog::backdrop { background: #1d1a17aa; }
#formDlg > * { background: var(--slip); }
.form {
  width: min(560px, 94vw); max-height: 92vh; overflow: auto; padding: 26px; border-radius: 6px;
  border: 1.5px solid var(--ink); box-shadow: 0 24px 60px -20px #000a;
  display: grid; gap: 14px;
}
.form h2 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 2rem; line-height: 1; }
.form .form-sub { margin: -8px 0 4px; color: var(--soft); padding-bottom: 12px; border-bottom: 2px dotted #1d1a1766; }
.form label { display: grid; gap: 4px; font-weight: 500; font-size: .95rem; }
.form .hint { font-weight: 400; font-size: .82rem; color: var(--soft); }
.form input, .form textarea { border-radius: 10px; width: 100%; }
.form textarea { resize: vertical; min-height: 92px; }
.form input[readonly] { background: var(--paper-2); }
.form .row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.form .row .spacer { flex: 1; }
.err { margin: 0; color: var(--stamp); min-height: 1.2em; font-size: .92rem; }
.pin-box { padding: 12px; border-radius: 10px; background: var(--paper); border: 1.5px dotted var(--soft); }

.img-dlg img { display: block; max-width: min(94vw, 760px); max-height: 92vh; border-radius: 4px; }
.img-dlg { cursor: zoom-out; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 10px 20px; border-radius: 999px; transition: .25s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  html { scroll-padding-top: 190px; }
  .folder-body { grid-template-columns: 1fr; padding: 22px 16px; }
  .card-col { position: static; max-width: 300px; margin: 0 auto; }
  .folder-tab { left: 16px; }
  .controls { flex-basis: 100%; max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
  .slip, .card-btn, .stamp { transform: none !important; }
}
