:root {
  --bg: #f2e9d9;
  --paper: #fdf8ee;
  --ink: #2f2620;
  --ink-soft: #7c6b59;
  --accent: #bf4b26;
  --accent-soft: #d98b45;
  --line: rgba(47, 38, 32, .15);
  --shadow: 0 14px 30px rgba(80, 55, 30, .14);
  --serif: 'Fraunces', Georgia, serif;
  --hand: 'Caveat', cursive;
  --body: 'Karla', system-ui, sans-serif;
  --ease: cubic-bezier(.2, .8, .3, 1);
}

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

html { overflow-x: hidden; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  min-height: 100vh;
  background-image: radial-gradient(circle at 15% 15%, rgba(210, 160, 100, .09), transparent 45%);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea, select { -webkit-user-select: text; user-select: text; }

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
}

.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px clamp(18px, 5vw, 56px);
}

.brand { font-family: var(--serif); font-weight: 500; font-size: 26px; }
.brand span { color: var(--accent); }
.sub { font-family: var(--hand); font-size: 19px; color: var(--ink-soft); }

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 8px clamp(16px, 5vw, 40px) 90px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.card {
  background: rgba(253, 248, 238, .88);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.muted { color: var(--ink-soft); font-size: 14px; }

/* ---------- login ---------- */
.login-card { max-width: 400px; margin: 6vh auto 0; }
.login-card h2 { font-family: var(--serif); font-weight: 500; font-size: 27px; margin-bottom: 4px; }
.login-card form { margin-top: 22px; display: flex; flex-direction: column; gap: 16px; }
.err { color: #a0341d; font-size: 13px; }

/* ---------- form ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.opt-note { font-weight: 400; font-style: italic; opacity: .75; }

input, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  font-family: var(--body);
  font-size: 14px;
  color: var(--ink);
  transition: border-color .18s ease, box-shadow .18s ease;
}

input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(191, 75, 38, .13); }

.btn {
  font-family: var(--body);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 11px;
  padding: 12px 20px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.primary:hover { box-shadow: 0 10px 22px rgba(47, 38, 32, .3); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink-soft); }
.btn.ghost:hover { border-color: var(--accent); color: var(--ink); }
.btn.danger { background: rgba(163, 52, 29, .1); color: #a0341d; }
.btn.small { padding: 11px 12px; font-size: 12px; white-space: nowrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.link { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- dropzone ---------- */
.dropzone {
  border: 2px dashed var(--line);
  background: rgba(253, 248, 238, .65);
  text-align: center;
  padding: 34px 26px 24px;
  transition: border-color .2s ease, background .2s ease;
}

.dropzone.drag { border-color: var(--accent); background: rgba(255, 250, 240, .95); }

.dz-title { font-family: var(--serif); font-size: 22px; }
.dz-sub { color: var(--ink-soft); font-size: 14px; margin: 6px 0 14px; }
.dz-hint { margin-top: 14px; font-size: 12px; color: var(--ink-soft); opacity: .8; }

.dz-opts {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-top: 26px;
  text-align: left;
  padding-top: 22px;
  border-top: 1px dashed var(--line);
}

.dz-opts label { flex: 1; min-width: 210px; }

.sel-row { display: flex; gap: 8px; align-items: flex-start; }
.sel-row select { flex: 1; }

.link { font-size: 12px; margin-top: 7px; display: inline-block; }

/* ---------- preview ---------- */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin: 18px 0 20px;
}

.preview-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--paper);
  position: relative;
}

.preview-card img { width: 100%; height: 110px; object-fit: cover; display: block; background: #e9e1d1; }

.preview-card .p-body { padding: 10px; }
.preview-card input {
  font-size: 13px;
  padding: 9px 10px;
  margin-top: 0;
  font-family: var(--hand);
  font-size: 15px;
}

.preview-card .p-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(24, 16, 10, .7);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
}

.p-progress {
  height: 5px;
  border-radius: 4px;
  background: #e9e1d1;
  margin-top: 9px;
  overflow: hidden;
  opacity: 0;
  transition: opacity .2s ease;
}

.p-progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft));
  transition: width .15s ease;
}

.p-status {
  display: block;
  font-size: 11.5px;
  margin-top: 5px;
  color: var(--ink-soft);
  min-height: 1.2em;
}

.preview-card.uploading { box-shadow: 0 0 0 2px var(--accent); }
.preview-card.done { opacity: .72; }
.preview-card.done .p-status { color: #3a7d44; font-weight: 600; }
.preview-card.error { box-shadow: 0 0 0 2px #a0341d; }
.preview-card.error .p-status { color: #a0341d; font-weight: 600; }

.preview-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- status ---------- */
.status { text-align: center; font-size: 14px; color: var(--ink-soft); }
.status.err { color: #a0341d; }

/* ---------- customize ---------- */
.custom-form { display: flex; flex-direction: column; gap: 14px; }
.custom-form label { margin-bottom: 0; }
.link-like { color: var(--accent); font-weight: 600; }

/* ---------- albums ---------- */
.albums-grid { display: flex; flex-direction: column; gap: 8px; }
.album-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf8;
}
.album-row .a-name { font-family: var(--hand); font-size: 19px; line-height: 1; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-row .a-count { font-size: 11.5px; color: var(--ink-soft); white-space: nowrap; }
.album-row .a-acts { display: flex; gap: 8px; }
.album-row .a-acts button { padding: 8px 12px; font-size: 12px; }

/* ---------- manage ---------- */
.manage-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.manage-head h2 { font-family: var(--serif); font-weight: 500; font-size: 20px; }

.manage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.photo {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--paper);
  transition: transform .15s ease, box-shadow .15s ease;
}

.photo:hover { transform: translateY(-3px); box-shadow: 0 12px 24px rgba(80, 55, 30, .18); }

.photo img { width: 100%; height: 130px; object-fit: cover; display: block; background: #e9e1d1; }
.photo .meta { padding: 10px 12px 4px; }
.photo .cap { font-family: var(--hand); font-size: 17px; line-height: 1.3; min-height: 1.3em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo .sub-meta { display: flex; justify-content: space-between; align-items: baseline; margin-top: 2px; }
.photo .cat { font-size: 10.5px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--accent-soft); font-weight: 600; }
.photo .date { font-family: var(--hand); font-size: 14px; color: var(--ink-soft); }
.photo .acts { display: flex; gap: 8px; padding: 8px 12px 12px; }
.photo .acts button { flex: 1; font-size: 12px; padding: 8px; }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(24, 16, 10, .55);
  backdrop-filter: blur(4px);
  padding: 16px;
}

.modal[hidden] { display: none; }

.modal-card {
  background: var(--paper);
  border-radius: 16px;
  padding: 26px;
  width: min(94vw, 430px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
  max-height: 92vh;
  overflow-y: auto;
}

.modal-card h3 { font-family: var(--serif); font-weight: 500; font-size: 22px; margin-bottom: 16px; }
.modal-card label { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

@media (max-width: 560px) {
  .head { flex-direction: column; gap: 8px; text-align: center; }
  .preview-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
