:root {
  --paper: #f7f1e7;
  --panel: #fffaf2;
  --ink: #2a1418;
  --muted: #7d6a66;
  --line: #e4d8c6;
  --wine: #4a0f1c;
  --wine-deep: #2b0810;
  --cream: #f3e6d0;
  --gold: #d98a2b;
  --tan: #ecd2a0;
  --ok: #3f7d4e;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 'Golos Text', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
h1, h2 { font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 700; margin: 0; line-height: 1.1; }
h2 { font-size: 28px; }
p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
.muted { color: var(--muted); font-size: 14px; }
.kicker { font-family: 'Caveat', cursive; font-size: 24px; color: var(--gold); }
.center { text-align: center; }

/* шапка */
#top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; flex-wrap: wrap; }
.logo { font-family: 'Caveat', cursive; font-size: 30px; font-weight: 700; color: var(--wine); text-decoration: none; }
#roomhead { display: flex; align-items: center; gap: 12px; min-width: 0; }
#roomname { font-family: 'Cormorant Garamond', serif; font-size: 22px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { padding: 8px 20px 40px; max-width: 1280px; margin: 0 auto; }

/* элементы форм */
label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: transparent; }
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 999px;
  padding: 11px 22px; text-decoration: none; display: inline-block; transition: transform .12s, background .15s;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--wine); color: var(--cream); }
.primary:hover { background: #631526; }
.ghost { background: transparent; color: var(--wine); border: 1px solid var(--wine); }
.ghost:hover { background: rgba(74, 15, 28, .07); }
.light { background: var(--cream); color: var(--wine-deep); }
.small { padding: 7px 14px; font-size: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px; display: grid; gap: 16px; align-content: start; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.count { font-family: 'Golos Text', sans-serif; font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 6px; }

/* главная */
#home { display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: center; max-width: 1040px; margin: 4vh auto 0; }
.hero h1 { font-size: clamp(44px, 7vw, 84px); color: var(--wine); margin: 4px 0 18px; }
.lead { font-size: 18px; max-width: 46ch; }
#join, #missing { max-width: 460px; margin: 6vh auto 0; }

/* личный кабинет */
#account { display: flex; align-items: center; gap: 8px; margin-left: auto; }
#account .who { font-weight: 600; font-size: 14px; }
#account .who small { font-weight: 400; color: var(--muted); }
#roomhead { order: 2; }
#account { order: 3; }
.link { background: none; color: var(--wine); padding: 4px; font-weight: 500; text-decoration: underline; border-radius: 4px; }
#cabinet { grid-column: 1 / -1; display: grid; gap: 16px; margin-top: 12px; }
#cabinet.top { order: -1; margin: 0 0 8px; }
.cabhead { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.myrooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.myrooms li { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; transition: border-color .15s, transform .15s; }
.myrooms li:hover { border-color: var(--gold); transform: translateY(-2px); }
.myrooms a { display: grid; gap: 6px; padding: 16px 18px; color: inherit; text-decoration: none; }
.myrooms b { font: 700 22px/1.1 'Cormorant Garamond', serif; padding-right: 70px; overflow-wrap: anywhere; }
.myrooms .badge { justify-self: start; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #f1e3c8; color: #7a4d10; }
.myrooms .badge.board { background: #f6d9de; color: var(--wine); }
.myrooms .badge.done { background: #e3efe4; color: #2d5c39; }
.myrooms .del { position: absolute; top: 12px; right: 12px; padding: 4px 10px; font-size: 12px; }
.myrooms .empty { padding: 18px; color: var(--muted); border-style: dashed; background: transparent; grid-column: 1 / -1; }
.myrooms .empty:hover { transform: none; border-color: var(--line); }
#shelfbox { display: grid; gap: 14px; margin-top: 10px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 16px; }
.shelf .cover { border-radius: 6px; box-shadow: 0 6px 14px rgba(43, 8, 16, .25); }
.shelf b { display: block; margin-top: 8px; font-size: 14px; line-height: 1.25; }
.shelf span { font-size: 12px; color: var(--muted); }
/* админка */
#admin { max-width: 900px; margin: 0 auto; }
#admin .cabhead { justify-content: space-between; align-items: center; }
.tablewrap { overflow-x: auto; }
#users { width: 100%; border-collapse: collapse; font-size: 15px; }
#users th { text-align: left; font-size: 13px; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
#users td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
#users td:last-child { text-align: right; white-space: nowrap; }
#users .tag { font-size: 12px; color: var(--gold); font-weight: 600; }
dialog { border: 0; padding: 0; background: transparent; width: min(400px, calc(100vw - 32px)); }
#confirm-text { font-size: 17px; }
dialog::backdrop { background: rgba(43, 8, 16, .6); }

/* сбор книг */
.cols { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(260px, 1fr); gap: 20px; align-items: start; }
.people { display: grid; gap: 8px; }
.people li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.people .dot { width: 9px; height: 9px; border-radius: 50%; background: #cdbfae; flex: none; }
.people .dot.on { background: var(--ok); }
.people .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.people .tag { font-size: 12px; color: var(--muted); }
.people .pr { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.people .pr.full { color: var(--ok); font-weight: 600; }
.people .free { border-style: dashed; background: transparent; color: var(--muted); font-size: 14px; }

.mybooks { display: grid; gap: 8px; }
.mybooks:empty { display: none; }
.mybooks li, .results li { display: flex; gap: 12px; align-items: center; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.mybooks .cover, .results .cover { width: 44px; flex: none; border-radius: 4px; }
.mybooks .t, .results .t { flex: 1; min-width: 0; }
.t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t span { display: block; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { display: flex; gap: 8px; }
.results { display: grid; gap: 6px; max-height: 340px; overflow: auto; }
.results:empty { display: none; }
.results li { cursor: pointer; }
.results li:hover { border-color: var(--gold); }
.results .src { font-size: 11px; color: var(--muted); flex: none; }
#adder { display: grid; gap: 14px; }
.bookform { display: grid; gap: 12px; padding-top: 14px; border-top: 1px dashed var(--line); }
.formtitle { font-weight: 600; }
.bookform-grid { display: grid; grid-template-columns: 110px 1fr; gap: 14px; }
.fields { display: grid; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 400; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--wine); flex: none; }
input:disabled { background: #f1ebe0; color: var(--muted); }
#readybtn { justify-self: start; }
.donebox { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: #eaf3ea; color: #2d5c39; border-radius: 12px; padding: 14px 16px; font-weight: 500; }
#hostbox { display: grid; gap: 10px; }

/* обложка: картинка поверх запасной «тканевой» обложки с названием */
.cover { position: relative; aspect-ratio: 2 / 3; overflow: hidden; background: linear-gradient(150deg, #6b1a2b, #2b0810); container-type: inline-size; }
.cover .nocover { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; gap: 6cqw; padding: 9cqw; text-align: center; color: var(--cream); }
.cover .nocover b { font: 700 13cqw/1.05 'Cormorant Garamond', serif; overflow-wrap: anywhere; }
.cover .nocover i { font-size: 7cqw; opacity: .8; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* полотно */
.boardhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
#status { font-family: 'Cormorant Garamond', serif; font-size: 24px; font-weight: 700; }
.boardactions { display: flex; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr)); gap: clamp(6px, 1.2vw, 16px); margin: 0 auto; }
.card { all: unset; display: block; cursor: pointer; aspect-ratio: 2 / 3; perspective: 1000px; container-type: inline-size; border-radius: 5cqw; }
.card:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.card .inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .9s cubic-bezier(.3, .7, .2, 1); }
.card.open .inner { transform: rotateY(180deg); }
.card .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 5cqw; overflow: hidden; box-shadow: 0 2px 8px rgba(43, 8, 16, .25); }
.card .back { background: var(--wine-deep) var(--back) center / 100% 100% no-repeat; display: grid; place-items: center; transition: transform .2s, box-shadow .2s; }
.card .back span { font: 700 34cqw/1 'Caveat', cursive; color: var(--cream); }
.card:not(.open):hover .back { transform: translateY(-2%) scale(1.02); box-shadow: 0 10px 22px rgba(43, 8, 16, .35); }
.card .front { transform: rotateY(180deg); }
.card .front .cover { width: 100%; height: 100%; }
.card.last .back { animation: pulse 1.6s ease-in-out infinite; }
.card.winner .front { box-shadow: 0 0 0 3px var(--gold), 0 0 26px rgba(217, 138, 43, .7); }
.card.open:not(.winner) .front { filter: saturate(.8); }
/* последняя карта: выезжает в центр, дрожит, раскручивается */
.card.final { position: relative; z-index: 15; box-shadow: 0 0 0 300vmax rgba(43, 8, 16, .86); animation: finalmove 3.4s both; }
.card.final .inner { transition: none; animation: finalspin 3.4s both; }
.card.final .back { animation: none; box-shadow: 0 0 0 3px var(--gold), 0 0 60px rgba(217, 138, 43, .9); }
.card.final .front { box-shadow: 0 0 0 3px var(--gold), 0 0 80px rgba(217, 138, 43, 1); filter: none; }
@keyframes finalmove {
  0% { transform: none; box-shadow: 0 0 0 300vmax rgba(43, 8, 16, 0); }
  22% { transform: translate(var(--dx), var(--dy)) scale(var(--sc)); box-shadow: 0 0 0 300vmax rgba(43, 8, 16, .86); animation-timing-function: ease-in-out; }
  29% { transform: translate(var(--dx), var(--dy)) scale(var(--sc)) rotate(-5deg); }
  36% { transform: translate(var(--dx), var(--dy)) scale(var(--sc)) rotate(5deg); }
  43% { transform: translate(var(--dx), var(--dy)) scale(var(--sc)) rotate(-6deg); }
  50% { transform: translate(var(--dx), var(--dy)) scale(var(--sc)) rotate(6deg); }
  56% { transform: translate(var(--dx), var(--dy)) scale(calc(var(--sc) * .92)); }
  100% { transform: translate(var(--dx), var(--dy)) scale(calc(var(--sc) * 1.08)); }
}
@keyframes finalspin {
  0%, 56% { transform: rotateY(0); animation-timing-function: cubic-bezier(.15, .6, .15, 1); }
  100% { transform: rotateY(900deg); }
}
@keyframes pulse { 50% { box-shadow: 0 0 0 3px var(--gold), 0 0 30px rgba(217, 138, 43, .8); transform: scale(1.03); } }

/* оверлеи */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto; }
#spot { background: rgba(43, 8, 16, .72); animation: fade .3s both; }
.slide { display: grid; grid-template-columns: minmax(0, 38%) 1fr; width: min(980px, 100%); background: var(--panel); border-radius: 18px; overflow: hidden; box-shadow: 0 30px 80px rgba(0, 0, 0, .45); animation: rise .5s cubic-bezier(.2, .8, .2, 1) both; margin: auto; }
.slide-cover { background: var(--tan); padding: 28px; display: grid; place-items: center; }
#spot-cover { width: 100%; max-width: 300px; }
#spot-cover .cover { border-radius: 6px; box-shadow: 0 14px 30px rgba(43, 8, 16, .35); animation: coverin .7s .1s cubic-bezier(.2, .8, .2, 1) both; }
.slide-text { padding: 34px 36px; display: grid; gap: 12px; align-content: center; justify-items: start; }
.slide-text h2 { font: 700 clamp(26px, 3.6vw, 42px)/1.05 'Golos Text', sans-serif; color: var(--gold); text-transform: uppercase; letter-spacing: .01em; overflow-wrap: anywhere; }
.slide-author { font-weight: 600; }
.slide-desc { white-space: pre-line; max-height: 38vh; overflow: auto; }
.slide-by { color: var(--muted); font-size: 14px; padding-top: 10px; border-top: 1px solid var(--line); width: 100%; }
.stamp { font: 700 26px/1 'Caveat', cursive; color: var(--wine); border: 2px solid var(--wine); border-radius: 8px; padding: 4px 12px 6px; transform: rotate(-4deg); opacity: .85; animation: stamp .4s .6s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(30px) scale(.97); } }
@keyframes coverin { from { opacity: 0; transform: rotateY(-70deg) scale(.8); } }
@keyframes stamp { from { opacity: 0; transform: rotate(-4deg) scale(2.2); } }

/* финал */
#finale { background: radial-gradient(circle at 50% 38%, #7a1c30, var(--wine-deep) 70%); color: var(--cream); animation: fade .6s both; overflow-x: hidden; }
.rays { position: fixed; left: 50%; top: 38%; width: 180vmax; height: 180vmax; margin: -90vmax 0 0 -90vmax; pointer-events: none;
  background: repeating-conic-gradient(rgba(243, 230, 208, .09) 0 7deg, transparent 7deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 0, transparent 55%); mask: radial-gradient(circle, #000 0, transparent 55%);
  animation: spin 50s linear infinite; }
.fin { position: relative; display: grid; justify-items: center; gap: 12px; text-align: center; max-width: 680px; margin: auto; padding: 10px 0; }
.fin-kicker { font: 700 clamp(34px, 6vw, 56px)/1 'Caveat', cursive; color: var(--tan); animation: rise .7s .2s both; }
.fin-cover { width: min(250px, 52vw); margin: 10px 0; animation: winner 1.3s .5s cubic-bezier(.2, .9, .2, 1) both; }
.fin-cover .cover { border-radius: 8px; box-shadow: 0 0 0 3px var(--gold), 0 0 70px rgba(217, 138, 43, .75), 0 30px 60px rgba(0, 0, 0, .5); }
#fin-title { font-size: clamp(34px, 6vw, 60px); animation: rise .7s 1.3s both; overflow-wrap: anywhere; }
.fin-author { font-size: 20px; color: var(--tan); animation: rise .7s 1.5s both; }
.fin-desc { max-width: 60ch; opacity: .88; max-height: 22vh; overflow: auto; white-space: pre-line; animation: rise .7s 1.7s both; }
.fin-by { font: 500 24px/1.2 'Caveat', cursive; color: var(--tan); animation: rise .7s 1.9s both; }
.fin-actions { display: flex; gap: 10px; margin-top: 8px; animation: rise .7s 2.2s both; }
@keyframes winner { 0% { opacity: 0; transform: scale(.2) rotateY(540deg); } 70% { transform: scale(1.08) rotateY(0); } 100% { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 40; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  #home, .cols { grid-template-columns: 1fr; }
  #home { gap: 20px; margin-top: 0; }
  main { padding: 4px 16px 32px; }
  #top { padding: 12px 16px; }
  .panel { padding: 18px; }
  .slide { grid-template-columns: 1fr; }
  .slide-cover { padding: 20px; }
  #spot-cover { max-width: 170px; }
  .slide-text { padding: 20px; }
  .bookform-grid { grid-template-columns: 80px 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; animation-delay: 0s !important; transition-duration: .01s !important; }
}
