/* ============================================================
   BRAND TOKENS
   ============================================================ */
:root {
  --deep-purple:  #4C1081;
  --soft-purple:  #BCA3C3;
  --lavender:     #EBE3ED;
  --dusty-rose:   #D0927F;
  --blush-beige:  #EDD9CC;
  --sage-green:   #6BAE18;
  --ink-black:    #1A1A1A;
  --white:        #FFFFFF;

  --font-primary:   'Abhaya Libre', Georgia, 'Times New Roman', serif;
  --font-secondary: 'Barlow', -apple-system, 'Helvetica Neue', Arial, sans-serif;

  --radius-sm:   8px;
  --radius-md:   16px;
  --radius-lg:   24px;
  --radius-pill: 100px;

  --shadow-sm: 0 1px 4px rgba(76,16,129,0.07);
  --shadow-md: 0 4px 16px rgba(76,16,129,0.11);
  --shadow-lg: 0 8px 32px rgba(76,16,129,0.18);

  --ease: 0.2s ease;

  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html { font-size: 18px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-secondary);
  color: var(--ink-black);
  background: var(--white);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

img  { display: block; max-width: 100%; }
button { font-family: var(--font-secondary); cursor: pointer; border: none; background: none; -webkit-tap-highlight-color: transparent; }
input, textarea { font-family: var(--font-secondary); font-size: 18px; }
textarea { resize: vertical; }

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--white);
  position: relative;
}

.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  animation: fadeUp 0.22s ease both;
}

/* Detail and form views pin their header by constraining to viewport height
   and scrolling only the inner content — fixes iOS sticky header issues */
.detail-view,
.form-view {
  height: 100dvh;
  min-height: unset;
  overflow: hidden;
}

.view-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; }
}

/* ============================================================
   APP BAR
   ============================================================ */
.app-bar {
  flex-shrink: 0;
  position: relative;
  background: var(--white);
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--lavender);
}

.app-bar-back {
  height: 40px;
  padding: 0 12px 0 6px;
  border-radius: var(--radius-pill);
  display: flex; align-items: center; gap: 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--deep-purple);
  flex-shrink: 0;
  transition: background var(--ease);
}
.app-bar-back .back-arrow { font-size: 20px; line-height: 1; }
.app-bar-back:active { background: var(--lavender); }

.app-bar-title {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  font-family: var(--font-primary);
  font-size: 19px;
  font-weight: 700;
  color: var(--deep-purple);
}

.app-bar-action {
  width: 52px; height: 52px;
  border-radius: var(--radius-pill);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  color: var(--deep-purple);
  margin-left: auto;
  transition: background var(--ease);
}
.app-bar-action:active { background: var(--lavender); }

/* ============================================================
   BROWSE HEADER
   ============================================================ */
.browse-header {
  padding: calc(var(--safe-top) + 18px) 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.browse-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.browse-brand-accent {
  width: 28px; height: 28px;
  object-fit: contain;
  opacity: 0.8;
  flex-shrink: 0;
}

.browse-brand-name {
  font-family: var(--font-primary);
  font-size: 26px;
  font-weight: 800;
  color: var(--deep-purple);
  letter-spacing: -0.3px;
}

.browse-export-btn {
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: var(--lavender);
  color: var(--deep-purple);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--ease);
}
.browse-export-btn:active { background: var(--soft-purple); color: var(--white); }

/* ============================================================
   ENTRY CARDS
   ============================================================ */
.entries-list {
  flex: 1;
  padding: 6px 16px calc(96px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.list-footer {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

.list-export-btn {
  padding: 9px 20px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  color: var(--deep-purple);
  border: 1.5px solid var(--lavender);
  background: transparent;
  transition: background var(--ease), color var(--ease);
}
.list-export-btn:active { background: var(--lavender); color: var(--deep-purple); }

.entry-card {
  border-radius: var(--radius-md);
  background: var(--white);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(188,163,195,0.25);
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--ease), box-shadow var(--ease);
}
.entry-card:active { transform: scale(0.98); box-shadow: var(--shadow-sm); }

.entry-card-photo {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}

.entry-card-body { padding: 14px 16px 16px; }

.entry-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.entry-type-badge.object  { background: rgba(208,146,127,0.14); color: var(--dusty-rose); }
.entry-type-badge.moment  { background: rgba(76,16,129,0.09);   color: var(--deep-purple); }

.entry-card-title {
  font-family: var(--font-primary);
  font-size: 21px;
  font-weight: 700;
  color: var(--ink-black);
  line-height: 1.3;
  margin-bottom: 6px;
}

.entry-card-preview {
  font-size: 17px;
  color: var(--ink-black);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 10px;
}

.entry-card-date {
  font-size: 14px;
  color: var(--deep-purple);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
  text-align: center;
  gap: 14px;
}

.empty-icon {
  width: 96px; height: 96px;
  object-fit: contain;
  opacity: 0.65;
  margin-bottom: 4px;
}

.empty-heading {
  font-family: var(--font-primary);
  font-size: 26px;
  font-weight: 700;
  color: var(--deep-purple);
  line-height: 1.3;
}

.empty-sub {
  font-size: 17px;
  color: var(--ink-black);
  line-height: 1.6;
  max-width: 260px;
}

.empty-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 280px;
  margin-top: 8px;
}

/* ============================================================
   FAB
   ============================================================ */
.fab-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  z-index: 9999;
}

.fab-options {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.fab-options.open { opacity: 1; pointer-events: auto; transform: translateY(0); }

.fab-option-pill {
  background: var(--ink-black);
  color: var(--white);
  padding: 11px 20px;
  border-radius: var(--radius-pill);
  font-family: var(--font-secondary);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--ease), transform var(--ease);
}
.fab-option-pill:active { opacity: 0.85; transform: scale(0.97); }

.fab-main {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--deep-purple);
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  line-height: 1;
  box-shadow: var(--shadow-lg);
  transition: background var(--ease), transform var(--ease);
}
.fab-main:active  { transform: scale(0.92); }
.fab-main.open    { background: var(--dusty-rose); transform: rotate(45deg); }

/* ============================================================
   FORM VIEW
   ============================================================ */
.form-body {
  flex: 1;
  padding: 22px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.form-footer {
  flex-shrink: 0;
  padding: 14px 20px calc(14px + var(--safe-bottom));
  background: linear-gradient(to top, var(--white) 65%, transparent);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.form-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--deep-purple);
}

.form-input {
  width: 100%;
  padding: 13px 15px;
  border: 1.5px solid var(--lavender);
  border-radius: var(--radius-md);
  font-size: 18px;
  color: var(--ink-black);
  background: var(--white);
  transition: border-color var(--ease);
  outline: none;
}
.form-input:focus          { border-color: var(--dusty-rose); }
.form-input::placeholder   { color: #c0b8c8; }
.form-textarea             { min-height: 130px; line-height: 1.65; }
.form-input.title-input    { font-family: var(--font-primary); font-size: 20px; font-weight: 700; }

/* Type selector */
.type-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.type-radio { display: none; }

.type-option-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 15px 10px;
  border-radius: var(--radius-md);
  border: 2px solid var(--lavender);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.type-option-label .type-icon { font-size: 22px; line-height: 1; color: var(--deep-purple); height: 36px; display: flex; align-items: center; justify-content: center; }
.type-option-label .type-icon--lg { font-size: 32px; color: var(--deep-purple); }
.type-option-label .type-name { font-weight: 600; font-size: 14px; color: var(--deep-purple); }
.type-option-label .type-desc { font-size: 11px; color: var(--deep-purple); text-align: center; }

#type-object:checked + .type-option-label {
  border-color: var(--dusty-rose);
  background: rgba(208,146,127,0.07);
}
#type-moment:checked + .type-option-label {
  border-color: var(--deep-purple);
  background: rgba(76,16,129,0.05);
}

/* Photo upload */
.photo-upload-area {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--lavender);
  border: 2px dashed var(--soft-purple);
  aspect-ratio: 4/3;
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--ease);
}
.photo-upload-area:active       { border-color: var(--dusty-rose); }
.photo-upload-area.has-photo    { border-style: solid; border-color: transparent; }

.photo-placeholder { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.photo-placeholder-icon { font-size: 30px; color: var(--deep-purple); }
.photo-placeholder-text { font-size: 13px; color: var(--deep-purple); font-weight: 500; }

.photo-preview {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;
}
.has-photo .photo-preview    { display: block; }
.has-photo .photo-placeholder { display: none; }
.has-photo .photo-change-btn  { display: flex; }

.photo-change-btn {
  position: absolute; bottom: 10px; right: 10px;
  display: none;
  align-items: center; gap: 5px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
}

#photo-input { display: none; }

/* Story prompt */
.story-prompt {
  font-size: 13px;
  color: var(--deep-purple);
  font-style: italic;
  padding: 10px 13px;
  background: var(--lavender);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--dusty-rose);
  line-height: 1.5;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  width: 100%;
  padding: 15px 24px;
  border-radius: var(--radius-pill);
  font-size: 18px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  transition: opacity var(--ease), transform var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.82; transform: scale(0.98); }

.btn-primary   { background: var(--deep-purple);      color: var(--white); }
.btn-secondary { background: var(--lavender);          color: var(--deep-purple); }
.btn-danger    { background: #fee2e2;                  color: #dc2626; }
.btn-ghost     { background: transparent; border: 1.5px solid var(--lavender); color: var(--deep-purple); }

/* ============================================================
   DETAIL VIEW
   ============================================================ */
.detail-photo {
  width: 100%;
  height: 260px;
  object-fit: cover;
  object-position: center;
  flex-shrink: 0;
}

.detail-body {
  flex: 1;
  padding: 22px 20px calc(32px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.detail-header { display: flex; flex-direction: column; gap: 8px; }

.detail-title {
  font-family: var(--font-primary);
  font-size: 30px;
  font-weight: 800;
  color: var(--ink-black);
  line-height: 1.2;
}

.detail-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-date { font-size: 15px; color: var(--deep-purple); }

.divider { height: 1px; background: var(--lavender); }

.detail-story-label {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--deep-purple); margin-bottom: 6px;
}

.detail-story {
  font-size: 18px;
  line-height: 1.8;
  color: var(--ink-black);
  white-space: pre-wrap;
}



.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 6px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(26,26,26,0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal-sheet {
  background: var(--white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px calc(24px + var(--safe-bottom));
  width: 100%; max-width: 480px;
  display: flex; flex-direction: column; gap: 14px;
}

.modal-handle {
  width: 36px; height: 4px;
  background: var(--lavender);
  border-radius: 2px;
  margin: -4px auto 8px;
}

.modal-title { font-family: var(--font-primary); font-size: 20px; font-weight: 700; }
.modal-text  { font-size: 17px; color: #666; line-height: 1.55; }

/* ============================================================
   PROMPTS
   ============================================================ */
.story-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.prompts-btn {
  font-family: var(--font-secondary);
  font-size: 12px;
  font-weight: 600;
  color: var(--dusty-rose);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--dusty-rose);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--ease), color var(--ease);
  flex-shrink: 0;
}
.prompts-btn:active {
  background: var(--dusty-rose);
  color: var(--white);
}

.prompts-list {
  display: none;
  flex-direction: column;
  gap: 6px;
  background: var(--lavender);
  border-radius: var(--radius-md);
  padding: 10px;
}
.prompts-list.open { display: flex; }

.prompt-item {
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--ink-black);
  font-family: var(--font-secondary);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.4;
  border: 1px solid rgba(188,163,195,0.3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--ease);
}
.prompt-item:active { background: var(--blush-beige); }

/* ============================================================
   LOADING VIEW
   ============================================================ */
.loading-view {
  align-items: center;
  justify-content: center;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--lavender);
  border-top-color: var(--deep-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   AUTH VIEW
   ============================================================ */
.auth-view {
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 32px) 24px calc(32px + var(--safe-bottom));
  background: linear-gradient(160deg, var(--lavender) 0%, var(--white) 60%);
}

.auth-body {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.auth-brand { text-align: center; }

.auth-brand-icon {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin: 0 auto 12px;
  opacity: 0.9;
}

.auth-brand-name {
  font-family: var(--font-primary);
  font-size: 34px;
  font-weight: 800;
  color: var(--deep-purple);
  letter-spacing: -0.5px;
  display: block;
}

.auth-brand-sub {
  font-size: 17px;
  color: var(--ink-black);
  margin-top: 6px;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-tabs {
  display: flex;
  background: var(--lavender);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 3px;
}

.auth-tab {
  flex: 1;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  color: var(--soft-purple);
  text-align: center;
  transition: background var(--ease), color var(--ease);
}

.auth-tab.active {
  background: var(--white);
  color: var(--deep-purple);
  box-shadow: var(--shadow-sm);
}

.auth-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-forgot-btn {
  align-self: flex-end;
  font-size: 14px;
  font-weight: 500;
  color: var(--deep-purple);
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 4px 0;
  opacity: 0.75;
  transition: opacity var(--ease);
}
.auth-forgot-btn:active { opacity: 1; }

/* Browse header sign-out + action group */
.browse-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.browse-signout-btn {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  color: var(--deep-purple);
  transition: background var(--ease), color var(--ease);
}
.browse-signout-btn:active { background: var(--lavender); color: var(--deep-purple); }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(30px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--ink-black);
  color: var(--white);
  padding: 11px 20px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 2000;
  white-space: nowrap;
  pointer-events: none;
  max-width: calc(100vw - 40px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
