/* ============================================
   THE UNDERSTORY — Mobile App Prototype
   Companion to Moonland Rover
   Queenstown, lutruwita / Tasmania
   ============================================ */

:root {
  /* Warm parchment palette */
  --bg-deep:       #faf5ee;
  --bg-surface:    #f4ede3;
  --bg-card:       #efe7db;
  --bg-elevated:   #e8dfd2;
  --border:        #d8ccbc;
  --border-light:  #e2d8ca;

  /* Text — warm grays and earth */
  --text-primary:  #2c2418;
  --text-secondary:#6b5e4f;
  --text-muted:    #a89880;

  /* Accents — Queenstown earth tones */
  --copper:        #b4654a;
  --copper-dim:    #8a4e39;
  --copper-glow:   rgba(180, 101, 74, 0.1);
  --ochre:         #c49540;
  --ochre-glow:    rgba(196, 149, 64, 0.08);
  --rust:          #a04030;
  --sage:          #7a8f6a;

  /* Deep Time layer colours */
  --layer-now:       #b4654a;
  --layer-human:     #c49540;
  --layer-ecological:#7a8f6a;
  --layer-geological:#6b7e94;
  --layer-deep:      #5a5070;

  /* Fragment moods */
  --mood-observation: #6b7e94;
  --mood-memory:      #c49540;
  --mood-imagination: #8a6e9f;
  --mood-question:    #b4654a;

  /* Sizing */
  --phone-w: 390px;
  --phone-h: 844px;
  --nav-h: 72px;
  --radius: 16px;
  --radius-sm: 10px;
}

/* ── Reset ─────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Crimson Pro', Georgia, 'Times New Roman', serif;
  background: #3a3228;
  color: var(--text-primary);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Phone Frame ───────────────── */
.phone-frame {
  width: var(--phone-w);
  height: var(--phone-h);
  background: var(--bg-deep);
  border-radius: 48px;
  border: 3px solid #c8bfb0;
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.04),
    0 40px 80px rgba(60,45,30,0.3),
    0 0 100px rgba(180,101,74,0.05);
  position: relative;
  overflow: hidden;
}
.phone-notch {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 34px;
  background: #2c2418;
  border-radius: 0 0 20px 20px;
  z-index: 100;
}
.phone-home-indicator {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 140px;
  height: 5px;
  background: rgba(44,36,24,0.15);
  border-radius: 3px;
  z-index: 100;
}

@media (max-width: 430px) {
  body { background: var(--bg-deep); }
  .phone-frame {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
  .phone-notch, .phone-home-indicator { display: none; }
}

/* ── App ───────────────────────── */
#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Screens ───────────────────── */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--nav-h);
  scrollbar-width: none;
}
.screen::-webkit-scrollbar { display: none; }
.screen.active { display: flex; flex-direction: column; }

/* ═══════════════════════════════════
   OPENING SCREEN
   ═══════════════════════════════════ */
#screenOpening {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 40px;
  background: linear-gradient(170deg, #faf5ee 0%, #f0e6d6 40%, #e8dace 100%);
}
.opening {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.opening-sigil {
  opacity: 0.7;
  animation: sigilBreathe 5s ease-in-out infinite;
}
@keyframes sigilBreathe {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.04); opacity: 0.9; }
}
.opening-title {
  font-family: 'Crimson Pro', serif;
  font-size: 32px;
  font-weight: 300;
  letter-spacing: 2px;
  color: var(--copper);
}
.opening-place {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.opening-epigraph {
  font-style: italic;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 260px;
  margin-top: 12px;
}
.opening-enter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 28px;
  padding: 14px 28px;
  background: var(--copper);
  color: var(--bg-deep);
  border: none;
  border-radius: 40px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.opening-enter:active { transform: scale(0.96); opacity: 0.9; }

/* ═══════════════════════════════════
   HOME SCREEN
   ═══════════════════════════════════ */
#screenHome { padding: 0; }
.home-scroll {
  padding: 50px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.home-time-badge {
  display: flex;
  flex-direction: column;
}
.time-label {
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--copper);
  font-weight: 600;
}
.time-value {
  font-family: 'Inter', sans-serif;
  font-size: 28px;
  font-weight: 300;
  color: var(--text-primary);
  letter-spacing: 1px;
}
.home-place {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* Ambient Card */
.ambient-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
}
#ambientCanvas {
  width: 100%;
  height: 160px;
  display: block;
}
.ambient-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 18px;
  background: linear-gradient(to top, rgba(250,245,238,0.95), transparent);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.ambient-label {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--copper);
  font-weight: 600;
}
.ambient-status {
  font-style: italic;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Prompt Card */
.prompt-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 22px;
  position: relative;
}
.prompt-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--copper);
  border-radius: 3px 0 0 3px;
}
.prompt-kicker {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.prompt-text {
  font-size: 19px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-primary);
  font-style: italic;
}
.prompt-respond-btn {
  margin-top: 16px;
  padding: 10px 22px;
  background: none;
  border: 1.5px solid var(--copper);
  border-radius: 24px;
  color: var(--copper);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.prompt-respond-btn:active {
  background: var(--copper-glow);
}

/* Fragments Preview */
.fragments-preview { display: flex; flex-direction: column; gap: 12px; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.section-header h3 {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.see-all-btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--copper);
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 500;
}
.fragment-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.fragment-scroll::-webkit-scrollbar { display: none; }

.fragment-card {
  min-width: 220px;
  max-width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 16px;
  scroll-snap-align: start;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fragment-card:active { transform: scale(0.97); }
.placeholder-card {
  align-items: center;
  justify-content: center;
  text-align: center;
  min-width: 260px;
}
.fragment-placeholder-text {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
}

.fragment-mood-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.fragment-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fragment-card-mood {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.fragment-card-text {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fragment-card-time {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-muted);
}

/* Layers Preview */
.layers-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}
.layers-preview:active { background: var(--bg-elevated); }
.layers-preview-bar {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
}
.layer-stripe {
  width: 32px;
  height: 4px;
  border-radius: 2px;
  opacity: 0.7;
}
.layers-preview-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.layers-preview-title {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.layers-preview-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ═══════════════════════════════════
   SCREEN HEADERS
   ═══════════════════════════════════ */
.screen-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 52px 22px 12px;
  flex-shrink: 0;
  background: var(--bg-deep);
}
.screen-head.floating-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(to bottom, var(--bg-deep) 70%, transparent);
  padding-bottom: 20px;
}
.screen-head h2 {
  font-family: 'Inter', sans-serif;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}
.back-btn {
  background: none;
  border: none;
  color: var(--copper);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  font-family: inherit;
}
.save-btn {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--copper);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 12px;
}

/* ═══════════════════════════════════
   FRAGMENTS LIST
   ═══════════════════════════════════ */
.fragments-list {
  padding: 0 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fragments-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 20px;
  gap: 14px;
}
.empty-icon { opacity: 0.3; }
.fragments-empty p { font-size: 16px; color: var(--text-secondary); }
.fragments-empty span { font-size: 13px; color: var(--text-muted); }

.fragment-list-item {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 18px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fragment-list-item:active { background: var(--bg-elevated); }
.fragment-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.fragment-list-mood {
  display: flex;
  align-items: center;
  gap: 6px;
}
.fragment-list-mood-label {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.fragment-list-time {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-muted);
}
.fragment-list-text {
  font-size: 16px;
  line-height: 1.55;
  color: var(--text-primary);
}

/* ═══════════════════════════════════
   COMPOSE
   ═══════════════════════════════════ */
.compose-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 22px;
}
.compose-mood-select {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.mood-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.mood-btn .mood-icon { font-size: 10px; }
.mood-btn.active {
  border-color: var(--copper);
  color: var(--copper);
  background: var(--copper-glow);
}
.mood-btn[data-mood="observation"].active { border-color: var(--mood-observation); color: var(--mood-observation); }
.mood-btn[data-mood="memory"].active { border-color: var(--mood-memory); color: var(--mood-memory); }
.mood-btn[data-mood="imagination"].active { border-color: var(--mood-imagination); color: var(--mood-imagination); }
.mood-btn[data-mood="question"].active { border-color: var(--mood-question); color: var(--mood-question); }

.compose-textarea {
  flex: 1;
  width: 100%;
  min-height: 200px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: 'Crimson Pro', serif;
  font-size: 19px;
  line-height: 1.65;
  resize: none;
  outline: none;
  padding: 0;
}
.compose-textarea::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.compose-footer {
  padding: 14px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}
.compose-meta {
  display: flex;
  gap: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-muted);
}
.compose-tools { display: flex; gap: 6px; }
.compose-tool-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.compose-tool-btn:active { background: var(--bg-elevated); }

/* ═══════════════════════════════════
   DEEP TIME LAYERS
   ═══════════════════════════════════ */
#screenLayers { padding: 0; }
.layers-scroll {
  padding: 80px 22px 40px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.layer-section {
  padding: 28px 0;
  border-left: 3px solid var(--layer-color);
  padding-left: 22px;
  margin-left: 14px;
}
.layer-era-badge {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--layer-color);
  font-weight: 600;
  margin-bottom: 6px;
}
.layer-title {
  font-family: 'Crimson Pro', serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 10px;
}
.layer-body {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-secondary);
  margin-bottom: 14px;
}
.layer-datum {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
}
.layer-datum:last-child { border-bottom: none; }
.datum-key {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.datum-val {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

.layer-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  margin-left: 14px;
}
.divider-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}
.divider-label {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.layers-coda {
  text-align: center;
  padding: 40px 20px;
  margin-left: 14px;
}
.layers-coda p {
  font-size: 17px;
  font-style: italic;
  color: var(--copper);
  line-height: 1.6;
}

/* ═══════════════════════════════════
   FRAGMENT DETAIL
   ═══════════════════════════════════ */
.fragment-detail-body {
  padding: 0 22px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.detail-mood-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}
.detail-fragment-text {
  font-size: 21px;
  line-height: 1.7;
  color: var(--text-primary);
}
.detail-timestamp {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}
.detail-whisper {
  background: var(--ochre-glow);
  border-left: 2px solid var(--ochre);
  padding: 14px 18px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px;
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ═══════════════════════════════════
   NAVIGATION BAR
   ═══════════════════════════════════ */
.nav-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 8px;
  z-index: 50;
}
.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  cursor: pointer;
  padding: 4px 14px;
  transition: color 0.2s;
}
.nav-tab.active { color: var(--copper); }

/* ═══════════════════════════════════
   TOAST
   ═══════════════════════════════════ */
.toast {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: var(--bg-elevated);
  border: 1px solid var(--copper);
  border-radius: 12px;
  padding: 10px 20px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--copper);
  z-index: 200;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(60,40,20,0.15);
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Animations ────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp 0.4s ease forwards; }
