* { box-sizing: border-box; margin: 0; padding: 0; }

/* the hidden attribute must always win, even over display:flex rules below */
[hidden] { display: none !important; }

:root {
  --bg: #0e1116;
  --panel: #161b23;
  --panel-2: #1d2430;
  --text: #e8ecf1;
  --muted: #8b96a5;
  --accent: #4f8cff;
  --danger: #e5534b;
  --radius: 10px;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* masked code fields (type=text so password managers ignore them) */
.code-input {
  -webkit-text-security: disc;
  background: var(--panel);
  border: 1px solid #2a3342;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 17px;
  padding: 13px 14px;
  outline: none;
}
.code-input:focus { border-color: var(--accent); }

.screen { min-height: 100dvh; }

.center-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.lock-badge { font-size: 52px; }

h1 { font-size: 26px; font-weight: 650; }

.muted { color: var(--muted); font-size: 14px; line-height: 1.5; }
.narrow { max-width: 420px; }
.center { text-align: center; padding: 40px 24px; }

.stack { display: flex; flex-direction: column; gap: 10px; width: min(340px, 90vw); }

input[type="password"] {
  background: var(--panel);
  border: 1px solid #2a3342;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 17px;
  padding: 13px 14px;
  outline: none;
}
input[type="password"]:focus { border-color: var(--accent); }

.btn {
  background: var(--panel-2);
  border: 1px solid #2a3342;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  padding: 11px 16px;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: #ff8d87; border-color: #53302e; }
.btn.small { padding: 7px 12px; font-size: 13px; }

.error { color: #ff8d87; font-size: 14px; }

/* ---- gallery ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.brand { font-weight: 650; font-size: 16px; white-space: nowrap; }
.spacer { flex: 1; }

/* ---- phones ----
   The toolbar used to run off the right edge (Lock ended up off-screen), which
   forced the page wider than the viewport and made the browser zoom out — the
   cause of "everything is tiny and I have to pinch to hit anything". Let it
   wrap, and give every control a proper 44px touch target. */
@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 8px;
    column-gap: 8px;
    padding-left: 10px;
    padding-right: 10px;
  }
  .topbar .spacer { display: none; }
  .topbar .btn.small {
    flex: 0 1 auto;
    min-height: 44px;
    padding: 10px 11px;
    font-size: 14px;
  }
  /* the header is sticky, so keep it short — photos get the screen */
  .topbar { position: sticky; }
  .group-select { min-height: 44px; max-width: 100%; flex: 1 1 140px; }
  #file-count { flex: 0 0 auto; }

  .filter-bar { padding: 6px 10px; scroll-padding-left: 10px; }
  .fbtn { min-height: 44px; padding: 10px 14px; font-size: 14px; }

  /* every control inside a dialog needs a real thumb-sized target too —
     the Close button was 41px, which is why closing things was fiddly */
  .modal button,
  .modal .btn,
  .modal .btn.small {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14px;
  }
  .modal-card { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

  /* the filter bar is sticky under the topbar, which is now taller */
  .filter-bar { top: auto; position: static; }
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 4px;
  padding: 4px 4px calc(24px + env(safe-area-inset-bottom));
}
@media (max-width: 480px) {
  .gallery { grid-template-columns: repeat(3, 1fr); }
}

.tile {
  aspect-ratio: 1;
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(0,0,0,.65);
  border-radius: 6px;
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
}
.tile .fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  color: var(--muted);
  font-size: 12px;
  padding: 8px;
  text-align: center;
  word-break: break-all;
}
.tile .fallback .ico { font-size: 30px; }

/* ---- upload ---- */
.upload-status { padding: 10px 16px; }
.upload-text { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.progress {
  background: var(--panel);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}
.progress-bar {
  background: var(--accent);
  border-radius: 99px;
  height: 100%;
  transition: width .15s;
  width: 0%;
}

.drop-hint {
  position: fixed;
  inset: 10px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: rgba(79, 140, 255, .12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  pointer-events: none;
  z-index: 50;
}

/* ---- groups / modals ---- */
.group-select {
  background: var(--panel-2);
  border: 1px solid #2a3342;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
  max-width: 40vw;
}
.group-select.wide { max-width: none; width: 100%; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, .8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  z-index: 200;
}
.modal-card {
  background: var(--panel);
  border: 1px solid #2a3342;
  border-radius: 14px;
  padding: 16px;
  width: min(440px, calc(100vw - 20px));
  max-width: calc(100vw - 20px);
  max-height: 86dvh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card > * { max-width: 100%; min-width: 0; }
.modal-card h2 { font-size: 19px; }
.modal-card .form-title { font-size: 15px; margin-top: 4px; }
.modal-card .stack { width: 100%; }
.modal-card input[type="text"] {
  background: var(--panel-2);
  border: 1px solid #2a3342;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
}
.field-label { font-size: 13px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.check-row input { margin-top: 2px; accent-color: var(--accent); }
.check-row strong { color: #ffb3ae; }

.review-list {
  list-style: none;
  max-height: 34dvh;
  overflow-y: auto;
  border: 1px solid #2a3342;
  border-radius: var(--radius);
  padding: 8px 12px;
}
.review-list li {
  font-size: 13px;
  color: var(--muted);
  padding: 4px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.review-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  flex: none;
  background: var(--panel-2);
}
.review-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.review-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.review-sel {
  flex: none;
  max-width: 40%;
  padding: 6px 8px;
  font-size: 13px;
}
.review-list.simple .review-sel { display: none; }
.review-summary { font-weight: 600; color: var(--text); padding: 8px 4px; }

.groups-list { display: flex; flex-direction: column; gap: 8px; }
.group-row {
  background: var(--panel-2);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  flex-wrap: wrap;
}
.group-row .gname { font-weight: 600; font-size: 15px; }
.group-row .gmeta { color: var(--muted); font-size: 12px; }

.tile .group-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(0,0,0,.65);
  border-radius: 6px;
  color: #cdd7e3;
  font-size: 11px;
  padding: 2px 7px;
  max-width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile .group-badge.unsorted { background: #b45309; color: #fff; font-weight: 700; }
.tile.is-unsorted { outline: 2px solid #f59e0b; outline-offset: -2px; }
.tile .group-badge.trashed { background: #6b21a8; color: #fff; font-weight: 700; }
.tile.is-trashed { opacity: .6; outline: 2px dashed #a855f7; outline-offset: -2px; }
.chip-warn {
  background: #b45309;
  border: none;
  border-radius: 99px;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  white-space: nowrap;
  flex: none;
}

/* ---- multi-select / batch move ---- */
.tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.selected::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.select-bar {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border: 1px solid #2a3342;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  z-index: 60;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

/* ---- chat ---- */
.chat-card { height: min(90dvh, 950px); width: min(720px, calc(100vw - 20px)); }
@media (max-width: 600px) {
  .modal:has(.chat-card) { padding: 0; }
  .chat-card {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}
.camera-card { width: min(560px, calc(100vw - 20px)); }

/* ---- calls ---- */
.call-card { width: min(560px, calc(100vw - 20px)); text-align: center; }
.call-videos { position: relative; }
#call-remote-video {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 10px;
  object-fit: cover;
}
#call-local-video {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 28%;
  border-radius: 8px;
  border: 1px solid #2a3342;
  background: #000;
  object-fit: cover;
}
.call-actions { justify-content: center; gap: 14px; }
#cam-preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 10px;
  object-fit: cover;
}
#cam-record.recording { background: var(--danger); border-color: var(--danger); }

.chat-media-wrap { position: relative; display: inline-block; }
.chat-media-wrap .play-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  text-shadow: 0 2px 8px rgba(0,0,0,.8);
  pointer-events: none;
}
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 2px;
}
.bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.bubble .bt { display: block; font-size: 10px; opacity: .6; margin-top: 3px; }
#chat-input { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid #2a3342; border-radius: var(--radius); color: var(--text); font-size: 15px; padding: 10px 12px; outline: none; }

/* ---- "more" menu (phones) ----
   The advanced controls live in here on a phone so the toolbar stays short
   and only shows things with an obvious meaning. */
.more-menu {
  position: absolute;
  top: calc(100% - 4px);
  right: 10px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid #2a3342;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5);
}
.more-item {
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  min-height: 46px;
  padding: 12px 14px;
  text-align: left;
}
.more-item:hover { background: var(--panel-2); }
.more-item[hidden] { display: none; }

/* phone: advanced buttons move into the menu */
body.phone .topbar .adv { display: none; }
/* desktop: no menu needed, everything fits */
body.desktop #btn-more { display: none; }

/* ---- post-unlock quiet screen ----
   After the code is accepted we land here, not on a wall of thumbnails, so
   nothing private is on screen if someone glances over in public. */
.gallery-curtain {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 24px;
}
.curtain-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  max-width: 30ch;
}
.curtain-lock { font-size: 34px; opacity: .8; }
.curtain-title { font-size: 17px; font-weight: 600; margin: 0; }
.curtain-sub { color: var(--muted); font-size: 14px; margin: 0 0 8px; line-height: 1.5; }
.gallery-curtain .btn { min-height: 46px; padding: 12px 22px; font-size: 15px; }

/* ---- reply to a specific message ---- */
.chat-reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 2px 6px;
  padding: 8px 10px;
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
}
.chat-reply-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-reply-who { color: var(--accent); font-size: 12px; font-weight: 600; }
.chat-reply-text {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* the quoted message shown inside a bubble */
.quote {
  display: block;
  border-left: 3px solid rgba(255,255,255,.35);
  padding: 4px 8px;
  margin-bottom: 5px;
  background: rgba(0,0,0,.18);
  border-radius: 6px;
  cursor: pointer;
}
.quote .qwho { display: block; font-size: 11px; font-weight: 600; opacity: .9; }
.quote .qtext {
  display: block;
  font-size: 12.5px;
  opacity: .85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.bubble .reply-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 14px;
  min-width: 44px;
  opacity: .55;
}
.bubble .reply-btn:hover { opacity: 1; }
.bubble.flash { animation: quoteflash 1.1s ease; }
@keyframes quoteflash {
  0%, 100% { background-color: inherit; }
  30% { background-color: rgba(90,160,255,.35); }
}
@media (prefers-reduced-motion: reduce) { .bubble.flash { animation: none; } }
.typing { font-size: 12px; color: var(--accent); }
.bubble .chat-media {
  max-width: min(220px, 60vw);
  border-radius: 10px;
  display: block;
  cursor: pointer;
  margin: 2px 0;
}
.bubble audio { max-width: min(230px, 62vw); display: block; margin: 2px 0; }
.bubble .att-btn {
  background: rgba(0,0,0,.25);
  border: none;
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  padding: 8px 12px;
  display: block;
  margin: 2px 0;
}
.bubble .ticks { font-size: 10px; opacity: .7; margin-left: 6px; }
#chat-mic.rec { background: var(--danger); border-color: var(--danger); }

/* ---- seen / watching eyes ---- */
.tile .eye {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(0,0,0,.65);
  border-radius: 6px;
  font-size: 12px;
  padding: 2px 6px;
  display: none;
}
.tile .eye.seen { display: block; filter: grayscale(1) opacity(.75); }
.tile .eye.live { display: block; filter: none; }
.tile .eye.live::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #2ecc71; margin-left: 4px; vertical-align: middle; }
.viewer-eye { font-size: 12px; color: var(--muted); margin-right: 6px; white-space: nowrap; }

/* ---- media filter bar ---- */
.filter-bar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  position: sticky;
  top: 52px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  z-index: 4;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.fbtn {
  background: var(--panel-2);
  border: 1px solid #2a3342;
  border-radius: 99px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  padding: 7px 14px;
  white-space: nowrap;
  flex: none;
}
.fbtn.active { background: var(--accent); border-color: var(--accent); font-weight: 600; }

.tile .from-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(0,0,0,.7);
  border-radius: 6px;
  color: #cdd7e3;
  font-size: 10px;
  padding: 2px 6px;
}

/* ---- viewer ---- */
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 110;
  background: rgba(0,0,0,.45);
  border: none;
  color: #fff;
  font-size: 40px;
  line-height: 1;
  width: 54px;
  height: 84px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.viewer-nav.prev { left: 0; border-radius: 0 10px 10px 0; }
.viewer-nav.next { right: 0; border-radius: 10px 0 0 10px; }
.viewer-nav:active { background: rgba(0,0,0,.7); }

.viewer {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, .96);
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
}
.viewer-name {
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
}
.viewer-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.viewer-body img,
.viewer-body video {
  max-width: 100vw;
  max-height: calc(100dvh - 70px);
  object-fit: contain;
}
.viewer-progress { width: min(320px, 80vw); text-align: center; display: flex; flex-direction: column; gap: 10px; }
