/* =========================================================
   SINGULAR & PLURAL — MATCH RUSH
   Orange Arcade Theme (Final + Optimized Animations)
========================================================= */

:root {
  --mr-bg: #0d0905;
  --mr-surface: #1a120b;
  --mr-card-bg: #261b10;
  --mr-card-border: #422b17;
  --mr-text: #fff3e6;
  --mr-text-dim: #b39b82;

  --mr-orange: #ff7d00;
  --mr-orange-glow: #ff9d00;
  --mr-orange-soft: #ffb866;

  --mr-correct: #10b981;
  --mr-wrong: #ef4444;
  --mr-modal-bg: rgba(13, 9, 5, 0.9);
  --mr-card-shadow: rgba(0, 0, 0, 0.4);
}

#matchRushGame.light {
  --mr-bg: #fff8f0;
  --mr-surface: #ffeedb;
  --mr-card-bg: #ffffff;
  --mr-card-border: #ffd0a8;
  --mr-text: #2d1800;
  --mr-text-dim: #8c6239;

  --mr-orange: #ea580c;
  --mr-orange-glow: #f97316;
  --mr-orange-soft: #c2410c;

  --mr-modal-bg: rgba(255, 248, 240, 0.94);
  --mr-card-shadow: rgba(234, 88, 12, 0.1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--mr-bg);
  color: var(--mr-text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: safe center;
}

/* ---------- CONTAINER ---------- */
.game-container {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 14px;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  overflow: hidden;
}

@media (min-height: 700px) {
  .game-container {
    min-height: 680px;
    height: 92vh;
    height: 92dvh;
    border-radius: 24px;
    background: var(--mr-surface);
    border: 2px solid var(--mr-card-border);
    box-shadow: 0 12px 32px var(--mr-card-shadow);
  }
}

/* ---------- HEADER ---------- */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.game-header h1 {
  font-size: 1.05rem;
  font-weight: 900;
  margin: 0;
  background: linear-gradient(135deg, #ffffff, var(--mr-orange-soft));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  text-align: center;
  flex: 1;
}

#matchRushGame.light .game-header h1 {
  background: linear-gradient(135deg, #2d1800, var(--mr-orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.controls {
  display: flex;
  gap: 8px;
}

.controls button,
.back-btn {
  background: var(--mr-card-bg);
  border: 1px solid var(--mr-card-border);
  color: var(--mr-text);
  font-size: 1.1rem;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}

.back-btn {
  border-radius: 50%;
}

.controls button:active,
.back-btn:active {
  transform: scale(0.92);
}

/* ---------- SCREENS ---------- */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

/* ---------- HOME SCREEN (Arcade style) ---------- */
#homeScreen {
  gap: 28px;
  text-align: center;
  justify-content: center;
  align-items: center;
  position: relative;
}

.high-score-banner {
  background: linear-gradient(135deg, #ff9d00, #ff7d00);
  color: #1a0f00;
  padding: 12px 28px;
  border-radius: 50px;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  box-shadow: 
    0 0 0 3px rgba(255, 157, 0, 0.3),
    0 6px 20px rgba(255, 125, 0, 0.4);
  text-transform: uppercase;
  animation: pulseGlow 2.5s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { 
    box-shadow: 0 0 0 3px rgba(255, 157, 0, 0.3), 0 6px 20px rgba(255, 125, 0, 0.4); 
  }
  50% { 
    box-shadow: 0 0 0 6px rgba(255, 157, 0, 0.15), 0 8px 28px rgba(255, 125, 0, 0.55); 
  }
}

#matchRushGame.light .high-score-banner {
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  box-shadow: 
    0 0 0 3px rgba(234, 88, 12, 0.25),
    0 6px 20px rgba(234, 88, 12, 0.3);
}

.mode-select-wrapper {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}

.mode-select-wrapper label {
  font-size: 0.85rem;
  color: var(--mr-text-dim);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.mode-select-wrapper select {
  padding: 14px 18px;
  border-radius: 16px;
  background: var(--mr-card-bg);
  color: var(--mr-text);
  border: 2px solid var(--mr-card-border);
  font-size: 1.05rem;
  font-weight: 800;
  outline: none;
  cursor: pointer;
  text-align: center;
  appearance: none;
  box-shadow: 0 4px 12px var(--mr-card-shadow);
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.mode-select-wrapper select:focus {
  border-color: var(--mr-orange);
  transform: scale(1.02);
}

/* ---------- BUTTONS ---------- */
.btn {
  width: 100%;
  max-width: 300px;
  padding: 14px 24px;
  border-radius: 14px;
  border: none;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn.primary {
  width: 100%;
  max-width: 300px;
  padding: 18px 32px;
  border-radius: 18px;
  border: none;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  background: linear-gradient(145deg, #ffb347, #ff7d00);
  color: #1a0f00;
  box-shadow: 
    0 6px 0 #c45f00,
    0 10px 25px rgba(255, 125, 0, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 8px 0 #c45f00,
    0 14px 30px rgba(255, 125, 0, 0.5);
}

.btn.primary:active {
  transform: translateY(3px);
  box-shadow: 
    0 2px 0 #c45f00,
    0 4px 12px rgba(255, 125, 0, 0.3);
}

#matchRushGame.light .btn.primary {
  background: linear-gradient(145deg, #fb923c, #ea580c);
  color: #fff;
  box-shadow: 
    0 6px 0 #c2410c,
    0 10px 25px rgba(234, 88, 12, 0.35);
}

#matchRushGame.light .btn.primary:hover {
  box-shadow: 
    0 8px 0 #c2410c,
    0 14px 30px rgba(234, 88, 12, 0.45);
}

#matchRushGame.light .btn.primary:active {
  box-shadow: 
    0 2px 0 #c2410c,
    0 4px 12px rgba(234, 88, 12, 0.25);
}

/* ---------- STATS BAR ---------- */
.stats-bar {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background: var(--mr-card-bg);
  border: 1px solid var(--mr-card-border);
  padding: 11px 14px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.stats-bar div {
  color: var(--mr-text-dim);
}

.stats-bar div span {
  color: var(--mr-orange);
  font-weight: 900;
  font-size: 1.05rem;
}

/* ---------- HINT + SHUFFLE ---------- */
.game-action-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  width: 100%;
  flex-shrink: 0;
}

.btn.secondary {
  flex: 1;
  background: var(--mr-card-bg);
  color: var(--mr-text);
  border: 1.5px solid var(--mr-card-border);
  padding: 12px 16px;
  font-size: 0.92rem;
  font-weight: 800;
  border-radius: 50px;
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn.secondary:active {
  transform: scale(0.96);
  border-color: var(--mr-orange);
  background: rgba(255, 125, 0, 0.1);
}

#matchRushGame.light .btn.secondary:active {
  background: rgba(234, 88, 12, 0.08);
}

/* ---------- BOARD — 5 soft-square cards left / 5 right, fill remaining height ---------- */
.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr;
  gap: 8px 12px;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  align-items: stretch;
}

.column {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.column::-webkit-scrollbar {
  display: none;
}

/* Soft-square cards: share column height equally (5 fit, fill the screen) */
.word {
  background: var(--mr-card-bg);
  border: 2px solid var(--mr-card-border);
  border-radius: 14px;
  padding: 8px 10px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  font-weight: 800;
  font-size: clamp(0.8rem, 2.8vw, 1.05rem);
  line-height: 1.2;
  color: var(--mr-text);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12), 0 8px 16px var(--mr-card-shadow);

  /* No aspect-ratio — flex distributes height so 5 cards fill the board */
  width: 100%;
  min-height: 0;
  height: 0; /* flex equal-height distribution trick */
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-word;
  overflow: hidden;

  will-change: transform, opacity;
  backface-visibility: hidden;

  transition: transform 0.15s ease, border-color 0.18s ease, background-color 0.2s ease,
              opacity 0.35s ease, filter 0.35s ease, box-shadow 0.18s ease;
}

.word:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12), 0 12px 20px var(--mr-card-shadow);
}

.word:active {
  transform: scale(0.95);
}

/* ---------- OPTIMIZED FEEDBACK ANIMATIONS ---------- */

.word.correct {
  border-color: var(--mr-correct);
  background-color: rgba(16, 185, 129, 0.28);
  color: #fff;
  animation: correctPop 0.4s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
}

@keyframes correctPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1.05); }
}

.word.wrong {
  border-color: var(--mr-wrong);
  background-color: rgba(239, 68, 68, 0.25);
  animation: wrongShake 0.38s ease-in-out;
}

@keyframes wrongShake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20%      { transform: translate3d(-8px, 0, 0); }
  40%      { transform: translate3d(8px, 0, 0); }
  60%      { transform: translate3d(-5px, 0, 0); }
  80%      { transform: translate3d(5px, 0, 0); }
}

.word.vanish {
  animation: cardVanish 0.25s ease-in forwards;
  pointer-events: none;
}

@keyframes cardVanish {
  0%   { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(0.65); }
}

.word.selected {
  border-color: var(--mr-orange-glow);
  background-color: rgba(255, 125, 0, 0.18);
  animation: selectedPulse 1s ease-in-out infinite alternate;
}

@keyframes selectedPulse {
  from { transform: scale(1.03); }
  to   { transform: scale(1.055); }
}

/* Matched cards stay on board — fade to muted, not bold, not clickable */
.word.matched {
  font-weight: 400 !important;
  opacity: 0.42;
  cursor: default;
  pointer-events: none;
  border-color: rgba(16, 185, 129, 0.35);
  background-color: rgba(16, 185, 129, 0.12);
  color: var(--mr-text);
  box-shadow: none;
  transform: scale(0.98);
  animation: matchFade 0.55s ease-out forwards;
}

.word.matched.correct {
  /* let matchFade take over after the brief correct pop */
  animation: correctPop 0.28s cubic-bezier(0.34, 1.4, 0.64, 1) forwards,
             matchFade 0.55s ease-out 0.22s forwards;
}

@keyframes matchFade {
  0% {
    opacity: 1;
    font-weight: 700;
    transform: scale(1.05);
    filter: brightness(1.15);
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.45);
  }
  45% {
    opacity: 0.75;
    transform: scale(1);
    filter: brightness(1.05);
  }
  100% {
    opacity: 0.42;
    font-weight: 400;
    transform: scale(0.98);
    filter: brightness(0.92);
    box-shadow: none;
  }
}

#matchRushGame.light .word.matched {
  opacity: 0.48;
  background-color: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #4b5563;
  font-weight: 400 !important;
}

#matchRushGame.light .word.matched.correct {
  animation: correctPop 0.28s cubic-bezier(0.34, 1.4, 0.64, 1) forwards,
             matchFade 0.55s ease-out 0.22s forwards;
}


.column-label {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
  text-align: center;
  margin-bottom: -4px;
}

.mode-help {
  max-width: 360px;
  margin: 0 auto 18px;
  font-size: 0.9rem;
  line-height: 1.5;
  opacity: 0.85;
  text-align: center;
}

.float-score {
  position: absolute;
  z-index: 50;
  font-weight: 800;
  font-size: 1.1rem;
  color: #34d399;
  pointer-events: none;
  animation: floatUp 0.85s ease-out forwards;
  transform: translateX(-50%);
}

@keyframes floatUp {
  0% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-36px); }
}


/* Light mode cards */
#matchRushGame.light .word {
  background: #ffffff;
  border-color: #ffd0a8;
  color: #2d1800;
}

#matchRushGame.light .word.selected {
  background-color: rgba(234, 88, 12, 0.12);
  border-color: #f97316;
  color: #2d1800;
}

#matchRushGame.light .word.correct {
  background-color: rgba(16, 185, 129, 0.2);
  color: #065f46;
}

#matchRushGame.light .word.wrong {
  background-color: rgba(239, 68, 68, 0.15);
  color: #9f1239;
}

/* ---------- FLOATING SCORE ---------- */
.floating-feedback {
  position: fixed;
  color: var(--mr-orange);
  font-weight: 900;
  font-size: 1.45rem;
  pointer-events: none;
  z-index: 1000;
  text-shadow: 0 2px 6px rgba(0,0,0,0.3);
  will-change: transform, opacity;
  animation: floatScore 0.75s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}

@keyframes floatScore {
  0% {
    opacity: 0;
    transform: translate3d(-50%, 6px, 0) scale(0.7);
  }
  25% {
    opacity: 1;
    transform: translate3d(-50%, -12px, 0) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translate3d(-50%, -48px, 0) scale(1);
  }
}

/* ---------- MODAL ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: var(--mr-modal-bg);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.modal-content {
  background: var(--mr-surface);
  border: 2px solid var(--mr-card-border);
  padding: 24px;
  border-radius: 20px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  margin-top: 0;
  font-size: 1.4rem;
  color: var(--mr-orange-soft);
}

.new-high-tag {
  color: #000;
  background: var(--mr-orange-glow);
  font-weight: 900;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  display: inline-block;
  margin-bottom: 12px;
}

.mistakes-container {
  margin: 16px 0;
  max-height: 130px;
  overflow-y: auto;
  text-align: left;
  background: var(--mr-card-bg);
  border: 1px solid var(--mr-card-border);
  padding: 10px;
  border-radius: 12px;
}

.mistakes-container h3 {
  margin: 0 0 8px 0;
  font-size: 0.85rem;
  color: var(--mr-text-dim);
  text-transform: uppercase;
}

.mistake-item {
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.no-mistakes {
  color: var(--mr-correct);
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
}

/* ---------- MOBILE ---------- */
@media (max-width: 400px) {
  .game-container {
    padding: 12px;
  }
  .game-header h1 {
    font-size: 0.95rem;
  }
  .stats-bar {
    font-size: 0.88rem;
  }
}


/* Phones: soft-square cards fill remaining screen height */
@media (max-width: 700px) {
  .board {
    gap: 6px 8px !important;
    overflow: hidden !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }
  .column {
    gap: 6px !important;
    height: 100% !important;
    overflow: hidden !important;
  }
  .word {
    /* no aspect-ratio — fill height equally */
    min-height: 0 !important;
    height: 0 !important;
    max-height: none !important;
    flex: 1 1 0 !important;
    padding: 6px 8px !important;
    font-size: clamp(0.78rem, 3.2vw, 0.98rem) !important;
    border-radius: 12px !important;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12), 0 5px 12px var(--mr-card-shadow) !important;
  }
}

@media (max-width: 380px) {
  .word {
    font-size: clamp(0.72rem, 3vw, 0.9rem) !important;
    padding: 5px 6px !important;
    border-radius: 10px !important;
  }
  .column { gap: 5px !important; }
  .board { gap: 5px 6px !important; }
}
