@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=Playfair+Display:wght@500;600;700&display=swap');

:root {
  --paper: #f4efe5;
  --ink: #45382f;
  --muted: #938477;
  --accent: #c76b4b;
  --card: #fffdf8;
  --line: #ded4c6;
}

* { box-sizing: border-box; }

body, html {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

header {
  padding: 22px 8%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  gap: 15px;
}

.brand {
  font: 700 27px 'Playfair Display', serif;
  color: var(--ink);
  text-decoration: none;
}
.brand span { color: var(--accent); }

nav { display: flex; gap: 12px; }
nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 8px 10px;
}
nav button.active, nav button:hover { color: var(--accent); }

/* 右側導覽列區塊（身分選單與批次管理按鈕） */
.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.user-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  background: #e8ded0;
  padding: 6px 12px;
  border-radius: 6px;
}
.user-switcher select {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
}

main { max-width: 1100px; margin: auto; padding: 40px 24px 70px; min-height: 75vh; }

.hero {
  padding: 62px 34px;
  background: #e8ded0;
  border-radius: 12px;
  margin-bottom: 52px;
}
.eyebrow { color: var(--accent); letter-spacing: 3px; font-size: 10px; font-weight: 700; }
.hero h1 { font: 600 clamp(38px, 6vw, 65px)/1.15 'Playfair Display', serif; margin: 18px 0; }
.hero > p:not(.eyebrow):not(.hint) { color: #78695d; }

.upload-button {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 13px 20px;
  border-radius: 5px;
  margin-top: 18px;
  cursor: pointer;
}
.upload-button input { display: none; }
.hint { color: var(--muted); font-size: 11px; margin-top: 12px; }

.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 22px; }
h2 { font: 600 32px 'Playfair Display', serif; margin: 8px 0 0; }
#photo-count { color: var(--muted); font-size: 12px; padding-bottom: 5px; }

/* -------------------------------------------------------------------------- */
/* 照片網格：強制 3 個一行 */
/* -------------------------------------------------------------------------- */
.photo-grid {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 3px !important;
}

.photo-card {
  position: relative;
}

.photo-card img {
  width: 100% !important;
  height: 140px !important;
  object-fit: cover !important;
  display: block !important;
  border-radius: 4px;
}

@media (min-width: 768px) {
  .photo-grid {
    gap: 6px !important;
  }
  .photo-card img {
    height: 280px !important;
  }
}

.photo-info h3,
.photo-info p,
.photo-info {
  display: none !important;
}

/* 卡片互動按鈕（愛心與刪除） */
.card-actions {
  position: absolute !important;
  top: 10px !important;
  right: 10px !important;
  background: rgba(0, 0, 0, 0.6) !important;
  backdrop-filter: blur(4px);
  padding: 4px 8px !important;
  border-radius: 20px !important;
  display: flex !important;
  gap: 8px !important;
  align-items: center !important;
  z-index: 20 !important;
  pointer-events: auto !important;
}

.like-button, .delete-button {
  border: 0 !important;
  background: transparent !important;
  cursor: pointer !important;
  font-size: 13px !important;
  color: #fff !important;
  padding: 2px !important;
}
.like-button.liked { color: #ff4757 !important; }
.delete-button { opacity: 0.8; }
.delete-button:hover { opacity: 1; }

/* 批次選取 Checkbox 樣式 */
.photo-card.selectable { cursor: pointer; }
.photo-card.selectable input.select-box { display: none; }

.photo-card.selectable::after {
  content: "✓";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid #ffffff;
  border-radius: 50%;
  color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 12px;
  transition: all 0.2s ease;
  z-index: 10;
}

.photo-card.selectable input.select-box:not(:checked) ~ img {
  opacity: 0.4;
  filter: grayscale(40%);
}
.photo-card.selectable input.select-box:checked ~ img {
  opacity: 1;
  filter: none;
}
.photo-card.selectable:has(input.select-box:checked)::after {
  background: var(--accent);
  border-color: #ffffff;
  color: #ffffff;
}

/* -------------------------------------------------------------------------- */
/* 燈箱 Modal 樣式 */
/* -------------------------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(69, 56, 47, 0.92);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}
.lightbox.hidden { display: none !important; }

.lightbox-content {
  max-width: 90vw;
  max-height: 90vh;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.lightbox-info {
  color: var(--paper);
  margin-top: 15px;
  display: flex !important;
  gap: 15px;
  justify-content: center !important;
  align-items: center;
}
.lightbox-info .like-button,
.lightbox-info .delete-button {
  background: rgba(244, 239, 229, 0.15);
  border: none;
  color: var(--paper);
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
.lightbox-info .like-button.liked {
  color: #ff4757 !important;
  background: rgba(255, 71, 87, 0.2);
}
.lightbox-info h3,
.lightbox-info p { display: none !important; }

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 30px;
  background: none;
  border: none;
  color: var(--paper);
  font-size: 2.5rem;
  cursor: pointer;
  z-index: 1150;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: none;
  font-size: 1.8rem;
  padding: 15px 12px;
  cursor: pointer;
  border-radius: 8px;
  z-index: 1100;
}
.lightbox-nav:hover { background: rgba(0, 0, 0, 0.8); }
.lightbox-nav.prev { left: 15px; }
.lightbox-nav.next { right: 15px; }

.btn-download {
  background: var(--paper);
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
}

/* -------------------------------------------------------------------------- */
/* 批次操作浮動工具列與手機響應式優化 */
/* -------------------------------------------------------------------------- */
.batch-bar {
  position: fixed;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 12px 20px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  z-index: 900;
}
.batch-bar.hidden { display: none !important; }
.batch-actions { display: flex; gap: 8px; align-items: center; }
.btn-danger { background: #c0392b; color: white; border: none; padding: 7px 14px; border-radius: 4px; cursor: pointer; font: inherit; font-size: 13px; }
.btn-secondary { background: #78695d; color: white; border: none; padding: 7px 14px; border-radius: 4px; cursor: pointer; font: inherit; font-size: 13px; }
.btn-text { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 14px; padding: 4px 8px; }
.btn-text:hover { color: var(--accent); }

@media (max-width: 600px) {
  .batch-bar {
    width: 92vw !important;
    bottom: 15px !important;
    padding: 10px 14px !important;
    border-radius: 16px !important;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px !important;
  }
  #batch-count {
    font-size: 13px !important;
    font-weight: 500;
  }
  .batch-actions {
    display: flex !important;
    width: 100% !important;
    gap: 4px !important;
  }
  .batch-actions button,
  .batch-actions .btn-secondary,
  .batch-actions .btn-danger,
  .batch-actions .btn-text {
    flex: 1 !important;
    padding: 6px 4px !important;
    font-size: 11px !important;
    text-align: center !important;
    white-space: nowrap !important;
    background: rgba(244, 239, 229, 0.15) !important;
    border: 1px solid rgba(244, 239, 229, 0.3) !important;
    color: var(--paper) !important;
    border-radius: 6px !important;
  }
  .batch-actions .btn-danger {
    background: #c0392b !important;
    border: none !important;
  }
}

.batch-toggle-btn {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.batch-toggle-btn:hover { background: #e8ded0; border-color: var(--muted); }
.batch-toggle-btn.active-mode { background: var(--accent); color: white; border-color: var(--accent); }

.bucket-card { background: var(--card); border-radius: 10px; padding: 25px; max-width: 650px; margin-top: 25px; }
.bucket-card h3 { font: 600 22px 'Playfair Display', serif; }
.bucket-card li { padding: 9px 0; color: #75685d; }
.empty { text-align: center; color: var(--muted); padding: 45px 10px; }
.hidden { display: none !important; }

footer { text-align: center; padding: 28px; color: var(--muted); border-top: 1px solid var(--line); font-size: 12px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 11px 17px;
  border-radius: 5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  font-size: 13px;
  max-width: 90vw;
  z-index: 1200;
}
.toast.show { opacity: 1; }

@media(max-width: 600px) {
  header { padding: 16px; flex-direction: column; gap: 12px; }
  main { padding: 25px 16px 50px; }
  .hero { padding: 40px 22px; }
  .section-heading { align-items: start; flex-direction: column; gap: 8px; }
}

/* -------------------------------------------------------------------------- */
/* 塔羅牌專屬樣式：完美支援手機等比例縮放與置中 */
/* -------------------------------------------------------------------------- */
.tarot-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start; /* 🌟 讓內容從上方開始排，不要被往下拉 */
  min-height: auto;
  padding: 30px 0 20px 0; /* 縮減上下距離 */
  text-align: center;
  overflow: visible; /* 確保不被裁切 */
  width: 100%;
}

.tarot-deck {
  position: relative;
  width: 100%;
  max-width: 650px;
  height: 220px; /* 給予足夠高度讓整張牌站立 */
  display: flex;
  justify-content: center;
  align-items: center; /* 🌟 改成置中，讓卡片完整浮現 */
  perspective: 1000px;
  margin-top: 25px; /* 緊貼在文字下方適當距離 */
}

.tarot-card {
  position: absolute;
  left: 50%;
  top: 10px; /* 🌟 讓卡片往上浮，完整露出全身 */
  transform: translateX(-50%) translateX(var(--offset-x, 0px)) rotate(var(--card-angle, 0deg));
  transform-origin: bottom center;
  width: 120px;
  height: 195px;
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.3s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--accent, #d4af37);
}

.card-back {
  width: 90%;
  height: 90%;
  border: 1px dashed var(--ink);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: rgba(244, 239, 229, 0.5);
}

.tarot-card:hover {
  transform: translateX(-50%) translateX(var(--offset-x, 0px)) translateY(-35px) scale(1.08) rotate(0deg) !important;
  box-shadow: 0 20px 35px rgba(212, 175, 55, 0.4);
  z-index: 100;
}

/* 🌟 手機版塔羅牌等比例響應式微調 */
@media screen and (max-width: 600px) {
  .tarot-container {
    width: 100%;
    padding: 10px 10px;
    /* overflow: hidden; 防止超出畫面造成左右晃動 */
  }
  .tarot-deck {
    width: 100%;
    max-width: 100%;
    height: 190px;
    margin-top: 15px;
    overflow: visible; /* 讓左右展開的牌不會被切掉 */
  }
  .tarot-card {
    width: 95px;
    height: 155px;
  }
  
}

/* 抽卡結果燈箱 */
.tarot-modal {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(43, 35, 29, 0.85);
  display: flex; justify-content: center; align-items: center;
  z-index: 9999;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.tarot-modal.show { opacity: 1; pointer-events: auto; }
.tarot-result-card {
  background: var(--card); color: var(--ink);
  padding: 25px; border-radius: 14px; width: 320px; text-align: center;
  box-shadow: 0 15px 40px rgba(0,0,0,0.5);
  transform: scale(0.8); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 2px solid var(--accent, #d4af37);
}
.tarot-modal.show .tarot-result-card { transform: scale(1); }
.tarot-result-card img { width: 100%; height: 210px; object-fit: cover; border-radius: 8px; margin-bottom: 12px; }
.tarot-result-card h3,
.tarot-result-card .tarot-card-title {
  display: none !important;
}