:root {
  --ink: #2f2926;
  --muted: #766960;
  --cream: #fff9ef;
  --paper: #fffaf2;
  --category-background: #52ab6f;
  --category-primary: #166a32;
  --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:
    linear-gradient(145deg, color-mix(in srgb, var(--category-background) 74%, #fffaf2) 0%, var(--category-background) 100%);
  transition: background 220ms ease;
}

button {
  color: inherit;
  font: inherit;
}

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

.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;
}

.loading-screen {
  display: grid;
  place-items: center;
}

.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;
  text-shadow: 0 2px 14px rgba(47, 41, 38, 0.24);
}

.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);
}

.fullscreen-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 18px;
  transition: transform 180ms ease;
}

.fullscreen-icon span {
  position: absolute;
  width: 6px;
  height: 6px;
  border-color: currentColor;
}

.fullscreen-icon span:nth-child(1) {
  top: 0;
  left: 0;
  border-top: 2px solid;
  border-left: 2px solid;
}

.fullscreen-icon span:nth-child(2) {
  top: 0;
  right: 0;
  border-top: 2px solid;
  border-right: 2px solid;
}

.fullscreen-icon span:nth-child(3) {
  bottom: 0;
  left: 0;
  border-bottom: 2px solid;
  border-left: 2px solid;
}

.fullscreen-icon span:nth-child(4) {
  right: 0;
  bottom: 0;
  border-right: 2px solid;
  border-bottom: 2px solid;
}

.fullscreen-button.is-fullscreen .fullscreen-icon {
  transform: scale(0.68);
}

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

.hero-copy h2 {
  margin-bottom: 12px;
  text-shadow: 0 3px 18px rgba(47, 41, 38, 0.24);
}

.hero-copy p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
  text-shadow: 0 2px 12px rgba(47, 41, 38, 0.18);
}

.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));
}

.play-controls {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.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-face {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 18px 8px 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: 10px;
  border: 1px solid rgba(255, 250, 242, 0.46);
  border-radius: 6px;
}

.deck-level {
  position: relative;
  z-index: 1;
  font-size: clamp(0.9rem, 3.6vw, 1.1rem);
  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(0.78rem, 2.8vw, 1rem);
  font-weight: 700;
  line-height: 1.05;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

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

.category-menu {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.category-button {
  min-width: 0;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 8px;
  border: 1px solid rgba(127, 89, 71, 0.18);
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.7);
  color: var(--ink);
  cursor: pointer;
  font-size: clamp(0.72rem, 3.3vw, 0.9rem);
  font-weight: 800;
  line-height: 1;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, color 180ms ease;
}

.category-button.active {
  border-color: transparent;
  background: var(--category-option-color);
  color: #fffaf2;
  box-shadow: 0 12px 26px color-mix(in srgb, var(--category-option-color) 32%, transparent);
}

.category-button.disabled {
  cursor: not-allowed;
  color: rgba(47, 41, 38, 0.42);
  background: rgba(255, 250, 242, 0.34);
  border-color: rgba(127, 89, 71, 0.12);
  box-shadow: none;
}

.category-button.disabled .category-swatch {
  background: rgba(47, 41, 38, 0.24);
  box-shadow: none;
}

.category-button:active {
  transform: scale(0.98);
}

.category-button.disabled:active {
  transform: none;
}

.category-swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--category-option-color);
  box-shadow: 0 0 0 2px rgba(255, 250, 242, 0.6);
}

.category-button.active .category-swatch {
  background: #fffaf2;
}

.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);
}

.draw-card.challenge .card-front {
  align-content: center;
  gap: 14px;
  color: #fffaf2;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 44%),
    var(--active-color);
}

.draw-card.challenge .card-front::before {
  border-color: rgba(255, 250, 242, 0.54);
}

.challenge-label {
  position: relative;
  z-index: 1;
  color: #fffaf2;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.question-text {
  position: relative;
  z-index: 1;
  margin: 0;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-width: none;
  color: var(--active-color, var(--category-primary));
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 7vw, 2.15rem);
  line-height: 1.12;
  text-align: center;
}

.question-text::-webkit-scrollbar {
  width: 4px;
}

.question-text:not(.scrollable)::-webkit-scrollbar {
  width: 0;
}

.question-text.scrollable {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, currentColor 34%, transparent) transparent;
}

.question-text::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 34%, transparent);
}

.draw-card.challenge .question-text {
  color: #fffaf2;
}

.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 h3 {
  margin: 18px 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 500;
}

.tutorial-body p {
  margin-bottom: 12px;
}

.tutorial-body p:last-child {
  margin-bottom: 0;
}

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

.modal-actions.single-action {
  grid-template-columns: 1fr;
}

@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;
  }

  .play-controls {
    order: 1;
    gap: 14px;
  }

  .decks {
    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;
  }
}
