/* =========================================
   MATCHMAKER STYLE
   ========================================= */

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  /* Background comes from theme.css */
}

/* --- UI BAR --- */
#ui-bar {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 20;
  pointer-events: none;
}
#ui-bar > * {
  pointer-events: auto;
}

/* Override back button margin for top bar so it fits nicely */
#btn-menu.back-btn {
  margin-top: 0;
  padding: 8px 16px;
  font-size: 0.9rem;
}

.score-display {
  font-family: "Roboto Mono", monospace;
  font-size: 1.2rem;
  color: var(--neon-gold);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

/* --- START SCREEN --- */
#start-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at center,
    var(--felt-green),
    var(--felt-dark)
  );
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

/* Logo Animation */
.logo-wrapper {
  display: flex;
  gap: 15px;
  margin-bottom: 10px;
}
.logo-tile {
  width: 80px;
  height: 110px;
  background: var(--tile-face);
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: "Noto Sans SC", sans-serif;
  font-weight: 700;
  font-size: 3.5rem;
  color: #b00;
  box-shadow: 1px 1px 0 #ccc, 2px 2px 0 #ccc, 4px 4px 0 var(--felt-dark),
    10px 10px 20px rgba(0, 0, 0, 0.5);
  transform: rotateX(10deg);
  animation: float 3s ease-in-out infinite;
}
.logo-tile:nth-child(2) {
  animation-delay: 1.5s;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) rotateX(10deg);
  }
  50% {
    transform: translateY(-10px) rotateX(10deg);
  }
}

.game-logo-text {
  font-size: 1.5rem;
  letter-spacing: 6px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 20px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* --- SETTINGS BOX STYLING --- */
/* The buttons and selects inside are styled by theme.css */
.settings-box {
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  padding: 25px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  width: 100%;
  box-sizing: border-box;
}

.setting-group {
  margin-bottom: 15px;
  text-align: left;
}
.setting-group label {
  display: block;
  color: var(--neon-blue);
  font-size: 0.85rem;
  margin-bottom: 8px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.match-selectors {
  display: flex;
  align-items: center;
  gap: 8px;
}
.match-selectors span {
  color: var(--neon-orange);
  font-size: 1.5rem;
  font-weight: bold;
}

/* --- TUTORIAL OVERLAY --- */
#rules-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}
.tutorial-content {
  background: #1a1a1a;
  border: 2px solid var(--neon-gold);
  border-radius: 20px;
  padding: 30px;
  width: 90%;
  max-width: 400px;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.tutorial-content h2 {
  color: var(--neon-gold);
  margin-bottom: 20px;
}
.tutorial-content p {
  color: #ccc;
  margin-bottom: 10px;
  line-height: 1.5;
}

.mockup-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin: 20px 0;
}
.mock-tile {
  width: 50px;
  height: 70px;
  background: var(--tile-face);
  color: #b00;
  font-family: "Noto Sans SC";
  font-weight: bold;
  font-size: 2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 6px;
  box-shadow: 2px 2px 0 #ccc;
  transform: rotateX(10deg);
}
.mock-tile.en {
  font-size: 0.8rem;
  color: var(--felt-green);
  font-family: "Rubik";
}
.arrow {
  color: var(--neon-blue);
  font-size: 1.5rem;
}

.close-x {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  color: #666;
  font-size: 2rem;
  cursor: pointer;
}
.close-x:hover {
  color: white;
}

/* --- GAME GRID & 3D TILES --- */
#game-grid {
  display: grid;
  gap: 15px;
  width: 95%;
  max-width: 650px;
  margin-top: 50px;
  perspective: 1000px;
  justify-content: center;
}

.tile-container {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  cursor: pointer;
  user-select: none;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
}
.tile-shadow {
  position: absolute;
  bottom: -10px;
  left: 5%;
  width: 90%;
  height: 20px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  filter: blur(8px);
  transform: translateZ(-40px);
  transition: all 0.6s;
  z-index: -1;
}
.tile-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --thickness: 12px;
  transform: rotateX(10deg);
}

/* States */
.tile-container.flipped .tile-inner {
  transform: rotateX(10deg) rotateY(180deg);
}
.tile-container.flipped .tile-shadow {
  transform: translateZ(-40px) scale(0.8);
  opacity: 0.6;
}
.tile-container.matched {
  pointer-events: none;
}
.tile-container.matched .tile-inner {
  opacity: 0;
  transform: rotateX(10deg) rotateY(180deg) scale(0.5);
}
.tile-container.matched .tile-shadow {
  opacity: 0;
  transform: scale(0);
}

/* Faces */
.tile-face {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  backface-visibility: hidden;
}

/* Front */
.tile-front {
  background: var(--tile-back);
  transform: translateZ(calc(var(--thickness) / 2));
  border: 1px solid rgba(255, 255, 255, 0.15);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.05) 0,
    rgba(255, 255, 255, 0.05) 2px,
    transparent 2px,
    transparent 6px
  );
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.tile-front::after {
  content: "中";
  font-family: "Noto Sans SC", serif;
  font-size: 3rem;
  font-weight: 900;
  color: rgba(0, 0, 0, 0.25);
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.1);
}
.tile-front::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--thickness);
  background: #bbb;
  transform: rotateX(-90deg) translateZ(calc(var(--thickness) / 2));
  transform-origin: bottom center;
}

/* Back */
.tile-back {
  background: var(--tile-face);
  transform: rotateY(180deg) translateZ(calc(var(--thickness) / 2));
  border: 1px solid #ddd;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.05);
}
.tile-inner::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: var(--thickness);
  height: 100%;
  background: #ccc;
  transform: rotateY(90deg) translateZ(calc(var(--thickness) / -2));
  transform-origin: right center;
}
.tile-inner::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: var(--thickness);
  height: 100%;
  background: #e0e0e0;
  transform: rotateY(-90deg) translateZ(calc(var(--thickness) / -2));
  transform-origin: left center;
}

/* Text */
.tile-back span {
  font-family: "Noto Sans SC", sans-serif;
  font-weight: 700;
  color: #b00;
  transform: translateZ(1px);
  text-align: center;
  width: 95%;
}
.tile-back.type-char span {
  font-size: 2.5rem;
}
.tile-back.type-text span {
  font-family: "Rubik", sans-serif;
  color: var(--felt-green);
  font-size: 1.5rem;
  line-height: 1.1;
  word-break: break-word;
}
.tile-back.type-text span.text-medium {
  font-size: 1.2rem;
}
.tile-back.type-text span.text-long {
  font-size: 1rem;
}

/* --- OVERLAY --- */
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
  backdrop-filter: blur(5px);
}
.win-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.btn-restart {
  padding: 15px 30px;
  font-size: 1.2rem;
  background: var(--neon-pink);
  border: none;
  color: white;
  border-radius: 50px;
  font-weight: bold;
  cursor: pointer;
  text-transform: uppercase;
}
.btn-secondary {
  padding: 15px 30px;
  font-size: 1.2rem;
  background: transparent;
  border: 2px solid white;
  color: white;
  border-radius: 50px;
  font-weight: bold;
  cursor: pointer;
  text-transform: uppercase;
}

/* --- GRIDS --- */
.grid-4-cols {
  grid-template-columns: repeat(4, 1fr);
}
.grid-5-cols {
  grid-template-columns: repeat(5, 1fr);
}
.grid-6-cols {
  grid-template-columns: repeat(6, 1fr);
}

@media (max-width: 600px) {
  .tile-back.type-char span {
    font-size: 2rem;
  }
  .grid-5-cols,
  .grid-6-cols {
    grid-template-columns: repeat(4, 1fr);
  }
}
