:root {
  --ink: #1d2b4a;
  --ru: #1f4fa3;
  --th: #b3202a;
  --gold: #e8a417;
  --cream: #fff8e8;
  --green: #2f9e57;
  --shadow: 0 0.6cqw 2cqw rgba(10, 30, 60, .35);
  /* Холст поля 1536×1024 */
  --stage-w: min(100vw, 150vh);
  --stage-h: calc(var(--stage-w) / 1.5);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d2f4f radial-gradient(ellipse at center, #1c5a85 0%, #0d2f4f 70%);
  font-family: Nunito, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; cursor: pointer; }

/* ---------- Поле ---------- */

.stage {
  position: absolute;
  left: 50%; top: 50%;
  width: var(--stage-w);
  height: var(--stage-h);
  transform: translate(-50%, -50%);
  container-type: size;
  overflow: hidden;
}

.board {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
}

/* Координаты ниже — проценты от 1536×1024 */

.decks { position: absolute; inset: 0; }

.deck {
  position: absolute;
  border: 0;
  background: transparent;
  border-radius: 2.2cqw;
  transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
  padding: 0;
}
.deck:not(.done):hover,
.deck:not(.done):focus-visible {
  transform: translateY(-1.2%) scale(1.02);
  box-shadow: 0 0 0 .35cqw #fff, 0 0 2.5cqw .6cqw rgba(255, 230, 120, .85);
  outline: none;
}
.deck:not(.done):active { transform: scale(.98); }

.deck-badge {
  position: absolute;
  top: -3%; right: 4%;
  min-width: 3.4cqw; height: 3.4cqw;
  padding: 0 .9cqw;
  border-radius: 1.7cqw;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  font-size: 1.9cqw;
  line-height: 3.4cqw;
  box-shadow: var(--shadow);
  border: .25cqw solid currentColor;
}

.deck.done { cursor: default; }
.deck.done::after {
  content: "";
  position: absolute; inset: 1.5% 2%;
  border-radius: 2cqw;
  background: rgba(255, 255, 255, .55);
  backdrop-filter: grayscale(.8);
}
.deck-check {
  display: none;
  position: absolute;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  z-index: 1;
  width: 8cqw; height: 8cqw;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 5cqw;
  font-weight: 900;
  line-height: 8cqw;
  box-shadow: var(--shadow);
}
.deck.done .deck-check { display: block; animation: pop .5s cubic-bezier(.3, 1.6, .5, 1); }
.deck.done .deck-badge { display: none; }

@keyframes pop { from { transform: translate(-50%, -50%) scale(0); } }

/* ---------- Части моста (координаты — из window.BRIDGE) ---------- */

.spans { position: absolute; inset: 0; pointer-events: none; }

.span { position: absolute; }
.span img { width: 100%; height: 100%; display: block; }

.span.building { animation: build 1.4s cubic-bezier(.5, 0, .3, 1) both; }
@keyframes build {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}

/* ---------- HUD ---------- */

.hud { position: absolute; z-index: 5; }
.hud-top { left: 1%; top: 1.5%; }
.hud-bottom {
  left: 50%; bottom: .9%;
  transform: translateX(-50%);
}

.hud-btn {
  width: 4cqw; height: 4cqw;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .85);
  color: var(--ink);
  font-size: 2.2cqw;
  box-shadow: var(--shadow);
}

.menu {
  position: absolute;
  top: 4.8cqw; left: 0;
  display: flex; flex-direction: column;
  background: #fff;
  border-radius: 1cqw;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 18cqw;
}
.menu button {
  border: 0;
  background: none;
  text-align: left;
  padding: 1cqw 1.6cqw;
  font-size: 1.5cqw;
  font-weight: 800;
  color: var(--ink);
}
.menu button:hover { background: #eef3fb; }

.progress {
  background: rgba(255, 248, 232, .92);
  border: .2cqw solid var(--gold);
  border-radius: 2cqw;
  padding: .3cqw 1.8cqw;
  font-weight: 800;
  font-size: 1.5cqw;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

/* ---------- Общие кнопки ---------- */

.btn {
  border: 0;
  border-radius: 999px;
  padding: .7em 1.6em;
  font-weight: 900;
  font-size: clamp(16px, 1.6vw, 28px);
  transition: transform .15s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; filter: none; transform: none; }
.btn-primary { background: var(--green); color: #fff; box-shadow: 0 4px 0 #1f7a40; }
.btn-ghost { background: rgba(255, 255, 255, .9); color: var(--ink); box-shadow: 0 4px 0 #b8c3d6; }
.btn-danger { background: var(--th); color: #fff; box-shadow: 0 4px 0 #7d151c; }

/* ---------- Экраны поверх поля ---------- */

.screen {
  position: fixed; inset: 0;
  z-index: 20;
  display: grid; place-items: center;
  background: rgba(8, 28, 52, .55);
  backdrop-filter: blur(6px);
  padding: 16px;
  animation: fade .3s ease;
}

@keyframes fade { from { opacity: 0; } }

.panel {
  background: var(--cream);
  border: 4px solid var(--gold);
  border-radius: 28px;
  padding: clamp(20px, 3vw, 48px) clamp(20px, 4vw, 64px);
  text-align: center;
  max-width: min(900px, 100%);
  max-height: 100%;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.panel-small { max-width: 560px; }

.logo { width: clamp(70px, 9vw, 130px); height: auto; }

.panel h1 {
  margin: .2em 0 .1em;
  font-size: clamp(30px, 4.4vw, 68px);
  font-weight: 900;
  letter-spacing: .02em;
  text-transform: uppercase;
  line-height: 1.05;
}
.panel h1 .ru { color: var(--ru); }
.panel h1 .th { color: var(--th); }
.subtitle { margin: 0 0 1.2em; font-size: clamp(16px, 1.6vw, 24px); font-weight: 600; }
.panel h2 { font-size: clamp(18px, 1.8vw, 28px); margin: 1em 0 .6em; }
.panel p { font-size: clamp(16px, 1.4vw, 22px); }

.resume { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.resume-info { font-weight: 600; opacity: .75; }

.modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}
.mode {
  border: 3px solid #d7c9a3;
  border-radius: 20px;
  background: #fff;
  padding: 14px 8px;
  color: var(--ink);
  transition: transform .15s ease, border-color .15s ease;
}
.mode:hover, .mode:focus-visible { border-color: var(--gold); transform: translateY(-3px); outline: none; }
.mode b { display: block; font-size: clamp(32px, 3.6vw, 56px); font-weight: 900; line-height: 1; color: var(--ru); }
.mode span { display: block; margin-top: 6px; font-size: clamp(13px, 1.1vw, 18px); font-weight: 600; }

.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- Карточка ---------- */

.card-screen {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.2vh;
  padding: 1.5vh 1vw;
  background: rgba(8, 28, 52, .78);
  backdrop-filter: blur(4px);
}
.card-screen.in { animation: fade .25s ease; }

.card-head { display: flex; gap: 12px; align-items: center; color: #fff; font-weight: 800; font-size: clamp(14px, 1.4vw, 24px); }
.card-cat { padding: .2em .9em; border-radius: 999px; background: var(--cat-color, var(--ru)); }
.card-count { opacity: .85; }

.card-img {
  /* Картинка целиком: 3:2, вписывается в экран за вычетом шапки и кнопок */
  width: min(98vw, calc((100vh - 9.5vh - 90px) * 1.5));
  aspect-ratio: 3 / 2;
  border-radius: 1.2vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  background: #fff;
  display: block;
}

.card-actions { display: flex; gap: 16px; }
.btn-done { font-size: clamp(18px, 1.9vw, 32px); }

/* Обложка колоды в полёте (переворот карточки) */
.flyer {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  backface-visibility: hidden;
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, .45));
}

/* ---------- Финал ---------- */

.final {
  position: fixed; inset: 0;
  z-index: 15;
  pointer-events: none;
}
.final-img {
  position: absolute;
  left: 50%; top: 50%;
  width: var(--stage-w);
  height: var(--stage-h);
  transform: translate(-50%, -50%);
  animation: fade 1.5s ease;
}
.final-banner {
  position: absolute;
  left: 50%; bottom: 4vh;
  transform: translateX(-50%);
  pointer-events: auto;
  background: var(--cream);
  border: 4px solid var(--gold);
  border-radius: 28px;
  padding: 18px 40px 24px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
  z-index: 1;
  animation: rise .8s cubic-bezier(.3, 1.4, .5, 1) .4s both;
  max-width: calc(100vw - 32px);
}
.final-banner h2 { margin: 0; font-size: clamp(26px, 3.4vw, 56px); font-weight: 900; color: var(--ru); }
.final-banner p { margin: .3em 0 .8em; font-size: clamp(15px, 1.4vw, 22px); font-weight: 600; }
@keyframes rise { from { transform: translate(-50%, 140%); } }

.confetti { position: absolute; inset: 0; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -4vh;
  width: 1vw; height: 1.6vw;
  min-width: 8px; min-height: 12px;
  border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); }
}

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