/* ============================================================
   Matru Pitru — minimal, content-first, Roboto. Light mode v1.
   ============================================================ */

/* ---- Self-hosted Roboto (variable, CSP-safe, no CDN) ---- */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('../fonts/roboto-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('../fonts/roboto-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---- Tokens ---- */
:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #0aa5b5;
  --accent-ink: #08828f;
  --line: #ececec;
  --radius: 10px;
  --wrap: 1000px;
  --font: 'Roboto', system-ui, -apple-system, Segoe UI, sans-serif;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); }
h1, h2, h3 { font-weight: 500; line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 .4em; }
h1 { font-size: clamp(1.55rem, 4vw, 2.1rem); }
h2 { font-size: 1.25rem; }
button { font-family: inherit; cursor: pointer; }
.muted { color: var(--muted); }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  max-width: var(--wrap); margin: 0 auto;
  padding: 1.1rem 1.25rem;
  flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; gap: .12rem; line-height: 1.2; }
.wordmark {
  font-weight: 700; font-size: 1.05rem; letter-spacing: -0.02em;
  color: var(--text); white-space: nowrap;
}
.brand-sub {
  font-size: .72rem; font-weight: 400; color: var(--muted);
  letter-spacing: 0; white-space: normal; max-width: 52ch;
}
.sample-tag {
  font-size: .68rem; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: .05rem .5rem; margin-left: -.4rem;
}
.tabs { display: flex; gap: 1.25rem; margin-left: auto; flex-wrap: wrap; }
.tabs a {
  color: var(--muted); font-size: .93rem; padding: .2rem 0;
  border-bottom: 2px solid transparent; transition: color .15s;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---- Layout ---- */
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 1rem 1.25rem 4rem; }
.tab[hidden] { display: none; }
.section-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin: 1.5rem 0 1rem;
}

/* ---- Buttons ---- */
.btn {
  display: inline-block; border: 1px solid var(--accent); background: var(--accent);
  color: #fff; padding: .6rem 1.15rem; border-radius: var(--radius);
  font-size: .95rem; font-weight: 500; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--accent-ink); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--accent-ink); }
.link-btn {
  border: none; background: none; color: var(--accent); padding: 0;
  font-size: .92rem; font-weight: 500;
}
.link-btn:hover { color: var(--accent-ink); }
.danger { color: #c0392b; }
.danger:hover { color: #96271b; }

/* ---- Find My Photos ---- */
.hero { max-width: 640px; margin: 2.5rem auto 1.5rem; text-align: center; }
.hero .lead { color: var(--muted); font-size: 1.05rem; margin: .4rem 0 1.5rem; }
.find-actions { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }
.status { min-height: 1.4em; margin-top: 1rem; color: var(--muted); font-size: .92rem; }

.cam-wrap { max-width: 480px; margin: 0 auto 2rem; text-align: center; }
.cam-video {
  width: 100%; border-radius: var(--radius); background: #000;
  transform: scaleX(-1); /* mirror the PREVIEW only; embedded pixels are unmirrored */
  aspect-ratio: 4 / 3; object-fit: cover;
}
.cam-controls { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: .9rem; }

.results { margin-top: 2rem; border-top: 1px solid var(--line); padding-top: 1.5rem; }
.results-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.results-actions { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.strict { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); }
.strict input[type=range] { accent-color: var(--accent); }
.strict-val { min-width: 2.6em; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

/* ---- Photo grid ---- */
.grid {
  display: grid; gap: 5px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.cell {
  position: relative; padding: 0; border: none; background: var(--bg-soft);
  border-radius: 6px; overflow: hidden; aspect-ratio: 1 / 1;
  transition: opacity .15s, transform .15s; outline: none;
}
.cell img { width: 100%; height: 100%; object-fit: cover; }
.cell:hover { opacity: .9; transform: scale(.99); }
.cell:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.badge {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(0,0,0,.62); color: #fff; font-size: .72rem; font-weight: 500;
  padding: .1rem .4rem; border-radius: 999px;
}
.badge-soft { background: rgba(0,0,0,.4); font-weight: 400; }

/* selection mode */
.cell.selectable { cursor: pointer; }
.cell .check {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px;
  border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.25);
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}
.cell.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.cell.selected img { opacity: .8; }
.cell.selected .check { background: var(--accent); border-color: #fff; }
.cell.selected .check::after {
  content: ''; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.cell-remove {
  position: absolute; top: 5px; right: 5px; width: 22px; height: 22px;
  border-radius: 50%; border: none; background: rgba(0,0,0,.55); color: #fff;
  font-size: 15px; line-height: 1; display: none;
}
.cell:hover .cell-remove, .cell:focus-within .cell-remove { display: block; }

/* ---- Chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; }
.chip {
  display: inline-flex; align-items: center; gap: .45rem;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: 999px; padding: .32rem .8rem; font-size: .85rem; transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-person { padding-left: .3rem; }
.chip-more { color: var(--accent); border-style: dashed; }
.avatar {
  display: inline-block; border-radius: 50%; background-size: cover; background-position: center;
  flex: none;
}

/* selection bar */
.selbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: 1rem; font-size: .9rem;
}
.selbar-actions { display: flex; gap: 1.25rem; }

/* ---- Collections ---- */
.col-list { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-top: 1.25rem; }
.col-card { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.col-cover {
  display: block; width: 100%; aspect-ratio: 3 / 2; border: none; padding: 0;
  background: var(--bg-soft) center/cover no-repeat;
}
.col-info { padding: .8rem .9rem 1rem; }
.col-name { font-weight: 500; }
.col-count { font-size: .82rem; margin: .1rem 0 .7rem; }
.col-actions { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .85rem; }
.detail-title { margin-top: .3rem; }
.empty { color: var(--muted); padding: 2rem 0; max-width: 40ch; }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45); padding: 1rem;
}
.modal-box {
  background: var(--bg); border-radius: var(--radius); padding: 1.4rem; width: 100%;
  max-width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal-box h3 { margin-bottom: .9rem; }
.modal-list { display: flex; flex-direction: column; gap: .3rem; max-height: 40vh; overflow: auto; margin-bottom: 1rem; }
.modal-item {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  padding: .55rem .75rem; font-size: .92rem; text-align: left; color: var(--text);
}
.modal-item:hover { border-color: var(--accent); }
.modal-new { display: flex; gap: .5rem; margin-bottom: 1rem; }
.modal-new input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .6rem; font: inherit; font-size: .9rem;
}
.modal-new input:focus { outline: none; border-color: var(--accent); }
.modal-new button {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 8px; padding: .5rem .7rem; font-size: .85rem; white-space: nowrap;
}
.modal-close { display: block; margin: 0 auto; border: none; background: none; color: var(--muted); font-size: .9rem; }

/* ---- Lightbox ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.9); padding: clamp(.5rem, 3vw, 2rem);
}
.lightbox[hidden] { display: none; }
.lb-figure { margin: 0; max-width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.lb-img { max-width: 100%; max-height: 82vh; object-fit: contain; border-radius: 6px; background: #111; }
.lb-cap {
  color: #eee; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; padding: .8rem .2rem 0; font-size: .88rem;
}
.lb-meta { color: #cfcfcf; }
.lb-actions { display: flex; gap: 1.25rem; }
.lb-actions a { color: #fff; }
.lb-actions a:hover { color: var(--accent); }
.lb-close {
  position: absolute; top: 1rem; right: 1.25rem; border: none; background: none;
  color: #fff; font-size: 2rem; line-height: 1; opacity: .8;
}
.lb-close:hover { opacity: 1; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); border: none;
  background: rgba(255,255,255,.1); color: #fff; font-size: 1.8rem; line-height: 1;
  width: 46px; height: 46px; border-radius: 50%;
}
.lb-nav:hover { background: rgba(255,255,255,.22); }
.lb-prev { left: 1rem; }
.lb-next { right: 1rem; }

/* ---- Footer ---- */
.site-footer {
  max-width: var(--wrap); margin: 0 auto; padding: 2rem 1.25rem 3rem;
  border-top: 1px solid var(--line); display: flex; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted);
}

/* ---- Boot / fatal / toast / spinner ---- */
.boot {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: .6rem; background: var(--bg); color: var(--muted); font-size: .95rem; z-index: 80;
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.fatal { text-align: center; max-width: 34ch; }
.fatal h1 { color: var(--text); }
#toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1.5rem);
  background: #1a1a1a; color: #fff; padding: .6rem 1rem; border-radius: 999px;
  font-size: .88rem; opacity: 0; pointer-events: none; transition: all .2s; z-index: 90;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Responsive ---- */
@media (max-width: 560px) {
  .topbar { padding: .9rem 1rem; }
  .tabs { gap: 1rem; width: 100%; margin-left: 0; }
  .tabs a { font-size: .88rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 4px; }
  .results-head { align-items: flex-start; }
  .site-footer { flex-direction: column; gap: .3rem; }
}
