/* ===========================================================================
   InstaNoah — Arraiá do Noah
   Tema: festa junina / campo. Azul bebê + azul marinho, girassol, xadrez.
   =========================================================================== */
:root {
  --blue: #4a7fb5;
  --blue-deep: #284b73;
  --blue-ink: #1d3a5a;
  --sky: #cfe6fb;
  --sky-soft: #e9f4ff;
  --sun: #f6c945;
  --sun-deep: #e0a425;
  --green: #8fb56a;
  --cream: #fbf6ea;
  --paper: #ffffff;
  --text: #2b3b4e;
  --muted: #7d8aa0;
  --danger: #e0573e;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(40, 75, 115, 0.12);
  --shadow-soft: 0 2px 10px rgba(40, 75, 115, 0.08);
  --maxw: 620px;
  --header-h: 60px;
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  background-color: var(--sky-soft);
  /* Xadrez (gingham) suave de fundo */
  background-image:
    linear-gradient(45deg, rgba(74, 127, 181, 0.05) 25%, transparent 25%, transparent 75%, rgba(74, 127, 181, 0.05) 75%),
    linear-gradient(45deg, rgba(74, 127, 181, 0.05) 25%, transparent 25%, transparent 75%, rgba(74, 127, 181, 0.05) 75%);
  background-size: 36px 36px;
  background-position: 0 0, 18px 18px;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
img, video { display: block; max-width: 100%; }

/* ----------------------------- App shell --------------------------------- */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

/* Cabeçalho com bandeirinhas */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-deep) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  box-shadow: var(--shadow-soft);
}
.appbar::after {
  /* bandeirinhas penduradas */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -11px;
  height: 12px;
  background:
    repeating-linear-gradient(135deg, var(--sun) 0 9px, transparent 9px 18px),
    repeating-linear-gradient(45deg, transparent 0 9px, var(--green) 9px 18px);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 16px, transparent 16px 18px);
          mask: repeating-linear-gradient(90deg, #000 0 16px, transparent 16px 18px);
  -webkit-mask-size: 18px 12px;
          mask-size: 18px 12px;
  clip-path: polygon(0 0, 100% 0, 100% 40%, 50% 100%, 0 40%);
  opacity: 0.9;
  z-index: 31;
}
.appbar__title { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .3px; }
.appbar__title .logo-emoji { font-size: 22px; }
.appbar__title small { display: block; font-size: 11px; font-weight: 600; opacity: .85; letter-spacing: .6px; }
.appbar__avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 18px; font-weight: 700; color: #fff;
  border: 2px solid rgba(255,255,255,.7);
  background: var(--sun);
  overflow: hidden;
}

/* ------------------------------ Views ------------------------------------ */
.view { display: none; padding: 22px 12px calc(var(--nav-h) + 24px); }
.view.active { display: block; }

.feed { display: flex; flex-direction: column; gap: 18px; }

/* Card de post */
.card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(74,127,181,.10);
}
.card__head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  font-size: 18px; font-weight: 700; color: #fff;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.5);
}
.card__author { font-weight: 700; font-size: 15px; color: var(--blue-ink); line-height: 1.1; }
.card__time { font-size: 12px; color: var(--muted); }
.card__media { background: #eef4fb; position: relative; }
.card__media img, .card__media video { width: 100%; height: auto; max-height: 78vh; object-fit: contain; background: #0c1d30; }
.card__actions { display: flex; align-items: center; gap: 6px; padding: 10px 12px 4px; }
.iconbtn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 12px; font-size: 14px; font-weight: 600;
  color: var(--blue-deep); transition: transform .12s ease, background .2s;
}
.iconbtn:active { transform: scale(.9); }
.iconbtn .ic { font-size: 22px; line-height: 1; }
.iconbtn.liked { color: var(--danger); }
.iconbtn.liked .ic { animation: pop .3s ease; }
@keyframes pop { 0%{transform:scale(.6)} 50%{transform:scale(1.3)} 100%{transform:scale(1)} }
.spacer { flex: 1; }
.card__caption { padding: 2px 14px 6px; font-size: 14.5px; line-height: 1.45; }
.card__caption b { color: var(--blue-ink); }
.card__comments-link { padding: 0 14px 14px; font-size: 13px; color: var(--muted); }
.card__comments-link button { color: var(--muted); font-size: 13px; }

.delete-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; color: var(--danger);
  background: #fdece8; padding: 6px 10px; border-radius: 20px;
}

/* ------------------------------ Empty / loaders -------------------------- */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 52px; }
.empty h3 { color: var(--blue-deep); margin: 12px 0 4px; }
.loader { text-align: center; padding: 24px; color: var(--muted); font-size: 14px; }

/* ------------------------------ Bottom nav ------------------------------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: var(--nav-h);
  max-width: var(--maxw); margin: 0 auto;
  background: var(--paper);
  border-top: 1px solid rgba(74,127,181,.14);
  display: flex; align-items: center; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 16px rgba(40,75,115,.06);
}
.navbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 16px; }
.navbtn .ic { font-size: 23px; }
.navbtn.active { color: var(--blue); }
.navbtn--create .ic {
  width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(135deg, var(--sun), var(--sun-deep));
  color: #fff; display: grid; place-items: center; font-size: 28px;
  box-shadow: 0 6px 14px rgba(224,164,37,.45); margin-top: -16px;
}

/* ------------------------------ Buttons ---------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border-radius: 14px; font-weight: 700; font-size: 15px;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep)); color: #fff;
  width: 100%; transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn--sun { background: linear-gradient(135deg, var(--sun), var(--sun-deep)); color: #4a3608; }
.btn--ghost { background: transparent; color: var(--blue-deep); box-shadow: inset 0 0 0 2px rgba(74,127,181,.3); }
.btn--danger { background: linear-gradient(135deg, #ef6a52, var(--danger)); }

/* ------------------------------ Modals ----------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 40, 65, .55);
  display: none; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.overlay.open { display: flex; }
.sheet {
  background: var(--cream);
  width: 100%; max-width: var(--maxw);
  border-radius: 22px 22px 0 0;
  max-height: 92dvh; overflow-y: auto;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  animation: slideup .25s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .6 } to { transform: translateY(0); opacity: 1 } }
.sheet--center { border-radius: 22px; margin: auto 14px; align-self: center; }
.overlay.center { align-items: center; }
.sheet__grip { width: 44px; height: 5px; border-radius: 5px; background: rgba(74,127,181,.3); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 4px; color: var(--blue-deep); font-size: 20px; }
.sheet .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--blue-deep); margin-bottom: 6px; }
.input, textarea.input {
  width: 100%; padding: 13px 14px; border-radius: 13px; font-size: 16px;
  border: 2px solid rgba(74,127,181,.2); background: #fff; color: var(--text);
  font-family: inherit; resize: vertical;
}
.input:focus { outline: none; border-color: var(--blue); }

.avatar-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-pick button {
  width: 44px; height: 44px; border-radius: 50%; font-size: 22px;
  display: grid; place-items: center; background: #fff; box-shadow: inset 0 0 0 2px rgba(74,127,181,.18);
}
.avatar-pick button.sel { box-shadow: inset 0 0 0 3px var(--sun); transform: scale(1.05); }
.color-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.color-pick button { width: 34px; height: 34px; border-radius: 50%; box-shadow: 0 0 0 2px #fff, 0 0 0 3px transparent; }
.color-pick button.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--blue-deep); }

/* preview de mídia no criar post */
.media-drop {
  border: 2px dashed rgba(74,127,181,.35); border-radius: 16px;
  padding: 28px 16px; text-align: center; color: var(--muted); background: #fff;
}
.media-drop .big { font-size: 40px; }
.media-preview { border-radius: 16px; overflow: hidden; background: #0c1d30; position: relative; }
.media-preview img, .media-preview video { width: 100%; max-height: 50vh; object-fit: contain; }
.media-preview .remove {
  position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 18px; display: grid; place-items: center;
}

/* Detalhe do post + comentários */
.detail__media { background: #0c1d30; }
.detail__media img, .detail__media video { width: 100%; max-height: 60vh; object-fit: contain; margin: 0 auto; }
.comments { margin-top: 8px; }
.comment { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid rgba(74,127,181,.08); }
.comment .avatar { width: 32px; height: 32px; font-size: 14px; }
.comment__body { flex: 1; font-size: 14px; line-height: 1.4; }
.comment__body .who { font-weight: 700; color: var(--blue-ink); margin-right: 6px; }
.comment__body .when { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
.comment__del { color: var(--muted); font-size: 16px; align-self: center; padding: 4px; }
.comment-bar { position: sticky; bottom: 0; background: var(--cream); display: flex; gap: 8px; padding-top: 10px; }
.comment-bar .input { flex: 1; }
.comment-bar .send { padding: 0 16px; border-radius: 13px; background: var(--blue); color: #fff; font-weight: 700; }

/* meus posts (perfil) em grade */
.profile-head { text-align: center; padding: 8px 0 18px; }
.profile-head .avatar { width: 84px; height: 84px; font-size: 36px; margin: 0 auto 10px; }
.profile-head h2 { margin: 0; color: var(--blue-deep); }
.profile-head .count { color: var(--muted); font-size: 13px; margin-top: 2px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.grid .cell { position: relative; aspect-ratio: 1; background: #dce8f5; border-radius: 8px; overflow: hidden; }
.grid .cell img, .grid .cell video { width: 100%; height: 100%; object-fit: cover; }
.grid .cell .badge { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color:#fff; font-size:10px; padding:2px 5px; border-radius: 6px; }
.grid .cell .vid { position: absolute; bottom: 4px; right: 6px; color: #fff; font-size: 14px; text-shadow: 0 1px 2px #000; }

/* welcome hero */
.hero { text-align: center; padding: 6px 6px 10px; }
.hero .flags { font-size: 22px; letter-spacing: 4px; }
.hero h1 { font-size: 26px; color: var(--blue-deep); margin: 6px 0 2px; }
.hero p { color: var(--muted); margin: 0 0 6px; font-size: 14px; }
.hero img.bingo { width: 130px; border-radius: 14px; box-shadow: var(--shadow); margin: 8px auto; }
.hero img.noah-hero {
  display: block;
  height: 180px; width: auto; margin: 4px auto 10px;
  filter: drop-shadow(0 5px 6px rgba(40, 75, 115, 0.18));
}

/* leitor de QR (tela de acesso) */
.scanner {
  position: relative; width: 100%; max-width: 320px; margin: 4px auto 12px;
  aspect-ratio: 1; border-radius: 18px; overflow: hidden; background: #0c1d30;
  box-shadow: var(--shadow);
}
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame {
  position: absolute; inset: 14%;
  border: 3px solid rgba(255,255,255,.9); border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(12,29,48,.35);
}
.scanner-frame::after {
  content: ""; position: absolute; left: 8%; right: 8%; top: 50%; height: 2px;
  background: var(--sun); box-shadow: 0 0 8px var(--sun); animation: scanline 2s ease-in-out infinite;
}
@keyframes scanline { 0%,100% { top: 12% } 50% { top: 88% } }
.scanner-status { text-align: center; font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.scanner-status.err { color: var(--danger); font-weight: 600; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%);
  background: var(--blue-deep); color: #fff; padding: 11px 18px; border-radius: 30px;
  font-size: 14px; font-weight: 600; z-index: 90; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { background: var(--danger); }

.center-actions { display: flex; gap: 10px; margin-top: 8px; }
.muted-link { color: var(--muted); font-size: 13px; text-align: center; display: block; margin-top: 14px; }
.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color:#fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }
