:root {
  color-scheme: light;
  font-size: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Poppins", "Segoe UI", Arial, sans-serif;
  background: linear-gradient(160deg, #fdf0d5, #f6c177 35%, #f28482 70%);
  color: #1f2933;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 2rem;
}

.layout {
  width: min(1100px, 96%);
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

header {
  text-align: center;
  padding: 2.5rem 1.5rem 1.5rem;
}

header h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(2rem, 4vw + 1rem, 3.2rem);
  letter-spacing: 0.02em;
}

header p {
  margin: 0;
  font-size: 1.1rem;
  opacity: 0.85;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: 240px;
  flex-shrink: 0;
}

.menu-button {
  border: none;
  border-radius: 18px;
  background: #264653;
  color: #fff;
  padding: 1rem 1.2rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  box-shadow: 0 12px 25px rgba(38, 70, 83, 0.2);
  text-align: left;
}

.menu-button:hover,
.menu-button:focus {
  outline: none;
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 15px 28px rgba(38, 70, 83, 0.25);
  background: #2a9d8f;
}

.menu-button.active {
  background: #e76f51;
  box-shadow: 0 12px 28px rgba(231, 111, 81, 0.35);
}

main {
  flex: 1;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 28px;
  box-shadow: 0 30px 60px rgba(31, 41, 51, 0.18);
  padding: 2.5rem 2.2rem;
  backdrop-filter: blur(12px);
  min-height: 520px;
}

main h2 {
  margin-top: 0;
  font-size: clamp(1.8rem, 3vw + 1rem, 2.6rem);
}

main p {
  font-size: 1.1rem;
  line-height: 1.6;
}

.game-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.game-section header {
  padding: 0;
  text-align: left;
}

.game-section header h2 {
  margin: 0 0 0.5rem;
}

.instructions {
  background: rgba(42, 157, 143, 0.12);
  border-left: 4px solid #2a9d8f;
  border-radius: 16px;
  padding: 1rem 1.25rem;
  font-size: 1.05rem;
}

.game-options {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.option-card {
  border: none;
  border-radius: 22px;
  background: #f1faee;
  padding: 1.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--card-text, #1d3557);
  cursor: pointer;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: inset 0 -6px 0 rgba(29, 53, 87, 0.08), 0 20px 40px rgba(29, 53, 87, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.option-card:hover,
.option-card:focus {
  outline: none;
  transform: translateY(-4px) scale(1.03);
  box-shadow: inset 0 -6px 0 rgba(29, 53, 87, 0.12), 0 24px 50px rgba(29, 53, 87, 0.2);
}

.option-card.correct {
  background: #2a9d8f;
  color: #fff;
}

.option-card.wrong {
  background: #e63946;
  color: #fff;
}

.feedback {
  font-size: 1.2rem;
  font-weight: 600;
  min-height: 1.5rem;
}

.feedback.success {
  color: #2a9d8f;
}

.feedback.error {
  color: #e63946;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.action-row button {
  border: none;
  border-radius: 18px;
  padding: 0.9rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: #1d3557;
  color: #fff;
  transition: background 0.2s ease, transform 0.2s ease;
}

.action-row button:hover,
.action-row button:focus {
  outline: none;
  background: #457b9d;
  transform: translateY(-2px);
}

.color-card {
  position: relative;
  border-radius: 22px;
  min-height: 160px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.color-card span {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  font-size: 1rem;
  font-weight: 600;
}

.letter-card {
  font-size: 3rem;
  letter-spacing: 0.05em;
}

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

.match-column {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.match-card {
  border-radius: 20px;
  background: #f8edeb;
  padding: 1.25rem 1.5rem;
  font-size: 1.15rem;
  cursor: pointer;
  box-shadow: inset 0 -6px 0 rgba(231, 111, 81, 0.12), 0 18px 36px rgba(231, 111, 81, 0.18);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.match-card:hover,
.match-card:focus {
  outline: none;
  transform: translateY(-3px) scale(1.02);
  box-shadow: inset 0 -6px 0 rgba(231, 111, 81, 0.18), 0 24px 46px rgba(231, 111, 81, 0.24);
}

.match-card.selected {
  background: #2a9d8f;
  color: #fff;
}

.match-card.solved {
  background: #264653;
  color: #fff;
  cursor: default;
  box-shadow: none;
}

footer {
  width: min(1100px, 96%);
  text-align: center;
  font-size: 0.95rem;
  padding: 1.5rem 1rem 0;
  color: rgba(31, 41, 51, 0.7);
}

.memory-levels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.memory-level-button {
  border: none;
  border-radius: 16px;
  padding: 0.65rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  background: #264653;
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 20px rgba(38, 70, 83, 0.18);
}

.memory-level-button:hover,
.memory-level-button:focus {
  outline: none;
  transform: translateY(-2px);
  background: #2a9d8f;
  box-shadow: 0 12px 24px rgba(42, 157, 143, 0.2);
}

.memory-level-button.active {
  background: #e76f51;
  box-shadow: 0 12px 28px rgba(231, 111, 81, 0.28);
}

.trace-layout {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: center;
}

.trace-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
}

.trace-number-display {
  font-size: clamp(6rem, 12vw, 10rem);
  font-weight: 700;
  color: #1d3557;
  text-shadow: 0 8px 22px rgba(29, 53, 87, 0.28);
}

.trace-word {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: capitalize;
  color: rgba(29, 53, 87, 0.85);
}

.trace-canvas-wrapper {
  display: flex;
  justify-content: center;
}

.trace-canvas {
  border-radius: 22px;
  background: radial-gradient(circle at top, #ffffff 0%, #f1faee 100%);
  box-shadow: 0 20px 40px rgba(29, 53, 87, 0.18);
  border: 2px dashed rgba(29, 53, 87, 0.18);
  touch-action: none;
  max-width: 100%;
}

.trace-choice-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 0.75rem;
}

.trace-choice-button {
  border: none;
  border-radius: 16px;
  padding: 0.75rem 0;
  font-size: 1.5rem;
  font-weight: 600;
  background: #f1faee;
  color: #1d3557;
  cursor: pointer;
  box-shadow: inset 0 -4px 0 rgba(29, 53, 87, 0.09), 0 12px 24px rgba(29, 53, 87, 0.16);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.trace-choice-button:hover,
.trace-choice-button:focus {
  outline: none;
  transform: translateY(-3px) scale(1.03);
  box-shadow: inset 0 -4px 0 rgba(29, 53, 87, 0.12), 0 18px 30px rgba(29, 53, 87, 0.22);
}

.emoji-options {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.emoji-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 1rem;
}

.emoji-symbol {
  font-size: clamp(3rem, 4vw, 4.5rem);
  line-height: 1;
}

.emoji-word {
  font-size: 1.1rem;
  font-weight: 600;
  color: rgba(29, 53, 87, 0.85);
}

.trace-choice-button.active {
  background: #2a9d8f;
  color: #fff;
  box-shadow: inset 0 -4px 0 rgba(42, 157, 143, 0.25), 0 20px 36px rgba(42, 157, 143, 0.28);
}

.memory-stats {
  display: flex;
  gap: 1.5rem;
  font-weight: 600;
  font-size: 1.05rem;
}

.memory-section {
  --memory-card-size: clamp(58px, 17vw, 86px);
  --memory-card-gap: clamp(0.5rem, 2.4vw, 0.9rem);
  --memory-card-radius: clamp(14px, 3.4vw, 20px);
}

.memory-board {
  --memory-columns: 4;
  margin-top: 0.5rem;
  display: grid;
  gap: var(--memory-card-gap);
  grid-template-columns: repeat(var(--memory-columns), var(--memory-card-size));
  justify-content: center;
  margin-left: auto;
  margin-right: auto;
  width: fit-content;
}

.memory-card {
  position: relative;
  border: none;
  border-radius: var(--memory-card-radius);
  background: #1d3557;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--memory-card-size);
  height: var(--memory-card-size);
  font-size: calc(var(--memory-card-size) * 0.42);
  cursor: pointer;
  box-shadow: inset 0 -4px 0 rgba(29, 53, 87, 0.18), 0 14px 24px rgba(29, 53, 87, 0.22);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.memory-card:hover,
.memory-card:focus {
  outline: none;
  transform: translateY(-3px) scale(1.03);
  box-shadow: inset 0 -5px 0 rgba(29, 53, 87, 0.22), 0 20px 36px rgba(29, 53, 87, 0.26);
}

.memory-card-cover,
.memory-card-symbol {
  position: absolute;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.memory-card-cover {
  opacity: 1;
  transform: scale(1);
  font-size: calc(var(--memory-card-size) * 0.5);
}

.memory-card-symbol {
  opacity: 0;
  transform: scale(0.75);
}

.memory-card.flipped .memory-card-cover {
  opacity: 0;
  transform: scale(0.65);
}

.memory-card.flipped .memory-card-symbol {
  opacity: 1;
  transform: scale(1);
}

.memory-card.matched {
  background: #2a9d8f;
  box-shadow: inset 0 -5px 0 rgba(42, 157, 143, 0.18), 0 18px 32px rgba(42, 157, 143, 0.24);
}

.placeholder-card {
  border-radius: var(--memory-card-radius);
  background: rgba(255, 255, 255, 0.4);
  border: 2px dashed rgba(29, 53, 87, 0.22);
  width: var(--memory-card-size);
  height: var(--memory-card-size);
  pointer-events: none;
}

@media (max-width: 640px) {
  :root {
    font-size: 16px;
  }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    width: 100%;
  }

  .menu-button {
    flex: 1 1 130px;
    text-align: center;
  }

  main {
    padding: 2rem 1.5rem;
  }

  .option-card {
    min-height: 100px;
  }

  .memory-section {
    --memory-card-size: clamp(52px, 22vw, 74px);
    --memory-card-gap: clamp(0.42rem, 3.4vw, 0.7rem);
  }
}

.match-card.wrong {
  background: #e63946;
  color: #fff;
}
