/* ============================================================
   Book Bingo 2027
   ============================================================ */

:root {
  --bg:          #faf7f2;
  --bg-tint:     #f3ece1;
  --surface:     #ffffff;
  --surface-2:   #f7f3ec;
  --ink:         #211d19;
  --ink-2:       #6b625a;
  --ink-3:       #a39a90;
  --line:        #ece6dc;
  --line-2:      #ded5c7;

  --accent:      #8a6a4f;
  --accent-tint: #f0e7db;
  --gold:        #c99a2e;
  --plan:        #b06a3c;
  --plan-tint:   #fbeee2;
  --done:        #2f5e3e;
  --done-tint:   #e6efe7;

  --p-patricia:  #c2576a;
  --p-carla:     #4f7d52;
  --p-ana:       #3f74a0;
  --p-catarina:  #c0862c;
  --p-micaela:   #7c5aa6;
  --p-rita:      #2b8079;
  --p-jessica:   #b04a8f;
  --p-marta:     #4f5aa0;

  --r-sm: 10px;
  --r:    16px;
  --r-lg: 24px;
  --r-xl: 30px;

  --sh-1: 0 1px 2px rgba(33,29,25,.04), 0 2px 8px rgba(33,29,25,.04);
  --sh-2: 0 2px 6px rgba(33,29,25,.05), 0 12px 32px rgba(33,29,25,.09);
  --sh-3: 0 24px 60px rgba(33,29,25,.20);

  --serif: 'Fraunces', Georgia, serif;
  --sans:  'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #131210;
    --bg-tint:     #1a1815;
    --surface:     #1e1b18;
    --surface-2:   #262220;
    --ink:         #f0ebe3;
    --ink-2:       #a79e93;
    --ink-3:       #756c62;
    --line:        #2d2926;
    --line-2:      #3b3531;
    --accent:      #c79a72;
    --accent-tint: #2c2620;
    --gold:        #e0bd4a;
    --plan:        #d59763;
    --plan-tint:   #2e241c;
    --done:        #7fb98d;
    --done-tint:   #1d2a20;
    --p-patricia:  #e58396;
    --p-carla:     #86b98c;
    --p-ana:       #77aad6;
    --p-catarina:  #e0ac57;
    --p-micaela:   #b394d8;
    --p-rita:      #6cc0b7;
    --p-jessica:   #dd8ec6;
    --p-marta:     #939dde;
    --sh-1: 0 1px 2px rgba(0,0,0,.3);
    --sh-2: 0 2px 6px rgba(0,0,0,.35), 0 12px 32px rgba(0,0,0,.4);
    --sh-3: 0 24px 60px rgba(0,0,0,.6);
  }
}

:root[data-theme="dark"] {
  --bg: #131210; --bg-tint: #1a1815; --surface: #1e1b18; --surface-2: #262220;
  --ink: #f0ebe3; --ink-2: #a79e93; --ink-3: #756c62; --line: #2d2926; --line-2: #3b3531;
  --accent: #c79a72; --accent-tint: #2c2620; --gold: #e0bd4a;
  --plan: #d59763; --plan-tint: #2e241c; --done: #7fb98d; --done-tint: #1d2a20;
  --p-patricia: #e58396; --p-carla: #86b98c; --p-ana: #77aad6; --p-catarina: #e0ac57; --p-micaela: #b394d8;
  --p-rita: #6cc0b7; --p-jessica: #dd8ec6; --p-marta: #939dde;
}

/* Cor de fundo escolhida pela utilizadora (pastéis). --tint vem do JS. */
:root[data-bg] {
  --bg:        color-mix(in srgb, var(--tint) 38%, #ffffff);
  --bg-tint:   color-mix(in srgb, var(--tint) 55%, #ffffff);
  --surface-2: color-mix(in srgb, var(--tint) 26%, #ffffff);
  --line:      color-mix(in srgb, var(--tint) 52%, #ece6dc);
  --line-2:    color-mix(in srgb, var(--tint) 62%, #ded5c7);
}
:root[data-theme="dark"][data-bg] {
  --bg:        color-mix(in srgb, var(--tint) 11%, #131210);
  --bg-tint:   color-mix(in srgb, var(--tint) 15%, #1a1815);
  --surface:   color-mix(in srgb, var(--tint) 8%,  #1e1b18);
  --surface-2: color-mix(in srgb, var(--tint) 13%, #262220);
  --line:      color-mix(in srgb, var(--tint) 14%, #2d2926);
  --line-2:    color-mix(in srgb, var(--tint) 18%, #3b3531);
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.02em; margin: 0; line-height: 1.15; }
h2 { font-size: clamp(1.5rem, 3.6vw, 2.1rem); }
p { margin: .3rem 0; }
.sub { color: var(--ink-2); font-size: .95rem; font-weight: 300; }
.soft { color: var(--ink-3); font-weight: 400; }

/* ---------------- Topbar ---------------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem clamp(16px, 5vw, 48px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: inherit; }
.brand-mark { display: block; width: 26px; height: 26px; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-mark rect:nth-child(1) { fill: var(--p-patricia); }
.brand-mark rect:nth-child(2) { fill: var(--p-carla); }
.brand-mark rect:nth-child(3) { fill: var(--p-ana); }
.brand-text { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; letter-spacing: -.02em; white-space: nowrap; }
.brand-text em { color: var(--accent); font-style: italic; }

.topbar-right { display: flex; align-items: center; gap: .5rem; }

.icon-btn {
  display: grid; place-content: center;
  width: 36px; height: 36px; flex: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 50%;
  cursor: pointer; box-shadow: var(--sh-1);
  transition: transform .16s, box-shadow .16s, border-color .16s, background .16s;
}
.icon-btn svg { width: 17px; height: 17px; stroke: var(--ink-2); }
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--sh-2); border-color: var(--line-2); }
.icon-btn:active { transform: scale(.94); }

/* ---------------- Paleta de fundos ---------------- */

.palette-wrap { position: relative; }
#palette-btn svg { stroke: var(--ink-2); color: var(--ink-3); }

.palette-pop {
  position: absolute; top: calc(100% + .55rem); right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: .85rem; box-shadow: var(--sh-2);
  animation: popIn .22s cubic-bezier(.34,1.35,.64,1) both;
}
.palette-pop[hidden] { display: none; }
.palette-title {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-3); margin: 0 0 .6rem; font-weight: 500;
}
.palette-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .45rem; }
.swatch {
  position: relative; width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid var(--line-2); cursor: pointer; padding: 0;
  transition: transform .16s cubic-bezier(.34,1.5,.64,1), border-color .16s;
}
.swatch:hover { transform: scale(1.16); }
.swatch.is-on { border-color: var(--ink); }
.swatch.is-on::after {
  content: '✓'; position: absolute; inset: 0;
  display: grid; place-content: center;
  font-size: .8rem; color: #3b3226; font-weight: 700;
}
.swatch.none { background: var(--surface); }
.swatch.none::before {
  content: ''; position: absolute; inset: 4px;
  background: linear-gradient(to top right, transparent 46%, var(--ink-3) 46%, var(--ink-3) 54%, transparent 54%);
}
:root[data-theme="dark"] .swatch.is-on::after { color: #17130f; }

.theme-toggle .ico-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .ico-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ico-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .ico-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .ico-moon { display: block; }
}
.theme-toggle svg { transition: transform .35s cubic-bezier(.34,1.4,.64,1); }
.theme-toggle:hover svg { transform: rotate(25deg); }

.who-chip {
  display: flex; align-items: center; gap: .45rem;
  font: inherit; font-size: .9rem; font-weight: 500; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: .28rem .75rem .28rem .3rem;
  cursor: pointer; box-shadow: var(--sh-1);
  transition: transform .16s, box-shadow .16s, border-color .16s;
}
.who-chip:hover { transform: translateY(-1px); box-shadow: var(--sh-2); border-color: var(--line-2); }
.who-chip .chev { width: 15px; height: 15px; stroke: var(--ink-3); }

/* ---------------- Avatares ---------------- */

.avatar, .who-avatar {
  position: relative; flex: none; overflow: hidden;
  display: grid; place-content: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--player, var(--accent)) 18%, transparent);
  color: var(--player, var(--accent));
  font-weight: 600; font-family: var(--sans);
  background-size: cover; background-position: center;
}
.who-avatar { width: 26px; height: 26px; font-size: .78rem; }
.avatar.big {
  width: 78px; height: 78px; font-size: 1.9rem;
  border: none; padding: 0; cursor: default;
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 4.5px color-mix(in srgb, var(--player, var(--accent)) 35%, transparent);
}
@media (max-width: 560px) { .avatar.big { width: 62px; height: 62px; font-size: 1.5rem; } }
button.avatar.big { cursor: pointer; }
.avatar.has-photo { color: transparent; }
.avatar-cam {
  position: absolute; inset: 0; display: grid; place-content: center;
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  opacity: 0; transition: opacity .18s;
}
.avatar-cam svg { width: 19px; height: 19px; stroke: #fff; }
button.avatar:hover .avatar-cam { opacity: 1; }
.avatar.busy { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

@media (max-width: 430px) {
  .topbar { padding-left: 14px; padding-right: 14px; gap: .5rem; }
  .brand-mark { width: 20px; height: 20px; }
  .brand-text { font-size: .95rem; }
  .brand-text em { display: none; }
  .topbar-right { gap: .35rem; }
  .icon-btn { width: 32px; height: 32px; }
  .icon-btn svg { width: 15px; height: 15px; }
  .who-chip { font-size: .82rem; padding: .22rem .6rem .22rem .24rem; }
  .who-avatar { width: 23px; height: 23px; }
}

/* ---------------- Tabs ---------------- */

.tabs {
  display: flex; gap: .2rem; overflow-x: auto; scrollbar-width: none;
  padding: 1.1rem clamp(16px, 5vw, 48px) 0;
  max-width: 1200px; margin: 0 auto;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  font: inherit; font-weight: 500; font-size: .95rem;
  color: var(--ink-3); background: none; border: none;
  padding: .5rem .9rem .7rem; cursor: pointer; white-space: nowrap;
  transition: color .18s;
}
.tab:hover { color: var(--ink-2); }
.tab.is-active { color: var(--ink); font-weight: 600; }
.tab.is-active::after {
  content: ''; position: absolute; left: .9rem; right: .9rem; bottom: 0;
  height: 2.5px; border-radius: 3px; background: var(--ink);
  animation: slideIn .28s cubic-bezier(.22,1,.36,1);
}
@keyframes slideIn { from { transform: scaleX(.2); opacity: 0; } to { transform: none; opacity: 1; } }

main { padding: 2rem clamp(16px, 5vw, 48px) 3.5rem; max-width: 1200px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.is-active { display: block; animation: fadeUp .34s cubic-bezier(.22,1,.36,1) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------------- Cabeçalho ---------------- */

.board-head {
  display: flex; flex-wrap: wrap; gap: 1.2rem;
  align-items: flex-end; justify-content: space-between;
  margin-bottom: 1.4rem;
}
.board-head h2 { font-size: clamp(1.7rem, 4.4vw, 2.4rem); }
.board-id { display: flex; align-items: center; gap: .9rem; }

.head-stats { display: flex; gap: .5rem; }
.stat {
  display: grid; gap: 0; text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: .55rem 1rem; min-width: 76px;
  box-shadow: var(--sh-1);
}
.stat strong { font-family: var(--serif); font-size: 1.35rem; line-height: 1.1; }
.stat span { font-size: .72rem; color: var(--ink-3); letter-spacing: .02em; }

.progress-line { display: flex; align-items: center; gap: .9rem; margin-bottom: 1.6rem; }
.progress-line .bar { flex: 1; }
.progress-line span { font-size: .82rem; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }

.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i {
  display: block; height: 100%; border-radius: 99px;
  background: var(--player, var(--accent));
  transition: width .9s cubic-bezier(.22,1,.36,1);
}

.back-link {
  display: inline-flex; align-items: center; gap: .3rem;
  font: inherit; font-size: .88rem; font-weight: 500; color: var(--accent);
  background: none; border: none; padding: 0; cursor: pointer;
}
.back-link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------------- Tabuleiro ---------------- */

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(9px, 1.1vw, 14px);
}

.cell {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .35rem; text-align: center;
  min-height: 132px; padding: 1rem .7rem;
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  cursor: pointer;
  transition: transform .2s cubic-bezier(.22,1,.36,1), box-shadow .2s, border-color .2s, background .3s;
}
.cell:hover { transform: translateY(-4px); box-shadow: var(--sh-2); border-color: var(--line-2); }
.cell:focus-visible { outline: 2px solid var(--player, var(--accent)); outline-offset: 3px; }
.cell:active { transform: translateY(-1px) scale(.985); }

.cell-emoji { font-size: 1.25rem; line-height: 1; filter: saturate(.95); }
.cell-goal { font-size: .82rem; font-weight: 500; line-height: 1.3; color: var(--ink); }
.cell-book {
  font-family: var(--serif); font-size: .76rem; font-style: italic;
  color: var(--ink-2); line-height: 1.25; margin-top: .1rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cell .rating { font-size: .66rem; color: var(--gold); letter-spacing: .08em; }

.cell-tag {
  position: absolute; top: .55rem; right: .6rem;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-content: center; font-size: .68rem;
}
.cell.reading .cell-tag { background: var(--plan-tint); color: var(--plan); }
.cell.done .cell-tag { background: var(--done); color: #fff; font-size: .62rem; }

.cell.reading {
  background: var(--surface);
  border-color: color-mix(in srgb, var(--plan) 35%, var(--line));
  border-style: dashed;
}
.cell.done {
  background: color-mix(in srgb, var(--player, var(--accent)) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--player, var(--accent)) 28%, var(--line));
}
.cell.done .cell-goal { color: color-mix(in srgb, var(--player, var(--accent)) 60%, var(--ink)); }
.cell.done .cell-emoji { transform: scale(1.05); }

.cell-cover {
  position: absolute; inset: 0; z-index: 0;
  background-size: cover; background-position: center;
}
.cell-cover::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to top,
    color-mix(in srgb, var(--surface) 97%, transparent) 30%,
    color-mix(in srgb, var(--surface) 86%, transparent) 52%,
    color-mix(in srgb, var(--surface) 42%, transparent) 100%);
}
.cell.has-cover > :not(.cell-cover) { position: relative; z-index: 1; }
.cell.has-cover { justify-content: flex-end; padding-bottom: .8rem; }
.cell.has-cover .cell-emoji { display: none; }
.cell.has-cover .cell-goal { text-shadow: 0 1px 2px color-mix(in srgb, var(--surface) 70%, transparent); }

.cell.just-done { animation: pop .65s cubic-bezier(.34,1.4,.64,1); }
@keyframes pop {
  0% { transform: scale(1); } 35% { transform: scale(1.09) rotate(-1.5deg); } 100% { transform: scale(1); }
}
.cell .cell-tag { animation: tagIn .45s cubic-bezier(.34,1.6,.64,1) both; }
@keyframes tagIn { from { transform: scale(0) rotate(-40deg); } to { transform: none; } }

.cell.in-bingo::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--gold) 70%, transparent);
  animation: glow 2.2s ease-in-out infinite;
}
@keyframes glow { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

@media (max-width: 860px) { .board { grid-template-columns: repeat(3, 1fr); } .cell { min-height: 120px; } }
@media (max-width: 480px) { .board { grid-template-columns: repeat(2, 1fr); gap: 9px; } .cell { min-height: 112px; padding: .85rem .6rem; } }

/* ---------------- As leitoras ---------------- */

.all-boards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.1rem; }

.friend {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 1.3rem; box-shadow: var(--sh-1);
  transition: transform .2s cubic-bezier(.22,1,.36,1), box-shadow .2s;
}
.friend:hover { transform: translateY(-3px); box-shadow: var(--sh-2); }
.friend-top { display: flex; align-items: center; gap: .6rem; margin-bottom: .2rem; }
.friend .avatar { width: 38px; height: 38px; font-size: 1rem; }
.friend h3 { font-size: 1.15rem; }
.friend .friend-meta { font-size: .82rem; color: var(--ink-3); }
.friend .bar { margin: .9rem 0 .2rem; }
.mini-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px;
  margin: 1rem auto .2rem; width: 100%; max-width: 205px;
}
.mini-cell { aspect-ratio: 1; border-radius: 4px; background: var(--line); }
.mini-cell.done { background: var(--player); }
.mini-cell.reading { background: transparent; box-shadow: inset 0 0 0 1.5px var(--plan); }
.friend-cta {
  display: block; width: 100%; margin-top: 1rem;
  font: inherit; font-size: .85rem; font-weight: 500; color: var(--ink-2);
  background: var(--surface-2); border: none; border-radius: var(--r-sm);
  padding: .5rem; cursor: pointer; transition: background .16s, color .16s;
}
.friend-cta:hover { background: var(--accent-tint); color: var(--ink); }

/* ---------------- Biblioteca ---------------- */

.lib-controls { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1.6rem 0 1.5rem; }
.lib-controls input, .lib-controls select {
  font: inherit; font-size: .9rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: .55rem 1.05rem; box-shadow: var(--sh-1);
}
.lib-controls input { flex: 1 1 240px; }
.lib-controls select {
  cursor: pointer; appearance: none; -webkit-appearance: none;
  padding-right: 2.5rem;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.15rem) 53%, calc(100% - .85rem) 53%;
  background-size: 5.5px 5.5px, 5.5px 5.5px;
  background-repeat: no-repeat;
  color: var(--ink-2);
}
.lib-controls input:focus-visible, .lib-controls select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .9rem; }
.book {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 1.05rem 1.15rem; box-shadow: var(--sh-1);
  animation: fadeUp .3s ease both;
  transition: transform .18s, box-shadow .18s;
}
.book:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.book.with-cover { display: grid; grid-template-columns: 62px 1fr; gap: .9rem; align-items: start; }
.book-cover {
  width: 62px; aspect-ratio: 2 / 3; border-radius: 7px;
  background-size: cover; background-position: center;
  box-shadow: 0 2px 8px rgba(33,29,25,.18);
}
.book-shared {
  font-size: .72rem; font-weight: 600; color: var(--accent);
  margin: .4rem 0 0; letter-spacing: .01em;
}
.book-reader { margin-top: .6rem; }
.book-reader + .book-reader { padding-top: .6rem; border-top: 1px solid var(--line); }
.book-reader .book-meta { margin-top: 0; }

.book-casas { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.casa-chip {
  font-size: .68rem; padding: .18rem .5rem; border-radius: 6px;
  background: var(--surface-2); color: var(--ink-2);
}
.casa-chip.is-done { background: var(--done-tint); color: var(--done); font-weight: 600; }
.book h4 { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; margin: .3rem 0 .1rem; letter-spacing: -.01em; }
.book-author { font-size: .85rem; color: var(--ink-2); font-weight: 300; }
.book-meta { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; margin-top: .7rem; font-size: .75rem; color: var(--ink-3); }
.chip {
  font-size: .7rem; font-weight: 500; padding: .2rem .6rem; border-radius: 999px;
  background: color-mix(in srgb, var(--player) 14%, transparent); color: var(--player);
}
.chip.state { background: var(--done-tint); color: var(--done); }
.chip.state.reading { background: var(--plan-tint); color: var(--plan); }
.book-notes { margin-top: .6rem; font-size: .83rem; color: var(--ink-2); font-style: italic; font-family: var(--serif); }
.book .rating { color: var(--gold); }

.empty-state {
  grid-column: 1 / -1; text-align: center; padding: 3.5rem 1rem;
  color: var(--ink-3); font-family: var(--serif); font-style: italic; font-size: 1.05rem;
}

/* ---------------- Como funciona ---------------- */

.rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1.8rem; }
@media (max-width: 900px) { .rules { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .rules { grid-template-columns: 1fr; } }
.rule-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 1.5rem; box-shadow: var(--sh-1);
}
.rule-ico {
  display: grid; place-content: center; width: 42px; height: 42px;
  border-radius: 13px; background: var(--accent-tint); font-size: 1.25rem; margin-bottom: .8rem;
}
.rule-card h3 { font-size: 1.12rem; margin-bottom: .35rem; }
.rule-card p { font-size: .92rem; color: var(--ink-2); font-weight: 300; }
.rule-card strong { font-weight: 600; color: var(--ink); }

/* ---------------- Modais ---------------- */

.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--ink) 42%, transparent);
  backdrop-filter: blur(5px); animation: fadeIn .22s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative; width: min(460px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--r-xl);
  padding: 1.8rem clamp(1.2rem, 4vw, 1.9rem) 1.5rem;
  box-shadow: var(--sh-3);
  animation: popIn .3s cubic-bezier(.34,1.35,.64,1) both;
}
@keyframes popIn { from { opacity: 0; transform: translateY(18px) scale(.96); } to { opacity: 1; transform: none; } }

.modal-x {
  position: absolute; top: .9rem; right: .9rem; width: 32px; height: 32px;
  display: grid; place-content: center;
  background: var(--surface-2); border: none; border-radius: 50%; cursor: pointer;
}
.modal-x[hidden] { display: none; }
.modal-x svg { width: 15px; height: 15px; stroke: var(--ink-2); }
.modal-x:hover { background: var(--line); }

.modal-head { display: flex; align-items: center; gap: .85rem; margin-bottom: 1.4rem; padding-right: 2rem; }
.modal-emoji {
  flex: none; width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-content: center; font-size: 1.45rem;
  background: var(--player-tint, var(--accent-tint));
}
.modal-kicker { font-size: .68rem; text-transform: uppercase; letter-spacing: .13em; color: var(--ink-3); margin: 0 0 .1rem; font-weight: 500; }
.modal-card h3 { font-size: 1.35rem; }

.field { display: grid; gap: .35rem; margin-bottom: .85rem; }
.field label { font-size: .85rem; font-weight: 500; color: var(--ink-2); }
.field input, .field textarea {
  font: inherit; font-size: .98rem; color: var(--ink);
  background: var(--bg); border: 1.5px solid var(--line);
  border-radius: var(--r-sm); padding: .7rem .85rem; width: 100%; resize: vertical;
  transition: border-color .16s, background .16s;
}
.field input::placeholder, .field textarea::placeholder { color: var(--ink-3); }
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--player, var(--accent)); background: var(--surface);
}
.row { display: flex; gap: .6rem; }
.row .field { flex: 1; }
.row .field.narrow { flex: 0 0 100px; }

.cover-row { display: grid; grid-template-columns: 78px 1fr; gap: .9rem; align-items: start; margin-bottom: .4rem; }
.cover-side { display: flex; flex-direction: column; }
.cover-drop {
  position: relative; overflow: hidden;
  width: 78px; aspect-ratio: 2 / 3;
  background: var(--bg); background-size: cover; background-position: center;
  border: 1.5px dashed var(--line-2); border-radius: var(--r-sm);
  cursor: pointer; padding: 0;
  transition: border-color .16s, background-color .16s;
}
.cover-drop:hover { border-color: var(--player, var(--accent)); }
.cover-drop.has-cover { border-style: solid; border-color: transparent; box-shadow: var(--sh-1); }
.cover-ph { display: grid; place-content: center; gap: .25rem; height: 100%; color: var(--ink-3); }
.cover-ph svg { width: 20px; height: 20px; stroke: currentColor; margin: 0 auto; }
.cover-ph em { font-style: normal; font-size: .68rem; }
.cover-drop.has-cover .cover-ph { opacity: 0; transition: opacity .16s; }
.cover-drop.has-cover:hover .cover-ph {
  opacity: 1; color: #fff;
  background: color-mix(in srgb, var(--ink) 50%, transparent);
}
.cover-drop.busy { animation: pulse 1s ease-in-out infinite; }
.cover-remove {
  align-self: flex-start; margin-top: .1rem;
  font: inherit; font-size: .78rem; color: var(--ink-3);
  background: none; border: none; padding: 0; cursor: pointer;
}
.cover-remove:hover { color: var(--p-patricia); text-decoration: underline; text-underline-offset: 3px; }
.cover-remove[hidden] { display: none; }

.more-toggle {
  display: inline-flex; align-items: center; gap: .35rem;
  font: inherit; font-size: .85rem; font-weight: 500; color: var(--ink-3);
  background: none; border: none; padding: .2rem 0 .6rem; cursor: pointer;
}
.more-toggle:hover { color: var(--ink-2); }
.more-toggle .chev { width: 15px; height: 15px; stroke: currentColor; transition: transform .22s; }
.more-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.more { animation: fadeUp .25s ease both; padding-top: .3rem; }
.more[hidden] { display: none; }

/* ---- Hipóteses da casa ---- */

/* Baralho de capas, quando a casa tem várias hipóteses */
.cell-fan { display: flex; align-items: center; justify-content: center; margin-bottom: .1rem; }
.fan-card {
  width: 32px; height: 48px; flex: none;
  border-radius: 4px; background: var(--surface-2) center/cover;
  border: 1.5px solid var(--surface);
  box-shadow: 0 2px 5px rgba(33,29,25,.22);
  display: grid; place-content: center; font-size: .8rem;
  transition: transform .25s cubic-bezier(.34,1.4,.64,1);
}
.fan-card + .fan-card { margin-left: -17px; }
.cell:hover .fan-card { transform: rotate(0deg) !important; }
.cell:hover .fan-card + .fan-card { margin-left: -11px; }
.fan-more {
  margin-left: .3rem; padding: 0 6px; height: 20px; border-radius: 99px;
  display: grid; place-content: center;
  background: var(--plan-tint); color: var(--plan);
  font-size: .68rem; font-weight: 700;
}
.cell.done .fan-more { background: var(--surface-2); color: var(--ink-2); }

.opt-hint { font-size: .84rem; color: var(--ink-3); font-weight: 300; margin: 0 0 .9rem; }
.opt-list { display: grid; gap: .5rem; margin-bottom: .9rem; }
.opt-item {
  display: flex; align-items: center; gap: .75rem; text-align: left;
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--r-sm); padding: .6rem .75rem; cursor: pointer;
  transition: border-color .16s, background .16s, transform .16s;
}
.opt-item:hover { border-color: var(--player, var(--accent)); transform: translateX(2px); }
.opt-item.is-done { border-color: color-mix(in srgb, var(--done) 45%, var(--line)); background: var(--done-tint); }
.opt-cover {
  width: 34px; height: 51px; flex: none; border-radius: 5px;
  background: var(--surface-2) center/cover;
  display: grid; place-content: center; font-size: .95rem;
}
.opt-body { flex: 1; min-width: 0; }
.opt-title { font-family: var(--serif); font-size: .96rem; font-weight: 600; }
.opt-title.empty { font-style: italic; color: var(--ink-3); font-weight: 400; }
.opt-sub { font-size: .76rem; color: var(--ink-3); }
.opt-state { font-size: .72rem; font-weight: 600; flex: none; }
.opt-item.is-done .opt-state { color: var(--done); }
.opt-item:not(.is-done) .opt-state { color: var(--plan); }

.btn.full { width: 100%; flex: none; margin-top: .2rem; }
#opt-back { margin-bottom: .9rem; }
#opt-back[hidden], #btn-another[hidden], #opt-view[hidden], #ask-keep[hidden] { display: none; }

/* ---- Também conta para ---- */

.also-count {
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: .1rem;
  border-radius: 99px; background: var(--player, var(--accent)); color: #fff;
  font-size: .66rem; font-weight: 700; line-height: 18px; text-align: center;
}
.also-count[hidden] { display: none; }

.also { animation: fadeUp .25s ease both; }
.also[hidden] { display: none; }
.also-hint { font-size: .78rem; color: var(--ink-3); font-weight: 300; margin: 0 0 .5rem; }
.also-list {
  max-height: 208px; overflow-y: auto;
  border: 1.5px solid var(--line); border-radius: var(--r-sm);
  padding: .3rem;
}
.also-row {
  display: flex; align-items: center; gap: .55rem;
  padding: .4rem .5rem; border-radius: 7px; cursor: pointer;
  font-size: .87rem; transition: background .14s;
}
.also-row:hover { background: var(--surface-2); }
.also-row input { accent-color: var(--player, var(--accent)); width: 15px; height: 15px; flex: none; cursor: pointer; }
.also-row .also-emoji { font-size: .95rem; flex: none; }
.also-row .also-name { flex: 1; min-width: 0; }
.also-row .also-taken {
  font-size: .7rem; color: var(--ink-3); font-style: italic;
  max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.also-row.checked { background: color-mix(in srgb, var(--player, var(--accent)) 9%, transparent); }

.stars { display: flex; align-items: center; gap: .1rem; }
.stars button {
  font-size: 1.45rem; line-height: 1; color: var(--line-2);
  background: none; border: none; cursor: pointer; padding: 0 .06rem;
  transition: transform .14s, color .14s;
}
.stars button:hover { transform: scale(1.2); }
.stars button.on { color: var(--gold); }
.stars .stars-clear { font-size: .75rem; color: var(--ink-3); margin-left: .55rem; font-family: var(--sans); }
.stars .stars-clear:hover { color: var(--ink-2); transform: none; }

.modal-actions { display: flex; gap: .6rem; margin-top: 1.3rem; }
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: .8rem 1rem; border-radius: var(--r-sm); cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform .14s, filter .14s, background .16s;
}
.btn:active { transform: scale(.97); }
.btn span { font-size: .9rem; }
.btn.plan { background: var(--plan-tint); border-color: color-mix(in srgb, var(--plan) 30%, transparent); color: var(--plan); }
.btn.plan:hover { background: color-mix(in srgb, var(--plan) 16%, var(--plan-tint)); }
.btn.primary { background: var(--done); color: #fff; }
.btn.primary:hover { filter: brightness(1.12); }

.clear-link {
  display: block; margin: .9rem auto 0;
  font: inherit; font-size: .82rem; color: var(--ink-3);
  background: none; border: none; cursor: pointer;
}
.clear-link:hover { color: var(--p-patricia); text-decoration: underline; text-underline-offset: 3px; }
.clear-link[hidden] { display: none; }

/* ---------------- Ajustar imagem ---------------- */

.crop-card { width: min(390px, 100%); text-align: center; }
.crop-card h3 { font-size: 1.3rem; }
.crop-hint { font-size: .84rem; color: var(--ink-3); font-weight: 300; margin: .2rem 0 1.1rem; }

.crop-stage {
  position: relative; overflow: hidden;
  margin: 0 auto; background: var(--surface-2);
  touch-action: none; cursor: grab;
  user-select: none; -webkit-user-select: none;
}
.crop-stage:active { cursor: grabbing; }
.crop-stage.round { border-radius: 50%; }
.crop-stage.rect { border-radius: var(--r-sm); }
.crop-stage img {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0; max-width: none; pointer-events: none;
}
.crop-stage::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ink) 12%, transparent);
}

.crop-zoom { display: flex; align-items: center; gap: .6rem; margin: 1.1rem .2rem .2rem; }
.crop-zoom span { font-size: .9rem; }
.crop-zoom input[type="range"] {
  flex: 1; appearance: none; -webkit-appearance: none;
  height: 5px; border-radius: 99px; background: var(--line); cursor: pointer;
}
.crop-zoom input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 19px; height: 19px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
  box-shadow: var(--sh-1); cursor: grab;
}
.crop-zoom input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface); cursor: grab;
}

/* ---------------- Escolher leitora ---------------- */

.picker-card { width: min(420px, 100%); text-align: center; }
.picker-card h3 { font-size: 1.7rem; margin-bottom: .4rem; }
.picker-sub { font-size: .9rem; color: var(--ink-2); font-weight: 300; margin-bottom: 1.4rem; }
.picker-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
/* Com um número ímpar de leitoras, a última fica centrada. */
.picker-grid > :last-child:nth-child(odd) {
  grid-column: 1 / -1; justify-self: center; width: calc(50% - .35rem);
}
.picker-btn {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  font: inherit; font-size: 1rem; font-weight: 600; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--r); padding: 1.1rem .6rem; cursor: pointer;
  transition: transform .18s cubic-bezier(.22,1,.36,1), border-color .18s, background .18s;
}
.picker-btn:hover { transform: translateY(-3px); border-color: var(--player); background: color-mix(in srgb, var(--player) 6%, var(--surface)); }
.picker-btn.is-me { border-color: var(--player); background: color-mix(in srgb, var(--player) 10%, var(--surface)); }
/* Só medidas: a cor e o enquadramento vêm de .avatar. Usar aqui o atalho
   `background` apagaria o background-size/position e a foto saía torta. */
.picker-avatar { width: 46px; height: 46px; font-size: 1.15rem; }

/* ---------------- Toast e celebração ---------------- */

.toast {
  position: fixed; left: 50%; bottom: 1.8rem; transform: translateX(-50%);
  z-index: 100; padding: .75rem 1.3rem; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-size: .9rem; font-weight: 500;
  box-shadow: var(--sh-2); animation: toastIn .3s cubic-bezier(.34,1.4,.64,1) both;
  max-width: calc(100vw - 2rem); text-align: center;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 95; }

.celebration { position: fixed; inset: 0; z-index: 96; display: grid; place-items: center; pointer-events: none; padding: 1rem; }
.celebration[hidden] { display: none; }
.celebration-inner {
  text-align: center; padding: 2.2rem 2.8rem;
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--sh-3);
  animation: celebrate .55s cubic-bezier(.34,1.5,.64,1) both;
}
@keyframes celebrate { from { opacity: 0; transform: scale(.82); } to { opacity: 1; transform: none; } }
.celebration-kicker { font-size: .7rem; text-transform: uppercase; letter-spacing: .25em; color: var(--gold); margin: 0; font-weight: 600; }
.celebration-inner h2 { font-size: clamp(1.6rem, 5vw, 2.3rem); margin: .35rem 0 .2rem; }
.celebration-inner p { color: var(--ink-2); font-size: .92rem; font-weight: 300; margin: 0; }

/* ---------------- Chat ---------------- */

.chat-btn { position: relative; overflow: visible; }
.chat-btn.is-open { background: var(--ink); border-color: var(--ink); }
.chat-btn.is-open svg { stroke: var(--bg); }
.chat-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 99px;
  background: var(--p-patricia); color: #fff;
  font-size: .66rem; font-weight: 700; line-height: 18px; text-align: center;
  border: 2px solid var(--bg);
  animation: tagIn .4s cubic-bezier(.34,1.6,.64,1) both;
}
.chat-badge[hidden] { display: none; }

.chat-panel {
  position: fixed; right: clamp(14px, 5vw, 48px); top: 4.1rem;
  z-index: 85; display: flex; flex-direction: column;
  width: min(370px, calc(100vw - 2rem)); height: min(560px, calc(100vh - 6rem));
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-3); overflow: hidden;
  animation: chatIn .3s cubic-bezier(.22,1,.36,1) both;
}
.chat-panel[hidden] { display: none; }
@keyframes chatIn { from { opacity: 0; transform: translateY(-14px) scale(.97); } to { opacity: 1; transform: none; } }

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .95rem 1.1rem; border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.chat-head h3 { font-size: 1.05rem; }
.chat-head .icon-btn { width: 30px; height: 30px; box-shadow: none; }

.chat-log {
  flex: 1; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: .7rem;
  scroll-behavior: smooth;
}
.msg { display: flex; gap: .5rem; align-items: flex-end; animation: fadeUp .25s ease both; }
.msg .avatar { width: 26px; height: 26px; font-size: .72rem; }
.msg-body { max-width: 78%; }
.msg-name { font-size: .7rem; font-weight: 600; color: var(--player); margin-bottom: .15rem; padding-left: .2rem; }
.msg-bubble {
  background: var(--surface-2); border-radius: 14px 14px 14px 5px;
  padding: .55rem .8rem; font-size: .9rem; line-height: 1.45;
  overflow-wrap: anywhere;
}
.msg-time { font-size: .65rem; color: var(--ink-3); margin-top: .2rem; padding-left: .2rem; }

.msg.mine { flex-direction: row-reverse; }
.msg.mine .avatar { display: none; }
.msg.mine .msg-body { margin-left: auto; }
.msg.mine .msg-name { display: none; }
.msg.mine .msg-bubble {
  background: color-mix(in srgb, var(--player) 16%, var(--surface-2));
  border-radius: 14px 14px 5px 14px;
}
.msg.mine .msg-time { text-align: right; padding: 0 .2rem 0 0; }

.chat-day {
  align-self: center; font-size: .68rem; color: var(--ink-3);
  background: var(--surface-2); padding: .2rem .7rem; border-radius: 99px;
}

.chat-form { display: flex; gap: .5rem; padding: .8rem; border-top: 1px solid var(--line); }
.chat-form input {
  flex: 1; font: inherit; font-size: .92rem; color: var(--ink);
  background: var(--bg); border: 1.5px solid var(--line);
  border-radius: 999px; padding: .6rem 1rem;
}
.chat-form input::placeholder { color: var(--ink-3); }
.chat-form input:focus { outline: none; border-color: var(--player, var(--accent)); }
.icon-btn.send { width: 40px; height: 40px; background: var(--ink); border-color: var(--ink); }
.icon-btn.send svg { stroke: var(--bg); width: 18px; height: 18px; }

@media (max-width: 520px) {
  .chat-panel {
    right: 0; bottom: 0; left: 0; top: auto;
    width: 100%; height: min(80vh, calc(100vh - 4.5rem));
    border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: none;
    animation-name: chatUp;
  }
  @keyframes chatUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
}

/* ---------------- Rodapé ---------------- */

.footer {
  border-top: 1px solid var(--line);
  padding: 1.8rem clamp(16px, 5vw, 48px);
  text-align: center; color: var(--ink-3); font-size: .85rem; font-weight: 300;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
