:root {
  --soft: #f5f5f7;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: #d2d2d7;
  --hair: #ececf0;
  --crayon: #127fa3;
  --pencil: #2c2c2e;
  --red: #d33a2c;
  --hand: "Caveat", "Bradley Hand", cursive;
  --ease: cubic-bezier(.22, 1, .36, 1);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: #fff; color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; letter-spacing: -0.01em;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
h1, h2 { margin: 0; letter-spacing: -0.025em; }
.hand { font-family: var(--hand); font-weight: 600; letter-spacing: 0; }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 18px; border-radius: 999px; background: var(--soft); font-weight: 500; text-decoration: none; white-space: nowrap;
  transition: background .2s, transform .15s, opacity .2s;
}
.btn:hover { background: #e8e8ed; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--pencil); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: #fdecea; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--soft); }
.btn.small { height: 32px; padding: 0 14px; font-size: 13px; }
.btn.wide { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; }
.field small { font-weight: 400; color: var(--faint); margin-left: 6px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--crayon); box-shadow: 0 0 0 4px rgba(18,127,163,.14); }
.note { margin: 0; font-size: 12.5px; color: var(--faint); }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card .eyebrow { font-size: 28px; color: var(--crayon); margin: 0; }
.login-card h1 { font-size: 40px; font-weight: 700; margin-bottom: 30px; }
.login-card h1 span, .brand span { color: var(--faint); font-weight: 500; }
.login-card .field { text-align: left; }
.login-card .btn { width: 100%; }
.error { color: var(--red); min-height: 22px; margin: 12px 0 0; font-size: 14px; }
.back-link { color: var(--faint); font-size: 14px; text-decoration: none; }
.back-link:hover { color: var(--text); }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- App layout ---------- */
.app { height: 100%; display: grid; grid-template-columns: 330px 1fr; grid-template-rows: 56px 1fr; }
.bar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--hair); }
.brand { font-weight: 600; font-size: 18px; }
.brand em { font-style: normal; font-size: 22px; color: var(--crayon); margin-left: 6px; }
.bar-links { display: flex; gap: 18px; font-size: 14px; }
.bar-links a, .bar-links button { color: var(--muted); text-decoration: none; }
.bar-links a:hover, .bar-links button:hover { color: var(--text); }

.side { border-right: 1px solid var(--hair); overflow-y: auto; padding: 18px 14px 40px; }
.demo-note { margin: 14px 4px 4px; padding: 12px 14px; border-radius: 14px; background: #fff8e6; font-size: 13px; }
.demo-note p { margin: 0 0 8px; }
.post-list { list-style: none; margin: 14px 0 0; padding: 0; }
.post-item {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 8px; border-radius: 14px; text-align: left;
  transition: background .2s;
}
.post-item:hover { background: var(--soft); }
.post-item.active { background: #e9f4f8; }
.post-item .art { width: 52px; height: 52px; border-radius: 10px; flex: none; }
.post-item .t { font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-item .d { font-size: 12px; color: var(--faint); margin-top: 2px; }
.post-item .d i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #a0761b; background: #fff3d6; padding: 2px 7px; border-radius: 6px; }
.month-head { font-family: var(--hand); font-size: 20px; color: var(--faint); margin: 14px 8px 2px; }

.editor { overflow-y: auto; padding: 28px 40px 80px; }
.empty { height: 100%; display: grid; place-items: center; }
.empty p { font-size: 26px; color: var(--faint); }
#form { max-width: 860px; }
.form-head { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.form-head h2 { font-size: 30px; font-weight: 700; }
.row { display: grid; grid-template-columns: 170px 1fr 1fr; gap: 14px; }

.art { background: var(--art, #eee); background-size: cover; background-position: center; }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
.ph-tile { position: relative; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; background: var(--soft) center / cover; cursor: grab; }
.ph-tile.dragging { opacity: .4; }
.ph-tile.over { outline: 2px solid var(--crayon); outline-offset: 2px; }
.ph-tile .cover-tag { position: absolute; left: 8px; top: 6px; font-family: var(--hand); font-size: 18px; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.ph-tools { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: flex-end; gap: 4px; padding: 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.45)); opacity: 0; transition: opacity .2s; }
.ph-tile:hover .ph-tools, .ph-tile:focus-within .ph-tools { opacity: 1; }
.ph-tools button { height: 26px; min-width: 26px; padding: 0 8px; border-radius: 999px; background: rgba(255,255,255,.92); font-size: 12px; font-weight: 600; }
.ph-tools button.del { color: var(--red); }
.ph-add {
  aspect-ratio: 4 / 3; border-radius: 14px; border: 2px dashed var(--line); color: var(--muted); font-size: 13px; line-height: 1.35;
  display: grid; place-items: center; text-align: center; transition: border-color .2s, color .2s, background .2s;
}
.ph-add:hover, .photos.dragging .ph-add { border-color: var(--crayon); color: var(--crayon); background: #f3fafc; }
.ph-add b { font-size: 22px; font-weight: 400; display: block; }
.ph-tile.loading { display: grid; place-items: center; font-size: 12px; color: var(--faint); cursor: default; }
.swatches-wrap { margin-top: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); transition: transform .15s; }
.swatch:hover { transform: scale(1.1); }
.swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--crayon); }

/* links */
.link-add { display: flex; gap: 8px; }
.link-add input { flex: 1; }
.link-add .btn { height: auto; }
.links { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.links li { display: flex; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--hair); border-radius: 14px; }
.links .lthumb { flex: none; width: 88px; height: 50px; border-radius: 8px; background: #1d1d1f center / cover; }
.links .lthumb.ig { background: linear-gradient(120deg, #feda75, #fa7e1e 30%, #d62976 60%, #962fbf 85%, #4f5bd5); }
.links .lbody { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.links .lbody input { padding: 6px 10px; border-radius: 8px; font-size: 14px; }
.links .ltype { font-size: 11.5px; color: var(--faint); }
.links .ltype a { color: inherit; }
.links button { color: var(--red); font-size: 13px; padding: 6px 8px; }

/* place */
.place { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
#place-map { width: 260px; height: 286px; border: 1px solid var(--hair); border-radius: 18px; background: #fff; cursor: pointer; }
#place-map.adding { cursor: crosshair; background: #f7fbfd; }
#place-map .coast { fill: #fff; stroke: var(--pencil); stroke-width: 2.4; }
#place-map .pl circle { fill: #aeaeb2; stroke: #fff; stroke-width: 3; }
#place-map .pl text { font-family: var(--hand); font-size: 22px; fill: var(--muted); pointer-events: none; }
#place-map .pl.on circle { fill: var(--crayon); }
#place-map .pl.on text { fill: var(--crayon); font-weight: 700; }
#place-map .pl:hover circle { fill: var(--pencil); }
#place-map .new circle { fill: var(--red); stroke: #fff; stroke-width: 3; }
.place-side { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.new-place { width: 100%; display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 14px; background: var(--soft); }
.inline { font-size: 13px; display: flex; align-items: center; gap: 8px; }
.inline select { width: auto; padding: 6px 8px; }
.btns { display: flex; gap: 6px; }

.actions { display: flex; align-items: center; gap: 10px; padding-top: 8px; position: sticky; bottom: -80px; background: linear-gradient(transparent, #fff 30%); padding-bottom: 20px; }
.spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); z-index: 10;
  background: var(--pencil); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--red); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; height: auto; }
  .side { border-right: 0; border-bottom: 1px solid var(--hair); max-height: 40vh; }
  .editor { padding: 22px 18px 60px; }
  .row, .photo, .place { grid-template-columns: 1fr; }
}
