:root {
  --bg-deep: #15242c;
  --bg-mid: #244251;
  --panel: rgba(14, 26, 33, 0.78);
  --panel-border: rgba(250, 250, 250, 0.18);
  --text-main: #f4f4ef;
  --text-soft: #c9d8db;
  --accent: #f2b544;
  --accent-2: #32c7a1;
  --error: #ff5d5d;
  --shadow: 0 24px 50px rgba(5, 10, 12, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Source Sans 3", "Trebuchet MS", sans-serif;
  color: var(--text-main);
  background: radial-gradient(circle at 15% 18%, #35657a 0%, transparent 32%),
    radial-gradient(circle at 82% 72%, #22534f 0%, transparent 31%),
    linear-gradient(145deg, var(--bg-mid), var(--bg-deep));
  overflow-x: hidden;
}

.ambient-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(32px);
  pointer-events: none;
  z-index: 0;
}

.shape-a {
  width: 340px;
  height: 340px;
  background: rgba(104, 151, 173, 0.22);
  top: -110px;
  right: -70px;
}

.shape-b {
  width: 280px;
  height: 280px;
  background: rgba(50, 199, 161, 0.22);
  bottom: -100px;
  left: -80px;
}

.game-shell {
  position: relative;
  z-index: 1;
  width: min(1320px, 96vw);
  margin: 20px auto 42px;
}

.title-block {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 18px 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
}

h1,
h2,
th {
  font-family: "Bree Serif", Georgia, serif;
}

h1 {
  margin: 8px 0 6px;
  font-size: clamp(1.45rem, 2vw + 1rem, 2.35rem);
}

.subtitle {
  margin: 0;
  color: var(--text-soft);
  font-size: 1rem;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  gap: 12px;
}

.progress-wrap {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
}

.progress-label {
  color: var(--text-soft);
  font-size: 0.94rem;
}

#progress-count {
  font-size: 1.08rem;
}

button {
  font-family: inherit;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

#restart-btn,
#play-again-btn {
  background: linear-gradient(120deg, #f2b544, #f57a53);
  color: #1d1d1d;
  font-weight: 700;
  padding: 10px 16px;
  transition: transform 180ms ease, box-shadow 180ms ease;
  box-shadow: 0 8px 18px rgba(245, 122, 83, 0.34);
}

#restart-btn:hover,
#play-again-btn:hover {
  transform: translateY(-1px);
}

.current-card-panel {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.current-card-panel h2 {
  margin: 0 0 10px;
}

.current-card {
  min-height: 150px;
  border-radius: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  background: rgba(11, 20, 26, 0.7);
  display: grid;
  place-items: center;
  padding: 10px;
  overflow: hidden;
}

.card-face {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background: linear-gradient(165deg, rgba(244, 244, 239, 0.18), rgba(56, 89, 104, 0.32));
  border: 1px solid rgba(255, 255, 255, 0.24);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.card-column {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.card-text {
  margin: 0;
  font-size: 1.06rem;
  line-height: 1.32;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

.card-image {
  width: min(270px, 100%);
  max-height: 130px;
  object-fit: contain;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.33);
  background: rgba(255, 255, 255, 0.14);
}

.card-hint {
  margin: 10px 2px 0;
  color: var(--text-soft);
}

.table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 12px;
  box-shadow: var(--shadow);
}

#match-table {
  border-collapse: collapse;
  table-layout: fixed;
  width: 1290px;
  min-width: 1290px;
}

#match-table .col-boundary-type {
  width: 120px;
}

#match-table .col-image {
  width: 230px;
}

#match-table .col-movement {
  width: 260px;
}

#match-table .col-features {
  width: 420px;
}

#match-table .col-examples {
  width: 260px;
}

th,
td {
  border: 1px solid rgba(255, 255, 255, 0.35);
  min-width: 120px;
}

th {
  background: rgba(255, 255, 255, 0.11);
  padding: 10px;
  font-size: 1.1rem;
  text-align: center;
}

td {
  padding: 0;
  height: 170px;
}

.drop-cell {
  width: 100%;
  height: 100%;
  padding: 8px;
  background: rgba(13, 25, 32, 0.64);
  color: var(--text-main);
  transition: background 200ms ease, transform 200ms ease;
}

.drop-cell:hover {
  background: rgba(29, 45, 53, 0.84);
}

.drop-cell.is-empty::before {
  content: "Place here";
  display: block;
  color: rgba(240, 240, 236, 0.45);
  font-size: 0.92rem;
}

.drop-cell.filled {
  background: rgba(13, 25, 32, 0.95);
}

.cell-content {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 6px;
}

.cell-content p {
  margin: 0;
  font-size: 1rem;
  line-height: 1.28;
  text-align: center;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

.cell-content img {
  max-width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.18);
}

.drop-cell[data-col="image"] {
  padding: 4px;
}

.drop-cell[data-col="image"] .cell-content {
  padding: 2px;
}

.drop-cell[data-col="image"] .cell-content img {
  max-height: 200px;
}

.match-row.row-complete td {
  background: rgba(48, 146, 74, 0.45);
  animation: rowPulse 720ms ease;
}

.match-row.row-complete .drop-cell {
  background: rgba(43, 133, 67, 0.92);
}

@keyframes rowPulse {
  0% {
    box-shadow: inset 0 0 0 rgba(48, 146, 74, 0.15);
  }
  45% {
    box-shadow: inset 0 0 24px rgba(92, 207, 122, 0.7);
  }
  100% {
    box-shadow: inset 0 0 0 rgba(48, 146, 74, 0.15);
  }
}

.error-flash {
  animation: errorFlash 520ms ease;
}

@keyframes errorFlash {
  0% {
    background: rgba(136, 37, 37, 0.58);
    transform: translateX(0);
  }
  20% {
    transform: translateX(-5px);
  }
  40% {
    transform: translateX(5px);
  }
  60% {
    transform: translateX(-4px);
  }
  100% {
    background: rgba(160, 57, 57, 0.2);
    transform: translateX(0);
  }
}

.flying-card {
  position: fixed;
  z-index: 80;
  margin: 0;
  pointer-events: none;
  transition: transform 420ms cubic-bezier(0.2, 0.85, 0.4, 1),
    opacity 420ms ease;
  transform-origin: top left;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.3);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: rgba(9, 19, 24, 0.93);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: var(--text-main);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  transition: opacity 240ms ease, transform 240ms ease;
  z-index: 120;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: rgba(255, 93, 93, 0.7);
}

.toast.success {
  border-color: rgba(50, 199, 161, 0.75);
}

.final-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 20, 0.74);
  display: grid;
  place-items: center;
  z-index: 110;
}

.final-overlay[hidden] {
  display: none;
}

.final-card {
  width: min(460px, 90vw);
  padding: 24px;
  border-radius: 16px;
  text-align: center;
  background: linear-gradient(150deg, rgba(22, 42, 53, 0.95), rgba(35, 68, 62, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.34);
  box-shadow: var(--shadow);
}

.final-card h2 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 2rem;
}

.final-card p {
  margin-top: 0;
  margin-bottom: 18px;
  font-size: 1.08rem;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 115;
}

.confetti-piece {
  position: absolute;
  top: -14px;
  width: 12px;
  height: 18px;
  opacity: 0.95;
  animation-name: confettiFall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 0.95;
  }
  100% {
    transform: translate3d(var(--drift), 112vh, 0) rotate(700deg);
    opacity: 0;
  }
}

@media (max-width: 900px) {
  .game-shell {
    width: min(100%, 98vw);
    margin-top: 10px;
  }

  .title-block,
  .current-card-panel,
  .table-wrap {
    border-radius: 14px;
  }

  td {
    height: 145px;
  }

  .drop-cell[data-col="image"] .cell-content img {
    max-height: 165px;
  }

  .card-text,
  .cell-content p {
    font-size: 0.95rem;
  }
}

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