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

/* ── Tokens ── */
:root {
  --bg:         #faf7f4;
  --bg-dark:    #0d0a09;
  --gold:       #c9a96e;
  --gold-light: #e8d5a3;
  --gold-dim:   rgba(201, 169, 110, 0.18);
  --wine:       #4a0e1c;
  --cream:      #f5efe6;
  --text:       #2c1f1a;
  --text-muted: #8a7060;
  --error:      #c94e4e;
  --border:     rgba(201, 169, 110, 0.16);
}

html, body {
  height: 100%;
  font-family: 'Cormorant Garamond', serif;
  background: var(--bg-dark);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* ════════════════════════════════════
   PIN SCREEN
════════════════════════════════════ */

#pin-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  /* subtle grain */
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  transition: opacity 0.55s ease, transform 0.55s cubic-bezier(0.23, 1, 0.32, 1);
}

#pin-screen.unlocking {
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
}

#pin-screen.gone {
  display: none;
}

.pin-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 20px;
}

.pin-heading {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 1.6rem;
  color: rgba(245, 239, 230, 0.18);
  letter-spacing: 0.12em;
  margin-bottom: -10px;
}

.pin-label {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 0.95rem;
  letter-spacing: 0.22em;
  color: var(--text-muted);
  text-align: center;
  min-height: 1.4em;
  transition: color 0.2s ease;
}

.pin-label.error { color: var(--error); }

/* ── Dots ── */
.pin-dots {
  display: flex;
  gap: 18px;
  align-items: center;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid rgba(201, 169, 110, 0.3);
  background: transparent;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.dot.filled {
  background: var(--gold);
  border-color: var(--gold);
  transform: scale(1.15);
}

.dot.error {
  background: var(--error);
  border-color: var(--error);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-9px); }
  40%       { transform: translateX(9px); }
  60%       { transform: translateX(-6px); }
  80%       { transform: translateX(4px); }
}

.pin-dots.shaking { animation: shake 0.48s ease; }

/* ── Keypad ── */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 70px);
  grid-template-rows: repeat(4, 70px);
  gap: 10px;
}

.key {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 1px solid rgba(201, 169, 110, 0.1);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(245, 239, 230, 0.85);
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.75rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.key:not(.key--empty):active,
.key.pressed {
  background: rgba(201, 169, 110, 0.12);
  border-color: rgba(201, 169, 110, 0.3);
  transform: scale(0.93);
}

.key--empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}

.key--back {
  color: rgba(201, 169, 110, 0.45);
}

.key--back:active {
  color: var(--gold);
}

/* ════════════════════════════════════
   JOURNAL VIEW
════════════════════════════════════ */

#journal {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

#journal.view-hidden { display: none; }

/* ── Header ── */
.journal-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
  z-index: 10;
}

.journal-title {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-weight: 400;
  font-size: 1.45rem;
  color: var(--text);
  letter-spacing: 0.06em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  background: none;
  border: none;
  color: rgba(138, 112, 96, 0.5);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: color 0.2s ease;
}

.btn-icon:hover { color: var(--gold); }

.btn-write {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--gold);
  background: none;
  border: 1px solid rgba(201, 169, 110, 0.28);
  padding: 6px 18px;
  border-radius: 100px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}

.btn-write:hover {
  background: rgba(201, 169, 110, 0.07);
  border-color: var(--gold);
}

/* ── Entries ── */
.journal-main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 80px;
  -webkit-overflow-scrolling: touch;
}

#entries-list {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.entry-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px 16px;
  position: relative;
  box-shadow: 0 2px 10px rgba(44, 31, 26, 0.055);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    box-shadow 0.3s ease,
    transform 0.3s ease,
    opacity 0.5s ease;
  opacity: 0;
  transform: translateY(14px);
}

.entry-card.visible {
  opacity: 1;
  transform: translateY(0);
}

.entry-card:hover {
  box-shadow: 0 5px 20px rgba(44, 31, 26, 0.1);
}

.entry-date {
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 9px;
}

.entry-title {
  font-weight: 500;
  font-size: 1.2rem;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 6px;
}

.entry-body {
  font-weight: 300;
  font-size: 1.03rem;
  line-height: 1.68;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entry-photo {
  margin-top: 12px;
  border-radius: 7px;
  overflow: hidden;
  height: 180px;
}

.entry-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.delete-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 0.85rem;
  color: rgba(138, 112, 96, 0.28);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.2s ease, background 0.2s ease;
}

.delete-btn:hover {
  color: var(--error);
  background: rgba(201, 78, 78, 0.06);
}

/* ── Empty state ── */
.empty-state {
  font-style: italic;
  font-weight: 300;
  font-size: 1.1rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.9;
  margin-top: 88px;
  opacity: 0.55;
}

.hidden { display: none !important; }

/* ════════════════════════════════════
   NEW ENTRY MODAL
════════════════════════════════════ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 10, 9, 0.55);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal.open .modal-backdrop { opacity: 1; }

.modal-sheet {
  position: relative;
  z-index: 1;
  background: #ffffff;
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.23, 1, 0.32, 1);
  overflow: hidden;
}

.modal.open .modal-sheet { transform: translateY(0); }

/* drag handle */
.modal-sheet::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(201, 169, 110, 0.25);
  margin: 10px auto 0;
  flex-shrink: 0;
}

.modal-top {
  display: flex;
  justify-content: flex-end;
  padding: 6px 14px 0;
  flex-shrink: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 0.9rem;
  color: rgba(138, 112, 96, 0.45);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 5px;
  transition: color 0.2s ease;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 24px 12px;
  -webkit-overflow-scrolling: touch;
}

.entry-title-input {
  width: 100%;
  border: none;
  outline: none;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.45rem;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  padding: 8px 0 6px;
}

.entry-title-input::placeholder { color: rgba(138, 112, 96, 0.35); }

.modal-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold) 40%, var(--gold) 60%, transparent);
  opacity: 0.25;
  margin: 2px 0 12px;
}

.entry-body-input {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.08rem;
  font-weight: 300;
  line-height: 1.72;
  color: var(--text);
  background: transparent;
  min-height: 130px;
}

.entry-body-input::placeholder { color: rgba(138, 112, 96, 0.35); }

.photo-preview-wrap {
  position: relative;
  margin-top: 12px;
  border-radius: 8px;
  overflow: hidden;
  max-height: 200px;
}

.photo-preview-wrap img {
  width: 100%;
  object-fit: cover;
  display: block;
  max-height: 200px;
}

.remove-photo {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(13, 10, 9, 0.55);
  border: none;
  color: rgba(255, 255, 255, 0.9);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.remove-photo:hover { background: rgba(13, 10, 9, 0.8); }

/* ── Modal footer ── */
.modal-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px calc(20px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(201, 169, 110, 0.1);
  background: #ffffff;
}

.btn-photo {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease;
  position: relative;
}

.btn-photo:hover { color: var(--gold); }

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.btn-post {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.08rem;
  color: #ffffff;
  background: var(--wine);
  border: none;
  padding: 10px 26px;
  border-radius: 100px;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn-post:hover  { background: #5c1224; }
.btn-post:active { transform: scale(0.96); }

/* ════════════════════════════════════
   ENTRY DETAIL VIEW
════════════════════════════════════ */

#entry-detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.34s cubic-bezier(0.23, 1, 0.32, 1);
  z-index: 50;
}

#entry-detail.open {
  transform: translateX(0);
}

.btn-back {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1rem;
  padding: 6px 10px 6px 2px;
  border-radius: 6px;
  min-height: 44px;
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-back:hover { color: var(--gold); }

.btn-detail-delete {
  color: rgba(138, 112, 96, 0.38);
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
}

.btn-detail-delete:hover { color: var(--error); }

.detail-content {
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.detail-title {
  font-weight: 500;
  font-size: 1.65rem;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 14px;
}

.detail-body {
  font-weight: 300;
  font-size: 1.08rem;
  line-height: 1.78;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.detail-photo {
  margin-top: 20px;
  border-radius: 10px;
  overflow: hidden;
}

.detail-photo img {
  width: 100%;
  height: auto;
  display: block;
}

/* ════════════════════════════════════
   RESPONSIVE
════════════════════════════════════ */

@media (min-width: 600px) {
  .modal-sheet {
    border-radius: 16px;
    margin-bottom: 40px;
    max-height: 80vh;
  }
}

/* ════════════════════════════════════
   REDUCED MOTION
════════════════════════════════════ */

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