/* Lower and Upper Case Matching — board game */

.cm-page {
  width: 100%;
  max-width: 100%;
  min-height: calc(100vh - 4rem);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.cm-page .back-link {
  align-self: flex-start;
  margin-bottom: 1rem;
}

.cm-header {
  text-align: center;
  margin-bottom: 1rem;
}

.cm-header h2 {
  font-size: clamp(1.3rem, 3.5vw, 1.9rem);
  font-weight: 700;
  color: #fff;
  text-shadow: 2px 2px 0 var(--jungle-dark), 0 3px 10px rgba(0, 0, 0, 0.3);
}

.cm-header p {
  margin-top: 0.35rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #d8f3dc;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.cm-score-bar {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.cm-score-pill {
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid var(--sun-yellow);
  border-radius: 999px;
  padding: 0.4rem 1.1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--jungle-dark);
  box-shadow: 0 3px 0 #c9a000, 0 5px 12px var(--box-shadow);
}

.cm-game-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* Start overlay */
.cm-start {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: rgba(26, 77, 46, 0.45);
  backdrop-filter: blur(3px);
  border-radius: 20px;
}

.cm-start.hidden {
  display: none;
}

.cm-start-icon {
  font-size: 3.5rem;
}

.cm-start-text {
  max-width: 300px;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.5;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.35);
}

.cm-btn {
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--jungle-dark);
  background: linear-gradient(145deg, #fff 0%, #ffe8a3 100%);
  border: 4px solid var(--sun-yellow);
  border-radius: 16px;
  padding: 0.75rem 1.75rem;
  cursor: pointer;
  box-shadow: 0 5px 0 #e6a800, 0 8px 20px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease;
}

.cm-btn:hover {
  transform: translateY(-3px);
}

.cm-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #e6a800;
}

/* Board */
.cm-board {
  position: relative;
  width: min(96vw, 720px);
  aspect-ratio: 1;
  background:
    linear-gradient(145deg, #8b5e3c 0%, #6f4e37 40%, #5c4033 100%);
  border: 8px solid #4a3228;
  border-radius: 18px;
  box-shadow:
    inset 0 0 30px rgba(0, 0, 0, 0.25),
    0 10px 30px var(--box-shadow);
  padding: 6px;
}

.cm-board::before {
  content: '';
  position: absolute;
  inset: 10px;
  border: 3px dashed rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  pointer-events: none;
}

.cm-board-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  gap: 4px;
}

.cm-rim-top,
.cm-rim-bottom {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}

.cm-board-middle {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 7fr 1fr;
  gap: 4px;
  min-height: 0;
}

.cm-rim-side {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
}

/* Letter tiles around the board */
.cm-letter {
  width: 100%;
  aspect-ratio: 1;
  min-height: 2rem;
  font-family: inherit;
  font-size: clamp(0.75rem, 2.2vw, 1.2rem);
  font-weight: 700;
  color: var(--jungle-dark);
  background: linear-gradient(160deg, #fff 0%, #e8f5e9 100%);
  border: 3px solid #a29bfe;
  border-radius: 10px;
  cursor: pointer;
  box-shadow:
    0 3px 0 #6c5ce7,
    0 4px 8px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, opacity 0.3s ease, background 0.3s ease;
  touch-action: manipulation;
}

.cm-letter:hover:not(:disabled) {
  transform: scale(1.08);
  background: linear-gradient(160deg, #fff 0%, #dcedc8 100%);
}

.cm-letter:active:not(:disabled) {
  transform: scale(0.95);
}

.cm-letter:disabled {
  cursor: default;
  opacity: 0.45;
  background: linear-gradient(160deg, #c8e6c9 0%, #a5d6a7 100%);
  border-color: #81c784;
  box-shadow: 0 2px 0 #66bb6a;
}

.cm-letter.wrong-flash {
  animation: cm-wrong-flash 0.45s ease;
}

@keyframes cm-wrong-flash {
  0%, 100% { background: linear-gradient(160deg, #fff 0%, #e8f5e9 100%); }
  50% { background: #ffcdd2; border-color: #e57373; }
}

.cm-letter.correct-flash {
  animation: cm-correct-flash 0.5s ease forwards;
}

@keyframes cm-correct-flash {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); background: #c8e6c9; }
  100% { transform: scale(1); opacity: 0.45; }
}

/* Center play area with doors */
.cm-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: linear-gradient(180deg, #2d6a4f 0%, #1a4d2e 100%);
  border-radius: 14px;
  border: 4px solid #40916c;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.3);
  padding: 0.75rem;
}

.cm-doors {
  display: flex;
  gap: clamp(0.5rem, 2vw, 1rem);
  align-items: flex-end;
  justify-content: center;
  width: 100%;
}

.cm-door {
  position: relative;
  width: clamp(70px, 18vw, 110px);
  height: clamp(100px, 22vw, 150px);
  perspective: 400px;
}

.cm-door-frame {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #5d4037 0%, #3e2723 100%);
  border: 4px solid #2c1810;
  border-radius: 8px 8px 4px 4px;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.4);
}

.cm-door-panel {
  position: absolute;
  inset: 6px 6px 4px;
  background: linear-gradient(180deg, #8d6e63 0%, #6d4c41 100%);
  border: 2px solid #4e342e;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: left center;
  transition: transform 0.6s ease;
  z-index: 2;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
}

.cm-door.open .cm-door-panel {
  transform: rotateY(-105deg);
}

.cm-door-mark {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.cm-door-reveal {
  position: absolute;
  inset: 6px 6px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #fff9c4 0%, #fff59d 100%);
  border: 2px solid #f9a825;
  border-radius: 4px;
  z-index: 1;
}

.cm-door-letter {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  color: var(--jungle-dark);
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.5);
}

.cm-door-knob {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  background: radial-gradient(circle, #ffd54f, #f9a825);
  border-radius: 50%;
  border: 1px solid #e65100;
  z-index: 3;
}

.cm-center-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #b7e4c7;
  text-align: center;
}

/* Win overlay */
.cm-win {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: rgba(26, 77, 46, 0.55);
  backdrop-filter: blur(4px);
  border-radius: 20px;
}

.cm-win.hidden {
  display: none;
}

.cm-win h3 {
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 700;
  color: #fff;
  text-shadow:
    3px 3px 0 var(--jungle-dark),
    0 0 20px rgba(255, 209, 102, 0.7);
  animation: cm-win-bounce 0.8s ease-in-out infinite alternate;
}

@keyframes cm-win-bounce {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-14px) scale(1.04); }
}

.cm-win p {
  font-size: 1.2rem;
  font-weight: 600;
  color: #d8f3dc;
}

@media (max-width: 500px) {
  .cm-board {
    width: min(98vw, 720px);
  }

  .cm-letter {
    border-width: 2px;
    border-radius: 6px;
    box-shadow: 0 2px 0 #6c5ce7;
  }

  .cm-board-layout,
  .cm-rim-top,
  .cm-rim-bottom,
  .cm-board-middle,
  .cm-rim-side {
    gap: 2px;
  }
}
