:root {
  --paper: #f4ece0;
  --paper-2: #efe4d3;
  --ink: #3b2f26;
  --ink-soft: #6b584a;
  --accent: #a8603a;      /* nâu đất/gạch cũ */
  --accent-2: #c99a5b;    /* vàng ngả màu thời gian */
  --gold: #b8894b;
  --shadow: rgba(59, 47, 38, 0.22);
  --frame: #fffdf7;
}

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

body {
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(201,154,91,0.18), transparent 40%),
    radial-gradient(circle at 85% 30%, rgba(168,96,58,0.12), transparent 45%),
    linear-gradient(160deg, var(--paper) 0%, var(--paper-2) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.6;
}

/* Hiệu ứng hạt phim / giấy cũ phủ toàn trang */
.grain {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none; opacity: 0.4;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

/* ------------------------------- HERO -------------------------------- */
.hero {
  position: relative;
  padding: 5.5rem 1.5rem 3.5rem;
  text-align: center;
  background:
    linear-gradient(rgba(59,47,38,0.35), rgba(59,47,38,0.55)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M0 0h60v60H0z' fill='%23a8603a' opacity='0.05'/%3E%3C/svg%3E"),
    linear-gradient(135deg, #6b4a30, #96633c);
  color: #f8f0e2;
  box-shadow: inset 0 -12px 30px rgba(0,0,0,0.25);
  border-bottom: 6px double rgba(255,250,235,0.3);
}
.kicker {
  font-family: 'Be Vietnam Pro'; letter-spacing: 0.35em; text-transform: uppercase;
  font-size: 0.72rem; font-weight: 500; opacity: 0.85; margin-bottom: 0.8rem;
}
.hero h1 {
  font-family: 'Playfair Display', serif; font-weight: 700;
  font-size: clamp(2.6rem, 6vw, 4.5rem); letter-spacing: 0.02em;
  text-shadow: 2px 3px 8px rgba(0,0,0,0.4); line-height: 1.05;
}
.subtitle {
  font-family: 'Dancing Script', cursive; font-size: clamp(1.4rem, 3vw, 2rem);
  color: var(--accent-2); margin-top: 0.4rem; text-shadow: 1px 2px 4px rgba(0,0,0,0.35);
}
.hero-count {
  display: inline-block; margin-top: 1.4rem; padding: 0.35rem 1.2rem;
  border: 1px solid rgba(248,240,226,0.4); border-radius: 999px;
  font-size: 0.85rem; letter-spacing: 0.05em; backdrop-filter: blur(2px);
  background: rgba(255,255,255,0.06);
}

.container { max-width: 1200px; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }

/* ----------------------------- UPLOAD -------------------------------- */
.upload-card {
  background: var(--frame);
  border-radius: 14px;
  padding: 1.6rem;
  margin: -3.5rem auto 3rem;
  max-width: 720px;
  box-shadow: 0 18px 45px var(--shadow), 0 2px 0 rgba(255,255,255,0.8) inset;
  border: 1px solid rgba(168,96,58,0.15);
  position: relative; z-index: 5;
}
.dropzone {
  display: flex; align-items: center; gap: 1rem;
  border: 2px dashed var(--accent); border-radius: 12px;
  padding: 1.4rem 1.6rem; cursor: pointer; transition: 0.25s;
  background: linear-gradient(0deg, rgba(201,154,91,0.06), transparent);
}
.dropzone:hover, .dropzone.drag {
  background: rgba(201,154,91,0.15); border-color: var(--gold);
  transform: translateY(-1px);
}
.dropzone-icon { font-size: 2.4rem; filter: sepia(0.3); }
.dropzone-text { display: flex; flex-direction: column; }
.dropzone-text strong { font-size: 1.05rem; color: var(--ink); }
.dropzone-text span { font-size: 0.85rem; color: var(--ink-soft); }

.file-list { margin: 0.8rem 0 0; font-size: 0.85rem; color: var(--accent); min-height: 0; }
.file-list:not(:empty) { min-height: 1.2rem; margin-bottom: 0.4rem; }

.caption-input {
  width: 100%; margin-top: 1rem; padding: 0.75rem 1rem;
  border: 1px solid rgba(168,96,58,0.25); border-radius: 9px;
  font-family: inherit; font-size: 0.95rem; color: var(--ink);
  background: var(--paper); outline: none;
}
.caption-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,154,91,0.2); }

.btn-upload {
  width: 100%; margin-top: 1rem; padding: 0.85rem;
  font-family: inherit; font-weight: 600; font-size: 1rem; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  border: none; border-radius: 10px; cursor: pointer; transition: 0.2s;
  letter-spacing: 0.03em; box-shadow: 0 8px 20px rgba(168,96,58,0.35);
}
.btn-upload:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(168,96,58,0.45); }
.btn-upload:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* ----------------------------- GALLERY ------------------------------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 2.2rem 1.8rem;
}
.photo-card {
  position: relative;
  background: var(--frame);
  padding: 0.7rem 0.7rem 0.4rem;
  border-radius: 3px;
  box-shadow: 0 10px 26px var(--shadow);
  transform: rotate(var(--r));
  transition: transform 0.28s ease, box-shadow 0.28s ease;
  cursor: pointer;
}
.photo-card:hover {
  transform: rotate(0deg) scale(1.03) translateY(-4px);
  box-shadow: 0 20px 40px rgba(59,47,38,0.32); z-index: 3;
}
.photo-frame { position: relative; overflow: hidden; border-radius: 2px; background: #ddd; }
.photo-frame img {
  display: block; width: 100%; height: 240px; object-fit: cover;
  filter: sepia(0.28) contrast(1.02) brightness(1.02) saturate(0.9);
  transition: filter 0.3s;
}
.photo-card:hover .photo-frame img { filter: sepia(0.1) contrast(1.04) saturate(1.02); }
/* băng dán góc ảnh */
.photo-tape {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%) rotate(-3deg);
  width: 78px; height: 26px; background: rgba(201,154,91,0.45);
  box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}
figcaption {
  padding: 0.6rem 0.4rem 0.3rem; text-align: center;
  display: flex; flex-direction: column; gap: 0.15rem;
}
.cap-text { font-family: 'Dancing Script', cursive; font-size: 1.15rem; color: var(--ink); line-height: 1.2; }
figcaption time { font-size: 0.72rem; color: var(--ink-soft); letter-spacing: 0.05em; }

.btn-del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px;
  border: none; border-radius: 50%; background: rgba(59,47,38,0.6); color: #fff;
  font-size: 1.1rem; line-height: 1; cursor: pointer; opacity: 0; transition: 0.2s;
}
.photo-card:hover .btn-del { opacity: 1; }
.btn-del:hover { background: #a8322a; }
.del-form { position: absolute; top: 0; right: 0; }

/* ------------------------------ EMPTY -------------------------------- */
.empty { text-align: center; padding: 4rem 1rem; color: var(--ink-soft); }
.empty-emoji { font-size: 3.5rem; margin-bottom: 1rem; filter: sepia(0.4); }
.empty p { font-family: 'Playfair Display', serif; font-size: 1.6rem; color: var(--ink); margin-bottom: 0.4rem; }

/* ----------------------------- LIGHTBOX ------------------------------ */
.lightbox {
  position: fixed; inset: 0; z-index: 10000; display: none;
  align-items: center; justify-content: center; flex-direction: column;
  background: rgba(30,22,16,0.92); backdrop-filter: blur(4px); padding: 2rem;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 92%; max-height: 82vh; border: 10px solid var(--frame);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6); border-radius: 2px;
  filter: sepia(0.15);
}
.lb-caption { color: #f0e6d6; font-family: 'Dancing Script', cursive; font-size: 1.5rem; margin-top: 1rem; text-align: center; }
.lb-close { position: absolute; top: 1.2rem; right: 1.8rem; font-size: 2.5rem; color: #f0e6d6; cursor: pointer; line-height: 1; }
.lb-close:hover { color: var(--accent-2); }

/* ------------------------------ LOGIN -------------------------------- */
.logout-link {
  display: inline-block; margin-top: 1rem; margin-left: 0.6rem;
  color: rgba(248,240,226,0.85); font-size: 0.8rem; text-decoration: none;
  border-bottom: 1px dotted rgba(248,240,226,0.5); transition: 0.2s;
}
.logout-link:hover { color: var(--accent-2); }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 400px; padding: 1.5rem; text-align: center; }
.login-card {
  background: var(--frame); border-radius: 14px; padding: 2.4rem 1.8rem;
  box-shadow: 0 18px 45px var(--shadow), 0 2px 0 rgba(255,255,255,0.8) inset;
  border: 1px solid rgba(168,96,58,0.15);
}
.login-emoji { font-size: 3rem; margin-bottom: 0.6rem; filter: sepia(0.4); }
.login-card h1 { font-family: 'Playfair Display', serif; font-size: 2rem; color: var(--ink); }
.login-sub { font-family: 'Dancing Script', cursive; font-size: 1.25rem; color: var(--accent); margin: 0.3rem 0 1.6rem; }
.login-input {
  width: 100%; padding: 0.8rem 1rem; margin-bottom: 1rem;
  border: 1px solid rgba(168,96,58,0.25); border-radius: 9px;
  font-family: inherit; font-size: 1rem; color: var(--ink);
  background: var(--paper); outline: none; text-align: center;
}
.login-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,154,91,0.2); }
.login-error {
  background: rgba(168,50,42,0.1); color: #a8322a; border: 1px solid rgba(168,50,42,0.25);
  border-radius: 8px; padding: 0.6rem; margin-bottom: 1rem; font-size: 0.88rem;
}

/* --------------------------- EDIT CAPTION ---------------------------- */
.btn-edit {
  position: absolute; top: 4px; right: 34px; width: 26px; height: 26px;
  border: none; border-radius: 50%; background: rgba(59,47,38,0.6); color: #fff;
  font-size: 0.9rem; line-height: 1; cursor: pointer; opacity: 0; transition: 0.2s;
}
.photo-card:hover .btn-edit { opacity: 1; }
.btn-edit:hover { background: var(--accent); }

.edit-form { display: none; padding: 0.4rem 0.4rem 0.2rem; }
.photo-card.editing .edit-form { display: block; }
.photo-card.editing figcaption { display: none; }
.edit-input {
  width: 100%; padding: 0.5rem 0.6rem; border: 1px solid rgba(168,96,58,0.3);
  border-radius: 7px; font-family: inherit; font-size: 0.9rem; color: var(--ink);
  background: var(--paper); outline: none;
}
.edit-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,154,91,0.2); }
.edit-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.btn-save, .btn-cancel {
  flex: 1; padding: 0.4rem; border: none; border-radius: 7px; cursor: pointer;
  font-family: inherit; font-size: 0.82rem; font-weight: 600; transition: 0.2s;
}
.btn-save { background: linear-gradient(135deg, var(--accent), var(--gold)); color: #fff; }
.btn-save:hover { transform: translateY(-1px); }
.btn-cancel { background: rgba(59,47,38,0.12); color: var(--ink-soft); }
.btn-cancel:hover { background: rgba(59,47,38,0.2); }

/* ------------------------------ FOOTER ------------------------------- */
.foot { text-align: center; padding: 2.5rem 1rem 3rem; color: var(--ink-soft); font-size: 0.85rem; }

@media (max-width: 600px) {
  .gallery { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1.5rem 1rem; }
  .photo-frame img { height: 170px; }
  .dropzone { flex-direction: column; text-align: center; }
}
