/* ═══════════════════════════════════════════════════════════════
   MY DIARY — Physical Leather Diary PWA Styles
   A beautiful, tactile digital diary experience
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ── */
:root {
  /* Leather & Paper */
  --leather-dark: #1a0f0a;
  --leather-mid: #2c1810;
  --leather-light: #3d2317;
  --leather-accent: #5a3a2a;
  --gold: #DAA520;
  --gold-light: #f0d060;
  --gold-dim: #8B6914;
  --paper: #faf6e9;
  --paper-aged: #f0e8d0;
  --paper-line: rgba(100, 130, 180, 0.15);
  --paper-shadow: rgba(60, 40, 20, 0.12);
  --ink: #1a1a2e;
  --ink-light: #3a3a5e;
  --ink-faded: rgba(26, 26, 46, 0.6);
  --red-ribbon: #c0392b;
  --blue-ribbon: #2980b9;
  --green-ribbon: #27ae60;
  --purple-ribbon: #8e44ad;
  --orange-ribbon: #e67e22;

  /* Spacing */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 64px;
  --top-bar-height: 56px;

  /* Typography */
  --font-diary: 'Georgia', 'Palatino Linotype', 'Book Antiqua', serif;
  --font-handwritten: 'Segoe Script', 'Comic Sans MS', 'Apple Chancery', cursive;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-size-base: 15px;

  /* Transitions */
  --ease-page: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Z-indices */
  --z-page: 1;
  --z-nav: 100;
  --z-modal: 200;
  --z-lightbox: 300;
  --z-toast: 400;
  --z-loading: 500;
}

/* Dark mode */
[data-theme="dark"] {
  --paper: #2a2520;
  --paper-aged: #231e1a;
  --paper-line: rgba(180, 160, 120, 0.1);
  --paper-shadow: rgba(0, 0, 0, 0.3);
  --ink: #e8dcc8;
  --ink-light: #c8b8a0;
  --ink-faded: rgba(232, 220, 200, 0.6);
}

/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  height: 100%;
}

body {
  font-family: var(--font-diary);
  background: var(--leather-dark);
  color: var(--ink);
  height: 100%;
  overflow: hidden;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ═══════════════════════════════════════════════════════════════
   LOADING SCREEN — Wax Seal Animation
   ═══════════════════════════════════════════════════════════════ */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--leather-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-loading);
  transition: opacity 0.8s ease, visibility 0.8s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
}

.wax-seal {
  width: 120px;
  height: 120px;
  position: relative;
  animation: seal-pulse 2s ease-in-out infinite;
}

.seal-outer {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 40% 35%, #d44040, #8b1a1a 60%, #5a0f0f);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 20px rgba(139, 26, 26, 0.5),
    inset 0 2px 4px rgba(255, 200, 200, 0.3),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
}

.seal-outer::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 2px solid rgba(255, 200, 200, 0.2);
  border-radius: 50%;
}

.seal-inner {
  width: 70px;
  height: 70px;
  background: radial-gradient(circle at 40% 35%, #e05050, #a02020);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 4px rgba(255, 200, 200, 0.3);
}

.seal-letter {
  font-family: var(--font-diary);
  font-size: 2.5rem;
  font-weight: bold;
  color: rgba(255, 220, 200, 0.8);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.seal-crack {
  position: absolute;
  inset: 0;
  background: var(--leather-dark);
  clip-path: polygon(48% 0%, 52% 0%, 55% 45%, 100% 50%, 55% 55%, 52% 100%, 48% 100%, 45% 55%, 0% 50%, 45% 45%);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.loading-screen.breaking .seal-crack {
  opacity: 1;
  animation: crack-spread 0.8s ease-out forwards;
}

.loading-screen.breaking .seal-outer {
  animation: seal-break 0.8s ease-out forwards;
}

@keyframes seal-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes crack-spread {
  0% { clip-path: polygon(49% 49%, 51% 49%, 51% 51%, 49% 51%); opacity: 1; }
  100% { clip-path: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%); opacity: 1; }
}

@keyframes seal-break {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); }
  100% { transform: scale(0.3); opacity: 0; }
}

.loading-text {
  margin-top: 2rem;
  color: var(--gold);
  font-family: var(--font-diary);
  font-size: 1.1rem;
  font-style: italic;
  opacity: 0.8;
  animation: text-fade 1.5s ease-in-out infinite;
}

@keyframes text-fade {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════
   DIARY COVER
   ═══════════════════════════════════════════════════════════════ */
.diary-cover {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: calc(var(--z-loading) - 1);
  cursor: pointer;
  perspective: 1200px;
}

.cover-texture {
  width: min(90vw, 420px);
  height: min(85vh, 600px);
  background:
    repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 4px),
    linear-gradient(135deg, #3d2317 0%, #2c1810 30%, #1a0f0a 60%, #2c1810 100%);
  border-radius: 4px 12px 12px 4px;
  position: relative;
  box-shadow:
    -4px 0 8px rgba(0,0,0,0.3),
    0 8px 32px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.05),
    inset 0 -1px 0 rgba(0,0,0,0.3);
  transition: transform 0.6s var(--ease-page);
  transform-origin: left center;
}

.cover-texture:active {
  transform: rotateY(-5deg);
}

/* Spine */
.cover-texture::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 20px;
  background: linear-gradient(90deg, rgba(0,0,0,0.3), transparent);
  border-radius: 4px 0 0 4px;
}

/* Stitching */
.cover-stitching {
  position: absolute;
  inset: 12px;
  border: 2px dashed rgba(218, 165, 32, 0.3);
  border-radius: 2px 8px 8px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.cover-content {
  text-align: center;
  padding: 2rem;
}

.cover-ornament {
  color: var(--gold);
  font-size: 1.2rem;
  letter-spacing: 1em;
  opacity: 0.6;
}

.top-ornament { margin-bottom: 2rem; }
.bottom-ornament { margin-top: 2rem; }

.cover-title {
  font-family: var(--font-diary);
  font-size: 2.8rem;
  color: var(--gold);
  text-shadow:
    0 2px 4px rgba(0,0,0,0.5),
    0 0 20px rgba(218, 165, 32, 0.2);
  letter-spacing: 0.1em;
  font-weight: normal;
  font-variant: small-caps;
}

.cover-subtitle {
  font-family: var(--font-diary);
  font-size: 1rem;
  color: var(--gold-dim);
  font-style: italic;
  margin-top: 0.5rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.cover-year {
  font-family: var(--font-diary);
  font-size: 1.4rem;
  color: var(--gold);
  margin-top: 1.5rem;
  opacity: 0.7;
}

/* Clasp */
.cover-clasp {
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 60px;
  background: linear-gradient(135deg, #c9a84c, #8B6914, #c9a84c);
  border-radius: 0 4px 4px 0;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.4);
}

.cover-clasp::after {
  content: '';
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 20px;
  background: var(--leather-dark);
  border-radius: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   MAIN DIARY APP
   ═══════════════════════════════════════════════════════════════ */
.diary-app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--leather-dark);
  overflow: hidden;
}

/* ── Top Bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  background: linear-gradient(180deg, var(--leather-mid), var(--leather-dark));
  border-bottom: 1px solid rgba(218, 165, 32, 0.15);
  height: var(--top-bar-height);
  flex-shrink: 0;
  z-index: var(--z-nav);
}

.top-btn {
  background: none;
  border: none;
  color: var(--gold);
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-btn:active {
  background: rgba(218, 165, 32, 0.15);
}

.date-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.day-name {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--gold-dim);
}

.day-date {
  font-family: var(--font-diary);
  font-size: 1rem;
  color: var(--gold);
  font-weight: 600;
}

.top-right-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

.streak-badge {
  font-size: 0.8rem;
  color: var(--gold);
  background: rgba(218, 165, 32, 0.1);
  padding: 2px 8px;
  border-radius: 12px;
  font-family: var(--font-ui);
}

/* ── Weather Widget ── */
.weather-widget {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 16px;
  background: rgba(218, 165, 32, 0.05);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: var(--gold-dim);
  flex-shrink: 0;
}

.weather-icon { font-size: 1rem; }

/* ── Page Container ── */
.page-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  perspective: 1500px;
  touch-action: pan-y;
}

.page-wrapper {
  display: flex;
  width: 200%;
  height: 100%;
  transition: transform 0.5s var(--ease-page);
  transform-style: preserve-3d;
}

.page-wrapper.turning {
  transition: none;
}

/* ── Individual Page ── */
.page {
  width: 50%;
  height: 100%;
  flex-shrink: 0;
  padding: 4px 6px;
  position: relative;
}

.page-paper {
  height: 100%;
  background: var(--paper);
  border-radius: 2px 4px 4px 2px;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  box-shadow:
    2px 0 8px var(--paper-shadow),
    -1px 0 4px var(--paper-shadow),
    inset 0 0 30px rgba(60, 40, 20, 0.05);
}

/* Ruled lines */
.page-paper::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    transparent,
    transparent 27px,
    var(--paper-line) 27px,
    var(--paper-line) 28px
  );
  pointer-events: none;
  z-index: 0;
}

/* Red margin line */
.page-paper::after {
  content: '';
  position: absolute;
  left: 36px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(200, 80, 80, 0.15);
  pointer-events: none;
  z-index: 0;
}

/* Page edge shadow (left page has binding shadow) */
.page-left .page-paper {
  border-radius: 4px 2px 2px 4px;
  box-shadow:
    inset 8px 0 16px -8px rgba(60, 40, 20, 0.15),
    2px 0 4px var(--paper-shadow);
}

.page-right .page-paper {
  box-shadow:
    inset -4px 0 8px -4px rgba(60, 40, 20, 0.08),
    -2px 0 4px var(--paper-shadow);
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px 44px;
  border-bottom: 1px solid var(--paper-line);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 2;
}

.page-date {
  font-family: var(--font-handwritten);
  font-size: 1.1rem;
  color: var(--ink-light);
}

.page-mood {
  font-size: 1.4rem;
}

/* ── Time Slots ── */
.time-slots {
  position: relative;
  z-index: 1;
  padding-bottom: 100px;
}

.time-slot {
  display: flex;
  min-height: 48px;
  border-bottom: 1px solid var(--paper-line);
  position: relative;
  transition: background 0.2s;
}

.time-slot:active {
  background: rgba(218, 165, 32, 0.06);
}

.time-slot:nth-child(even) {
  background: rgba(0, 0, 0, 0.01);
}

.time-slot.current-time {
  background: rgba(218, 165, 32, 0.08);
}

.time-slot.current-time::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gold);
  border-radius: 0 2px 2px 0;
}

.time-label {
  width: 44px;
  flex-shrink: 0;
  padding: 8px 4px 8px 8px;
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: var(--ink-faded);
  text-align: right;
  line-height: 1;
  padding-top: 10px;
}

.time-content {
  flex: 1;
  padding: 4px 8px;
  min-height: 48px;
  position: relative;
}

.time-content:empty::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: transparent;
}

/* ── Entry Cards ── */
.entry-card {
  background: rgba(255, 255, 255, 0.6);
  border-radius: 4px;
  padding: 8px 10px;
  margin: 4px 0;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s var(--ease-bounce), box-shadow 0.2s;
  border-left: 3px solid var(--gold-dim);
  animation: ink-bleed 0.4s ease-out;
}

.entry-card:active {
  transform: scale(0.98);
}

.entry-card.pinned {
  border-left-color: var(--red-ribbon);
  background: rgba(255, 240, 230, 0.7);
}

.entry-card.pinned::after {
  content: '📌';
  position: absolute;
  top: -4px;
  right: 4px;
  font-size: 0.7rem;
}

@keyframes ink-bleed {
  0% { opacity: 0; transform: translateY(-4px); filter: blur(2px); }
  100% { opacity: 1; transform: translateY(0); filter: blur(0); }
}

/* Entry type: Text */
.entry-text {
  font-family: var(--font-handwritten);
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Entry type: Link */
.entry-link {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px;
  background: rgba(41, 128, 185, 0.06);
  border-radius: 4px;
  border-left: 3px solid var(--blue-ribbon);
  text-decoration: none;
  color: var(--ink);
}

.entry-link .link-favicon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
}

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

.entry-link .link-title {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-link .link-url {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: var(--blue-ribbon);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-link .link-description {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--ink-faded);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Entry type: Image (Polaroid style) */
.entry-image {
  background: white;
  padding: 6px 6px 24px;
  border-radius: 2px;
  box-shadow:
    0 2px 8px rgba(0,0,0,0.15),
    0 1px 3px rgba(0,0,0,0.1);
  transform: rotate(-1deg);
  display: inline-block;
  max-width: 90%;
}

.entry-image img {
  width: 100%;
  border-radius: 1px;
  display: block;
}

.entry-image .image-caption {
  font-family: var(--font-handwritten);
  font-size: 0.7rem;
  color: var(--ink-faded);
  text-align: center;
  margin-top: 4px;
}

/* Entry type: Video */
.entry-video {
  position: relative;
  border: 6px solid transparent;
  border-image: repeating-linear-gradient(
    45deg,
    var(--leather-mid) 0px,
    var(--leather-mid) 4px,
    var(--leather-light) 4px,
    var(--leather-light) 8px
  ) 6;
  border-radius: 2px;
  overflow: hidden;
}

.entry-video video {
  width: 100%;
  max-height: 200px;
  display: block;
  border-radius: 1px;
}

/* Entry type: File */
.entry-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(240, 232, 208, 0.5);
  border-radius: 4px;
  position: relative;
}

.entry-file::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.05) 50%);
}

.file-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

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

.file-name {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: var(--ink-faded);
}

/* Entry type: Voice */
.entry-voice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(142, 68, 173, 0.06);
  border-radius: 20px;
  border-left: 3px solid var(--purple-ribbon);
}

.voice-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--purple-ribbon);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 0.8rem;
}

.voice-waveform {
  flex: 1;
  height: 30px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.voice-waveform .wave-bar {
  width: 3px;
  background: var(--purple-ribbon);
  border-radius: 2px;
  opacity: 0.5;
  transition: height 0.1s;
}

.voice-duration {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--ink-faded);
  flex-shrink: 0;
}

/* Entry tags */
.entry-tags-display {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.tag {
  font-family: var(--font-ui);
  font-size: 0.6rem;
  background: rgba(218, 165, 32, 0.12);
  color: var(--gold-dim);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ── Page Turn Hints ── */
.page-turn-hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-dim);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 5;
}

.page-turn-hint.visible {
  opacity: 0.5;
}

.left-hint { left: 0; }
.right-hint { right: 0; }

/* ── Page Indicator ── */
.page-indicator {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 4px;
  flex-shrink: 0;
}

.page-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(218, 165, 32, 0.3);
  transition: all 0.3s;
}

.page-dot.active {
  background: var(--gold);
  width: 18px;
  border-radius: 3px;
}

/* ── Page Stats ── */
.page-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 4px;
  flex-shrink: 0;
}

.stat {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: var(--gold-dim);
}

/* ═══════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION — Ribbon Bookmarks
   ═══════════════════════════════════════════════════════════════ */
.bottom-nav {
  display: flex;
  justify-content: space-around;
  padding: 0 4px;
  padding-bottom: calc(4px + var(--safe-bottom));
  background: linear-gradient(0deg, var(--leather-dark), var(--leather-mid));
  border-top: 1px solid rgba(218, 165, 32, 0.1);
  flex-shrink: 0;
  z-index: var(--z-nav);
}

.ribbon {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px 4px;
  cursor: pointer;
  position: relative;
  min-width: 56px;
  transition: transform 0.2s var(--ease-bounce);
}

.ribbon:active {
  transform: translateY(-2px);
}

.ribbon-fold {
  width: 28px;
  height: 32px;
  clip-path: polygon(0 0, 100% 0, 100% 80%, 50% 100%, 0 80%);
  transition: height 0.2s;
}

.ribbon-today .ribbon-fold { background: var(--red-ribbon); }
.ribbon-calendar .ribbon-fold { background: var(--blue-ribbon); }
.ribbon-add .ribbon-fold { background: var(--green-ribbon); height: 38px; }
.ribbon-api .ribbon-fold { background: var(--orange-ribbon); }
.ribbon-settings .ribbon-fold { background: var(--purple-ribbon); }

.ribbon-label {
  font-family: var(--font-ui);
  font-size: 0.6rem;
  color: var(--gold-dim);
  margin-top: 2px;
  transition: color 0.2s;
}

.ribbon.active .ribbon-label {
  color: var(--gold);
}

/* ═══════════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--paper);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  animation: slide-up 0.3s var(--ease-bounce);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--paper-line);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 2;
}

.modal-header h2 {
  font-family: var(--font-diary);
  font-size: 1.2rem;
  color: var(--ink);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--ink-faded);
  cursor: pointer;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Entry Modal ── */
.entry-modal-content {
  padding-bottom: calc(16px + var(--safe-bottom));
}

.entry-type-selector {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.type-btn {
  background: rgba(0, 0, 0, 0.04);
  border: 2px solid transparent;
  border-radius: 20px;
  padding: 8px 14px;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  color: var(--ink-light);
}

.type-btn.active {
  background: rgba(218, 165, 32, 0.1);
  border-color: var(--gold);
  color: var(--gold-dim);
}

.entry-time-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 12px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--ink-light);
}

.time-input {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 6px 10px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.03);
  color: var(--ink);
}

.entry-body {
  padding: 0 16px;
}

.entry-input {
  display: none;
}

.entry-input.active {
  display: block;
}

.entry-input textarea,
.entry-input input[type="url"],
.entry-input input[type="text"] {
  width: 100%;
  font-family: var(--font-handwritten);
  font-size: 0.95rem;
  padding: 12px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink);
  resize: vertical;
  line-height: 1.6;
}

.entry-input textarea:focus,
.entry-input input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(218, 165, 32, 0.1);
}

.text-toolbar {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.format-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.format-btn:active {
  background: rgba(218, 165, 32, 0.1);
}

/* File drop zone */
.file-drop-zone {
  border: 2px dashed var(--paper-line);
  border-radius: 12px;
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.file-drop-zone:active {
  border-color: var(--gold);
  background: rgba(218, 165, 32, 0.05);
}

.drop-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 8px;
}

.file-drop-zone p {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--ink-faded);
}

.file-drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Link preview */
.link-preview {
  margin-top: 12px;
}

/* Image/Video preview */
.image-preview,
.video-preview,
.file-preview {
  margin-top: 12px;
}

.image-preview img,
.video-preview video {
  max-width: 100%;
  border-radius: 8px;
}

/* Voice recorder */
.voice-recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
}

.record-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--red-ribbon);
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.record-icon {
  width: 28px;
  height: 28px;
  background: var(--red-ribbon);
  border-radius: 50%;
  transition: all 0.2s;
}

.recording .record-icon {
  border-radius: 4px;
  width: 22px;
  height: 22px;
}

.recording .record-btn {
  animation: record-pulse 1s ease-in-out infinite;
}

@keyframes record-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(192, 57, 43, 0); }
}

.record-time {
  font-family: var(--font-ui);
  font-size: 1.2rem;
  color: var(--ink);
}

.waveform {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

/* Entry tags input */
.entry-tags {
  padding: 12px 16px;
}

.entry-tags label {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--ink-light);
  display: block;
  margin-bottom: 4px;
}

.entry-tags input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 8px 12px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink);
}

/* Modal actions */
.modal-actions {
  display: flex;
  gap: 12px;
  padding: 16px;
}

.btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel {
  background: rgba(0, 0, 0, 0.06);
  color: var(--ink-light);
}

.btn-save {
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: white;
  box-shadow: 0 2px 8px rgba(218, 165, 32, 0.3);
}

.btn-save:active {
  transform: scale(0.97);
}

.btn-fetch {
  width: 100%;
  background: linear-gradient(135deg, var(--orange-ribbon), #d35400);
  color: white;
  margin: 16px 0;
}

.btn-export, .btn-import {
  background: rgba(41, 128, 185, 0.1);
  color: var(--blue-ribbon);
  width: 100%;
}

.btn-danger {
  background: rgba(192, 57, 43, 0.1);
  color: var(--red-ribbon);
  width: 100%;
}

/* ── Expanded Entry ── */
.expanded-content {
  max-height: 80vh;
}

.expanded-time {
  font-family: var(--font-handwritten);
  font-size: 1rem;
  color: var(--ink-light);
}

.expanded-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.modal-action-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.modal-action-btn:active {
  background: rgba(0, 0, 0, 0.05);
}

.expanded-body {
  padding: 20px;
  font-family: var(--font-handwritten);
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink);
}

.expanded-body img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

.expanded-body video {
  max-width: 100%;
  border-radius: 8px;
}

.expanded-tags {
  padding: 0 20px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.expanded-meta {
  padding: 12px 20px;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--ink-faded);
  border-top: 1px solid var(--paper-line);
}

/* ── Search Modal ── */
.search-content {
  border-radius: 16px 16px 0 0;
  max-height: 80vh;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--paper-line);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 2;
}

.search-bar svg {
  flex-shrink: 0;
  color: var(--ink-faded);
}

.search-bar input {
  flex: 1;
  border: none;
  font-family: var(--font-ui);
  font-size: 1rem;
  background: none;
  color: var(--ink);
  outline: none;
}

.search-results {
  padding: 12px;
  max-height: 60vh;
  overflow-y: auto;
}

.search-placeholder {
  text-align: center;
  color: var(--ink-faded);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 32px 16px;
}

.search-result-item {
  padding: 12px;
  border-bottom: 1px solid var(--paper-line);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}

.search-result-item:active {
  background: rgba(218, 165, 32, 0.06);
}

.search-result-date {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--gold-dim);
}

.search-result-text {
  font-family: var(--font-handwritten);
  font-size: 0.85rem;
  color: var(--ink);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-text mark {
  background: rgba(218, 165, 32, 0.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

/* ── Mood Selector ── */
.mood-content {
  padding: 24px;
  text-align: center;
  border-radius: 16px 16px 0 0;
}

.mood-content h3 {
  font-family: var(--font-diary);
  color: var(--ink);
  margin-bottom: 20px;
}

.mood-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.mood-btn {
  width: 56px;
  height: 56px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.03);
  font-size: 1.8rem;
  cursor: pointer;
  transition: all 0.2s var(--ease-bounce);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.mood-btn:active {
  transform: scale(1.2);
  border-color: var(--gold);
  background: rgba(218, 165, 32, 0.1);
}

/* ── API Modal ── */
.api-content {
  max-height: 85vh;
}

.api-form {
  padding: 16px;
}

.api-field {
  margin-bottom: 16px;
}

.api-field label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-light);
  margin-bottom: 6px;
}

.api-field input,
.api-field select,
.api-field textarea {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 10px 12px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink);
}

.api-field textarea {
  font-family: monospace;
  font-size: 0.8rem;
  resize: vertical;
}

.api-result {
  margin-top: 16px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 8px;
  font-family: monospace;
  font-size: 0.75rem;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.api-saved {
  margin-top: 20px;
  border-top: 1px solid var(--paper-line);
  padding-top: 16px;
}

.api-saved h3 {
  font-family: var(--font-diary);
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 12px;
}

.btn-save-endpoint {
  width: 100%;
  background: rgba(39, 174, 96, 0.1);
  color: var(--green-ribbon);
  margin-top: 12px;
}

.saved-endpoint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.02);
  border-radius: 8px;
  margin-bottom: 8px;
}

.saved-endpoint-name {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
}

.saved-endpoint-url {
  font-family: monospace;
  font-size: 0.65rem;
  color: var(--ink-faded);
}

/* ── Calendar ── */
.calendar-content {
  max-height: 80vh;
  border-radius: 16px 16px 0 0;
}

.calendar-content .modal-header {
  gap: 12px;
}

.cal-nav {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
}

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

.cal-day-header {
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: var(--ink-faded);
  padding: 8px 0;
  text-transform: uppercase;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--ink);
  transition: all 0.2s;
  position: relative;
}

.cal-day:active {
  background: rgba(218, 165, 32, 0.1);
}

.cal-day.today {
  background: rgba(218, 165, 32, 0.15);
  font-weight: 700;
  color: var(--gold-dim);
}

.cal-day.has-entries::after {
  content: '';
  width: 5px;
  height: 5px;
  background: var(--gold);
  border-radius: 50%;
  position: absolute;
  bottom: 4px;
}

.cal-day.other-month {
  color: var(--ink-faded);
  opacity: 0.4;
}

/* ── Settings ── */
.settings-content {
  max-height: 80vh;
  border-radius: 16px 16px 0 0;
}

.settings-list {
  padding: 16px;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--paper-line);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--ink);
}

.settings-list hr {
  border: none;
  border-top: 1px solid var(--paper-line);
  margin: 8px 0;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle input:checked + .toggle-slider {
  background: var(--gold);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-lightbox);
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content {
  max-width: 95vw;
  max-height: 90vh;
}

.lightbox-content img,
.lightbox-content video {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
}

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--leather-mid);
  color: var(--gold);
  padding: 12px 20px;
  border-radius: 12px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  animation: toast-in 0.3s var(--ease-bounce);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.toast.toast-out {
  animation: toast-out 0.3s ease-in forwards;
}

.toast-undo {
  background: rgba(218, 165, 32, 0.2);
  border: none;
  color: var(--gold);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
}

@keyframes toast-in {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(20px); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════
   PAGE FLIP ANIMATION
   ═══════════════════════════════════════════════════════════════ */
.page-wrapper.flip-left {
  animation: flip-left 0.6s var(--ease-page) forwards;
}

.page-wrapper.flip-right {
  animation: flip-right 0.6s var(--ease-page) forwards;
}

@keyframes flip-left {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

@keyframes flip-right {
  0% { transform: translateX(-50%); }
  100% { transform: translateX(0); }
}

/* Page shadow during turn */
.page-wrapper.turning .page-paper::before {
  background:
    repeating-linear-gradient(
      transparent,
      transparent 27px,
      var(--paper-line) 27px,
      var(--paper-line) 28px
    ),
    linear-gradient(90deg, rgba(0,0,0,0.1), transparent 30%, transparent 70%, rgba(0,0,0,0.1));
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  .page-wrapper {
    width: 100%;
  }

  .page {
    width: 50%;
  }

  .modal-content {
    border-radius: 16px;
    margin: auto;
    max-height: 85vh;
  }

  .modal {
    align-items: center;
  }
}

@media (max-width: 380px) {
  :root {
    --font-size-base: 14px;
  }

  .cover-title {
    font-size: 2.2rem;
  }

  .ribbon {
    padding: 6px 8px 2px;
    min-width: 48px;
  }
}

/* ── Print styles ── */
@media print {
  .bottom-nav,
  .top-bar,
  .page-turn-hint,
  .page-indicator,
  .page-stats,
  .weather-widget {
    display: none;
  }

  .page-paper {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── High contrast ── */
[data-high-contrast="true"] {
  --ink: #000;
  --ink-light: #111;
  --paper: #fff;
  --gold: #b8860b;
}
