/* ============================================================
   Хогвартские Сундуки — стили
   ============================================================ */

:root {
  --ink: #14100b;
  --night: #0a100d;
  --green-deep: #0d1a14;
  --green: #16342a;
  --green-light: #1f4a38;
  --gold: #c9a227;
  --gold-light: #f2dfae;
  --gold-deep: #8a6a12;
  --parch: #efdcb4;
  --parch-dark: #d9c294;
  --garnet: #7b1e28;
  --garnet-light: #a8323f;
  --wood: #4a2f1c;
  --wood-light: #6b4429;
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --display-deco: 'Forum', Georgia, 'Times New Roman', serif;
  --hand: 'Caveat', 'Segoe Script', cursive;
  --shadow: 0 18px 40px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--night);
  color: var(--parch);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #1a3b2c 0%, rgba(13, 26, 20, 0) 60%),
    radial-gradient(800px 500px at 10% 100%, #14251d 0%, rgba(10, 16, 13, 0) 60%),
    var(--night);
  overflow-x: hidden;
}

/* ---------------- Фоновая магия ---------------- */
.ambience { position: fixed; inset: 0; pointer-events: none; z-index: 0; }

.vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(0,0,0,.72) 100%);
}

.dust {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 20% 30%, rgba(242,223,174,.5), transparent),
    radial-gradient(1.5px 1.5px at 70% 60%, rgba(242,223,174,.35), transparent),
    radial-gradient(1.5px 1.5px at 45% 80%, rgba(242,223,174,.4), transparent),
    radial-gradient(1.5px 1.5px at 85% 20%, rgba(242,223,174,.3), transparent);
  background-size: 380px 380px, 520px 520px, 610px 610px, 440px 440px;
  animation: drift 26s linear infinite;
  opacity: .55;
}

@keyframes drift {
  0%   { transform: translate3d(0, 0, 0); }
  50%  { transform: translate3d(24px, -32px, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

.candles { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; padding: 0 4vw; }
.candle { position: relative; width: 6px; height: 120px; background: linear-gradient(#e8dcc0, #b8a87f); opacity: .35; }
.candle .flame {
  position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  width: 10px; height: 20px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 50% 70%, #fff6cf, #f0a53c 60%, #b9500f);
  box-shadow: 0 0 22px 8px rgba(240, 165, 60, .35);
  animation: flicker 1.6s ease-in-out infinite;
}
.candle:nth-child(2) .flame { animation-delay: .5s; }
.candle:nth-child(3) .flame { animation-delay: 1s; }
@keyframes flicker {
  0%, 100% { transform: translateX(-50%) scaleY(1); opacity: .95; }
  50%      { transform: translateX(-50%) scaleY(1.16) translateX(1px); opacity: .75; }
}

/* ---------------- Дисклеймер ---------------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at center, rgba(10,16,13,.86), rgba(3,6,5,.97));
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.gate.hidden { display: none; }

.scroll {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  filter: drop-shadow(0 30px 60px rgba(0,0,0,.7));
  animation: unroll .6s cubic-bezier(.2,.8,.2,1);
}
@keyframes unroll {
  from { transform: scaleY(.82); opacity: 0; }
  to   { transform: scaleY(1); opacity: 1; }
}

.scroll-rod {
  height: 22px; border-radius: 11px;
  background: linear-gradient(#8a6a3a, #4a2f1c 45%, #2c1a0f);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 6px 14px rgba(0,0,0,.5);
  margin: 0 -14px;
  position: relative; z-index: 2;
}
.scroll-rod::before, .scroll-rod::after {
  content: ""; position: absolute; top: 50%; transform: translateY(-50%);
  width: 16px; height: 34px; border-radius: 6px;
  background: linear-gradient(#c9a227, #6d5210);
}
.scroll-rod::before { left: -16px; }
.scroll-rod::after  { right: -16px; }

.scroll-body {
  background:
    radial-gradient(ellipse at top left, rgba(255,255,255,.28), transparent 55%),
    radial-gradient(ellipse at bottom right, rgba(140,100,40,.22), transparent 55%),
    linear-gradient(var(--parch), var(--parch-dark));
  color: var(--ink);
  padding: 34px clamp(22px, 4vw, 46px) 30px;
  overflow-y: auto;
  border-left: 1px solid rgba(0,0,0,.15);
  border-right: 1px solid rgba(0,0,0,.15);
}

.scroll-body h1 {
  font-family: var(--display-deco);
  font-size: clamp(22px, 3.4vw, 32px);
  text-align: center;
  margin: 6px 0 14px;
  color: #3a1c18;
  letter-spacing: .5px;
}
.scroll-body .lead { text-align: center; font-size: 19px; margin-bottom: 18px; }
.scroll-body .rules { margin: 0 0 16px; padding-left: 22px; }
.scroll-body .rules li { margin-bottom: 9px; }
.scroll-body .small { font-family: var(--hand); font-size: 17px; opacity: .9; }
.scroll-body .tiny { font-family: var(--hand); font-size: 16px; text-align: center; opacity: .85; margin: 12px 0 0; }

.seal { display: flex; justify-content: center; margin-top: -6px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.4)); }

.agree {
  display: flex; align-items: flex-start; gap: 12px;
  margin: 18px 0 16px; cursor: pointer; font-size: 17px;
  padding: 12px 14px; border: 1px dashed rgba(90,50,20,.45); border-radius: 10px;
  background: rgba(255,255,255,.22);
}
.agree input { position: absolute; opacity: 0; width: 0; height: 0; }
.agree .box {
  flex: 0 0 auto; width: 24px; height: 24px; margin-top: 2px;
  border: 2px solid var(--garnet); border-radius: 5px; background: rgba(255,255,255,.5);
  position: relative; transition: .18s;
}
.agree input:checked + .box { background: var(--garnet); }
.agree input:checked + .box::after {
  content: ""; position: absolute; left: 7px; top: 2px;
  width: 6px; height: 12px; border: solid var(--parch); border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}
.agree input:focus-visible + .box { outline: 3px solid rgba(123,30,40,.4); outline-offset: 2px; }

.btn {
  font-family: var(--display);
  letter-spacing: .06em;
  cursor: pointer;
  border: none;
  transition: transform .15s, box-shadow .2s, opacity .2s, background .2s;
}
.btn:disabled { cursor: not-allowed; opacity: .45; }
.btn:not(:disabled):hover { transform: translateY(-2px); }

.btn-seal {
  display: block; width: 100%;
  padding: 15px 20px;
  font-size: 19px;
  color: var(--gold-light);
  background: linear-gradient(#8f2530, var(--garnet) 55%, #5d121c);
  border: 2px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.22);
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.btn-seal:not(:disabled):hover { box-shadow: 0 12px 26px rgba(0,0,0,.5), 0 0 24px rgba(201,162,39,.35), inset 0 1px 0 rgba(255,255,255,.25); }

/* ---------------- Основная страница ---------------- */
.page { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 40px 18px calc(70px + env(safe-area-inset-bottom)); }

.hero { text-align: center; margin-bottom: 26px; }
.crest { display: flex; justify-content: center; margin-bottom: 6px; filter: drop-shadow(0 8px 18px rgba(0,0,0,.6)); }

.title {
  font-family: var(--display-deco);
  font-size: clamp(30px, 6vw, 56px);
  margin: 4px 0 8px;
  color: var(--gold-light);
  letter-spacing: 1px;
  text-shadow: 0 2px 0 #4b3a10, 0 0 34px rgba(201,162,39,.35);
}
.subtitle { color: #cdbd93; font-size: clamp(16px, 2.2vw, 20px); margin: 0; }
.subtitle strong { color: var(--gold); }

/* ---------------- Панель статистики ---------------- */
.panel {
  background: linear-gradient(rgba(20,44,34,.86), rgba(11,24,19,.92));
  border: 1px solid rgba(201,162,39,.35);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr)) 2.2fr;
  gap: 18px;
  align-items: center;
  padding: 20px 24px;
  margin-bottom: 28px;
}
.stat { text-align: center; }
.stat-num {
  display: block;
  font-family: var(--display-deco);
  font-size: clamp(26px, 4vw, 40px);
  color: var(--gold);
  text-shadow: 0 0 18px rgba(201,162,39,.3);
  line-height: 1.1;
}
.stat-label { display: block; font-size: 14px; letter-spacing: .14em; text-transform: uppercase; color: #a9bdab; }

.progress-wrap { min-width: 0; }
.progress {
  height: 16px; border-radius: 999px; overflow: hidden;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(201,162,39,.3);
}
.progress-bar {
  height: 100%; width: 0;
  background: linear-gradient(90deg, #7b1e28, #c9a227 60%, #f2dfae);
  transition: width .55s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 0 14px rgba(201,162,39,.5);
}
.progress-hint { margin-top: 8px; font-family: var(--hand); font-size: 19px; color: #b9c9b8; }

/* ---------------- Сетка сундуков ---------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 22px;
}

.box {
  position: relative;
  border-radius: 14px;
  padding-top: 26px;
  background: linear-gradient(var(--wood-light), var(--wood) 60%, #2e1c10);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.12);
  border: 1px solid rgba(0,0,0,.5);
  transition: transform .2s, box-shadow .25s;
}
.box:hover { transform: translateY(-4px); box-shadow: 0 24px 46px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.12); }

.box-lid {
  position: absolute; top: 0; left: -1px; right: -1px; height: 26px;
  border-radius: 14px 14px 6px 6px;
  background: linear-gradient(#7d5330, #56371e);
  border-bottom: 2px solid rgba(0,0,0,.45);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.16);
}

.box-face { padding: 16px 16px 18px; text-align: center; }

.box-num {
  font-family: var(--display-deco);
  font-size: 30px;
  color: var(--gold-light);
  text-shadow: 0 2px 0 #3a2409, 0 0 16px rgba(201,162,39,.35);
}
.box-seal { margin: 4px 0 8px; opacity: .95; }
.box-status {
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #e8d9ae;
  margin-bottom: 12px;
}
.box-time { font-family: var(--hand); font-size: 16px; color: #b6c1a9; opacity: .85; margin-top: 10px; min-height: 18px; }

.btn-box {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--gold-light);
  background: linear-gradient(rgba(0,0,0,.35), rgba(0,0,0,.5));
  border: 1px solid rgba(201,162,39,.5);
  border-radius: 9px;
}
.btn-box:hover { box-shadow: 0 0 16px rgba(201,162,39,.35); }

.box[data-state="found"] {
  background: linear-gradient(#2a5b46, #17382c 60%, #0e231b);
  border-color: rgba(201,162,39,.6);
  box-shadow: 0 0 0 1px rgba(201,162,39,.25), 0 18px 40px rgba(0,0,0,.55), 0 0 40px rgba(47,138,90,.18);
}
.box[data-state="found"] .box-status { color: #9fe6b6; }
.box[data-state="found"] .btn-box { border-color: rgba(159,230,182,.5); color: #d7f5e1; }
.box[data-state="found"] .box-seal { animation: pop .45s ease; }

@keyframes pop {
  0% { transform: scale(.6) rotate(-18deg); opacity: .2; }
  60% { transform: scale(1.15) rotate(6deg); }
  100% { transform: scale(1) rotate(0); }
}

.box.saving { opacity: .65; pointer-events: none; }

/* ---------------- Подвал ---------------- */
.footer { text-align: center; margin-top: 44px; color: #9fb098; }
.footer .tiny { font-size: 13px; opacity: .7; margin-top: 6px; }
#syncNote { font-family: var(--hand); font-size: 15px; }
.footer .tip { font-family: var(--hand); font-size: 18px; opacity: .95; }
.tip-ico { margin-right: 4px; }

@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .progress-wrap { grid-column: 1 / -1; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
  .box-num { font-size: 24px; }
}

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