/* ===== Design Tokens ===== */
:root {
  --bg-top: #FFFDF7;
  --bg-bottom: #FFF8E7;
  --accent-gold: #D4AF37;
  --text-primary: #333;
  --text-secondary: #807366;
  --font-serif: 'Cormorant Garamond', 'Georgia', serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --max-width: 480px;
  --radius-lg: 20px;
}

/* ===== Hidden attribute must win over display rules ===== */
[hidden] { display: none !important; }

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--text-primary);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* ===== App Shell ===== */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 4px;
}

/* ===== Date Header ===== */
.date-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
}

.header-icon {
  color: var(--accent-gold);
  width: 32px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.date-nav {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.nav-arrow {
  color: var(--accent-gold);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.nav-arrow:disabled,
.nav-arrow[disabled] {
  opacity: 0.25;
  pointer-events: none;
}

.date-display {
  text-align: center;
  min-width: 160px;
}

.day-of-week {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.date-text {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2px;
}

/* ===== Content Area ===== */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 16px;
  touch-action: pan-y;
}

/* ===== Loading Skeleton ===== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 20px 0;
  gap: 20px;
}

.skeleton {
  background: linear-gradient(90deg, #f0ead6 25%, #faf5e4 50%, #f0ead6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite ease-in-out;
  border-radius: 12px;
}

.skeleton-image {
  width: 100%;
  height: 300px;
  border-radius: var(--radius-lg);
}

.skeleton-text {
  width: 80%;
  height: 16px;
}

.skeleton-text.short { width: 60%; }
.skeleton-text.shorter { width: 40%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== Error State ===== */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px 40px;
  gap: 16px;
  text-align: center;
}

.error-icon { color: var(--accent-gold); opacity: 0.6; }

.error-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
}

.error-message {
  font-size: 13px;
  color: var(--text-secondary);
}

.btn-retry {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--accent-gold);
  padding: 10px 28px;
  border-radius: 50px;
  margin-top: 8px;
  transition: opacity 0.15s;
}

.btn-retry:active { opacity: 0.8; }

/* ===== Quote View ===== */
.quote-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
  gap: 24px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Image */
.image-container {
  position: relative;
  width: calc(100% - 40px);
}

.quote-image {
  width: 100%;
  height: 300px;
  object-fit: cover;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(212, 175, 55, 0.2);
  background: linear-gradient(135deg, rgba(135,180,220,0.3), rgba(212,175,55,0.2));
}

/* Like Button */
.like-button {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-gold);
  opacity: 0.7;
  transition: transform 0.15s, opacity 0.15s;
}

.like-button.liked {
  opacity: 1;
}

.like-button.liked svg {
  fill: var(--accent-gold);
  stroke: var(--accent-gold);
}

.like-button:active { transform: scale(0.92); }

@keyframes heartBounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.3); }
  60% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

.like-button.bounce {
  animation: heartBounce 0.4s ease;
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  gap: 8px;
}

.divider-line {
  display: block;
  width: 24px;
  height: 1px;
  background: var(--accent-gold);
  opacity: 0.3;
}

.divider-dot {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-gold);
  opacity: 0.5;
}

/* Quote Text */
.quote-text {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 400;
  font-style: italic;
  line-height: 1.65;
  text-align: center;
  color: var(--text-primary);
  padding: 0 32px;
  border: none;
}

/* Attribution */
.attribution {
  text-align: center;
}

.book {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.section {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-secondary);
  opacity: 0.8;
  margin-top: 4px;
  font-variant: small-caps;
}

/* ===== Footer ===== */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 24px 12px;
}

.handle {
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.5;
}

.privacy-link {
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.5;
  transition: opacity 0.15s;
}

.privacy-link:hover { opacity: 0.8; }

/* ===== Overlay Common ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.overlay[hidden] { display: none !important; }

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  animation: fadeInBackdrop 0.2s ease;
}

@keyframes fadeInBackdrop {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-sheet {
  position: relative;
  z-index: 1;
  background: var(--bg-top);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.overlay-header {
  display: flex;
  align-items: center;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(212, 175, 55, 0.15);
  gap: 8px;
}

.overlay-title {
  flex: 1;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  color: var(--text-primary);
}

.btn-done {
  color: var(--accent-gold);
  font-size: 16px;
  font-weight: 500;
  padding: 4px 8px;
}

/* ===== Calendar ===== */
.calendar-sheet {
  max-height: 80dvh;
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 8px 12px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 4px 12px 20px;
  overflow-y: auto;
}

.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.1s;
}

.cal-cell:active { transform: scale(0.95); }

.cal-cell.empty {
  cursor: default;
  pointer-events: none;
}

.cal-cell .cal-thumb {
  position: absolute;
  inset: 2px;
  border-radius: 10px;
  object-fit: cover;
  z-index: 0;
}

.cal-cell .cal-day {
  position: relative;
  z-index: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-shadow: 0 1px 3px rgba(255,255,255,0.8);
}

.cal-cell.has-thumb .cal-day {
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.cal-cell.current {
  outline: 2px solid var(--accent-gold);
  outline-offset: -2px;
}

.cal-cell.today {
  background: var(--accent-gold);
}

.cal-cell.today .cal-day {
  color: #fff;
}

.cal-cell .cal-heart {
  position: absolute;
  bottom: 2px;
  right: 3px;
  z-index: 2;
  font-size: 8px;
  color: var(--accent-gold);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
}

/* ===== Liked Quotes ===== */
.liked-sheet {
  max-height: 80dvh;
}

.liked-list {
  overflow-y: auto;
  padding: 8px 16px 20px;
}

.liked-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(212, 175, 55, 0.1);
  cursor: pointer;
  transition: opacity 0.15s;
}

.liked-item:active { opacity: 0.7; }

.liked-thumb {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.liked-info {
  flex: 1;
  min-width: 0;
}

.liked-date {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.liked-excerpt {
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.liked-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  gap: 12px;
  color: var(--text-secondary);
  text-align: center;
}

.liked-empty-hint {
  font-size: 13px;
  opacity: 0.7;
}

/* ===== Privacy Page ===== */
.privacy-page {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 24px 40px;
}

.privacy-page[hidden] { display: none !important; }

.privacy-header {
  padding: 12px 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent-gold);
  font-size: 16px;
  font-weight: 500;
}

.privacy-content h1 {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.privacy-content h2 {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 28px;
  margin-bottom: 8px;
}

.privacy-content p,
.privacy-content li {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.privacy-content ul {
  padding-left: 20px;
}

.privacy-content strong {
  color: var(--text-primary);
}

/* ===== Reader Page ===== */
.reader-page {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 24px 40px;
}

.reader-page[hidden] { display: none !important; }

.reader-heading {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 600;
  color: var(--accent-gold);
  margin-bottom: 4px;
}

.reader-section-num {
  font-family: var(--font-ui);
  font-size: 14px;
  font-variant: small-caps;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.reader-section {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 400;
  line-height: 1.75;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.reader-unavailable {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.reader-unavailable p:first-child {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 8px;
}

.reader-unavailable-hint {
  font-size: 13px;
  opacity: 0.7;
}

/* Attribution link */
.attribution-link {
  text-decoration: none;
  color: inherit;
  transition: opacity 0.15s;
  cursor: pointer;
}

.attribution-link:hover {
  opacity: 0.7;
}

.attribution-link .section {
  text-decoration: underline;
  text-decoration-color: var(--accent-gold);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

/* ===== Tablet / Desktop adjustments ===== */
@media (min-width: 600px) {
  .app {
    max-width: 560px;
  }

  .quote-image {
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .skeleton-image {
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .overlay {
    align-items: center;
  }

  .overlay-sheet {
    border-radius: 20px;
    max-height: 70vh;
    margin: 20px;
  }
}

/* ===== Safe area for mobile ===== */
@supports (padding: env(safe-area-inset-bottom)) {
  .footer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .overlay-sheet {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
