@import url('https://fonts.googleapis.com/css2?family=Hanken+Grotesk:wght@400;500;600;700&family=Space+Mono:wght@400;700&family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  --bg: #F4EEDF;
  --ink: #2A1E13;
  --muted: #857862;
  --soft: #bcae90;
  --lilac: #2E6F4E;
  --lilac-2: #245539;
  --cyan: #C0392B;
  --cyan-2: #A52B1F;
  --line: #E9E0CD;
  --card: #FFFFFF;
  --mono: 'Space Mono', monospace;
  --serif: 'Cormorant Garamond', serif;
  --sans: 'Hanken Grotesk', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--sans);
  background-color: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

html {
  height: -webkit-fill-available;
}

#appContainer {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow-x: clip;
}

/* --- Screen Transitions --- */
.screen {
  display: none;
  flex: 1;
  animation: fadeIn 0.4s ease forwards;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Welcome Screen --- */
#welcomeScreen {
  position: relative;
}

.welcome-photo-area {
  background: repeating-linear-gradient(135deg, #e8dcc0 0 9px, #e0d2ac 9px 18px);
  flex: none;
  height: min(50vh, 325px);
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 24px;
  color: #fff;
}

.welcome-photo-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(33,25,20,0.28) 0%, rgba(33,25,20,0) 38%, rgba(33,25,20,0.62) 100%);
  z-index: -1;
}

.welcome-photo-area .mono-tag {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .34em;
  text-transform: uppercase;
  opacity: .92;
}

.welcome-photo-area .title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 38px;
  line-height: 1.04;
  margin: 8px 0 0;
}

.welcome-card {
  flex: 1;
  background: var(--bg);
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom));
  border-radius: 30px 30px 0 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.welcome-card .subtitle-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.welcome-card .subtitle-row .dot-lilac {
  width: 6px; height: 6px; border-radius: 50%; background: var(--lilac);
}
.welcome-card .subtitle-row .dot-cyan {
  width: 6px; height: 6px; border-radius: 50%; background: var(--cyan);
}

.welcome-card .subtitle-row span:not([class]) {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
}

.welcome-card h4 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 30px;
  color: var(--ink);
  text-align: center;
  margin: 14px 0 0;
}

.welcome-card p {
  font-size: 13px;
  line-height: 1.62;
  color: var(--muted);
  margin: 10px 0 0;
  text-align: center;
}

.input-group {
  margin-top: 30px;
  margin-bottom: 14px;
}

.input-group label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--soft);
  display: block;
}

.input-group input {
  margin-top: 9px;
  width: 100%;
  border: 1.5px solid var(--lilac);
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--ink);
  font-size: 15px;
  font-family: var(--sans);
  outline: none;
}

.btn-primary {
  width: 100%;
  border: none;
  background: var(--lilac);
  color: #fff;
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: .02em;
  padding: 15px;
  border-radius: 14px;
  box-shadow: 0 10px 22px rgba(46,111,78,.34);
  cursor: pointer;
  transition: transform 0.2s;
}
.btn-primary:active {
  transform: scale(0.98);
}

/* --- Main Content Area --- */
main {
  flex: 1;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* --- Gallery Header --- */
.gallery-title-area {
  padding: 20px 18px 10px;
}

.gallery-title {
  font-family: var(--serif);
  font-size: 24px;
  color: var(--ink);
  line-height: 1;
}

.gallery-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

/* --- YOU Tab --- */
.you-header {
  padding: 24px 20px 8px;
}
.you-eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--soft);
}
.you-name {
  font-family: var(--serif);
  font-size: 24px;
  color: var(--ink);
  margin-top: 4px;
}
.you-donut-wrap {
  display: flex;
  justify-content: center;
  padding: 14px 0 6px;
}
.you-donut {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.4s ease;
}
.you-donut-inner {
  width: 126px;
  height: 126px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.you-donut-count {
  font-family: var(--serif);
  font-size: 42px;
  color: var(--ink);
  line-height: 1;
}
.you-donut-count span {
  font-size: 22px;
  color: var(--soft);
}
.you-donut-pts {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .14em;
  color: var(--lilac-2);
  margin-top: 4px;
}
.you-stats {
  display: flex;
  gap: 10px;
  padding: 14px 20px 4px;
}
.you-stat {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}
.you-stat-val {
  font-family: var(--serif);
  font-size: 24px;
  color: var(--ink);
}
.you-stat-pts { color: var(--cyan-2); }
.you-stat-label {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--soft);
  letter-spacing: .1em;
  margin-top: 2px;
}
.you-captured-label {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  padding: 16px 20px 6px;
}
.you-grid {
  padding: 0 20px 90px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-content: start;
}
.you-thumb {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: var(--line);
}
.you-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.you-thumb-empty {
  background: var(--card);
  border: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--soft);
  font-size: 20px;
  cursor: default;
}

/* --- Rules Screen (Direction B) --- */
#rulesTab.active {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 70px);
}

.rules-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: 66px;
}

.rules-header {
  padding: 26px 24px 10px;
}

.rules-eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--soft);
}

.rules-title {
  font-family: var(--serif);
  font-size: 28px;
  color: var(--ink);
  margin-top: 4px;
}

.rules-steps {
  flex: 1;
  padding: 8px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rules-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.rules-step-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 15px;
  flex-shrink: 0;
}

.rules-step-num.lilac { background: var(--lilac); }
.rules-step-num.cyan  { background: var(--cyan); }

.rules-step-heading {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
}

.rules-step-body {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 2px;
}

.rules-footer {
  padding: 20px 24px;
  background: var(--card);
  border: 1px solid var(--soft);
  border-radius: 16px;
  margin: 0 16px 16px;
  text-align: center;
  margin-top: auto;
}

.rules-footer-label {
  font-size: 12px;
  color: var(--cyan);
}

.rules-footer-names {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  color: var(--lilac);
  margin-top: 4px;
}

/* --- App Header (Progress Area) --- */
.app-header {
  padding: 20px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-text-area {
  display: flex;
  flex-direction: column;
}

.header-text-area .mono {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .28em;
  color: var(--lilac-2);
}

.header-text-area h1 {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--ink);
  line-height: 1;
  margin-top: 4px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--lilac);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 18px;
  text-transform: uppercase;
}

/* --- Progress Card --- */
.progress-card {
  margin: 0 16px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.progress-label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--soft);
}

.progress-value {
  font-family: var(--serif);
  font-size: 30px;
  color: var(--ink);
  line-height: 1.1;
}

.progress-value span {
  color: var(--lilac-2);
}

.progress-bar-container {
  margin-top: 12px;
  height: 7px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--lilac);
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* --- Tab Header --- */
.tab-header {
  padding: 18px 16px 8px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.tab-title {
  font-family: var(--serif);
  font-size: 20px;
  color: var(--ink);
}

.tab-subtitle {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--soft);
}

/* --- Challenges Grid --- */
#challengesList {
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  padding-bottom: 90px;
}

.challenge-card {
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  aspect-ratio: 1/1.12;
  background: var(--card);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px;
  cursor: pointer;
  transition: transform 0.2s;
}

.challenge-card:active {
  transform: scale(0.97);
}

.card-top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.card-icon-area {
  font-size: 20px;
}

.card-pts {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--lilac-2);
}

.card-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  flex: 1;
}

.card-title {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink);
  line-height: 1.12;
  margin-top: auto;
}

.challenge-card.completed {
  background: repeating-linear-gradient(135deg, #ecd5c6 0 8px, #e2c4b2 8px 16px);
  border: none;
  padding: 0;
}

.challenge-card.completed::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(33,25,20,0) 40%, rgba(33,25,20,.7));
  z-index: 0;
}

.challenge-card.completed .card-pts {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,.94);
  color: var(--lilac-2);
  padding: 3px 7px;
  border-radius: 8px;
  z-index: 1;
}

.challenge-card.completed .card-completed-indicator {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  z-index: 1;
}

.challenge-card.completed .card-title {
  position: absolute;
  left: 9px;
  bottom: 28px;
  right: 9px;
  color: #fff;
  font-size: 15px;
  z-index: 1;
}

.card-add-more {
  position: absolute;
  left: 9px;
  bottom: 9px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .06em;
  color: rgba(255,255,255,.7);
  z-index: 2;
}

.challenge-card.completed .card-thumbnail {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0.6;
  z-index: 0;
}

/* --- Live Feed --- */
.feed-header {
  padding: 0 18px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.feed-toggle {
  display: flex;
  background: var(--line);
  border-radius: 11px;
  padding: 3px;
}

.feed-toggle span {
  font-family: var(--mono);
  font-size: 10px;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}

.feed-toggle span.active {
  background: var(--card);
  color: var(--ink);
}

.refresh-btn {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .06em;
  color: var(--lilac-2);
  background: var(--line);
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.refresh-btn:active { opacity: 0.65; }

#galleryGrid {
  padding: 0 18px 90px;
  column-count: 2;
  column-gap: 9px;
}

#galleryGrid.person-view {
  column-count: 1;
}

/* --- Gallery Skeleton Loader --- */
.gallery-loader {
  display: none;
  padding: 0 18px;
}
.gallery-loader.active {
  display: block;
}
.skeleton-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--soft);
  text-align: center;
  padding: 12px 0 16px;
}
.skeleton-masonry {
  column-count: 2;
  column-gap: 9px;
}
.skeleton-card {
  break-inside: avoid;
  margin-bottom: 9px;
  border-radius: 14px;
  background: linear-gradient(90deg, var(--line) 25%, #ede8f5 50%, var(--line) 75%);
  background-size: 300% 100%;
  animation: skeleton-shimmer 1.6s ease infinite;
}
@keyframes skeleton-shimmer {
  from { background-position: 100% 0; }
  to   { background-position: -100% 0; }
}

/* --- Gallery Empty State --- */
.gallery-empty {
  column-span: all;
  text-align: center;
  padding: 48px 24px;
  color: var(--soft);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
}

/* --- By Person Grouped View --- */
.person-group {
  margin-bottom: 20px;
}
.person-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 0 10px;
}
.person-avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--lilac);
  color: #fff;
  font-family: var(--serif);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.person-group-name {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
}
.person-group-count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--soft);
  margin-left: auto;
}
.person-photo-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.person-photo-strip::-webkit-scrollbar { display: none; }
.person-photo-thumb {
  flex-shrink: 0;
  width: 100px;
  height: 100px;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
}
.person-photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.person-photo-more {
  flex-shrink: 0;
  width: 100px;
  height: 100px;
  border-radius: 12px;
  background: var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 18px;
  color: var(--muted);
}

/* --- Toast Notifications --- */
#toastContainer {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 568px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 13.5px;
  line-height: 1.4;
  pointer-events: all;
  animation: toast-in 0.3s ease;
}
.toast.toast-exit {
  animation: toast-out 0.35s ease forwards;
}
.toast-success {
  background: var(--lilac);
  color: #fff;
}
.toast-error {
  background: #9b3030;
  color: #fff;
}
.toast-icon { font-size: 17px; flex-shrink: 0; }
.toast-msg  { flex: 1; }
@keyframes toast-in  {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(8px); }
}

.gallery-item {
  break-inside: avoid;
  margin-bottom: 9px;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  background: var(--card);
}

.gallery-item img {
  width: 100%;
  display: block;
}

.gallery-caption {
  position: absolute;
  left: 7px;
  bottom: 7px;
  background: rgba(255,255,255,.94);
  font-family: var(--mono);
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--ink);
}

/* --- Bottom Nav --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  height: 66px;
  border-top: 1px solid var(--line);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--soft);
  background: transparent;
  border: none;
  cursor: pointer;
}

.nav-item.active {
  color: var(--lilac-2);
}

.nav-icon {
  font-size: 19px;
}

.nav-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .08em;
}

/* --- Modals --- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.modal.active {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(33,25,20,.5);
  backdrop-filter: blur(2px);
}

.modal-backdrop::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(135deg, #ecd5c6 0 8px, #e2c4b2 8px 16px);
  opacity: .5;
}

.modal-content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  border-radius: 30px 30px 0 0;
  padding: 20px 22px 40px;
  box-shadow: 0 -20px 50px rgba(0,0,0,.3);
  z-index: 1;
}

.modal-handle {
  width: 42px;
  height: 5px;
  border-radius: 99px;
  background: var(--line);
  margin: 0 auto 18px;
}

.upload-preview-container {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  aspect-ratio: 4/5;
  background: var(--line);
}

#previewImage {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-points-tag {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--lilac);
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 10px;
}

.modal-challenge-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 14px;
}

.modal-challenge-title {
  font-family: var(--serif);
  font-size: 21px;
  color: var(--ink);
  line-height: 1.05;
}

#photoCaption {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 13px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--ink);
  font-family: var(--sans);
  outline: none;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn-secondary {
  flex: 1;
  border: 1.5px solid var(--lilac);
  background: transparent;
  color: var(--lilac-2);
  font-family: var(--serif);
  font-size: 17px;
  padding: 13px;
  border-radius: 13px;
  cursor: pointer;
}

.btn-primary-large {
  flex: 1.4;
  border: none;
  background: var(--lilac);
  color: #fff;
  font-family: var(--serif);
  font-size: 17px;
  padding: 13px;
  border-radius: 13px;
  box-shadow: 0 10px 22px rgba(46,111,78,.34);
  cursor: pointer;
}

/* Loading Overlay */
#loadingOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(30,24,50,.8);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #fff;
}
#loadingOverlay.active { display: flex; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Zoom Modal */
#zoomImage {
  width: 100%;
  border-radius: 16px;
  margin-bottom: 15px;
}
#zoomCaption {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
  font-style: italic;
  margin-top: 10px;
}
