:root {
  color-scheme: light;
}

body {
  margin: 0;
  font-family: 'DM Sans', 'Inter', 'Montserrat', -apple-system, BlinkMacSystemFont,
    'Segoe UI', sans-serif;
  background: #f5f6fb;
  color: #111;
}

/* ===== MENU LAYOUT ===== */
.menu-body {
  background: radial-gradient(circle at top, rgba(0, 0, 0, 0.08), transparent 55%), #ffffff;
}

.menu-wrapper {
  min-height: 100vh;
  padding: clamp(36px, 5vw, 64px) clamp(18px, 6vw, 72px) clamp(72px, 7vw, 120px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(28px, 4vw, 48px);
}

.menu-heading {
  text-align: center;
  display: grid;
  gap: 12px;
}

.menu-heading h1 {
  margin: 0;
  font-family: 'NeonBold', 'DM Sans', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: clamp(2rem, 3vw + 1.5rem, 3rem);
}

.tagline-secondary {
  margin: 0;
  font-family: 'NeonMedium', 'DM Sans', sans-serif;
  letter-spacing: 0.05em;
  font-size: clamp(1rem, 0.6vw + 0.9rem, 1.2rem);
}

.menu-content {
  max-width: 960px;
  width: 100%;
  display: grid;
  gap: clamp(22px, 3vw, 36px);
  padding: clamp(28px, 4vw, 44px) clamp(22px, 4vw, 36px);
  border: 2px solid #111;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.08);
}

.home-lead {
  margin: 0;
  padding: 16px 20px;
  border-radius: 12px;
  border: 2px solid #111;
  background: #fff;
  font-size: clamp(1rem, 0.7vw + 1rem, 1.25rem);
  text-align: center;
  letter-spacing: 0.03em;
}

.menu-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.deck-button {
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  border-radius: 12px;
  border: 2px solid #000;
  padding: 14px 18px;
  background: #fff;
  color: #000;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  justify-content: center;
  text-align: left;
  letter-spacing: 0.02em;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease,
    transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.05);
  width: 100%;
  max-width: 100%;
}

.deck-button:hover,
.deck-button:focus-visible {
  background: #000;
  color: #fff;
  border-color: #000;
  transform: translateY(-2px);
  outline: none;
  box-shadow: 0 18px 26px rgba(0, 0, 0, 0.12);
}

.menu-button__title {
  font-size: clamp(1.05rem, 0.9vw + 1rem, 1.4rem);
  overflow-wrap: anywhere;
  max-width: 100%;
}

.menu-button__meta {
  font-size: 0.95rem;
  opacity: 0.8;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.menu-note {
  margin: 0;
  text-align: center;
  font-size: 0.95rem;
  color: #555b69;
  letter-spacing: 0.04em;
}

.deck-button--highlight {
  outline: 3px solid rgba(255, 215, 0, 0.9);
  outline-offset: 3px;
}

.primary,
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 1rem;
  letter-spacing: 0.03em;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary {
  background: #000;
  color: #fff;
  border: 2px solid #000;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.18);
}

.primary:hover,
.primary:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.24);
}

.secondary {
  background: #fff;
  color: #000;
  border: 2px solid #000;
}

.secondary:hover,
.secondary:focus-visible {
  transform: translateY(-2px);
}

@media (max-width: 640px) {
  .menu-wrapper {
    padding-inline: 18px;
  }

  .menu-content {
    padding-inline: 18px;
  }

  .deck-button {
    align-items: center;
    text-align: center;
  }

  .status-row,
  .bottom-group {
    flex-wrap: wrap;
  }
}

/* ===== GAME LAYOUT ===== */
body.sort-body {
  background: linear-gradient(160deg, rgba(0, 0, 0, 0.08), transparent 60%), #f7f8ff;
  min-height: 100vh;
  padding-top: var(--header-offset, 220px);
  padding-bottom: var(--footer-offset, 140px);
  --layout-padding-x: clamp(12px, 4vw, 32px);
  --side-tray-width-base: clamp(700px, 60vw, 1100px);
  --side-tray-width: var(--side-tray-width-dynamic, var(--side-tray-width-base));
  --side-tray-gap: 0px;
  --side-tray-left: 0px;
  --translation-gap: clamp(28px, 3vw, 42px);
}

.sort-body .fixed-controls {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.98);
  border-bottom: 4px solid #000;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  padding: clamp(14px, 2.4vw, 22px) clamp(18px, 4vw, 38px) clamp(12px, 2vw, 18px);
  display: grid;
  gap: clamp(8px, 1.6vw, 14px);
}


.top-controls {
  display: grid;
  gap: clamp(10px, 1.6vw, 16px);
}

.status-nav-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 0.8vw, 10px);
  flex-wrap: nowrap;
}

.status-row {
  display: flex;
  gap: clamp(4px, 0.8vw, 8px);
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
}

.nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: clamp(48px, 4vw, 64px);
  min-height: clamp(48px, 4vw, 64px);
  width: clamp(48px, 4vw, 64px);
  max-width: none;
  flex-direction: row;
  height: clamp(48px, 4vw, 64px);
  font-size: clamp(1.4rem, 1vw + 1rem, 1.8rem);
  padding: 0;
  border-radius: 18px;
  box-shadow: none;
  line-height: 1;
  margin: 0;
}

.nav-arrow:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.items-scroll {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border: 2px solid #000;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.04);
  padding: clamp(7px, 1vw, 10px) clamp(12px, 2vw, 18px);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.08);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: auto;
  width: fit-content;
  max-width: none;
  flex-direction: row;
  gap: 6px;
  padding: clamp(4px, 0.8vw, 8px) clamp(10px, 1.2vw, 12px);
  border-radius: 10px;
  border: 2px solid #000;
  background: #fff;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
}

.title-pill {
  display: inline-grid;
  gap: 6px;
  padding-inline: clamp(12px, 2.2vw, 22px);
  text-align: center;
}

.title-pill__main {
  font-family: 'NeonBold', 'DM Sans', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: clamp(1.2rem, 1.4vw + 1rem, 1.8rem);
}

.title-pill__sub {
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.instructions-banner {
  text-align: center;
  font-size: 1.05rem;
  letter-spacing: 0.03em;
}

.instructions-banner strong {
  font-family: 'NeonMedium', 'DM Sans', sans-serif;
}

.fireworks-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4000;
  overflow: hidden;
}

.firework {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  opacity: 0;
  animation: firework-burst 1.4s ease-out forwards;
  transform: scale(0.2);
  box-shadow:
    0 0 0 0 rgba(255, 255, 255, 0.9),
    18px 0 0 0 rgba(255, 99, 71, 0.9),
    -18px 0 0 0 rgba(72, 209, 204, 0.9),
    0 18px 0 0 rgba(255, 215, 0, 0.9),
    0 -18px 0 0 rgba(147, 112, 219, 0.9),
    13px 13px 0 0 rgba(135, 206, 235, 0.9),
    -13px 13px 0 0 rgba(240, 128, 128, 0.9),
    13px -13px 0 0 rgba(152, 251, 152, 0.9),
    -13px -13px 0 0 rgba(255, 182, 193, 0.9);
}

.firework--b {
  animation-delay: 0.2s;
}

.firework--c {
  animation-delay: 0.35s;
}

@keyframes firework-burst {
  0% {
    opacity: 0;
    transform: scale(0.2) translateY(10px);
  }
  20% {
    opacity: 1;
    transform: scale(0.9) translateY(0);
  }
  60% {
    opacity: 1;
    transform: scale(1.5);
  }
  100% {
    opacity: 0;
    transform: scale(1.8);
  }
}

/* Main layout */

.side-tray {
  position: fixed;
  top: var(--header-offset, 220px);
  left: var(--side-tray-left);
  width: var(--side-tray-width);
  display: flex;
  align-items: flex-start;
  z-index: 15;
  box-sizing: border-box;
  padding: 0;
  max-height: calc(100vh - var(--header-offset, 220px) - 32px);
}


.side-tray__panel {
  width: 100%;
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid #000;
  border-radius: 18px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.08);
  padding: clamp(18px, 2.4vw, 28px);
  box-sizing: border-box;
  max-height: inherit;
  overflow: hidden;
}

.line-table {
  width: max-content;
  border-collapse: separate;
  border-spacing: 0 clamp(6px, 1vw, 12px);
}

.line-table--snaking {
  width: 100%;
  max-width: 100%;
  table-layout: auto;
}

.line-table--snaking .line-table__cell {
  white-space: normal;
}

.line-table--snaking .line-table__cell--english {
  min-width: 0;
}

.line-table--snaking .line-table__text--english {
  max-width: none;
}

.line-table__head th {
  padding-bottom: clamp(6px, 0.8vw, 10px);
}

.line-table__row {
  vertical-align: top;
}

.line-table__heading {
  font-family: 'NeonMedium', 'DM Sans', sans-serif;
  font-size: clamp(1.05rem, 0.6vw + 1rem, 1.3rem);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
}

.line-table__heading--english {
  padding-left: clamp(24px, 2.4vw, 36px);
}

.line-table__cell {
  padding: 0;
  vertical-align: top;
  text-align: left;
  white-space: nowrap;
}

.line-table__cell--english {
  padding-left: clamp(24px, 2.4vw, 36px);
  white-space: normal;
  min-width: clamp(460px, 52vw, 900px);
}

.side-tray__panel[data-mode="latin-only"] .line-table__heading--english,
.side-tray__panel[data-mode="latin-only"] .line-table__cell--english {
  display: none;
}

.line-number {
  font-family: 'NeonMedium', 'DM Sans', sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1rem, 0.5vw + 0.95rem, 1.15rem);
  color: #222;
  min-width: 3ch;
  text-align: right;
  padding-right: clamp(6px, 1vw, 10px);
  display: inline-block;
}

.line-table__text {
  display: inline;
  font-size: clamp(1.18rem, 0.6vw + 1.1rem, 1.4rem);
  line-height: 1.65;
  letter-spacing: 0.015em;
  font-family: 'DM Sans', 'Inter', 'Montserrat', -apple-system, BlinkMacSystemFont,
    'Segoe UI', sans-serif;
  font-weight: 400;
  white-space: inherit;
}

.line-table__text--english {
  display: inline-block;
  max-width: clamp(520px, 55vw, 980px);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.latin-token,
.english-token {
  display: inline;
  padding: 1px 4px;
  margin: 0;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.latin-token.token--interactive {
  cursor: grab;
}

.latin-token.token--interactive:active {
  cursor: grabbing;
}

.latin-token.token--dragging {
  opacity: 0.75;
}

.english-token[data-item-id] {
  cursor: pointer;
}

.token--hint-correct {
  animation: tokenHintCorrect 0.6s ease;
}

.token--hint-incorrect {
  animation: tokenHintIncorrect 0.9s ease;
}

@keyframes tokenHintCorrect {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.05);
  }
  60% {
    transform: scale(0.98);
  }
  100% {
    transform: scale(1);
  }
}

.token--selected {
  outline: 2px solid #000;
  outline-offset: 2px;
}

@keyframes tokenHintIncorrect {
  0% {
    background-color: #ff4d4d;
  }
  40% {
    background-color: rgba(255, 77, 77, 0.45);
  }
  100% {
    background-color: inherit;
  }
}

.board-area {
  margin-left: calc(var(--side-tray-width) + var(--side-tray-gap));
  width: max(0px, calc(100% - var(--side-tray-width) - var(--side-tray-gap)));
  padding: clamp(24px, 4vw, 48px) var(--layout-padding-x)
    calc(var(--footer-offset, 140px) + clamp(36px, 4vw, 56px));
  min-height: calc(100vh - var(--header-offset, 220px) - var(--footer-offset, 140px));
  box-sizing: border-box;
}

.board-area > .panel {
  max-width: 1200px;
  margin: 0 auto;
}

.zones-panel {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  gap: clamp(16px, 2vw, 24px);
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid #000;
  border-radius: 18px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.08);
  padding: clamp(22px, 2vw + 18px, 32px);
  display: grid;
  gap: clamp(16px, 2vw, 24px);
}

.panel h2 {
  margin: 0;
  font-family: 'NeonMedium', 'DM Sans', sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: clamp(1.15rem, 0.8vw + 1rem, 1.35rem);
}

.instructions-text {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.025em;
  color: #333;
}

.latin-text {
  margin: 0;
  font-size: clamp(1.18rem, 0.6vw + 1.1rem, 1.4rem);
  line-height: 1.65;
  letter-spacing: 0.015em;
  padding-right: 6px;
}

.items-container,
.dropzone__items {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.items-container {
  min-height: 74px;
  flex-wrap: wrap;
}

.items-scroll .items-container {
  flex: 1 0 auto;
  flex-wrap: nowrap;
  gap: 12px;
  min-width: min(640px, 100%);
  padding: 4px 0;
}

.items-scroll {
  display: none;
}

.items-scroll .items-container::after {
  content: '';
  flex: 0 0 12px;
}

.items-scroll .item {
  flex: 0 0 auto;
}

.item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  min-height: auto;
  line-height: 1.02;
  text-align: center;
  border-radius: 12px;
  border: 2px solid var(--item-border, #000);
  background: var(--item-bg, rgba(0, 0, 0, 0.04));
  color: var(--item-text, #111);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: grab;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease,
    background-color 0.15s ease, color 0.15s ease;
}

.item--periphrastic {
  gap: 6px;
  padding: 6px 12px;
}

.item-word {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border-radius: 8px;
  border: 2px solid transparent;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  background-clip: padding-box;
}

.item-word--base {
  margin-right: 2px;
}

.item-word--aux {
  margin-left: 2px;
}

.item:active {
  cursor: grabbing;
}

.item.dragging {
  opacity: 0.75;
  transform: scale(1.06);
}

.item--hint-correct {
  animation: itemHintCorrect 0.6s ease;
}

.item--hint-incorrect {
  animation: itemHintIncorrect 0.9s ease;
}

@keyframes itemHintCorrect {
  0% {
    transform: scale(1);
  }
  25% {
    transform: scale(1.06);
  }
  60% {
    transform: scale(0.98);
  }
  100% {
    transform: scale(1);
  }
}

.item--selected {
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3);
}

@keyframes itemHintIncorrect {
  0% {
    transform: translateY(0);
    background-color: #ff4d4d;
  }
  25% {
    transform: translateY(-2px);
    background-color: #ff4d4d;
  }
  60% {
    transform: translateY(2px);
    background-color: rgba(255, 77, 77, 0.45);
  }
  100% {
    transform: translateY(0);
  }
}

.item--correct {
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.22);
}

.item--incorrect {
  box-shadow: 0 0 0 3px rgba(198, 40, 40, 0.22);
}

.dropzone-sections {
  display: grid;
  gap: clamp(16px, 2.5vw, 26px);
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  align-items: start;
}



.dropzone-section {
  display: grid;
  gap: 12px;
  padding: clamp(16px, 2vw, 22px);
}

.dropzone-section--pos {
}

.dropzone-section--cases {
}

.dropzone-section__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
}

.dropzone-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.dropzone {
  border: 2px solid #000;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.03);
  padding: 16px;
  display: grid;
  gap: 12px;
  min-height: 140px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.dropzone__title {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.category-shortcut {
  font-size: 0.85rem;
  font-weight: 700;
  margin-left: 6px;
}

.dropzone--active {
  transform: translateY(-3px);
  border-color: #000;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.15);
  background: rgba(0, 0, 0, 0.05);
}

.fixed-bottom-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.98);
  border-top: 4px solid #000;
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.16);
  padding: clamp(16px, 2vw + 12px, 24px) clamp(18px, 5vw, 48px);
}

.bottom-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.4vw, 14px);
  flex-wrap: nowrap;
}

.bottom-group .deck-button {
  min-width: auto;
  flex: 0 0 auto;
  width: auto;
  align-items: center;
  text-align: center;
  padding: clamp(7px, 1vw, 10px) clamp(14px, 1.8vw, 18px);
}

.bottom-group .deck-button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.result-dialog {
  border: none;
  border-radius: 18px;
  max-width: 420px;
  width: min(90vw, 420px);
  padding: 24px;
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.25);
}

.result-dialog::backdrop {
  background: rgba(12, 14, 30, 0.45);
}

.dialog-content {
  display: grid;
  gap: 16px;
  text-align: center;
}

.dialog-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.win-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: clamp(32px, 6vw, 72px);
  background: radial-gradient(circle at top, rgba(0, 0, 0, 0.08), transparent 60%),
    #ffffff;
}

.win-card {
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid #000;
  border-radius: 22px;
  padding: clamp(32px, 4vw + 20px, 56px);
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.16);
  display: grid;
  gap: 20px;
  text-align: center;
}

.win-card h1 {
  margin: 0;
  font-family: 'NeonBold', 'DM Sans', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.win-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

body.side-tray-stacked {
  --side-tray-width: 0px;
  --translation-gap: 0px;
}

body.side-tray-stacked .side-tray {
  position: static;
  width: auto;
  height: auto;
  top: auto;
  bottom: auto;
  margin: clamp(12px, 3vw, 20px) 0 0;
  max-height: none;
}

body.side-tray-stacked .side-tray__panel {
  padding: clamp(18px, 2.4vw, 28px);
}

body.side-tray-stacked .side-tray__columns {
  flex-direction: column;
  gap: clamp(16px, 3vw, 24px);
}

body.side-tray-stacked .side-tray__column {
  width: 100%;
  max-height: none;
}

body.side-tray-stacked .side-tray__column--english {
  padding-top: clamp(12px, 1.6vw, 18px);
}

body.side-tray-stacked .line-table {
  width: 100%;
  border-spacing: 0 clamp(6px, 1vw, 12px);
}

body.side-tray-stacked .line-table__heading--english,
body.side-tray-stacked .line-table__cell--english {
  padding-left: clamp(16px, 2vw, 28px);
}

body.side-tray-stacked .line-table__cell--english {
  min-width: auto;
}

@media (max-width: 900px) {
  .top-controls {
    justify-content: center;
  }

  .status-nav-wrapper {
    flex-wrap: wrap;
  }

  .status-row {
    flex-wrap: wrap;
  }

  .status-pill {
    min-width: clamp(110px, 40vw, 160px);
    }
}

@media (max-width: 640px) {
  body.sort-body {
    padding-top: var(--header-offset, 240px);
    padding-bottom: var(--footer-offset, 180px);
  }

  .bottom-group .deck-button {
    width: 100%;
    min-width: unset;
  }
}
