.game-root,
.game-root * {
  box-sizing: border-box;
}

.game-root {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #efe9df;
  color: #263b4a;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.memory-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.88), transparent 28%),
    radial-gradient(circle at 84% 74%, rgba(217, 234, 221, 0.72), transparent 32%),
    linear-gradient(145deg, #f7f0e5, #e8f0e9);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.memory-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.memory-canvas canvas {
  display: block;
}

.memory-heading {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  z-index: 4;
  width: min(720px, calc(100% - 240px));
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.memory-heading h1 {
  margin: 0 0 8px;
  color: #263b4a;
  font-size: clamp(19px, 3vw, 36px);
  font-weight: 900;
  line-height: 1.05;
  text-wrap: balance;
}

.memory-levels {
  display: inline-flex;
  gap: 4px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 12px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 10px 28px rgba(38, 59, 74, 0.14);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.memory-levels button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  background: transparent;
  color: #526776;
  font: 800 clamp(12px, 1.4vw, 15px) / 1 system-ui, sans-serif;
  cursor: pointer;
}

.memory-levels button.is-active {
  background: #477e72;
  color: #ffffff;
  box-shadow: 0 5px 12px rgba(46, 98, 87, 0.22);
}

.memory-levels button:focus-visible,
.memory-primary:focus-visible,
.memory-secondary:focus-visible {
  outline: 4px solid #f3c95d;
  outline-offset: 3px;
}

.memory-progress {
  position: absolute;
  top: 50px;
  left: calc(100% + 18px);
  min-width: 66px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.78);
  color: #263b4a;
  font-size: clamp(14px, 1.8vw, 20px);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(38, 59, 74, 0.13);
  backdrop-filter: blur(8px);
}

.memory-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(38, 53, 62, 0.22);
  backdrop-filter: blur(5px);
}

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

.memory-dialog {
  width: min(100%, 510px);
  border: 3px solid #ffffff;
  border-radius: 20px;
  padding: clamp(25px, 4vw, 42px);
  background: rgba(255, 255, 255, 0.96);
  text-align: center;
  box-shadow: 0 24px 64px rgba(31, 48, 61, 0.23);
}

.memory-dialog h2 {
  margin: 0;
  color: #263b4a;
  font-size: clamp(27px, 5vw, 46px);
  font-weight: 950;
  line-height: 1.04;
  text-wrap: balance;
}

.memory-dialog p {
  margin: 14px auto 0;
  max-width: 390px;
  color: #566b79;
  font-size: clamp(15px, 2vw, 19px);
  font-weight: 700;
  line-height: 1.4;
}

.memory-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.memory-primary,
.memory-secondary {
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  padding: 0 22px;
  background: #477e72;
  color: #ffffff;
  text-decoration: none;
  font: 900 17px/1 system-ui, sans-serif;
  box-shadow: 0 12px 24px rgba(46, 98, 87, 0.24);
  cursor: pointer;
}

.memory-dialog > .memory-primary {
  margin-top: 24px;
}

.memory-primary:disabled {
  opacity: 0.62;
  cursor: wait;
}

.memory-secondary {
  background: #5e7391;
  box-shadow: 0 12px 24px rgba(62, 82, 110, 0.22);
}

.memory-error {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 28px;
  background: #efe9df;
  color: #93463f;
  font-size: clamp(17px, 2.6vw, 24px);
  font-weight: 850;
  line-height: 1.4;
  text-align: center;
}

.memory-error[hidden] {
  display: none;
}

@media (max-width: 700px) {
  .memory-heading {
    top: max(62px, calc(env(safe-area-inset-top) + 58px));
    width: calc(100% - 24px);
  }

  .memory-heading h1 {
    margin-bottom: 6px;
    font-size: clamp(15px, 4.2vw, 21px);
  }

  .memory-levels button {
    min-height: 32px;
    padding: 0 9px;
    font-size: 12px;
  }

  .memory-progress {
    top: 72px;
    right: 4px;
    left: auto;
    min-width: 52px;
    padding: 6px 9px;
    font-size: 14px;
  }

  .memory-dialog {
    border-radius: 16px;
    padding: 26px 18px;
  }
}

@media (max-height: 570px) and (orientation: landscape) {
  .memory-heading {
    top: max(8px, env(safe-area-inset-top));
  }

  .memory-heading h1 {
    font-size: clamp(17px, 4vh, 24px);
  }

  .memory-levels button {
    min-height: 30px;
  }
}

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