/* ==========================================================================
   Words for Home — Design System & Styles
   Traditional Japanese Art Aesthetic (Sumi-e inspired)
   ========================================================================== */

/* --- Custom Properties & Tokens --- */
:root {
  /* Color Palette (Traditional Washi & Ink tones) */
  --bg-color: #faf7f2;
  --bg-paper-radial: radial-gradient(circle at center, #fdfbf8 0%, #f4eee1 100%);
  --text-ink: #1c1a17;
  --text-ink-muted: #5e574a;
  
  /* Hanko Stamp Red (Traditional Vermilion) */
  --accent-hanko: #c83c28;
  --accent-hanko-hover: #b0301d;
  --accent-hanko-light: rgba(200, 60, 40, 0.08);
  
  /* Borders & Highlights */
  --border-ink-thin: #e3decb;
  --border-ink-bold: #1c1a17;
  --accent-gold: #b38d43;
  --shadow-color: rgba(28, 26, 23, 0.06);

  /* Layout (Wider for 4-column daily grid layout) */
  --max-width: 1200px;

  /* Typography */
  --font-serif: "Noto Serif JP", serif;
  --font-sans: "Noto Sans JP", sans-serif;
  --font-cursive: "Playfair Display", serif;
  --font-brush: "Yuji Syuku", serif;
}

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

html {
  scroll-behavior: smooth;
  height: 100%;
}

body {
  background-color: var(--bg-color);
  /* Washi Paper texture layered over radial gradient */
  background-image: 
    var(--bg-paper-radial),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
  color: var(--text-ink);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Custom ink scrollbar */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(244, 238, 225, 0.5);
  border-left: 1px solid var(--border-ink-thin);
}
::-webkit-scrollbar-thumb {
  background: var(--text-ink-muted);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-ink);
}

/* --- Layout Elements --- */

.scroll-sentinel {
  height: 0;
  width: 0;
  visibility: hidden;
  position: absolute;
  top: 0;
}

/* Sticky Header */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 100;
  /* Glassmorphism reflecting ink-soaked paper */
  background-color: rgba(250, 247, 242, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-ink-thin);
  box-shadow: 0 4px 20px var(--shadow-color);
  transition: padding 0.3s ease, border-color 0.3s ease;
}

/* Subtle header double-border effect on scroll */
.sticky-header.scrolled {
  border-bottom: 2px solid var(--border-ink-bold);
  padding-bottom: 4px;
}

.header-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.brand {
  display: flex;
  flex-direction: column;
}

.site-title {
  font-family: var(--font-brush);
  font-size: 1.95rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.25;
}

.site-subtitle {
  font-family: var(--font-serif);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-ink-muted);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 24px;
}

/* Language Switcher Selector */
.lang-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-serif);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-ink-muted);
  border: 1px solid var(--border-ink-thin);
  padding: 4px 10px;
  background-color: rgba(255, 255, 255, 0.4);
  border-radius: 1px;
}

.btn-lang {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-ink-muted);
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  padding: 2px 6px;
  outline: none;
  transition: color 0.2s, text-shadow 0.2s;
}

.btn-lang:hover {
  color: var(--text-ink);
}

.btn-lang.active {
  color: var(--accent-hanko);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
  font-weight: 900;
}

.lang-divider {
  color: var(--border-ink-thin);
  user-select: none;
}

/* Progress indicator */
.progress-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.progress-label {
  font-family: var(--font-serif);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-ink-muted);
  letter-spacing: 0.05em;
}

.progress-bar-container {
  width: 90px;
  height: 4px;
  background: var(--border-ink-thin);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent-hanko);
  border-radius: 2px;
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Stamps Group */
.stamps-group {
  display: flex;
  gap: 12px;
}

/* Hanko Seal Button with Dual-State (Kanji -> English on Hover) */
.btn-stamp {
  position: relative;
  width: 48px;
  height: 48px;
  border: none;
  background: transparent;
  cursor: pointer;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.stamp-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  background-color: var(--accent-hanko);
  border: 2px double rgba(250, 247, 242, 0.8);
  box-shadow: 0 0 0 2px var(--accent-hanko), 0 4px 8px var(--shadow-color);
  transition: background-color 0.25s ease;
}

.stamp-text-kanji,
.stamp-text-english {
  position: absolute;
  z-index: 2;
  font-family: var(--font-serif);
  font-weight: 900;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

/* Vertical Kanji text by default */
.stamp-text-kanji {
  font-size: 0.85rem;
  color: #faf7f2;
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0.05em;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  top: 50%;
  left: 50%;
}

/* Horizontal English text hidden on default */
.stamp-text-english {
  font-family: var(--font-cursive);
  font-size: 0.65rem;
  color: #faf7f2;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  letter-spacing: 0px;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.7);
  top: 50%;
  left: 50%;
}

/* Hover State - Swapping Texts */
.btn-stamp:hover {
  transform: scale(1.08) rotate(5deg);
}

.btn-stamp:hover .stamp-bg {
  background-color: var(--accent-hanko-hover);
}

.btn-stamp:hover .stamp-text-kanji {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.7);
}

.btn-stamp:hover .stamp-text-english {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.btn-stamp:active {
  transform: scale(0.95) rotate(-2deg);
}

/* --- Manga Feed Container --- */
.manga-feed-container {
  flex: 1;
  width: 100%;
  padding: 40px 24px 80px 24px;
}

/* CSS Grid: 4 columns on desktop */
.manga-feed {
  max-width: var(--max-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 40px 24px;
  position: relative;
}

/* --- Manga Panel Card --- */
.frame-card {
  position: relative;
  z-index: 1;
  background: #ffffff;
  border: 2px solid var(--border-ink-bold);
  border-radius: 1px;
  box-shadow: 5px 5px 0px var(--border-ink-thin);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.frame-card:hover {
  transform: translateY(-4px);
  box-shadow: 7px 7px 0px var(--text-ink-muted);
}

/* Card Header (Meta Info) */
.frame-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-ink-thin);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fafcfb;
}

/* Panel count badge styled as mini Hanko */
.frame-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-serif);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-hanko);
  border: 1px solid var(--accent-hanko);
  padding: 2px 6px;
  background-color: var(--accent-hanko-light);
  border-radius: 1px;
}

.frame-date {
  font-family: var(--font-serif);
  font-size: 0.7rem;
  color: var(--text-ink-muted);
  letter-spacing: 0.05em;
}

/* Image Container */
.frame-image-wrapper {
  width: 100%;
  position: relative;
  background-color: #fcfbf9;
  /* Maintain layout while loading */
  aspect-ratio: 1 / 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.frame-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Once fully loaded, fade in */
.frame-image.loaded {
  opacity: 1;
}

.frame-image-wrapper.loading::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(244, 238, 225, 0.6),
    transparent
  );
  animation: loading-shimmer 1.8s infinite;
}

@keyframes loading-shimmer {
  100% {
    left: 100%;
  }
}

/* Card Caption */
.frame-caption {
  padding: 16px 18px;
  background-color: #ffffff;
  border-top: 1px solid var(--border-ink-thin);
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.frame-caption-text {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-ink);
  line-height: 1.6;
  letter-spacing: 0.02em;
  text-align: justify;
}

/* Sub-decorative touch at the bottom of the caption */
.frame-caption::after {
  content: "✦";
  display: block;
  text-align: center;
  margin-top: 8px;
  color: var(--border-ink-thin);
  font-size: 0.75rem;
}

/* --- Loading States & Indicators --- */
.loading-state {
  grid-column: 1 / -1; /* Stretch loader across all columns */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 16px;
  text-align: center;
}

.loading-brush {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-ink-thin);
  border-top-color: var(--accent-hanko);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

.loading-text {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  color: var(--text-ink-muted);
  letter-spacing: 0.1em;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* --- Footer --- */
.manga-footer {
  background-color: rgba(28, 26, 23, 0.98);
  /* Layer washi noise on dark footer background */
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.08'/%3E%3C/svg%3E");
  color: #eae3d2;
  border-top: 4px solid var(--accent-gold);
  padding: 48px 24px;
  text-align: center;
}

.footer-content {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.footer-copyright {
  font-family: var(--font-serif);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.footer-desc {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  line-height: 1.7;
  max-width: 500px;
  opacity: 0.6;
}

/* Red Stamp for the Footer (Functional Scroll-to-Top Button) */
.hanko-seal {
  background: transparent;
  border: 2px solid var(--accent-hanko);
  border-radius: 3px;
  transform: rotate(-5deg);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
  outline: none;
  padding: 0;
  margin-top: 16px;
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.25s ease;
}

.hanko-seal::before {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border: 1px solid var(--accent-hanko);
  border-radius: 4px;
  opacity: 0.4;
}

.seal-inner {
  font-family: var(--font-serif);
  font-size: 0.75rem;
  font-weight: 900;
  color: var(--accent-hanko);
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0.1em;
  line-height: 1.1;
  padding: 2px;
}

.hanko-seal:hover {
  transform: scale(1.1) rotate(2deg);
  box-shadow: 0 4px 10px rgba(200, 60, 40, 0.2);
}

.hanko-seal:active {
  transform: scale(0.95) rotate(-5deg);
}

/* --- Media Queries (Responsiveness) --- */

/* Tablets & Medium Viewports */
@media (max-width: 1000px) {
  .manga-feed {
    grid-template-columns: repeat(2, 1fr);
    gap: 32px 20px;
  }
}

/* Mobile Devices */
@media (max-width: 600px) {
  .header-content {
    padding: 12px 16px;
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
    gap: 12px;
  }
  
  .brand {
    width: 100%;
    align-items: center;
  }
  
  .site-title {
    font-size: 1.6rem;
  }
  
  .site-subtitle {
    font-size: 0.72rem;
  }
  
  .header-controls {
    width: 100%;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid var(--border-ink-thin);
    gap: 8px;
  }

  .progress-badge {
    align-items: flex-start;
  }

  .progress-bar-container {
    width: 100px;
  }

  .manga-feed-container {
    padding: 24px 12px 60px 12px;
  }

  /* Stack panels vertically on mobile */
  .manga-feed {
    grid-template-columns: 1fr;
    gap: 28px 0;
  }

  .frame-card {
    box-shadow: 4px 4px 0px var(--border-ink-thin);
  }

  .frame-caption {
    padding: 16px 20px;
  }

  .frame-caption-text {
    font-size: 0.95rem;
  }
}
