:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-alt: #faf8f5;
  --text: #1c1a17;
  --muted: #7a736a;
  --line: #e9e4dc;
  --accent: #b08d57;
  --accent-soft: #f3ece0;
  --danger: #b4483f;
  --shadow: 0 1px 2px rgba(28, 26, 23, .06),
             0 8px 24px rgba(28, 26, 23, .06);
  --radius: 14px;
}

:root[data-theme="dark"] {
  --bg: #121110;
  --surface: #1b1a18;
  --surface-alt: #232120;
  --text: #f1ede7;
  --muted: #9b958b;
  --line: #322f2c;
  --accent: #d2ad74;
  --accent-soft: #2b2620;
  --danger: #e08379;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4),
             0 8px 24px rgba(0, 0, 0, .35);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont,
        "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 96px;
}

h1,
h2,
h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: .01em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 660px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-family: Georgia, serif;
  font-size: 20px;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs {
  display: flex;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.tab {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--muted);
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 17px;
}

/* ---------- feed ---------- */

.feed {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 22px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card.challenge {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}

.card-ribbon {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 600;
  flex: none;
}

.card-name {
  font-weight: 600;
  font-size: 15px;
}

.card-time {
  color: var(--muted);
  font-size: 13px;
}

.card-image {
  width: 100%;
  display: block;
  background: var(--surface-alt);
  cursor: zoom-in;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
}

.action {
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  text-decoration: none;
  color: inherit;
}

.action:hover {
  background: var(--surface-alt);
}

.action.liked {
  color: var(--danger);
}

.action.delete {
  margin-left: auto;
  color: var(--muted);
}

/* ---------- gallery ---------- */

.gallery-tools {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

select,
input[type="text"],
input[type="password"] {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 15px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: .5;
  cursor: default;
}

.grid {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
}

.grid-item {
  position: relative;
  aspect-ratio: 1;
}

.grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 4px;
  cursor: zoom-in;
  background: var(--surface-alt);
}

.grid-item.challenge img {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---------- upload button ---------- */

.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 22px;
  z-index: 25;
  border: 0;
  background: var(--accent);
  color: #fff;
  padding: 14px 26px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(176, 141, 87, .4);
}

/* ---------- progress ---------- */

.uploads {
  position: fixed;
  right: 12px;
  bottom: 90px;
  z-index: 26;
  width: min(300px, calc(100vw - 24px));
  display: grid;
  gap: 6px;
}

.upload-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.upload-row.failed {
  color: var(--danger);
}

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(20, 18, 16, .55);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border-radius: 18px;
  padding: 24px;
  width: min(440px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.modal-box h2 {
  margin: 0;
  font-size: 22px;
}

.modal-box p {
  margin: 0;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.error {
  color: var(--danger);
  font-size: 14px;
  min-height: 18px;
}

.challenge-text {
  background: var(--accent-soft);
  color: var(--text);
  border-left: 3px solid var(--accent);
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 17px;
}

.preview {
  width: 100%;
  max-height: 38dvh;
  object-fit: contain;
  border-radius: 10px;
  display: block;
  background: var(--surface-alt);
}

.challenge-actions {
  position: sticky;
  bottom: -24px;
  background: var(--surface);
  padding-top: 8px;
}

/* ---------- upload choice ---------- */

.upload-choice {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(20, 18, 16, .55);
  display: grid;
  place-items: center;
  padding: 16px;
}

.upload-choice-box {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.upload-choice-box h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.upload-choice-btn {
  width: 100%;
  min-height: 50px;
  font-size: 16px;
}

.upload-choice-cancel {
  margin-top: 4px;
}

/* ---------- lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(12, 11, 10, .94);
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  display: block;
  object-fit: contain;
}

.lightbox-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  color: #f4f1ec;
}

.lightbox-bar .btn {
  background: rgba(255, 255, 255, .12);
  border-color: transparent;
  color: #f4f1ec;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}

.sentinel {
  height: 40px;
}

/* ---------- mobitel ---------- */

@media (max-width: 600px) {

  .topbar-inner {
    padding: 8px 10px;
    gap: 7px;
  }

  .brand {
    font-size: 17px;
  }

  .tab {
    padding: 6px 10px;
    font-size: 13px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }

  .gallery-tools {
    padding: 12px;
    gap: 7px;
  }

  .gallery-tools select,
  .gallery-tools .btn {
    flex: 1;
    min-width: 0;
  }

  .grid {
    padding: 8px;
    gap: 3px;
    grid-template-columns: repeat(3, 1fr);
  }

  .feed {
    padding: 10px;
    gap: 16px;
  }

  .card-actions {
    padding: 8px;
  }

  .action {
    padding: 8px 7px;
    font-size: 14px;
  }

  .modal {
    padding: 12px;
    align-items: end;
  }

  .modal-box {
    width: 100%;
    max-height: calc(100dvh - 24px);
    padding: 18px;
    border-radius: 18px 18px 14px 14px;
  }

  .challenge-text {
    font-size: 16px;
    padding: 12px 14px;
  }

  .preview {
    max-height: 32dvh;
  }

  .challenge-actions {
    bottom: -18px;
  }

  .upload-choice {
    padding: 12px;
    align-items: end;
  }

  .upload-choice-box {
    width: 100%;
    padding: 18px;
    border-radius: 18px 18px 14px 14px;
  }

  .upload-choice-btn {
    min-height: 54px;
  }

  .fab {
    bottom: max(18px, env(safe-area-inset-bottom));
    padding: 13px 22px;
  }

  .uploads {
    bottom: 82px;
    right: 8px;
    width: calc(100vw - 16px);
  }
}