:root {
  --bg: #0c0d10; --panel: #16181d; --panel2: #1e2128; --line: #2a2e37;
  --text: #e8eaee; --dim: #9aa0ab; --accent: #ff5c7a; --accent2: #7aa2ff;
  --love: #ff4d6d; --like: #58c470; --dislike: #e05252; --warn: #ffb454;
  /* Safe-area insets: injected by Capacitor SystemBars (insetsHandling=css) on
     Android; falls back to env() elsewhere. Keeps content clear of the status
     and navigation bars (plan §9 mobile padding fix). */
  --sat: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --sab: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, sans-serif; height: 100%; }
body { display: flex; flex-direction: column; }
.hidden { display: none !important; }

#view { flex: 1; overflow-y: auto; padding-top: var(--sat); padding-bottom: calc(76px + var(--sab)); -webkit-overflow-scrolling: touch; }
#view.with-genbar { padding-bottom: calc(178px + var(--sab)); } /* keep last card's buttons clear of the Generate bar */
#nav { position: fixed; bottom: 0; left: 0; right: 0; padding-bottom: var(--sab); display: flex;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  background: var(--panel); border-top: 1px solid var(--line); z-index: 40; }
#nav::-webkit-scrollbar { display: none; }
#nav a { flex: 0 0 auto; min-width: 96px; display: flex; align-items: center; justify-content: center; height: 60px;
  color: var(--dim); text-decoration: none; font-weight: 600; font-size: 15px; }
#nav a.active { color: var(--accent); }

h1 { font-size: 22px; margin: 14px 16px 6px; } h2 { font-size: 17px; margin: 14px 16px 6px; }
.pad { padding: 0 16px; }
input, select, textarea { width: 100%; padding: 12px; margin: 6px 0; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 16px; }
textarea { resize: vertical; min-height: 84px; }
button { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-size: 16px; font-weight: 600; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button:disabled { opacity: .45; }
.row { display: flex; gap: 8px; align-items: center; } .row > * { flex: 1; }
.muted { color: var(--dim); font-size: 13px; }
.err { color: var(--dislike); font-size: 14px; white-space: pre-wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  margin: 10px 16px; padding: 14px; }

/* round cards */
.imgcard { margin: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.imgcard img { width: 100%; display: block; aspect-ratio: 832/1216; object-fit: cover; background: #000; }
.actions { display: flex; border-top: 1px solid var(--line); }
.actions button { flex: 1; border: 0; border-radius: 0; background: transparent; font-size: 20px; padding: 12px 0; }
.actions button.sel-love { color: var(--love); background: rgba(255,77,109,.12); }
.actions button.sel-like { color: var(--like); background: rgba(88,196,112,.12); }
.actions button.sel-dislike { color: var(--dislike); background: rgba(224,82,82,.12); }
.roundblock { margin-bottom: 6px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 8px; background: var(--panel2);
  color: var(--dim); font-size: 12px; margin: 2px 4px 2px 0; }
.badge.explore { color: var(--warn); }

/* sticky generate bar */
#genbar { position: fixed; left: 0; right: 0; bottom: calc(60px + var(--sab)); padding: 10px 16px;
  background: linear-gradient(transparent, var(--bg) 30%); z-index: 30; }
#genbar button { width: 100%; padding: 15px; font-size: 17px; }

/* modal */
#modal-root .overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50;
  display: flex; align-items: flex-end; }
#modal-root .sheet { background: var(--panel); width: 100%; max-height: 82vh; overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet h3 { margin: 4px 0 10px; }
.sheet .kv { margin: 4px 0; } .sheet .kv b { color: var(--dim); font-weight: 600; margin-right: 6px; }
pre.wrap { white-space: pre-wrap; word-break: break-word; background: var(--panel2);
  padding: 10px; border-radius: 10px; font-size: 13px; }

/* tag chips */
.chiprow { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { display: flex; align-items: center; gap: 6px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; font-size: 13px; }
.chip .w { min-width: 26px; text-align: center; font-weight: 700; }
.chip .w.pos { color: var(--like); } .chip .w.neg { color: var(--dislike); }
.chip button { padding: 0 8px; border: 0; background: transparent; color: var(--text); font-size: 15px; }

/* collection grid */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 12px; }
.grid3 .thumb { position: relative; border-radius: 10px; overflow: hidden; background: #000; }
.grid3 img { width: 100%; aspect-ratio: 832/1216; object-fit: cover; display: block; }
.galcell { margin-bottom: 10px; }
.galcap { font-size: 11px; padding: 4px 2px 8px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.galcap .badge { font-size: 10px; }
.galwhy { width: 100%; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.roundhead { padding: 10px 12px 4px; }
.roundhead .rowline { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.roundhead .badge { font-size: 10px; }
.whyline { padding: 2px 12px 0; font-size: 12px; color: var(--dim); }
.whyprompt { padding: 2px 12px 6px; font-size: 11px; color: var(--dim); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.whyprompt[data-expand="1"] { white-space: normal; }
.grid3 .imgcard { margin: 0 0 8px 0; border-radius: 10px; }
.grid3 .imgcard .actions { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px; }
.grid3 .imgcard .actions button { flex: 1; min-width: 0; padding: 4px 2px; font-size: 12px; }
.grid2 .thumb { position: relative; border-radius: 12px; overflow: hidden; background: #000; }
.grid2 img { width: 100%; aspect-ratio: 832/1216; object-fit: cover; display: block; }

/* fullscreen image viewer */
.viewer { position: fixed; inset: 0; background: #000; z-index: 45; display: flex; flex-direction: column; }
.vw-top { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--sat)) 12px 8px; }
.vw-stage { position: relative; flex: 1; overflow: hidden; touch-action: none; }
#vw-img { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; user-select: none; -webkit-user-drag: none; touch-action: none; }
.vw-bar { display: flex; gap: 8px; padding: 10px 12px calc(10px + var(--sab)); }
.vw-bar button { flex: 1; }
.vw-bar #vw-close { flex: 0 0 auto; width: 46px; }

#toast { position: fixed; bottom: 130px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px;
  border-radius: 10px; z-index: 80; font-size: 14px; }
.spin { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--dim);
  border-top-color: var(--text); border-radius: 50%; animation: r 0.9s linear infinite; vertical-align: -2px; }
@keyframes r { to { transform: rotate(360deg); } }
button.sdel { flex: 0 0 auto; width: 52px; }
.confirm-veil { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.confirm-pop { background: var(--panel); border-radius: 14px; padding: 16px; width: 100%; max-width: 360px; }
.confirm-pop h3 { margin: 2px 0 8px; }
.confirm-pop .row { margin-top: 14px; }
button.danger { background: #b23b3b; }
button.danger:disabled { opacity: .55; }
#ts-pending { margin-top: 8px; }
#ts-pending:empty { display: none; }
#ts-pending .chip { outline: 1px dashed var(--dim); }
#ts-pending { margin-top: 8px; }
#ts-pending:empty { display: none; }
#ts-pending .chip { outline: 1px dashed var(--dim); }
#collbar { position: fixed; left: 0; right: 0; bottom: calc(60px + var(--sab)); padding: 10px 16px;
  background: linear-gradient(transparent, var(--bg) 30%); z-index: 30; display: flex; gap: 8px; align-items: center; }
#collbar.hidden { display: none; }
#collbar #cb-info { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#collbar button { flex: 0 0 auto; padding: 10px 12px; }
#coll .thumb.sel { outline: 2px solid var(--accent2); }
.switch { position: relative; display: inline-block; width: 52px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .knob { position: absolute; inset: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; transition: .2s; }
.switch .knob::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: var(--dim); border-radius: 50%; transition: .2s; }
.switch input:checked + .knob { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .knob::before { transform: translateX(24px); background: #fff; }
.tt-pick { position: relative; }
.tt-pick img { width: 100%; display: block; border-radius: 8px; }
.tt-pick.sel img { outline: 2px solid var(--accent2); }
#genbar button { white-space: nowrap; }

/* v0.26.1: targeted-rating sheet — the selected state must be VISIBLE
   (the chips toggled a bare .sel class with no styling: taps "did nothing") */
#tr-tags .chip { cursor: pointer; }
#tr-tags.tr-like .chip.sel { outline: 2px solid var(--like); background: rgba(88,196,112,.15); }
#tr-tags.tr-dislike .chip.sel { outline: 2px solid var(--dislike); background: rgba(224,82,82,.15); }
#tr-tags .chip.sel::after { content: '\2713'; font-size: 13px; font-weight: 700; }
/* v0.57: the \U0001F9EC profile sheet's chips - same lesson as tr-tags above:
   a toggled .sel class with no styling reads as "taps do nothing" */
#cp-chips .chip { cursor: pointer; }
#cp-chips .chip.sel { outline: 2px solid var(--like); background: rgba(88,196,112,.15); }
#cp-chips .chip.sel::after { content: '\2713'; font-size: 13px; font-weight: 700; }

@keyframes savespin { to { transform: rotate(360deg); } }
@keyframes savepulse { 50% { opacity: .35; } }
.save-spin.perm { display: block; width: auto; height: auto; padding: 5px 12px;
  background: #e8b44a; color: #000; font-size: 12px; font-weight: 700;
  border-radius: 14px; cursor: pointer; pointer-events: auto;
  animation: savepulse 1.6s ease infinite; }
