:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #15120f;
  color: #f4efe5;
  --card-ratio: 3 / 5;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 18% 18%, rgba(185, 56, 56, .28), transparent 30%),
    radial-gradient(circle at 82% 14%, rgba(49, 130, 117, .24), transparent 28%),
    linear-gradient(145deg, #15120f, #221915 54%, #121819);
}

.app {
  width: min(980px, 100%);
  min-height: 100vh;
  padding: 18px;
  display: grid;
  align-content: center;
  gap: 14px;
}

.language-switch {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 200;
  display: flex;
  gap: 8px;
}

.language-switch__button {
  width: 82px;
  height: 34px;
  padding: 0 12px;
  background: rgba(255, 255, 255, .08);
  color: #f4efe5;
  font-size: 13px;
}

.language-switch__button[aria-pressed="true"] {
  background: #d7a34b;
  color: #1d1308;
}

.app.has-result .language-switch {
  position: static;
  justify-content: flex-end;
}

.stage {
  position: relative;
  min-height: min(680px, calc(100vh - 120px));
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
}

.deck-area {
  position: relative;
  min-height: 470px;
  display: grid;
  place-items: center;
}

.result {
  position: relative;
  min-height: auto;
  display: none;
  place-items: center;
  padding: 18px 0 6px;
}

.deck {
  position: relative;
  width: 250px;
  aspect-ratio: var(--card-ratio);
}

.card {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, .26);
  border-radius: 8px;
  background: #090807 center / contain no-repeat;
  box-shadow: 0 18px 46px rgba(0, 0, 0, .38);
  transform: translate(var(--x), var(--y)) rotate(var(--r));
  transition: transform .6s cubic-bezier(.2, .8, .2, 1), opacity .35s ease;
}

.deck.shuffling .card {
  animation: shuffle .72s ease-in-out both;
  animation-delay: calc(var(--i) * 18ms);
}

.deck.cutting .card:nth-child(n + 12) {
  transform: translate(0, 0) rotate(var(--r));
}

.deck.cutting .card.cut-top {
  transform: translate(-76px, -30px) rotate(-5deg);
}

.deck.cutting .card.cut-bottom {
  transform: translate(84px, 36px) rotate(5deg);
}

.deck.settled .card {
  transform: translate(0, 0) rotate(0deg);
}

.card.drawn {
  z-index: 120;
  transform: translate(0, 140px) rotate(0deg) scale(1.08);
  transition: transform .9s cubic-bezier(.65, 0, 1, .8), opacity .35s ease;
}

.result img {
  width: min(340px, 86vw, calc(78vh * 3 / 5));
  aspect-ratio: var(--card-ratio);
  object-fit: contain;
  border-radius: 10px;
  opacity: 0;
  transform: translateY(24px) scale(.96);
  transition: opacity .5s ease, transform .5s ease;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .46);
}

.result.revealed {
  display: grid;
  z-index: 120;
}

.result.revealed img {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.prompt-note {
  position: absolute;
  z-index: 80;
  width: min(430px, 92vw);
  padding: 18px 20px;
  color: #f4efe5;
  font-size: 18px;
  line-height: 1.55;
  text-align: center;
  background: rgba(21, 18, 15, .62);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  backdrop-filter: blur(3px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .28);
  opacity: 1;
  transition: opacity .7s ease, transform .7s ease, visibility .7s ease;
}

.prompt-note p {
  margin: 0 0 6px;
}

.prompt-note__example {
  color: #f2c36b;
  font-size: 14px;
  font-weight: 700;
}

.prompt-note ul {
  margin: 0;
  padding: 0;
  list-style: none;
  color: #d8cfc2;
}

.prompt-note.is-hidden {
  visibility: hidden;
  opacity: 0;
  transform: translateY(8px);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 0 0;
}

label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #e9dfd0;
}

input,
button,
.wiki-link {
  height: 44px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  font: inherit;
}

input {
  width: 72px;
  padding: 0 10px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

button {
  padding: 0 18px;
  background: #d7a34b;
  color: #1d1308;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: .72;
}

.wiki-link {
  width: fit-content;
  margin-top: 18px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  background: rgba(215, 163, 75, .16);
  color: #f2c36b;
  font-weight: 700;
  text-decoration: none;
}

.meaning {
  width: min(760px, 100%);
  margin: 8px auto 40px;
  padding: 20px 0;
}

.meaning[hidden] {
  display: none;
}

.meaning h2 {
  margin: 0 0 18px;
  font-size: 24px;
}

.meaning article {
  padding: 16px 0;
  border-top: 1px solid rgba(255, 255, 255, .16);
}

.meaning h3 {
  margin: 0 0 8px;
  font-size: 15px;
  color: #f2c36b;
}

.meaning p {
  margin: 0;
  line-height: 1.8;
  color: #eee5d8;
}

@keyframes shuffle {
  0%, 100% {
    transform: translate(var(--x), var(--y)) rotate(var(--r));
  }
  32% {
    transform: translate(calc(var(--x) - 95px), calc(var(--y) - 18px)) rotate(-10deg);
  }
  66% {
    transform: translate(calc(var(--x) + 112px), calc(var(--y) + 22px)) rotate(12deg);
  }
}

@media (max-width: 820px) {
  body {
    place-items: start center;
  }

  .app {
    min-height: 100dvh;
    padding: 42px 8px calc(128px + env(safe-area-inset-bottom));
    align-content: center;
    gap: 8px;
    overflow: visible;
  }

  .app.has-result {
    height: auto;
    max-height: none;
    padding-bottom: 6px;
    overflow-y: auto;
  }

  .stage {
    grid-template-columns: 1fr;
    min-height: min(620px, calc(100dvh - 150px));
  }

  .deck-area {
    min-height: min(500px, 62dvh);
    overflow: visible;
  }

  .deck {
    width: min(190px, 50vw);
  }

  .card.drawn {
    transform: translate(0, 140px) rotate(0deg) scale(1.04);
  }

  .result img {
    width: min(340px, 90vw, calc(76svh * 3 / 5));
    max-height: 76svh;
  }

  .controls {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 190;
    gap: 10px;
    padding-top: 0;
    padding-bottom: 0;
  }

  .app.has-result .controls {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: auto;
  }

  .prompt-note {
    font-size: 17px;
    line-height: 1.5;
    width: min(390px, 92vw);
    padding: 15px 16px;
  }

  .prompt-note p {
    margin-bottom: 4px;
  }

  label {
    font-size: 13px;
  }

  button {
    width: min(100%, 320px);
  }

  .language-switch {
    top: 8px;
    right: 8px;
  }

  .language-switch__button {
    width: 74px;
    height: 32px;
    padding: 0 8px;
    font-size: 12px;
  }

  .meaning {
    margin-bottom: 28px;
    padding: 14px 4px 24px;
  }
}
