:root {
  --bg: #14110f;
  --bg-2: #1c1815;
  --paper: #f3ebe3;
  --paper-2: #e7dcd0;
  --art: #f5ede5; /* фон самих иллюстраций — чтобы не было шва */
  --ink: #1a1410;
  --muted: #9a8c82;
  --soft: #cbbdb2;
  --accent: #c45c4a;
  --accent-2: #a64b3c;
  --line: rgba(243, 235, 227, 0.12);
  --cube: 188px;
  --radius: 22px;
  --font: "Manrope", system-ui, sans-serif;
  --serif: "Instrument Serif", "Times New Roman", serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--paper);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

img {
  max-width: 100%;
  display: block;
}

button,
a {
  font-family: inherit;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 8;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 20px 20px max(28px, env(safe-area-inset-bottom));
  max-width: 1180px;
  margin: 0 auto;
}

.app.is-locked {
  display: none;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 4px 8px;
}

.top__side {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.sound-btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.sound-btn:hover {
  color: var(--paper);
  border-color: rgba(243, 235, 227, 0.28);
}

.sound-btn .icon {
  width: 18px;
  height: 18px;
  display: block;
}

.sound-btn .icon--off,
.sound-btn[aria-pressed="false"] .icon--on {
  display: none;
}

.sound-btn[aria-pressed="false"] .icon--off {
  display: block;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
  transition: opacity 0.2s ease;
}

.brand:hover,
.brand:active {
  opacity: 0.7;
}

.brand__mark {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: block;
}

.brand__name {
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: 0.02em;
  line-height: 1;
}

.top__tag {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px 0 8px;
  min-height: 0;
  width: 100%;
}

.play {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.scene-wrap {
  position: relative;
  width: calc(var(--cube) + 40px);
  height: calc(var(--cube) + 40px);
  margin: 8px 0 28px;
  display: grid;
  place-items: center;
}

.cube-hit {
  position: absolute;
  inset: -28px;
  z-index: 5;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.cube-hit:disabled {
  cursor: default;
}

.cube,
.face {
  pointer-events: none;
}

.scene {
  width: var(--cube);
  height: var(--cube);
  perspective: 920px;
  perspective-origin: 50% 46%;
  z-index: 1;
}

.cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-16deg) rotateY(26deg);
}

.cube.idle {
  animation: idle-turn 9s ease-in-out infinite;
}

.cube.is-rolling {
  animation: none;
}

.face {
  position: absolute;
  inset: 0;
  background: var(--art);
  border: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(26, 20, 16, 0.08);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.face img {
  transition: opacity 0.35s ease;
}

.face img:not([src]) {
  opacity: 0;
  transition: none;
}

.face::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.28),
    transparent 42%,
    rgba(26, 20, 16, 0.16)
  );
  pointer-events: none;
}

.face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  background: var(--art);
}

.face--front {
  transform: translateZ(calc(var(--cube) / 2));
}

.face--back {
  transform: rotateY(180deg) translateZ(calc(var(--cube) / 2));
}

.face--right {
  transform: rotateY(90deg) translateZ(calc(var(--cube) / 2));
}

.face--left {
  transform: rotateY(-90deg) translateZ(calc(var(--cube) / 2));
}

.face--top {
  transform: rotateX(90deg) translateZ(calc(var(--cube) / 2));
}

.face--bottom {
  transform: rotateX(-90deg) translateZ(calc(var(--cube) / 2));
}

.shadow {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 58%;
  height: 22px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.45), transparent 70%);
  filter: blur(2px);
  pointer-events: none;
  transition: width 0.5s var(--ease), opacity 0.5s var(--ease);
}

.scene-wrap.is-rolling .shadow {
  width: 44%;
  opacity: 0.55;
}

.scene-wrap.is-landing .scene {
  animation: land-pop 380ms var(--ease);
}

.hint {
  position: relative;
  z-index: 2;
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}

.btn {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 28px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  touch-action: manipulation;
  transition: transform 0.2s var(--ease), background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn--solid {
  background: var(--paper);
  color: var(--ink);
}

.btn--solid:hover:not(:disabled) {
  background: #fff8f1;
}

.btn--ghost {
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--line);
}

.btn--ghost:hover {
  background: rgba(243, 235, 227, 0.06);
}

.btn--roll {
  position: relative;
  z-index: 6;
  min-width: 220px;
  margin-top: 4px;
}

.result {
  display: none;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 0;
}

.app.has-result .result {
  display: flex;
  flex: 1;
  min-height: 0;
}

.empty,
.empty.is-gone {
  display: none !important;
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  animation: rise 0.55s var(--ease);
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.card[hidden] {
  display: none !important;
}

.card__media {
  position: relative;
  background: var(--art);
  flex: 1 1 0;
  min-height: 140px;
  overflow: hidden;
}

.card__media img {
  position: absolute;
  inset: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  object-fit: contain;
  object-position: center;
}

.card__body {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  padding: 16px 20px 18px;
  background: var(--bg-2);
}

.card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.card__diff[data-level="easy"] {
  color: #c9d4b8;
}

.card__diff[data-level="medium"] {
  color: #e2c58d;
}

.card__diff[data-level="hard"] {
  color: #e0a090;
}

.card__title {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 400;
  line-height: 1.15;
}

.card__text {
  margin: 0;
  color: var(--soft);
  font-size: 14px;
  line-height: 1.55;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 18px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(196, 92, 74, 0.16), transparent 50%),
    var(--bg);
}

.gate[hidden] {
  display: none;
}

.gate__card {
  width: min(440px, 100%);
  text-align: center;
}

.gate__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-family: var(--font);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.gate__title {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 400;
}

.gate__text {
  margin: 0 0 28px;
  color: var(--soft);
  line-height: 1.65;
}

.gate__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

@keyframes idle-turn {
  0% {
    transform: rotateX(-16deg) rotateY(26deg);
  }
  50% {
    transform: rotateX(-20deg) rotateY(40deg);
  }
  100% {
    transform: rotateX(-16deg) rotateY(26deg);
  }
}

@keyframes land-pop {
  0% {
    transform: scale(1.05);
  }
  55% {
    transform: scale(0.98);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 900px) {
  :root {
    --cube: 200px;
  }

  .app {
    height: 100dvh;
    overflow: hidden;
    padding: 24px 32px 20px;
  }

  .app.has-result {
    --cube: 176px;
  }

  .app.has-result .stage {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 36px;
    align-items: stretch;
    justify-content: stretch;
  }

  .app.has-result .play {
    justify-content: center;
  }

  .app.has-result .hint {
    display: none;
  }

  .app.has-result .result {
    max-width: none;
    height: 100%;
  }

  .scene-wrap {
    margin-bottom: 36px;
  }

  .app.has-result .scene-wrap {
    margin-bottom: 20px;
  }

  .card__title {
    font-size: 30px;
  }

  .card__text {
    font-size: 15px;
  }
}

@media (max-width: 899px) {
  /* На телефоне не пытаемся втиснуть всё в один экран: карточка
     раскрывается целиком, страница обычным образом скроллится. */
  .app.has-result .stage {
    justify-content: flex-start;
  }

  .app.has-result .result {
    flex: 0 0 auto;
  }

  .card {
    height: auto;
  }

  .card__media {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 0;
    padding: 10px;
  }

  /* Картинка занимает всю ширину карточки и растёт по своему
     соотношению сторон — вертикальные ограничиваем по высоте экрана. */
  .card__media img {
    position: static;
    inset: auto;
    width: 100%;
    height: auto;
    max-height: 46vh;
    object-fit: contain;
  }

  .card__body {
    padding-bottom: 20px;
  }

  .card__text {
    font-size: 15px;
    line-height: 1.6;
  }
}

@media (max-width: 640px) {
  :root {
    --cube: 168px;
  }

  .app {
    padding: 16px 16px 18px;
  }

  .app.has-result {
    --cube: 150px;
  }

  .app.has-result .stage {
    justify-content: flex-start;
    gap: 12px;
  }

  .app.has-result .scene-wrap {
    margin: 4px 0 8px;
  }

  .app.has-result .hint {
    display: none;
  }

  .brand__name {
    font-size: 24px;
  }

  .brand__mark {
    width: 23px;
    height: 23px;
  }

  .hint {
    font-size: 13px;
    padding: 0 12px;
  }

  .btn--roll {
    width: min(280px, 100%);
  }

  .card__title {
    font-size: 24px;
  }

  .card__body {
    padding: 14px 16px 16px;
  }

  .gate__title {
    font-size: 32px;
  }
}

@media (max-width: 380px) {
  :root {
    --cube: 148px;
  }

  .top__tag {
    display: none;
  }
}

@media (min-width: 900px) and (max-height: 640px) {
  .app {
    height: auto;
    overflow: auto;
  }

  .card {
    height: auto;
  }

  .card__media {
    position: relative;
    flex: 0 0 auto;
    height: min(42vh, 280px);
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --cube: 150px;
  }

  .app.has-result .stage {
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 16px;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cube.idle,
  .card,
  .scene-wrap.is-landing .scene {
    animation: none;
  }

  .cube,
  .btn {
    transition: none;
  }
}
