/* NyaFind Mini App — black + soft pink brand, Apple-style */
:root {
  --bg: #0a0a0e;
  --bg2: #121218;
  --text: #f5f5f7;
  --hint: #8f8f9a;
  --pink: #ff4d94;
  --pink-soft: #ffb3cf;
  --pink-dim: rgba(255, 77, 148, .16);
  --fill: rgba(255, 255, 255, .07);
  --sep: rgba(255, 255, 255, .09);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --dock-h: 118px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
  min-height: 100vh;
}
button { font-family: inherit; }
::selection { background: var(--pink-dim); }

/* ---------- top hud: context chip only ---------- */
.context {
  position: sticky; top: 0; z-index: 20;
  display: none; align-items: center; gap: 10px;
  margin: 0; padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  backdrop-filter: saturate(160%) blur(20px);
  border-bottom: .5px solid var(--sep);
  font-size: 13px; color: var(--hint);
}
.context img { width: 32px; height: 32px; border-radius: 9px; object-fit: cover; background: var(--fill); }
.context .ctx-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 500; }
.context button {
  border: 0; background: var(--fill); color: var(--pink-soft); font-size: 13px;
  cursor: pointer; padding: 7px 12px; font-weight: 500; border-radius: 999px;
}

/* ---------- hero / examples ---------- */
.hero { text-align: center; padding: 54px 24px 6px; }
.hero .logo { display: flex; justify-content: center; margin-bottom: 4px; }
.hero .logo svg { filter: drop-shadow(0 6px 24px rgba(255, 46, 126, .35)); }
.hero h1 { font-size: 23px; font-weight: 700; margin: 12px 0 6px; letter-spacing: -.02em; }
.hero h1 em { font-style: normal; color: var(--pink); }
.hero p { color: var(--hint); font-size: 14px; margin: 0 auto; max-width: 300px; line-height: 1.45; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 18px 16px 6px; }
.chip {
  border: .5px solid var(--sep); background: var(--fill); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; cursor: pointer;
  transition: transform .1s, border-color .15s;
}
.chip:active { transform: scale(.95); border-color: var(--pink); }
.disclaimer {
  color: #5b5b66; font-size: 11px; line-height: 1.55; text-align: center;
  padding: 8px 26px 18px; max-width: 560px; margin: 0 auto;
}

/* ---------- settings row (history tab) ---------- */
.setrow {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border: .5px solid var(--sep);
  border-radius: 14px; padding: 13px 14px; margin: 10px 0 14px;
}
.setrow .stitle { flex: 1; font-size: 15px; }
.setrow .ssub { font-size: 12px; color: var(--hint); margin-top: 2px; }
.switch { position: relative; width: 50px; height: 30px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.knob {
  position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,.16);
  transition: background .2s; cursor: pointer;
}
.knob::before {
  content: ""; position: absolute; width: 26px; height: 26px; border-radius: 50%;
  top: 2px; left: 2px; background: #fff; transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.switch input:checked + .knob { background: var(--pink); }
.switch input:checked + .knob::before { transform: translateX(20px); }

/* ---------- gallery ---------- */
#status { padding: 10px 16px 8px; color: var(--hint); font-size: 13px; min-height: 18px; }
.grid { display: flex; gap: 8px; padding: 0 8px calc(var(--dock-h) + var(--safe-b) + 14px); align-items: flex-start; }
.col { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cell {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: var(--bg2); cursor: pointer;
  transform: translateZ(0);
}
.cell img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .25s ease;
}
.cell img.ld { opacity: 1; }
.cell .cos {
  position: absolute; top: 6px; left: 6px; font-size: 10px; font-weight: 600;
  background: rgba(0,0,0,.6); color: var(--pink-soft); border-radius: 6px; padding: 2px 5px;
  font-variant-numeric: tabular-nums;
}
.skeleton { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

.loader { display: none; justify-content: center; padding: 18px 0 calc(var(--dock-h) + 24px); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--fill); border-top-color: var(--pink);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 60px 30px; color: var(--hint); font-size: 14px; line-height: 1.5; display: none; }

/* ---------- viewer ---------- */
#viewer {
  position: fixed; inset: 0; z-index: 50; display: none;
  background: rgba(4, 4, 7, .94); flex-direction: column;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
#viewer.open { display: flex; animation: vfade .18s ease; }
@keyframes vfade { from { opacity: 0; } to { opacity: 1; } }
.vimg-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 8px; }
#vimg { max-width: 100%; max-height: 100%; border-radius: 10px; object-fit: contain; }
.vclose {
  position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: 12px;
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.12); color: #fff; font-size: 16px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 2;
}
.vmeta { padding: 4px 18px 0; color: rgba(255,255,255,.45); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vactions { display: flex; gap: 10px; padding: 12px 16px calc(14px + var(--safe-b)); }
.vbtn {
  flex: 1; border: 0; border-radius: 13px; padding: 13px 10px;
  font-size: 15px; font-weight: 600; cursor: pointer; transition: transform .1s, opacity .15s;
}
.vbtn:active { transform: scale(.97); opacity: .85; }
.vbtn.primary { background: linear-gradient(135deg, #ff2e7e, #ff5c9d); color: #fff;
  box-shadow: 0 4px 18px rgba(255, 46, 126, .3); }
.vbtn.secondary { background: rgba(255,255,255,.1); color: #fff; }

/* ---------- bottom dock: search + tabs ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 12px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(24px); backdrop-filter: saturate(160%) blur(24px);
  border-top: .5px solid var(--sep);
}
.dock-inner { max-width: 680px; margin: 0 auto; }
.searchrow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.searchbox {
  flex: 1; display: flex; align-items: center; gap: 6px;
  background: var(--fill); border: .5px solid var(--sep);
  border-radius: 999px; padding: 0 8px 0 14px;
  height: 44px; transition: border-color .18s, box-shadow .18s;
}
.searchbox:focus-within {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--pink-dim);
}
.searchbox > svg { flex: 0 0 auto; color: var(--hint); }
#q {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--text); font-size: 16px; height: 100%;
}
#q::placeholder { color: var(--hint); }
#q::-webkit-search-cancel-button { display: none; }
.iconbtn {
  border: .5px solid var(--sep); background: var(--fill); color: var(--pink-soft);
  width: 44px; height: 44px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto; transition: transform .1s, opacity .15s;
}
.iconbtn:active { transform: scale(.92); opacity: .7; }
.iconbtn.go { background: linear-gradient(135deg, #ff2e7e, #ff5c9d); color: #fff; border: 0; }
#clearq {
  display: none; border: 0; background: rgba(255,255,255,.25); color: var(--bg);
  width: 20px; height: 20px; border-radius: 50%; font-size: 11px; line-height: 1;
  align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto; padding: 0;
}
.tabbar { display: flex; justify-content: space-around; }
.tab {
  border: 0; background: transparent; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; font-weight: 500; cursor: pointer; padding: 3px 28px; border-radius: 10px;
}
.tab.active { color: var(--pink); }

/* ---------- history ---------- */
#history { display: none; padding: 8px 12px calc(var(--dock-h) + var(--safe-b) + 10px); max-width: 680px; margin: 0 auto; }
.hrow {
  display: flex; align-items: center; gap: 12px; padding: 11px 8px;
  border-bottom: .5px solid var(--sep); cursor: pointer; border-radius: 10px;
}
.hrow:active { background: var(--fill); }
.hicon {
  width: 34px; height: 34px; border-radius: 10px; background: var(--fill);
  display: flex; align-items: center; justify-content: center;
  color: var(--pink-soft); flex: 0 0 auto;
}
.hbody { flex: 1; min-width: 0; }
.htitle { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsub { font-size: 12px; color: var(--hint); margin-top: 2px; }
.hthumbs { display: flex; flex: 0 0 auto; }
.hthumbs img {
  width: 34px; height: 34px; border-radius: 8px; object-fit: cover;
  border: 2px solid var(--bg); margin-left: -10px; background: var(--fill);
}
.hthumbs img:first-child { margin-left: 0; }

/* ---------- overlays ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: none; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px;
}
.gate .logo { margin-bottom: 14px; }
.gate .logo svg { filter: drop-shadow(0 6px 24px rgba(255, 46, 126, .35)); }
.gate h2 { font-size: 20px; margin: 0 0 10px; letter-spacing: -.02em; }
.gate p { color: var(--hint); font-size: 13.5px; max-width: 320px; line-height: 1.55; margin: 0 0 26px; text-align: left; }
.gate p b { color: var(--text); }
.gate .vbtn { flex: none; width: 100%; max-width: 320px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-h) + 14px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #1d1d24; color: var(--text); border: .5px solid var(--sep);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 86vw; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
