/* ============ Theme variables ============ */
:root {
  --bg: #14100c;
  --bg-elevated: #1e1712;
  --page-bg: #241a12;
  --page-border: #4a3520;
  --ink: #e8dcc4;
  --ink-dim: #a8987c;
  --accent: #8a1f1f;
  --accent-bright: #c73e3e;
  --gold: #b8923c;
  --font-display: 'Cinzel Decorative', 'Cinzel', serif;
  --font-heading: 'Cinzel', serif;
  --font-body: 'EB Garamond', Georgia, serif;
  --entry-font-size: 18px;
}

[data-theme="shadow"] {
  --bg: #0a0a0c;
  --bg-elevated: #131318;
  --page-bg: #16161c;
  --page-border: #34344a;
  --ink: #d8d8ea;
  --ink-dim: #8686a0;
  --accent: #4a2a8a;
  --accent-bright: #6c3ec7;
  --gold: #8c8cc7;
}

[data-theme="parchment"] {
  --bg: #e9dfc4;
  --bg-elevated: #f3ead2;
  --page-bg: #f7efd8;
  --page-border: #c8b184;
  --ink: #3a2a18;
  --ink-dim: #6a5636;
  --accent: #7a2020;
  --accent-bright: #a13030;
  --gold: #8a6a20;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
  background: radial-gradient(ellipse at top, var(--bg-elevated), var(--bg) 70%);
}

.hidden { display: none !important; }

/* ============ Cover / Lock screen ============ */
.cover-screen, .lock-screen {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  position: relative;
  z-index: 50;
  background: var(--bg);
}

.cover-glow {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(200,60,60,0.25), transparent 70%);
  filter: blur(10px);
  pointer-events: none;
}

.cover-title {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(184,146,60,0.45);
  margin: 0 0 4px;
  z-index: 1;
}
.cover-title.small { font-size: 2rem; }

.cover-subtitle {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0 0 28px;
  z-index: 1;
}

.cover-tagline {
  color: var(--ink-dim);
  font-style: italic;
  margin: 0 0 32px;
  z-index: 1;
}

.cover-privacy {
  margin-top: 28px;
  font-size: 0.85rem;
  color: var(--ink-dim);
  z-index: 1;
}

.lock-error {
  color: var(--accent-bright);
  margin-top: 10px;
}

/* ============ Buttons ============ */
.rune-btn {
  font-family: var(--font-heading);
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  color: #f4e9d8;
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 14px 28px;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  z-index: 1;
  transition: transform .12s ease, box-shadow .12s ease;
}
.rune-btn:active { transform: translateY(1px) scale(0.98); }
.rune-btn.small { padding: 10px 18px; font-size: 0.9rem; }
.rune-btn.danger { background: linear-gradient(180deg, #5a1a1a, #3a1010); border-color: #7a2a2a; }

.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
  margin: 4px 0 12px;
  padding: 4px;
}

.arrow-btn {
  background: none;
  border: 1px solid var(--page-border);
  color: var(--gold);
  border-radius: 6px;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
}

/* ============ App shell ============ */
.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 14px 16px 10px;
  text-align: center;
  border-bottom: 1px solid var(--page-border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}
.app-header-title {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 1.3rem;
  margin: 0;
  letter-spacing: 0.05em;
}
.app-header-sub {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
  text-transform: uppercase;
}

.view-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 24px;
}

.view { animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.page-frame {
  background: var(--page-bg);
  border: 1px solid var(--page-border);
  border-radius: 10px;
  padding: 18px;
  max-width: 560px;
  margin: 0 auto;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35), inset 0 0 40px rgba(0,0,0,0.15);
}

.section-title {
  font-family: var(--font-heading);
  color: var(--gold);
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  margin-top: 0;
}

/* ============ Journal ============ */
.page-date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.page-date {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  color: var(--gold);
  text-align: center;
  flex: 1;
}

.journal-textarea {
  width: 100%;
  min-height: 42vh;
  background: transparent;
  border: none;
  border-top: 1px dashed var(--page-border);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--entry-font-size);
  line-height: 1.6;
  padding-top: 14px;
  resize: vertical;
  outline: none;
}
.journal-textarea::placeholder { color: var(--ink-dim); font-style: italic; }

.journal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.journal-status {
  margin-right: auto;
  font-size: 0.82rem;
  color: var(--ink-dim);
  font-style: italic;
}

/* ============ Calendar ============ */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.calendar-month-label {
  font-family: var(--font-heading);
  color: var(--gold);
  font-size: 1.05rem;
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.75rem;
  margin-bottom: 6px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
  color: var(--ink);
  font-size: 0.85rem;
  cursor: pointer;
  position: relative;
}
.cal-day.empty { visibility: hidden; cursor: default; }
.cal-day.today { border-color: var(--gold); }
.cal-day.has-entry::after {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent-bright);
  position: absolute;
  bottom: 5px;
}
.cal-day:hover { background: rgba(255,255,255,0.08); }
.calendar-legend {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem; color: var(--ink-dim); margin-top: 12px;
}
.legend-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent-bright); display: inline-block;
}

/* ============ Gallery ============ */
.gallery-frame { max-width: 640px; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.gallery-item {
  border: 1px solid var(--page-border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 3/4;
  background: #000;
}
.gallery-item img {
  width: 100%; height: 100%; object-fit: cover;
  display: block;
  filter: sepia(0.15) contrast(1.05);
  transition: transform .2s ease;
}
.gallery-item:active img { transform: scale(0.97); }

.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.lightbox img {
  max-width: 100%; max-height: 90vh;
  border-radius: 6px;
  box-shadow: 0 0 40px rgba(184,146,60,0.25);
}
.lightbox-close {
  position: absolute; top: 18px; right: 18px;
  background: none; border: 1px solid var(--gold); color: var(--gold);
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.1rem; cursor: pointer;
}

/* ============ Settings ============ */
.settings-group {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px dashed var(--page-border);
}
.settings-group:last-child { border-bottom: none; }
.settings-label {
  display: block;
  font-family: var(--font-heading);
  color: var(--gold);
  font-size: 0.9rem;
  margin-bottom: 10px;
}
.settings-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.settings-row-between { justify-content: space-between; }
.settings-note {
  font-size: 0.82rem;
  color: var(--ink-dim);
  margin: 0 0 10px;
}
.settings-footer {
  font-size: 0.75rem;
  color: var(--ink-dim);
  text-align: center;
  margin: 0;
}

.theme-swatch {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 2px solid var(--page-border);
  cursor: pointer;
}
.theme-swatch[data-theme="crimson"] { background: linear-gradient(135deg, #241a12, #8a1f1f); }
.theme-swatch[data-theme="shadow"] { background: linear-gradient(135deg, #16161c, #4a2a8a); }
.theme-swatch[data-theme="parchment"] { background: linear-gradient(135deg, #f7efd8, #7a2020); }
.theme-swatch.selected { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }

.text-input {
  background: var(--bg-elevated);
  border: 1px solid var(--page-border);
  color: var(--ink);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 1rem;
  width: 100%;
  max-width: 260px;
}
.text-input.center { text-align: center; letter-spacing: 0.3em; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--page-border);
  border-radius: 26px;
  transition: .2s;
}
.switch-slider::before {
  content: '';
  position: absolute; height: 20px; width: 20px;
  left: 3px; bottom: 3px;
  background: var(--ink);
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }

#lock-passcode-wrap { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

/* ============ Tab bar ============ */
.tab-bar {
  display: flex;
  border-top: 1px solid var(--page-border);
  background: var(--bg-elevated);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--ink-dim);
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-family: var(--font-heading);
}
.tab-btn .tab-icon { font-size: 1.25rem; }
.tab-btn .tab-label { font-size: 0.68rem; letter-spacing: 0.03em; }
.tab-btn.active { color: var(--gold); }

/* ============ Responsive ============ */
@media (min-width: 700px) {
  .view-container { padding: 32px; }
  .gallery-grid { grid-template-columns: repeat(3, 1fr); }
}
