:root {
  --duration: 0.6s;
  --book-w: min(350px, 45vw);
  --book-h: min(500px, 70vh);
  --font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  --line-height: clamp(24px, 4vw, 30px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  font-family: "Kalam", cursive;
  overflow-x: hidden;
  padding: 10px;
}

/* ===== HEADER & CONTROLS ===== */
.header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px 15px;
  border-radius: 15px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
  margin-bottom: 10px;
  max-width: 95vw;
}

.month-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.month-selector select,
.month-selector input {
  padding: 8px 10px;
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  border: 2px solid #667eea;
  border-radius: 8px;
  font-family: "Kalam", cursive;
  cursor: pointer;
  max-width: 120px;
}

.month-selector select:focus,
.month-selector input:focus {
  outline: none;
  border-color: #764ba2;
}

.current-btn {
  padding: 8px 15px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: clamp(0.8rem, 2.5vw, 1rem);
  font-family: "Kalam", cursive;
  transition: transform 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}

.current-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

/* ===== ARCHIVE BADGE ===== */
.archive-badge {
  background: #ff6b6b;
  color: white;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  display: none;
}

.archive-badge.visible {
  display: inline-block;
}

/* ===== INDICATORS ===== */
.indicators {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  justify-content: center;
}

.page-indicator,
.date-indicator {
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

/* ===== BOOK CONTAINER ===== */
.book-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: var(--book-h);
  width: 100%;
  padding: 0 50px;
}

.book {
  position: relative;
  width: var(--book-w);
  height: var(--book-h);
  transition: transform 0.5s;
}

/* ===== PAPER & PAGES ===== */
.paper {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  perspective: 1500px;
}

.content {
  position: absolute;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--duration) cubic-bezier(0.25, 1, 0.5, 1);
  transform-origin: left top;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  border-radius: 5px;
}

.front,
.back {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: #fdfbf7;
  backface-visibility: hidden;
  padding: 15px 15px 40px 35px;

  background-image: linear-gradient(
      90deg,
      transparent 29px,
      #ff9999 29px,
      #ff9999 31px,
      transparent 31px
    ),
    linear-gradient(#e1e1e1 1px, transparent 1px);
  background-size: 100% 100%, 100% var(--line-height);
}

.back {
  transform: rotateY(180deg);
  padding: 15px 35px 40px 15px;
  background-image: linear-gradient(
      90deg,
      transparent calc(100% - 31px),
      #ff9999 calc(100% - 31px),
      #ff9999 calc(100% - 29px),
      transparent calc(100% - 29px)
    ),
    linear-gradient(#e1e1e1 1px, transparent 1px);
}

.flipped .content {
  transform: rotateY(-180deg);
}

/* ===== COVERS ===== */
.front-cover {
  background: var(--cover-color, #2c3e50) !important;
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 3px solid rgba(255, 255, 255, 0.3);
  background-image: none !important;
  text-align: center;
}

.front-cover h2 {
  border: 2px solid rgba(255, 255, 255, 0.5);
  padding: 10px 20px;
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.5rem);
}

.front-cover .year {
  margin-top: 10px;
  font-size: clamp(1rem, 3vw, 1.2rem);
  opacity: 0.8;
}

.back-cover {
  background: var(--cover-color, #2c3e50) !important;
  background-image: none !important;
}

/* ===== PAGE CONTENT ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 5px;
  border-bottom: 1px dashed #ccc;
  flex-wrap: wrap;
  gap: 5px;
}

.page-date {
  font-size: clamp(0.75rem, 2.5vw, 0.95rem);
  color: #666;
  font-weight: bold;
}

.page-day {
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  color: #888;
  text-transform: capitalize;
}

.page-number {
  position: absolute;
  bottom: 10px;
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  color: #666;
}

.front .page-number {
  right: 15px;
}

.back .page-number {
  left: 15px;
}

/* ===== TEXTAREA ===== */
textarea {
  width: 100%;
  height: calc(100% - 40px);
  background: transparent;
  border: none;
  resize: none;
  font-family: "Kalam", cursive;
  font-size: var(--font-size);
  line-height: var(--line-height);
  outline: none;
  color: #333;
  overflow: hidden;
}

textarea:disabled {
  color: #333;
  cursor: default;
}

/* ===== NAVIGATION BUTTONS ===== */
.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: clamp(10px, 3vw, 15px);
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  font-size: clamp(1rem, 3vw, 1.2rem);
  transition: all 0.2s;
  z-index: 100;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  width: clamp(40px, 10vw, 50px);
  height: clamp(40px, 10vw, 50px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn:hover:not(:disabled) {
  background: white;
  transform: translateY(-50%) scale(1.1);
}

.nav-btn.next {
  right: 5px;
}

.nav-btn.prev {
  left: 5px;
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ===== ARCHIVES PANEL ===== */
.archives-panel {
  position: fixed;
  top: 0;
  right: -100%;
  width: min(350px, 90vw);
  height: 100%;
  background: white;
  box-shadow: -5px 0 20px rgba(0, 0, 0, 0.2);
  transition: right 0.3s ease;
  z-index: 1000;
  overflow-y: auto;
}

.archives-panel.open {
  right: 0;
}

.archives-header {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
}

.archives-header h3 {
  margin: 0;
  font-size: clamp(1rem, 3vw, 1.2rem);
}

.close-archives {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 5px 10px;
}

.archives-list {
  padding: 15px;
}

.archive-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  margin-bottom: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.archive-item:hover {
  background: #e9ecef;
  transform: translateX(-5px);
}

.archive-item.current {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.archive-item .month-name {
  font-weight: bold;
  font-size: clamp(0.9rem, 2.5vw, 1rem);
}

.archive-item .entries-count {
  font-size: clamp(0.75rem, 2vw, 0.85rem);
  opacity: 0.7;
}

.toggle-archives {
  position: fixed;
  top: 10px;
  right: 10px;
  padding: 10px 15px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-family: "Kalam", cursive;
  font-size: clamp(0.8rem, 2.5vw, 1rem);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  z-index: 500;
  transition: all 0.2s;
}

.toggle-archives:hover {
  transform: scale(1.05);
}

/* ===== MONTH COLORS ===== */
.month-1 {
  --cover-color: #3498db;
}
.month-2 {
  --cover-color: #e91e63;
}
.month-3 {
  --cover-color: #4caf50;
}
.month-4 {
  --cover-color: #ff9800;
}
.month-5 {
  --cover-color: #9c27b0;
}
.month-6 {
  --cover-color: #00bcd4;
}
.month-7 {
  --cover-color: #f44336;
}
.month-8 {
  --cover-color: #ff5722;
}
.month-9 {
  --cover-color: #795548;
}
.month-10 {
  --cover-color: #607d8b;
}
.month-11 {
  --cover-color: #673ab7;
}
.month-12 {
  --cover-color: #1a237e;
}

/* ===== RESPONSIVE - TABLET ===== */
@media (max-width: 768px) {
  :root {
    --book-w: min(300px, 42vw);
    --book-h: min(420px, 60vh);
  }

  body {
    padding: 5px;
  }

  .header {
    padding: 8px 12px;
    gap: 8px;
  }

  .book-container {
    padding: 0 45px;
  }

  .front,
  .back {
    padding: 12px 12px 35px 30px;
    background-image: linear-gradient(
        90deg,
        transparent 24px,
        #ff9999 24px,
        #ff9999 26px,
        transparent 26px
      ),
      linear-gradient(#e1e1e1 1px, transparent 1px);
  }

  .back {
    padding: 12px 30px 35px 12px;
    background-image: linear-gradient(
        90deg,
        transparent calc(100% - 26px),
        #ff9999 calc(100% - 26px),
        #ff9999 calc(100% - 24px),
        transparent calc(100% - 24px)
      ),
      linear-gradient(#e1e1e1 1px, transparent 1px);
  }
}

/* ===== RESPONSIVE - MOBILE ===== */
@media (max-width: 480px) {
  :root {
    --book-w: min(280px, 80vw);
    --book-h: min(380px, 55vh);
    --font-size: 0.85rem;
    --line-height: 22px;
  }

  .header {
    flex-direction: column;
    padding: 10px;
  }

  .month-selector {
    width: 100%;
    justify-content: center;
  }

  .month-selector select {
    flex: 1;
    max-width: none;
  }

  .month-selector input {
    width: 70px;
  }

  .current-btn {
    width: 100%;
  }

  .book-container {
    padding: 0 40px;
    min-height: calc(var(--book-h) + 20px);
  }

  .nav-btn {
    width: 35px;
    height: 35px;
    padding: 8px;
  }

  .nav-btn.next {
    right: 2px;
  }

  .nav-btn.prev {
    left: 2px;
  }

  .front,
  .back {
    padding: 10px 10px 30px 25px;
    background-image: linear-gradient(
        90deg,
        transparent 19px,
        #ff9999 19px,
        #ff9999 21px,
        transparent 21px
      ),
      linear-gradient(#e1e1e1 1px, transparent 1px);
  }

  .back {
    padding: 10px 25px 30px 10px;
    background-image: linear-gradient(
        90deg,
        transparent calc(100% - 21px),
        #ff9999 calc(100% - 21px),
        #ff9999 calc(100% - 19px),
        transparent calc(100% - 19px)
      ),
      linear-gradient(#e1e1e1 1px, transparent 1px);
  }

  .toggle-archives {
    padding: 8px 12px;
    top: 5px;
    right: 5px;
  }

  .indicators {
    gap: 5px;
  }

  .page-indicator,
  .date-indicator {
    padding: 5px 10px;
  }
}

/* ===== RESPONSIVE - VERY SMALL SCREENS ===== */
@media (max-width: 360px) {
  :root {
    --book-w: 85vw;
    --book-h: 50vh;
    --font-size: 0.8rem;
    --line-height: 20px;
  }

  .book-container {
    padding: 0 35px;
  }

  .nav-btn {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
  }
}

/* ===== LANDSCAPE MODE ===== */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --book-w: min(250px, 30vw);
    --book-h: min(320px, 80vh);
    --font-size: 0.8rem;
    --line-height: 20px;
  }

  body {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 5px;
  }

  .header {
    width: auto;
    margin-bottom: 5px;
  }

  .indicators {
    margin-bottom: 5px;
  }

  .book-container {
    min-height: auto;
  }

  .toggle-archives {
    top: 5px;
    right: 5px;
    padding: 5px 10px;
    font-size: 0.8rem;
  }
}
