:root {
  --ink: #2f2926;
  --muted: #766960;
  --cream: #fff9ef;
  --paper: #fffaf2;
  --rose: #d98d85;
  --rose-dark: #9f5b5d;
  --sage: #87966f;
  --blue: #6c8aa0;
  --shadow: 0 22px 70px rgba(69, 45, 35, 0.2);
  --soft-shadow: 0 14px 34px rgba(69, 45, 35, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: #f7eadc;
}

body {
  height: 100%;
  min-height: var(--app-height, 100vh);
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  background:
    radial-gradient(circle at 10% 10%, rgba(217, 141, 133, 0.28), transparent 28rem),
    radial-gradient(circle at 90% 20%, rgba(135, 150, 111, 0.22), transparent 24rem),
    linear-gradient(145deg, #fff4e7 0%, #f3dfce 52%, #efe4dc 100%);
}

button {
  color: inherit;
  font: inherit;
}

.app {
  height: var(--app-height, 100vh);
  overflow: hidden;
  position: relative;
}

.app::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.32;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.45) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.35) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
}

.screen {
  position: relative;
  z-index: 1;
  height: var(--app-height, 100vh);
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: clamp(14px, 4vw, 22px);
}

.language-screen {
  display: grid;
  align-content: center;
  gap: 28px;
}

.language-card {
  padding: 30px 24px;
  border: 1px solid rgba(127, 89, 71, 0.16);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--rose-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 11ch;
  margin-bottom: 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 16vw, 6rem);
  line-height: 0.88;
  font-weight: 500;
}

h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.85rem, 8vw, 4.5rem);
  line-height: 0.94;
  font-weight: 500;
}

.intro {
  max-width: 34rem;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.55;
}

.language-actions,
.modal-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 0;
  cursor: pointer;
  min-height: 48px;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.primary-button {
  border-radius: 999px;
  padding: 14px 18px;
  background: var(--ink);
  color: #fffaf2;
  box-shadow: 0 12px 26px rgba(47, 41, 38, 0.22);
  font-weight: 750;
}

.secondary-button {
  border: 1px solid rgba(127, 89, 71, 0.22);
  border-radius: 999px;
  padding: 13px 18px;
  background: rgba(255, 250, 242, 0.7);
  color: var(--ink);
  font-weight: 750;
}

.primary-button:active,
.secondary-button:active,
.icon-button:active,
.deck-button:active {
  transform: scale(0.98);
}

.game-screen {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: clamp(12px, 2.7vh, 22px);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}

.brand {
  display: grid;
  gap: 2px;
}

.brand-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  line-height: 1;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.82rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(127, 89, 71, 0.18);
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.76);
  box-shadow: 0 8px 22px rgba(69, 45, 35, 0.1);
}

.hero-copy {
  max-width: 35rem;
  align-self: end;
}

.hero-copy h2 {
  margin-bottom: 12px;
}

.hero-copy p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.table {
  align-self: stretch;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(10px, 2vh, 16px);
  min-height: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

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

.deck-button {
  position: relative;
  min-width: 0;
  height: clamp(128px, calc(var(--app-height, 100vh) * 0.24), 172px);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  perspective: 900px;
}

.deck-button:disabled {
  cursor: default;
}

.deck-stack {
  position: absolute;
  inset: 22px 8px 0;
  border-radius: 8px;
  transform: rotate(var(--tilt));
  background: var(--deck-color);
  box-shadow: var(--soft-shadow);
}

.deck-stack::before,
.deck-stack::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: inherit;
  border: 1px solid rgba(255, 255, 255, 0.45);
  transform: translateY(-7px) rotate(-2deg);
}

.deck-stack::after {
  transform: translateY(-14px) rotate(2deg);
}

.deck-face {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 18px 10px 14px;
  border-radius: 8px;
  overflow: hidden;
  color: #fffaf2;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 44%),
    var(--deck-color);
  box-shadow: var(--soft-shadow);
}

.deck-face::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(255, 250, 242, 0.46);
  border-radius: 6px;
}

.deck-level {
  position: relative;
  z-index: 1;
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.deck-name {
  position: relative;
  z-index: 1;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.05rem, 4.6vw, 1.5rem);
  line-height: 1;
}

.deck-count {
  position: relative;
  z-index: 1;
  font-size: 0.75rem;
  opacity: 0.86;
}

.deck-button.empty .deck-stack {
  opacity: 0;
}

.deck-button.empty .deck-face {
  color: var(--muted);
  background: rgba(255, 250, 242, 0.42);
  border: 1px dashed rgba(127, 89, 71, 0.32);
  box-shadow: none;
}

.deck-button.empty .deck-face::before {
  border-color: rgba(127, 89, 71, 0.2);
}

.card-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  perspective: 1200px;
}

.draw-card {
  width: min(84vw, 380px);
  height: clamp(168px, calc(var(--app-height, 100vh) * 0.28), 226px);
  position: relative;
  transform-style: preserve-3d;
  transform: translateY(36px) scale(0.78) rotateY(0deg);
  opacity: 0;
  transition: transform 660ms cubic-bezier(0.2, 0.78, 0.18, 1), opacity 220ms ease;
}

.draw-card.dealt {
  transform: translateY(0) scale(1) rotateY(0deg);
  opacity: 1;
}

.draw-card.flipped {
  transform: translateY(0) scale(1) rotateY(180deg);
}

.card-side {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 28px;
  border-radius: 8px;
  backface-visibility: hidden;
  box-shadow: var(--shadow);
}

.card-back {
  color: #fffaf2;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 44%),
    var(--active-color, var(--rose));
}

.card-back::before,
.card-front::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(255, 250, 242, 0.52);
  border-radius: 6px;
}

.card-mark {
  position: relative;
  z-index: 1;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 4.8rem;
  line-height: 1;
}

.card-front {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.84), rgba(255, 250, 242, 0.72)),
    var(--paper);
  transform: rotateY(180deg);
}

.question-text {
  position: relative;
  z-index: 1;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 7vw, 2.15rem);
  line-height: 1.12;
  text-align: center;
}

.empty-state {
  width: min(84vw, 380px);
  height: clamp(168px, calc(var(--app-height, 100vh) * 0.28), 226px);
  display: grid;
  place-items: center;
  padding: 28px;
  border: 1px dashed rgba(127, 89, 71, 0.32);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.58);
  color: var(--muted);
  text-align: center;
  box-shadow: 0 16px 40px rgba(69, 45, 35, 0.1);
}

.empty-state strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.6rem;
  font-weight: 500;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(47, 41, 38, 0.34);
  backdrop-filter: blur(10px);
}

.modal {
  width: min(100%, 430px);
  padding: 24px;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.modal h2 {
  margin-bottom: 12px;
  font-size: 2.1rem;
}

.modal p {
  color: var(--muted);
  line-height: 1.5;
}

.modal-actions {
  margin-top: 22px;
}

@media (min-width: 680px) {
  .screen {
    padding: 34px;
  }

  .language-screen {
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: center;
  }

  .language-card {
    padding: 36px;
  }

  .language-actions,
  .modal-actions {
    grid-template-columns: 1fr 1fr;
  }

  .game-screen {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .table {
    grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
    grid-template-rows: auto;
    align-items: end;
    gap: clamp(18px, 3vw, 34px);
  }

  .card-stage {
    order: 2;
    min-height: 0;
  }

  .decks {
    order: 1;
    align-items: end;
  }

  .deck-button {
    height: clamp(180px, calc(var(--app-height, 100vh) * 0.32), 230px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
