/* Globe Images — mobile-first stock library.
   Dark neutral ground on purpose: photographs read better against it than
   against white, and it keeps the watermarked thumbnails the brightest thing
   on screen. */

:root {
  --bg: #0d1014; --panel: #161a21; --panel-2: #1d222b; --border: #2a303b;
  --text: #e8ebf0; --muted: #98a2b3; --faint: #6b7483;
  --accent: #2f9e7e; --accent-2: #27856a; --accent-soft: rgba(47, 158, 126, .14);
  --danger: #f2706b; --warn: #e5a94a; --ok: #43c18f;
  --maxw: 1100px;
  --tab-h: 56px;
  --radius: 12px;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  /* Transparent, not painted: html owns the canvas colour. A background here
     would paint as an in-flow block and cover negative stack levels. */
  background: transparent;
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --- App bar ------------------------------------------------------------ */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(13, 16, 20, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.appbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; letter-spacing: -.01em; font-size: 16px;
  color: var(--text); text-decoration: none;
}
.brand svg { width: 22px; height: 22px; flex: 0 0 auto; }
.appbar-spacer { flex: 1; }

/* --- Scrolling view ----------------------------------------------------- */
#view {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 8px;
}
.wrap { max-width: var(--maxw); margin: 0 auto; }

/* --- Bottom tab bar ----------------------------------------------------- */
/* Last in-flow child of a flex column body, not position:fixed. iOS mis-anchors
   fixed elements on the first paint of a standalone launch and only corrects
   them after a scroll; layout has nothing to get wrong. */
.tabbar {
  flex: 0 0 auto;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 2px 6px;
  color: var(--faint); text-decoration: none;
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
}
.tab svg { width: 21px; height: 21px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab-badge {
  position: absolute; transform: translate(12px, -4px);
  background: var(--accent); color: #04120d;
  font-size: 10px; font-weight: 800; line-height: 1;
  padding: 3px 5px; border-radius: 9px;
}

/* --- Search ------------------------------------------------------------- */
.searchbar { position: relative; display: flex; gap: 8px; }
.searchbar input {
  flex: 1; width: 100%;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 34px 11px 12px; font-size: 16px;
}
.searchbar input:focus { outline: none; border-color: var(--accent); }
.search-clear {
  position: absolute; right: 94px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; color: var(--faint); font-size: 18px;
  padding: 4px 8px; cursor: pointer;
}
.hint { color: var(--faint); font-size: 12.5px; margin: 8px 2px 0; }

/* --- Chips / filters ---------------------------------------------------- */
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}

/* --- Results grid ------------------------------------------------------- */
/* 2 columns on a phone as specified, widening on larger screens. */
.grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(2, 1fr);
  margin-top: 12px;
}
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 12px; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  text-decoration: none; color: inherit;
  display: flex; flex-direction: column;
}
.card-img {
  width: 100%; display: block; background: var(--panel-2);
  object-fit: cover;           /* fills the box without distorting */
}
.card-body { padding: 8px 9px 10px; display: flex; flex-direction: column; gap: 3px; }
.card-caption {
  font-size: 13px; font-weight: 600; line-height: 1.3;
  /* Story 4.3: truncate to 2 lines with an ellipsis. */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 5px; align-items: baseline; }
.card-meta .sep { color: var(--faint); }
.card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 3px; }
.card-id { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.card-price { font-size: 13px; font-weight: 700; color: var(--accent); }
.card-flag {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--warn);
}

/* --- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 15px; font-size: 14.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04120d; }
.btn.primary:disabled { background: var(--panel-2); border-color: var(--border); color: var(--muted); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(242, 112, 107, .35); }
.btn.block { width: 100%; }

/* --- Forms -------------------------------------------------------------- */
.field { margin-bottom: 14px; }
.label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.label .req { color: var(--accent); }
.input, .textarea, .select {
  width: 100%; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; /* 16px stops iOS zooming on focus */
  font-family: inherit;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); }
.input.invalid, .select.invalid { border-color: var(--danger); }
.textarea { min-height: 76px; resize: vertical; }
.err { color: var(--danger); font-size: 12.5px; margin-top: 5px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.check { display: flex; gap: 9px; align-items: flex-start; font-size: 13.5px; color: var(--muted); }
.check input { margin-top: 2px; width: 17px; height: 17px; accent-color: var(--accent); }

/* Price tier pills (single-select, story 2.3) */
.tiers { display: flex; gap: 8px; }
.tier {
  flex: 1; text-align: center; cursor: pointer;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 6px;
}
.tier input { position: absolute; opacity: 0; pointer-events: none; }
.tier-price { display: block; font-size: 16px; font-weight: 800; }
.tier-name { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.tier:has(input:checked) {
  border-color: var(--accent); background: var(--accent-soft);
}
.tier:has(input:checked) .tier-price { color: var(--accent); }

/* --- Panels, headings --------------------------------------------------- */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.panel + .panel { margin-top: 12px; }
h1 { font-size: 20px; margin: 4px 0 12px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 18px 0 8px; }
.sub { color: var(--muted); font-size: 13.5px; margin: -6px 0 14px; }
.count { color: var(--muted); font-size: 13px; margin: 12px 2px 0; }

/* --- States ------------------------------------------------------------- */
.empty { text-align: center; color: var(--muted); padding: 40px 18px; }
.empty-title { font-weight: 700; color: var(--text); margin-bottom: 6px; }
.spinner {
  width: 22px; height: 22px; margin: 28px auto;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 16px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.toast.bad { border-color: rgba(242, 112, 107, .5); color: var(--danger); }

/* --- Demo notice (checkout + payout) ------------------------------------ */
.notice {
  display: flex; gap: 9px; align-items: flex-start;
  background: rgba(229, 169, 74, .1); border: 1px solid rgba(229, 169, 74, .3);
  color: #f0cf96; border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px; line-height: 1.45; margin-bottom: 14px;
}

/* --- Pagination --------------------------------------------------------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 18px 0 4px; }
.pager-info { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* --- Detail page -------------------------------------------------------- */
.hero-img {
  width: 100%; border-radius: var(--radius);
  background: var(--panel-2); display: block;
}
.kv { display: flex; justify-content: space-between; gap: 14px; padding: 7px 0; font-size: 13.5px; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; text-decoration: none;
}
.buybar {
  position: sticky; bottom: 0; margin-top: 14px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  padding: 12px 0 4px;
  display: flex; gap: 10px; align-items: center;
}
.buybar .price { font-size: 19px; font-weight: 800; }

/* --- Upload ------------------------------------------------------------- */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 28px 16px; text-align: center; color: var(--muted);
  background: var(--panel); cursor: pointer;
}
.dropzone:hover { border-color: var(--accent); }
.preview-wrap { position: relative; }
.preview-wrap img { width: 100%; border-radius: var(--radius); display: block; }
.corner-x {
  position: absolute; top: 8px; right: 8px;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(0, 0, 0, .65); border: 1px solid var(--border);
  color: #fff; font-size: 16px; line-height: 1; cursor: pointer;
}
.progress { height: 5px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .18s ease; }

/* --- Cart / receipt ----------------------------------------------------- */
.line { display: flex; gap: 11px; padding: 11px 0; align-items: center; }
.line + .line { border-top: 1px solid var(--border); }
.line img { width: 62px; height: 62px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; }
.line-main { flex: 1; min-width: 0; }
.line-title { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-meta { font-size: 11.5px; color: var(--muted); }
.total { display: flex; justify-content: space-between; font-size: 16px; font-weight: 800; padding-top: 12px; border-top: 1px solid var(--border); margin-top: 6px; }

/* --- Auth --------------------------------------------------------------- */
.segmented { display: flex; background: var(--panel-2); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.segmented button {
  flex: 1; background: none; border: 0; color: var(--muted);
  padding: 9px; font-size: 14px; font-weight: 700; border-radius: 8px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--panel); color: var(--text); }
