:root {
  --brown: #95380d;
  --brick: #9f532b;
  --emerald: #78ffec;
  --black: #000000;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  position: relative;
  isolation: isolate;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--black);
  color: var(--emerald);
  font-family: "Trebuchet MS", "Segoe UI", Arial, Helvetica, sans-serif;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background: url("../assets/kubiki.png") center / cover no-repeat;
  filter: blur(4px);
  transform: scale(1.02);
  opacity: 1;
  z-index: -2;
}

body::after {
  background: rgba(0, 0, 0, 0.5);
  z-index: -1;
}

body.landing-page::before {
  background-image: url("../assets/sortirovka.png");
  background-position: center 72%;
  filter: blur(1.4px);
  transform: scale(1.01);
}

body.sort-page::before {
  background-image: url("../assets/sortirovka.png");
  background-position: center 24%;
  background-size: auto 118%;
  filter: blur(1.4px);
  transform: scale(1.012);
}

body.dice-page::before {
  background-image: url("../assets/kubiki.png");
  background-position: center;
  filter: blur(4px);
}

body.landing-page::after {
  background: rgba(0, 0, 0, 0.58);
}

body.sort-page::after {
  background: rgba(0, 0, 0, 0.38);
}

button,
select,
a.primary-button {
  font: inherit;
}

.app-shell {
  position: relative;
  width: min(100%, 520px);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: 10px 10px 12px;
  overflow: hidden;
}

.game-screen {
  display: grid;
  height: 100%;
  min-height: 0;
  gap: 8px;
}

.intro,
.action-panel,
.message-panel,
.rules-modal {
  border: 1px solid rgba(120, 255, 236, 0.28);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.86);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.44);
}

.intro {
  padding: 24px 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--emerald);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p,
span,
strong {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  color: var(--emerald);
  font-size: 33px;
  line-height: 1.04;
}

h2,
h3 {
  margin: 0;
}

.description {
  margin: 14px 0 0;
  color: rgba(120, 255, 236, 0.78);
  line-height: 1.45;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 54px;
  border: 1px solid rgba(120, 255, 236, 0.62);
  border-radius: 8px;
  background: rgba(159, 83, 43, 0.9);
  color: var(--emerald);
  font-weight: 900;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.loading-text {
  margin: 12px 0 0;
  color: var(--emerald);
  text-align: center;
}

.message-panel {
  padding: 16px;
  line-height: 1.45;
}

.message-panel strong {
  display: block;
  margin-bottom: 6px;
  color: var(--emerald);
  font-size: 18px;
}

.message-panel.alert {
  border-color: var(--brick);
  background: rgba(149, 56, 13, 0.92);
}

.result-panel {
  display: grid;
  height: 100%;
  min-height: 0;
}

.screenshot-area {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: max-content minmax(120px, 1fr) max-content;
  gap: 8px;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}

.game-number-card {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(120, 255, 236, 0.38);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(2px);
  text-align: center;
}

.game-number-card h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  color: var(--emerald);
  font-size: clamp(22px, 7vw, 36px);
  line-height: 1;
  font-weight: 900;
  white-space: nowrap;
}

.game-number-action {
  display: grid;
  gap: 4px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.game-number-action .primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  min-height: 38px;
  padding: 0 8px;
  font-size: 14px;
  line-height: 1;
}

.prize-stack {
  display: grid;
  gap: 10px;
}

.prize-banner {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 2px solid var(--emerald);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brick), var(--brown));
  text-align: center;
}

.prize-banner strong {
  color: var(--emerald);
  font-size: 22px;
  line-height: 1.08;
  font-weight: 900;
  text-transform: uppercase;
}

.prize-banner span {
  color: var(--emerald);
  line-height: 1.35;
}

.dice-stage {
  display: grid;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.dice-scene {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  overflow: hidden;
}

.dice-scene canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.cocktail-card {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid rgba(120, 255, 236, 0.38);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(2px);
}

.cocktail-card-header {
  display: grid;
  place-items: center;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(120, 255, 236, 0.22);
  text-align: center;
}

.cocktail-card-header .eyebrow {
  color: var(--emerald);
  margin-bottom: 0;
  font-size: 12px;
}

.ingredient-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.ingredient-row {
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 6px;
  min-width: 0;
  padding: 7px 5px;
  border: 1px solid rgba(120, 255, 236, 0.42);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(2px);
}

.ingredient-row-swap-moving {
  position: relative;
  z-index: 3;
  transition: transform 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

.ingredient-row-wildcard {
  border-color: var(--emerald);
  background: rgba(0, 0, 0, 0.32);
}

.ingredient-label {
  color: var(--emerald);
  font-size: 10px;
  line-height: 1.1;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.ingredient-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: stretch;
  width: 100%;
  min-height: 30px;
  padding: 5px 4px;
  border-radius: 8px;
  background: rgba(120, 255, 236, 0.92);
  color: var(--black);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.12;
  text-align: center;
}

.ingredient-row-options {
  grid-template-columns: 1fr;
  align-items: start;
  gap: 12px;
}

.ingredient-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
}

.ingredient-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 22px;
  padding: 3px 4px;
  border: 1px solid rgba(120, 255, 236, 0.34);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.42);
  color: var(--emerald);
  font-size: 9px;
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  white-space: normal;
}

.ingredient-select {
  justify-self: end;
  width: 100%;
  max-width: none;
  min-height: 32px;
  border: 2px solid var(--emerald);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(120, 255, 236, 0.16), rgba(0, 0, 0, 0.9)),
    var(--black);
  color: var(--emerald);
  padding: 0 4px;
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.swap-modal-backdrop {
  z-index: 30;
}

.swap-modal {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 36px);
  max-height: calc(100dvh - 36px);
  overflow: auto;
}

.swap-modal p {
  margin: 0;
  text-align: center;
}

.swap-modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.swap-preview-card {
  gap: 6px;
  padding: 7px;
}

.swap-preview-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.swap-preview-item {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(66, 245, 222, 0.38);
  background: rgba(0, 0, 0, 0.28);
}

.swap-preview-title {
  color: var(--emerald);
  font-size: 11px;
  letter-spacing: 0;
  text-align: center;
}

.swap-preview-line {
  display: grid;
  gap: 2px;
  min-width: 0;
  font-size: 10px;
  text-align: center;
}

.swap-preview-line span {
  color: var(--muted);
}

.swap-preview-line b {
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.swap-preview-line-after b {
  color: var(--emerald);
}

@media (max-width: 380px) {
  .swap-preview-list {
    grid-template-columns: 1fr;
  }
}

.sort-shell {
  width: min(100%, 520px);
}

.sort-screen,
.sort-play-area {
  display: grid;
  height: 100%;
  min-height: 0;
}

.sort-screen {
  gap: 8px;
}

.sort-message {
  align-self: start;
}

.sort-play-area {
  position: relative;
  grid-template-rows: max-content max-content minmax(180px, 1fr) max-content;
  gap: 8px;
  overflow: hidden;
}

.sort-status {
  display: grid;
  gap: 8px;
}

.sort-number-card h2 {
  font-size: clamp(22px, 7vw, 34px);
}

.sort-progress-wrap {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid rgba(120, 255, 236, 0.38);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(2px);
}

.sort-progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--emerald);
  font-size: 14px;
  font-weight: 900;
  text-transform: uppercase;
}

.sort-progress-track {
  height: 12px;
  border: 1px solid rgba(120, 255, 236, 0.44);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.48);
  overflow: hidden;
}

.sort-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brick), var(--emerald));
  transition: width 180ms ease;
}

.sort-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid rgba(120, 255, 236, 0.38);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(2px);
  color: var(--emerald);
  text-transform: uppercase;
}

.sort-hint strong {
  font-size: 18px;
  font-weight: 900;
}

.sort-hint span {
  color: rgba(120, 255, 236, 0.78);
  font-size: 13px;
  font-weight: 900;
}

.sort-hint-up {
  border-color: rgba(120, 255, 236, 0.5);
}

.sort-hint-down {
  border-color: rgba(159, 83, 43, 0.76);
}

.sort-stage {
  position: relative;
  min-height: 0;
  border: 1px solid rgba(120, 255, 236, 0.26);
  border-radius: 8px;
  background:
    radial-gradient(ellipse at center 62%, rgba(120, 255, 236, 0.1), rgba(0, 0, 0, 0) 42%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.28));
  backdrop-filter: blur(0.5px);
  overflow: hidden;
  touch-action: none;
}

.sort-stage::before,
.sort-stage::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  height: 1px;
  background: rgba(120, 255, 236, 0.26);
}

.sort-stage::before {
  top: 28%;
}

.sort-stage::after {
  bottom: 28%;
}

.sort-item {
  position: absolute;
  left: 0;
  top: calc(50% - 62px);
  z-index: 2;
  width: clamp(104px, 34vw, 150px);
  height: clamp(104px, 34vw, 150px);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  cursor: grab;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.56));
  will-change: transform, opacity;
}

.sort-item:active {
  cursor: grabbing;
}

.sort-item-flying {
  transition:
    transform 340ms ease-in,
    opacity 340ms ease-in;
}

.sort-screenshot-area {
  grid-template-rows: max-content minmax(180px, 1fr) max-content;
}

.sort-final-card {
  display: grid;
  align-content: center;
  gap: 12px;
  min-height: 0;
  padding: 16px;
  border: 2px solid var(--emerald);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(159, 83, 43, 0.82), rgba(0, 0, 0, 0.78));
  text-align: center;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.44);
}

.sort-final-card h1 {
  font-size: clamp(28px, 8vw, 48px);
  line-height: 1.02;
}

.sort-final-card h1.sort-final-title-compact {
  font-size: clamp(20px, 5.4vw, 30px);
  line-height: 1.16;
}

.sort-final-card p {
  margin: 0;
  color: rgba(120, 255, 236, 0.84);
  font-size: clamp(15px, 4vw, 20px);
  line-height: 1.35;
}

.sort-final-card .eyebrow {
  color: var(--emerald);
  font-size: 12px;
}

.sort-final-stats .ingredient-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 520px) {
  .app-shell {
    padding: 8px 8px 10px;
  }

  .screenshot-area {
    grid-template-rows: max-content minmax(150px, 1fr) max-content;
  }

  .screenshot-area:has(.ingredient-row-options) {
    grid-template-rows: max-content minmax(118px, 1fr) max-content;
  }

  .game-number-card {
    gap: 6px;
    padding: 7px 8px;
  }

  .screenshot-area:has(.prize-stack:not([hidden])) {
    grid-template-rows: max-content max-content minmax(118px, 1fr) max-content;
  }

  .prize-stack {
    gap: 5px;
  }

  .prize-banner {
    gap: 3px;
    padding: 6px 8px;
  }

  .prize-banner strong {
    font-size: 14px;
    line-height: 1.02;
  }

  .prize-banner span {
    font-size: 11px;
    line-height: 1.15;
  }

  .game-number-card h2 {
    min-height: 32px;
    font-size: clamp(20px, 7vw, 32px);
  }

  .sort-play-area {
    grid-template-rows: max-content max-content minmax(210px, 1fr) max-content;
  }

  .sort-hint {
    min-height: 38px;
    padding: 7px 10px;
  }

  .sort-hint strong {
    font-size: 16px;
  }

  .sort-final-card {
    padding: 12px;
  }
}

@media (max-width: 520px) and (max-height: 620px) {
  .app-shell {
    padding-block: 5px;
  }

  .screenshot-area {
    grid-template-rows: max-content minmax(118px, 1fr) max-content;
    gap: 5px;
    padding: 4px;
  }

  .screenshot-area:has(.ingredient-row-options) {
    grid-template-rows: max-content minmax(88px, 1fr) max-content;
  }

  .screenshot-area:has(.prize-stack:not([hidden])) {
    grid-template-rows: max-content max-content minmax(92px, 1fr) max-content;
  }

  .prize-banner {
    padding: 4px 6px;
  }

  .prize-banner strong {
    font-size: 12px;
  }

  .prize-banner span {
    font-size: 10px;
  }

  .game-number-card {
    gap: 4px;
    padding: 5px 6px;
  }

  .game-number-card h2 {
    min-height: 28px;
    font-size: clamp(19px, 6vw, 28px);
  }

  .primary-button {
    height: 32px;
    min-height: 32px;
  }

  .sort-play-area {
    grid-template-rows: max-content max-content minmax(150px, 1fr) max-content;
    gap: 5px;
  }

  .sort-progress-wrap {
    gap: 5px;
    padding: 6px;
  }

  .sort-hint {
    min-height: 32px;
    padding: 5px 8px;
  }

  .sort-hint strong {
    font-size: 14px;
  }

  .sort-hint span {
    font-size: 11px;
  }

  .sort-item {
    width: clamp(88px, 30vw, 120px);
    height: clamp(88px, 30vw, 120px);
    top: calc(50% - 48px);
  }

  .cocktail-card {
    gap: 5px;
    padding: 6px;
  }

  .cocktail-card-header {
    padding-bottom: 3px;
  }

  .ingredient-list {
    gap: 4px;
  }

  .ingredient-row {
    gap: 4px;
    padding: 5px 4px;
  }

  .ingredient-option {
    min-height: 19px;
    padding-block: 2px;
    font-size: 8px;
  }
}

@media (min-width: 720px) {
  .app-shell {
    width: min(100%, 720px);
    padding: 12px;
  }

  .screenshot-area {
    grid-template-rows: max-content minmax(120px, 1fr) max-content;
    gap: 10px;
    padding: 0;
  }

  .game-number-card {
    padding: 8px 10px;
  }

  .game-number-card h2 {
    min-height: 30px;
    font-size: clamp(24px, 4vw, 34px);
  }

  .primary-button {
    min-height: 38px;
  }

  .cocktail-card {
    gap: 8px;
    padding: 9px;
  }

  .ingredient-list {
    gap: 8px;
  }

  .ingredient-option {
    min-height: 20px;
    font-size: 9px;
  }

  .sort-shell {
    width: min(100%, 720px);
  }

  .sort-play-area {
    grid-template-rows: max-content max-content minmax(220px, 1fr) max-content;
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.86);
  z-index: 20;
}

.rules-modal {
  width: min(100%, 440px);
  padding: 22px;
}

.rules-modal h2 {
  color: var(--emerald);
  font-size: 25px;
  line-height: 1.12;
  text-align: center;
}

.rules-modal p {
  color: rgba(120, 255, 236, 0.78);
  line-height: 1.5;
}

.rules-modal .primary-button {
  margin-top: 8px;
}

.return-button {
  background: rgba(0, 0, 0, 0.44);
}

.landing-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.86);
  z-index: 20;
}

.landing-panel {
  display: grid;
  grid-template-rows: max-content max-content max-content;
  align-content: center;
  gap: 14px;
  width: min(100%, 620px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  padding: 18px 20px;
  border: 1px solid rgba(120, 255, 236, 0.38);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.72);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.44);
  overflow: hidden;
}

.landing-hero {
  display: grid;
  gap: 8px;
  text-align: center;
}

.landing-hero .eyebrow {
  margin-bottom: 0;
  text-transform: none;
}

.landing-hero h1 {
  color: var(--emerald);
  font-size: clamp(30px, 5vw, 52px);
  line-height: 1.04;
  text-align: center;
}

.landing-copy {
  width: min(100%, 560px);
  margin: 0 auto;
  color: rgba(120, 255, 236, 0.78);
  font-size: 15px;
  line-height: 1.35;
}

.landing-hotspots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: clamp(8px, 2.2vw, 16px);
  justify-self: center;
  width: min(88%, 500px);
  min-height: clamp(82px, 18vh, 148px);
}

.landing-hotspot-card,
.landing-hotspot-dice,
.landing-hotspot-circle {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 16px 22px rgba(0, 0, 0, 0.5));
}

.landing-hotspot-card,
.landing-hotspot-dice {
  max-height: clamp(74px, 15vh, 124px);
}

.landing-hotspot-card {
  justify-self: center;
  transform: translateY(-4px);
}

.landing-hotspot-dice {
  justify-self: center;
}

.landing-hotspot-circle {
  justify-self: center;
  max-width: clamp(72px, 15vw, 124px);
  max-height: clamp(72px, 15vw, 124px);
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.55));
}

.landing-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 12px;
  font-size: 17px;
  line-height: 1;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

@media (max-width: 520px) {
  .landing-backdrop {
    padding: 10px;
  }

  .landing-panel {
    gap: 12px;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    padding: 12px;
  }

  .landing-hero {
    gap: 6px;
  }

  .landing-hero h1 {
    font-size: clamp(27px, 9vw, 38px);
  }

  .landing-copy {
    font-size: 13px;
    line-height: 1.28;
  }

  .landing-hotspots {
    gap: clamp(4px, 1.8vw, 10px);
    width: min(90%, 380px);
    min-height: clamp(68px, 15vh, 104px);
  }

  .landing-hotspot-card,
  .landing-hotspot-dice {
    max-height: clamp(62px, 13vh, 96px);
  }

  .landing-hotspot-circle {
    max-width: clamp(58px, 17vw, 86px);
    max-height: clamp(58px, 17vw, 86px);
  }

  .landing-button {
    min-height: 40px;
    font-size: 15px;
  }
}

@media (max-width: 360px), (max-height: 620px) {
  .landing-panel {
    gap: 10px;
    padding: 10px;
  }

  .landing-hero h1 {
    font-size: clamp(24px, 8vw, 32px);
  }

  .landing-copy {
    font-size: 12px;
    line-height: 1.2;
  }

  .landing-hotspots {
    min-height: clamp(52px, 12vh, 78px);
  }

  .landing-hotspot-card,
  .landing-hotspot-dice {
    max-height: clamp(48px, 11vh, 70px);
  }

  .landing-hotspot-circle {
    max-width: clamp(44px, 15vw, 62px);
    max-height: clamp(44px, 15vw, 62px);
  }

  .landing-button {
    min-height: 36px;
  }
}
